diff options
author | 2019-06-19 11:58:03 +0300 | |
---|---|---|
committer | 2019-06-19 11:58:03 +0300 | |
commit | c499fc7bc9e1c3b8fe04ea5c80e5a7e0b16b11fc (patch) | |
tree | 5ec5eaeb3eb951f65715aa62a043c6ae7eac7854 /test/time.c | |
parent | ef5cc380045bba05acfcba7d0e1c03046fdc82d0 (diff) | |
download | librin-c499fc7bc9e1c3b8fe04ea5c80e5a7e0b16b11fc.tar.gz librin-c499fc7bc9e1c3b8fe04ea5c80e5a7e0b16b11fc.tar.bz2 librin-c499fc7bc9e1c3b8fe04ea5c80e5a7e0b16b11fc.zip |
time: add a generalized time comparison function.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'test/time.c')
-rw-r--r-- | test/time.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/time.c b/test/time.c index 4307fd1..017597b 100644 --- a/test/time.c +++ b/test/time.c @@ -27,6 +27,7 @@ int time_test(char *testname) {"add", rin_time_add_test}, {"sub", rin_time_sub_test}, {"normalize", rin_time_normalize_test}, + {"cmp", rin_time_cmp_test}, {"cmpless", rin_time_cmpless_test}, {"cmpmore", rin_time_cmpmore_test}, {"cmplessequal", rin_time_cmplessequal_test}, @@ -111,6 +112,25 @@ static int rin_time_normalize_test(void) return ret; } +static int rin_time_cmp_test(void) +{ + int ret; + size_t i; + static const struct timespec in_a[] = { {187, 100}, {1, 100}, {1, 200}, {1, 100}, {9, 10}, {3, 100}, {4, 101}, {0, 0} }; + static const struct timespec in_b[] = { {187, 100}, {0, 100}, {1, 200}, {1, 200}, {10, 10}, {4, 101}, {3, 100}, {0, 0} }; + static const long int expected[] = {0, 1, 0, -100, -1, -1, 1, 0}; + + for (i = 0; i < arrlen(expected); ++i) { + ret = ok(rin_time_cmp(in_a + i, in_b + i) != expected[i], + "%s: expected: %li, got: %li", + __func__, + expected[i], + rin_time_cmp(in_a + i, in_b + i)); + } + + return ret; +} + static int rin_time_cmpless_test(void) { int ret; |