summaryrefslogtreecommitdiff
path: root/tests/math.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/math.c')
-rw-r--r--tests/math.c67
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;
+}