aboutsummaryrefslogtreecommitdiffstats
path: root/test.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-05 20:16:14 +0100
committerMattias Andrée <maandree@kth.se>2016-03-05 20:16:14 +0100
commit5860237d2f05f6ae45a98569b0d567c2227904c6 (patch)
treebbddb91e2a6a5e7efe7825971c726a9e4db87dd6 /test.c
parentMore detailed description of division and modulus (diff)
downloadlibzahl-5860237d2f05f6ae45a98569b0d567c2227904c6.tar.gz
libzahl-5860237d2f05f6ae45a98569b0d567c2227904c6.tar.bz2
libzahl-5860237d2f05f6ae45a98569b0d567c2227904c6.tar.xz
Fix bugs and add a randomised testing
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'test.c')
-rw-r--r--test.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/test.c b/test.c
index 69d5170..624abb0 100644
--- a/test.c
+++ b/test.c
@@ -62,7 +62,7 @@ main(void)
/* static because otherwise it would have to be volatile yeilding a lot of stupid
* warnings. auto variables are not guaranteed to be readable after a long jump. */
static z_t a, b, c, d, _0, _1, _2, _3;
- static char buf[1000];
+ static char buf[2000];
static int ret = 0;
static jmp_buf env, env2;
static size_t n;
@@ -309,6 +309,19 @@ main(void)
assert((zadd_unsigned(a, b, _2), zcmp(a, _3)), == 0);
assert((zadd_unsigned(a, _1, c), zcmp(a, _3)), == 0);
+ assert((zadd_unsigned(a, _0, _0), zcmp(a, _0)), == 0);
+ assert((zadd_unsigned(a, _0, _1), zcmp(a, _1)), == 0);
+ assert((zadd_unsigned(a, _1, _1), zcmp(a, _2)), == 0);
+ assert((zadd_unsigned(a, _1, _0), zcmp(a, _1)), == 0);
+ zneg(_1, _1);
+ assert((zadd_unsigned(a, _0, _0), zcmp(a, _0)), == 0);
+ assert((zadd_unsigned(a, _0, _1), zcmp(a, _1)), != 0);
+ assert((zadd_unsigned(a, _0, _1), zcmpmag(a, _1)), == 0);
+ assert((zadd_unsigned(a, _1, _1), zcmp(a, _2)), == 0);
+ assert((zadd_unsigned(a, _1, _0), zcmp(a, _1)), != 0);
+ assert((zadd_unsigned(a, _1, _0), zcmpmag(a, _1)), == 0);
+ zneg(_1, _1);
+
assert((zsub_unsigned(a, _2, _1), zcmp(a, _1)), == 0);
assert((zsub_unsigned(a, _2, b), zcmp(a, _1)), == 0);
assert((zsub_unsigned(a, c, _1), zcmp(a, _1)), == 0);
@@ -992,8 +1005,11 @@ main(void)
zsqr(a, a);
assert_s(zstr(a, buf), "1000000000000000000000000000000");
+#include "test-random.c"
+
done:
zfree(a), zfree(b), zfree(c), zfree(d), zfree(_0), zfree(_1), zfree(_2), zfree(_3);
zunsetup();
return ret;
}
+