diff options
author | EuAndreh <eu@euandre.org> | 2024-05-24 11:35:20 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-05-24 13:03:56 -0300 |
commit | fef0a487a119a5cbcd2fd95c6a35e0a9c4ab8ac1 (patch) | |
tree | 542e59d44cf82c988e90cc05217cb4b35b22a76d /tests | |
parent | Add some version of vector.c (diff) | |
download | pindaiba-fef0a487a119a5cbcd2fd95c6a35e0a9c4ab8ac1.tar.gz pindaiba-fef0a487a119a5cbcd2fd95c6a35e0a9c4ab8ac1.tar.xz |
src/math.c: Add mul_size()
Diffstat (limited to 'tests')
-rw-r--r-- | tests/math.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/math.c b/tests/math.c new file mode 100644 index 0000000..34f54ce --- /dev/null +++ b/tests/math.c @@ -0,0 +1,67 @@ +#include "../src/math.c" + +#include "../src/testing.h" + + +static void +test_mul_size(void) { + test_start("mul_size()"); + + size_t val; + { + testing("zero values"); + + assert(mul_size(1U, 1U, &val) == 0); + assert(val == 1U); + + test_ok(); + } + { + testing("small values"); + + assert(mul_size(2U, 3U, &val) == 0); + assert(val == 6U); + + assert(mul_size(10U, 10U, &val) == 0); + assert(val == 100U); + + assert(mul_size(15U, 15U, &val) == 0); + assert(val == 225U); + + test_ok(); + } + { + testing("big values"); + + assert(mul_size(SIZE_MAX, 1U, &val) == 0); + assert(val == SIZE_MAX); + + assert(mul_size(1U, SIZE_MAX, &val) == 0); + assert(val == SIZE_MAX); + + assert(mul_size(SIZE_MAX / 2U, 2U, &val) == 0); + assert(val == SIZE_MAX - 1U); + + test_ok(); + } + { + testing("overflowing values"); + + val = 123U; + + assert(mul_size(SIZE_MAX, 2U, &val) != 0); + assert(val == 123U); + + assert(mul_size(3U, SIZE_MAX / 2U, &val) != 0); + assert(val == 123U); + + test_ok(); + } +} + + +int +main(void) { + test_mul_size(); + return 0; +} |