aboutsummaryrefslogtreecommitdiff
path: root/src/or/test.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-11-03 20:12:38 +0000
committerNick Mathewson <nickm@torproject.org>2007-11-03 20:12:38 +0000
commitc217be996d55560b6fbb2932ab498372306b2379 (patch)
treefbc188a15cd3d6dbc7cf8505f0bac1ad973d95f5 /src/or/test.c
parentd4e339ed879ef60e645a2b2d1fea87aaecc342fe (diff)
downloadtor-c217be996d55560b6fbb2932ab498372306b2379.tar
tor-c217be996d55560b6fbb2932ab498372306b2379.tar.gz
r14677@tombo: nickm | 2007-11-03 15:16:27 -0400
Add a smartlist_bsearch_idx function that gives more useful output than regular bsearch for the value-not-found case. svn:r12360
Diffstat (limited to 'src/or/test.c')
-rw-r--r--src/or/test.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/or/test.c b/src/or/test.c
index 13d227948..bd67f5841 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -1487,6 +1487,23 @@ test_util_smartlist(void)
test_streq("and", smartlist_bsearch(sl, " AND", _compare_without_first_ch));
test_eq_ptr(NULL, smartlist_bsearch(sl, " ANz", _compare_without_first_ch));
+ /* Test bsearch_idx */
+ {
+ int f;
+ test_eq(0, smartlist_bsearch_idx(sl," aaa",_compare_without_first_ch,&f));
+ test_eq(f, 0);
+ test_eq(0, smartlist_bsearch_idx(sl," and",_compare_without_first_ch,&f));
+ test_eq(f, 1);
+ test_eq(1, smartlist_bsearch_idx(sl," arm",_compare_without_first_ch,&f));
+ test_eq(f, 0);
+ test_eq(1, smartlist_bsearch_idx(sl," arma",_compare_without_first_ch,&f));
+ test_eq(f, 1);
+ test_eq(2, smartlist_bsearch_idx(sl," armb",_compare_without_first_ch,&f));
+ test_eq(f, 0);
+ test_eq(7, smartlist_bsearch_idx(sl," zzzz",_compare_without_first_ch,&f));
+ test_eq(f, 0);
+ }
+
/* Test reverse() and pop_last() */
smartlist_reverse(sl);
cp = smartlist_join_strings(sl, ",", 0, NULL);