Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKirill A. Shutemov <kirill@shutemov.name>2011-07-02 01:41:49 +0400
committerKirill A. Shutemov <kirill@shutemov.name>2011-07-05 18:52:39 +0400
commit476c42acc554e7b3f79c945c2a461d4e25dde41c (patch)
tree82808af7f61a45323ae8d71ed2504216c04e8a6b /tests
parent0b0a6b115d617fe79a0be0ddecd89738aefa574c (diff)
vector: implement git_vector_uniq()
The routine remove duplictes from the vector. Only the last added element of elements with equal keys remains in the vector. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Diffstat (limited to 'tests')
-rw-r--r--tests/t00-core.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/t00-core.c b/tests/t00-core.c
index ba5188a43..661f92508 100644
--- a/tests/t00-core.c
+++ b/tests/t00-core.c
@@ -73,6 +73,28 @@ BEGIN_TEST(vector1, "don't read past array bounds on remove()")
git_vector_free(&x);
END_TEST
+static int test_cmp(const void *a, const void *b)
+{
+ int n1 = *(int *)a;
+ int n2 = *(int *)b;
+
+ return n1 - n2;
+}
+
+BEGIN_TEST(vector2, "remove duplicates")
+ git_vector x;
+ must_pass(git_vector_init(&x, 5, test_cmp));
+ must_pass(git_vector_insert(&x, (void *) 0xdeadbeef));
+ must_pass(git_vector_insert(&x, (void *) 0xcafebabe));
+ must_pass(git_vector_insert(&x, (void *) 0xcafebabe));
+ must_pass(git_vector_insert(&x, (void *) 0xdeadbeef));
+ must_pass(git_vector_insert(&x, (void *) 0xcafebabe));
+ must_be_true(x.length == 5);
+ git_vector_uniq(&x);
+ must_be_true(x.length == 2);
+ git_vector_free(&x);
+END_TEST
+
BEGIN_TEST(path0, "get the dirname of a path")
char dir[64], *dir2;
@@ -480,6 +502,7 @@ BEGIN_SUITE(core)
ADD_TEST(vector0);
ADD_TEST(vector1);
+ ADD_TEST(vector2);
ADD_TEST(path0);
ADD_TEST(path1);