diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2022-12-09 14:36:38 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2022-12-09 14:36:38 +0100 |
commit | 5391a2681f812e773ddc97088183312d3eaa74f0 (patch) | |
tree | 66ba4008a975435cc0543950d8ac2393617b59a1 /source/test/unittests | |
parent | 1963d9c64dd0a9a14394e30244d64b82501ddc1f (diff) | |
download | kit-5391a2681f812e773ddc97088183312d3eaa74f0.zip |
Big integer math
Diffstat (limited to 'source/test/unittests')
-rw-r--r-- | source/test/unittests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | source/test/unittests/bigint.test.c | 47 |
2 files changed, 49 insertions, 2 deletions
diff --git a/source/test/unittests/CMakeLists.txt b/source/test/unittests/CMakeLists.txt index fe4c902..261b69e 100644 --- a/source/test/unittests/CMakeLists.txt +++ b/source/test/unittests/CMakeLists.txt @@ -1,8 +1,8 @@ target_sources( ${KIT_TEST_SUITE} PRIVATE - async_function.test.c mutex.test.c test_duration.test.c - main.test.c string_ref.test.c atomic.test.c thread.test.c + async_function.test.c bigint.test.c mutex.test.c + test_duration.test.c main.test.c string_ref.test.c atomic.test.c thread.test.c array_ref.test.c input_stream.test.c lower_bound.test.c condition_variable.test.c mersenne_twister_64.test.c input_buffer.test.c move_back.test.c dynamic_array.test.c file.test.c) 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))); +} + |