diff options
author | George Kadianakis <desnacked@riseup.net> | 2014-07-24 14:31:49 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-09-09 12:28:15 -0400 |
commit | 01800ea1e4e0312c8b204541a8e43d7aad67ad61 (patch) | |
tree | 83d81a65e11e78644055a0a39cdbd77ebe02bfd9 /src/test/test_containers.c | |
parent | 8e3939519999f73fadad1a8b8cff75aad0667312 (diff) | |
download | tor-01800ea1e4e0312c8b204541a8e43d7aad67ad61.tar.gz tor-01800ea1e4e0312c8b204541a8e43d7aad67ad61.zip |
Add unittests for finding the third quartile of a set.
Diffstat (limited to 'src/test/test_containers.c')
-rw-r--r-- | src/test/test_containers.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/test_containers.c b/src/test/test_containers.c index a9f5e727f4..d7b7b3cfee 100644 --- a/src/test/test_containers.c +++ b/src/test/test_containers.c @@ -835,6 +835,7 @@ static void test_container_order_functions(void) { int lst[25], n = 0; + unsigned int lst2[25]; // int a=12,b=24,c=25,d=60,e=77; #define median() median_int(lst, n) @@ -856,6 +857,28 @@ test_container_order_functions(void) test_eq(25, median()); /* 12,12,24,25,60,77,77 */ #undef median +#define third_quartile() third_quartile_uint32(lst2, n) + + n = 0; + lst2[n++] = 1; + test_eq(1, third_quartile()); /* ~1~ */ + lst2[n++] = 2; + test_eq(2, third_quartile()); /* 1, ~2~ */ + lst2[n++] = 3; + lst2[n++] = 4; + lst2[n++] = 5; + test_eq(4, third_quartile()); /* 1, 2, 3, ~4~, 5 */ + lst2[n++] = 6; + lst2[n++] = 7; + lst2[n++] = 8; + lst2[n++] = 9; + test_eq(7, third_quartile()); /* 1, 2, 3, 4, 5, 6, ~7~, 8, 9 */ + lst2[n++] = 10; + lst2[n++] = 11; + test_eq(9, third_quartile()); /* 1, 2, 3, 4, 5, 6, 7, 8, ~9~, 10, 11 */ + +#undef third_quartile + done: ; } |