Sun, 20 Nov 2022 16:28:03 +0100
#219 array list: implement compare member func
src/array_list.c | file | annotate | diff | comparison | revisions | |
test/test_list.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/array_list.c Sun Nov 20 16:22:50 2022 +0100 1.2 +++ b/src/array_list.c Sun Nov 20 16:28:03 2022 +0100 1.3 @@ -272,7 +272,21 @@ 1.4 struct cx_list_s const *list, 1.5 struct cx_list_s const *other 1.6 ) { 1.7 - 1.8 + if (list->size == other->size) { 1.9 + char const *left = ((cx_array_list const *) list)->data; 1.10 + char const *right = ((cx_array_list const *) other)->data; 1.11 + for (size_t i = 0; i < list->size; i++) { 1.12 + int d = list->cmpfunc(left, right); 1.13 + if (d != 0) { 1.14 + return d; 1.15 + } 1.16 + left += list->itemsize; 1.17 + right += other->itemsize; 1.18 + } 1.19 + return 0; 1.20 + } else { 1.21 + return list->size < other->size ? -1 : 1; 1.22 + } 1.23 } 1.24 1.25 static void cx_arl_reverse(struct cx_list_s *list) {
2.1 --- a/test/test_list.cpp Sun Nov 20 16:22:50 2022 +0100 2.2 +++ b/test/test_list.cpp Sun Nov 20 16:28:03 2022 +0100 2.3 @@ -974,7 +974,6 @@ 2.4 } 2.5 2.6 TEST_F(ArrayList, cxListCompare) { 2.7 - ASSERT_EQ(1,0); // TODO: remove when implemented 2.8 auto left = arrayListFromTestData(); 2.9 auto right = arrayListFromTestData(); 2.10 verifyCompare(left, right);