diff options
Diffstat (limited to '')
-rw-r--r-- | sorting.c | 28 |
1 files changed, 27 insertions, 1 deletions
@@ -18,7 +18,33 @@ doublepcmp(const void *avp, const void *bvp) int main(void) { - return 0; /* TODO add test */ + double a, b; + + a = 1.0, b = 1.0; + ASSERT(doublepcmp(&a, &b) == 0); + ASSERT(doublepcmp(&b, &a) == -doublepcmp(&a, &b)); + + a = -1.0, b = 1.0; + ASSERT(doublepcmp(&a, &b) == -1); + ASSERT(doublepcmp(&b, &a) == -doublepcmp(&a, &b)); + + a = 1.0, b = -1.0; + ASSERT(doublepcmp(&a, &b) == +1); + ASSERT(doublepcmp(&b, &a) == -doublepcmp(&a, &b)); + + a = 0.0, b = 0.0; + ASSERT(doublepcmp(&a, &b) == 0); + ASSERT(doublepcmp(&b, &a) == -doublepcmp(&a, &b)); + + a = -1.0, b = 2.5; + ASSERT(doublepcmp(&a, &b) == -1); + ASSERT(doublepcmp(&b, &a) == -doublepcmp(&a, &b)); + + a = 1.0, b = -2.5; + ASSERT(doublepcmp(&a, &b) == +1); + ASSERT(doublepcmp(&b, &a) == -doublepcmp(&a, &b)); + + return 0; } |