sapling/cfastmanifest/bsearch_test.c
Tony Tung fc8c0d61a1 [fastmanifest] rename fastmanifest c library directory to cfastmanifest
Summary: This allows us to use fastmanifest as a directory to drop in the python module.

Test Plan: compiles, passes existing tests.

Reviewers: lcharignon

Reviewed By: lcharignon

Subscribers: mitrandir, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3351021

Signature: t1:3351021:1464284417:6cbcde514ab1fd7b5caa6c83cb5577f3502dbc58
2016-05-26 11:33:07 -07:00

66 lines
1.7 KiB
C

// Copyright 2016-present Facebook. All Rights Reserved.
//
// bsearch_test.c: tests for binary search with a context-aware callback.
//
// no-check-code
#include "bsearch.h"
#include "tests.h"
#define CMP(left, right) ((int) (*((intptr_t*) left) - *((intptr_t*) right)))
COMPARATOR_BUILDER(intptr_cmp, CMP)
#define BSEARCH_TEST(needle, expected, ...) \
{ \
size_t result; \
intptr_t _needle = needle; \
intptr_t* array = (intptr_t[]) {__VA_ARGS__}; \
\
result = bsearch_between( \
&_needle, \
array, \
sizeof((intptr_t[]) {__VA_ARGS__}) / sizeof(intptr_t), \
sizeof(intptr_t), \
&intptr_cmp, \
NULL); \
ASSERT(result == expected); \
}
void test_bsearch() {
BSEARCH_TEST(
20,
1,
18, 21);
BSEARCH_TEST(
20,
2,
15, 18, 21,
);
BSEARCH_TEST(
20,
2,
15, 18, 20, 21,
);
BSEARCH_TEST(
10,
0,
15, 18, 20, 21,
);
BSEARCH_TEST(
30,
4,
15, 18, 20, 21,
);
}
int main(int argc, char *argv[]) {
test_bsearch();
return 0;
}