Fix of accidentally printing "prev" when using $checks. Updated binary search.

This commit is contained in:
Christoffer Lerno
2023-07-04 02:29:02 +02:00
parent 55d17ec990
commit c249c3f3b6
5 changed files with 70 additions and 53 deletions

View File

@@ -27,11 +27,23 @@ fn void search()
usz cmp_idx = binarysearch::cmp_search(tc.data, tc.x, &cmp_int);
assert(cmp_idx == tc.index, "%s: got %d; want %d", tc.data, cmp_idx, tc.index);
usz cmp_idx2 = binarysearch::cmp_search(tc.data, tc.x, &cmp_int2);
assert(cmp_idx2 == tc.index, "%s: got %d; want %d", tc.data, cmp_idx2, tc.index);
usz cmp_idx3 = binarysearch::cmp_search(tc.data, tc.x, fn int(int a, int b) => a - b);
assert(cmp_idx3 == tc.index, "%s: got %d; want %d", tc.data, cmp_idx2, tc.index);
}
}
module binarysearch_test;
fn int cmp_int(void* x, void* y) {
return *(int*)x - *(int*)y;
}
}
fn int cmp_int2(int x, int y) {
return x - y;
}