diff options
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))); +} + |