summaryrefslogtreecommitdiff
path: root/src/or/test.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-09-17 18:27:49 +0000
committerNick Mathewson <nickm@torproject.org>2007-09-17 18:27:49 +0000
commit8c139678038832cf982ab2ef3a25679ff677c491 (patch)
tree67036be82e4014a736d44aa36fb9d794ddb54985 /src/or/test.c
parent93d4ad974318f48b4def653f94d7088bdc6b4e09 (diff)
downloadtor-8c139678038832cf982ab2ef3a25679ff677c491.tar.gz
tor-8c139678038832cf982ab2ef3a25679ff677c491.zip
r14448@Kushana: nickm | 2007-09-17 14:26:56 -0400
Unify all of the divergent median/nth-percentile code in container.[ch] svn:r11457
Diffstat (limited to 'src/or/test.c')
-rw-r--r--src/or/test.c59
1 files changed, 23 insertions, 36 deletions
diff --git a/src/or/test.c b/src/or/test.c
index 8503cdb609..bb673f953a 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -2386,42 +2386,29 @@ test_same_voter(networkstatus_voter_info_t *v1,
}
static void
-test_util_dirvote_helpers(void)
+test_util_order_functions(void)
{
- smartlist_t *sl = smartlist_create();
- int a=12,b=24,c=25,d=60,e=77;
- time_t v=99, w=150, x=700, y=1000, z=time(NULL);
-
- test_assert(y<z);
- smartlist_add(sl, &a);
- test_eq(a, median_int(sl)); /* a */
- smartlist_add(sl, &e);
- smartlist_shuffle(sl);
- test_eq(a, median_int(sl)); /* a,e */
- smartlist_add(sl, &e);
- smartlist_shuffle(sl);
- test_eq(e, median_int(sl)); /* a,e,e */
- smartlist_add(sl, &b);
- test_eq(b, median_int(sl)); /* a,b,e,e */
- smartlist_add(sl, &d);
- smartlist_add(sl, &a);
- smartlist_add(sl, &c);
- smartlist_shuffle(sl);
- test_eq(c, median_int(sl)); /* a,a,b,c,d,e,e */
-
- smartlist_clear(sl);
- smartlist_add(sl, &y);
- test_eq(y, median_time(sl)); /*y*/
- smartlist_add(sl, &w);
- test_eq(w, median_time(sl)); /*w,y*/
- smartlist_add(sl, &x);
- test_eq(x, median_time(sl)); /*w,x,y*/
- smartlist_add(sl, &v);
- test_eq(w, median_time(sl)); /*v,w,x,y*/
- smartlist_add(sl, &z);
- test_eq(x, median_time(sl)); /*v,w,x,y,z*/
-
- smartlist_free(sl);
+ int lst[25], n = 0;
+ // int a=12,b=24,c=25,d=60,e=77;
+
+#define median() median_int(lst, n)
+
+ lst[n++] = 12;
+ test_eq(12, median()); /* 12 */
+ lst[n++] = 77;
+ //smartlist_shuffle(sl);
+ test_eq(12, median()); /* 12, 77 */
+ lst[n++] = 77;
+ //smartlist_shuffle(sl);
+ test_eq(77, median()); /* 12, 77, 77 */
+ lst[n++] = 24;
+ test_eq(24, median()); /* 12,24,77,77 */
+ lst[n++] = 60;
+ lst[n++] = 12;
+ lst[n++] = 25;
+ //smartlist_shuffle(sl);
+ test_eq(25, median()); /* 12,12,24,25,60,77,77 */
+#undef median
}
static void
@@ -3121,7 +3108,7 @@ static struct {
SUBENT(util, pqueue),
SUBENT(util, mmap),
SUBENT(util, threads),
- SUBENT(util, dirvote_helpers),
+ SUBENT(util, order_functions),
ENT(onion_handshake),
ENT(dir_format),
ENT(v3_networkstatus),