diff options
author | EuAndreh <eu@euandre.org> | 2024-05-31 11:48:58 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-05-31 11:48:58 -0300 |
commit | fa2862fa648cca9a181184a849444409d07e9fb2 (patch) | |
tree | 3f3e79879df960b493f9c5f903464b03dc321855 /tests | |
parent | src/util.h: Add EXIT_USAGE (diff) | |
download | pindaiba-fa2862fa648cca9a181184a849444409d07e9fb2.tar.gz pindaiba-fa2862fa648cca9a181184a849444409d07e9fb2.tar.xz |
src/math.h: Add "add_size()"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/math.c | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/tests/math.c b/tests/math.c index 34f54ce..d2b64c6 100644 --- a/tests/math.c +++ b/tests/math.c @@ -1,9 +1,72 @@ #include "../src/math.c" +#include <stdlib.h> + #include "../src/testing.h" static void +test_add_size(void) { + test_start("add_size()"); + + size_t val; + { + testing("zero values"); + + assert(add_size(0U, 0U, &val) == 0); + assert(val == 0U); + + assert(add_size(1U, 0U, &val) == 0); + assert(val == 1U); + + assert(add_size(0U, 1U, &val) == 0); + assert(val == 1U); + + assert(add_size(0U, 3U, &val) == 0); + assert(val == 3U); + + assert(add_size(30U, 0U, &val) == 0); + assert(val == 30U); + + test_ok(); + } + { + testing("small values"); + + assert(add_size(1U, 2U, &val) == 0); + assert(val == 3U); + + assert(add_size(34U, 56U, &val) == 0); + assert(val == 90U); + + assert(add_size(121U, 122U, &val) == 0); + assert(val == 243U); + + test_ok(); + } + { + testing("big values"); + + assert(add_size(SIZE_MAX, 0U, &val) == 0); + assert(val == SIZE_MAX); + + assert(add_size(SIZE_MAX - 10U, 3U, &val) == 0); + assert(val == (SIZE_MAX - 7U)); + + test_ok(); + } + { + testing("overflowing values"); + + val = 0U; + assert(add_size(SIZE_MAX, 1U, &val) != 0); + assert(val == 0U); + + test_ok(); + } +} + +static void test_mul_size(void) { test_start("mul_size()"); @@ -62,6 +125,7 @@ test_mul_size(void) { int main(void) { + test_add_size(); test_mul_size(); - return 0; + return EXIT_SUCCESS; } |