summaryrefslogtreecommitdiff
path: root/source/test/unittests/bigint.test.c
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2022-12-09 14:36:38 +0100
committerMitya Selivanov <automainint@guattari.tech>2022-12-09 14:36:38 +0100
commit5391a2681f812e773ddc97088183312d3eaa74f0 (patch)
tree66ba4008a975435cc0543950d8ac2393617b59a1 /source/test/unittests/bigint.test.c
parent1963d9c64dd0a9a14394e30244d64b82501ddc1f (diff)
downloadkit-5391a2681f812e773ddc97088183312d3eaa74f0.zip
Big integer math
Diffstat (limited to 'source/test/unittests/bigint.test.c')
-rw-r--r--source/test/unittests/bigint.test.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/source/test/unittests/bigint.test.c b/source/test/unittests/bigint.test.c
new file mode 100644
index 0000000..7df2fcc
--- /dev/null
+++ b/source/test/unittests/bigint.test.c
@@ -0,0 +1,47 @@
+#include "../../kit/bigint.h"
+
+#define KIT_TEST_FILE bigint
+#include "../../kit_test/test.h"
+
+#include <stdio.h>
+
+TEST("bigint hex add") {
+ SZ(foo, "4242424242424242424242424242424242424242");
+ SZ(bar, "1111111111111111111111111111111111111111");
+ SZ(sum, "5353535353535353535353535353535353535353");
+
+ REQUIRE(bi_equal(bi_add(bi_hex(foo), bi_hex(bar)), bi_hex(sum)));
+}
+
+TEST("bigint hex sub") {
+ SZ(foo, "4242424242424242424242424242424242424242");
+ SZ(bar, "1111111111111111111111111111111111111111");
+ SZ(dif, "3131313131313131313131313131313131313131");
+
+ REQUIRE(bi_equal(bi_sub(bi_hex(foo), bi_hex(bar)), bi_hex(dif)));
+}
+
+TEST("bigint base58") {
+ SZ(foo, "31");
+
+ REQUIRE(bi_equal(bi_base58(foo), bi_uword(58 * 2)));
+}
+
+TEST("bigint base58 add") {
+ SZ(foo, "4242424242424242424242424242424242424242");
+ SZ(bar, "2222222222222222222222222222222222222222");
+ SZ(sum, "5353535353535353535353535353535353535353");
+
+ REQUIRE(bi_equal(bi_add(bi_base58(foo), bi_base58(bar)),
+ bi_base58(sum)));
+}
+
+TEST("bigint base58 sub") {
+ SZ(foo, "42");
+ SZ(bar, "22");
+ SZ(dif, "31");
+
+ REQUIRE(bi_equal(bi_sub(bi_base58(foo), bi_base58(bar)),
+ bi_base58(dif)));
+}
+