summaryrefslogtreecommitdiff
path: root/tests/core
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-03-22 00:18:44 -0400
committerEdward Thomson <ethomson@github.com>2016-03-22 06:21:13 -0700
commite2e4bae9a091152166773fb5681f2b3acb18b43b (patch)
tree08675b516edbab7506697e96e599cb79c7ff8e1d /tests/core
parent7adca53ed653802663096b8c2977a03dbe39c601 (diff)
downloadlibgit2-e2e4bae9a091152166773fb5681f2b3acb18b43b.tar.gz
tree: drop the now-unnecessary entries vector
Remove the now-unnecessary entries vector. Add `git_array_search` to binary search through an array to accomplish this.
Diffstat (limited to 'tests/core')
-rw-r--r--tests/core/array.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/core/array.c b/tests/core/array.c
new file mode 100644
index 000000000..375cc8df3
--- /dev/null
+++ b/tests/core/array.c
@@ -0,0 +1,55 @@
+#include "clar_libgit2.h"
+#include "array.h"
+
+static int int_lookup(const void *k, const void *a)
+{
+ const int *one = (const int *)k;
+ int *two = (int *)a;
+
+ return *one - *two;
+}
+
+#define expect_pos(k, n, ret) \
+ key = (k); \
+ cl_assert_equal_i((ret), \
+ git_array_search(&p, integers, int_lookup, &key)); \
+ cl_assert_equal_i((n), p);
+
+void test_core_array__bsearch2(void)
+{
+ git_array_t(int) integers = GIT_ARRAY_INIT;
+ int *i, key;
+ size_t p;
+
+ i = git_array_alloc(integers); *i = 2;
+ i = git_array_alloc(integers); *i = 3;
+ i = git_array_alloc(integers); *i = 5;
+ i = git_array_alloc(integers); *i = 7;
+ i = git_array_alloc(integers); *i = 7;
+ i = git_array_alloc(integers); *i = 8;
+ i = git_array_alloc(integers); *i = 13;
+ i = git_array_alloc(integers); *i = 21;
+ i = git_array_alloc(integers); *i = 25;
+ i = git_array_alloc(integers); *i = 42;
+ i = git_array_alloc(integers); *i = 69;
+ i = git_array_alloc(integers); *i = 121;
+ i = git_array_alloc(integers); *i = 256;
+ i = git_array_alloc(integers); *i = 512;
+ i = git_array_alloc(integers); *i = 513;
+ i = git_array_alloc(integers); *i = 514;
+ i = git_array_alloc(integers); *i = 516;
+ i = git_array_alloc(integers); *i = 516;
+ i = git_array_alloc(integers); *i = 517;
+
+ /* value to search for, expected position, return code */
+ expect_pos(3, 1, GIT_OK);
+ expect_pos(2, 0, GIT_OK);
+ expect_pos(1, 0, GIT_ENOTFOUND);
+ expect_pos(25, 8, GIT_OK);
+ expect_pos(26, 9, GIT_ENOTFOUND);
+ expect_pos(42, 9, GIT_OK);
+ expect_pos(50, 10, GIT_ENOTFOUND);
+ expect_pos(68, 10, GIT_ENOTFOUND);
+ expect_pos(256, 12, GIT_OK);
+}
+