aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorSimon Warta <[email protected]>2015-07-22 00:15:55 +0200
committerSimon Warta <[email protected]>2015-07-24 10:33:40 +0200
commite5e8635ab5e21991e890b229c9c563ffeec2db31 (patch)
tree3f8e34c177b46ac95706958f9d84dfa8cdcd1783 /src/tests
parent10883bb5b8fb2804b9af08c7cfe9f869be811d0b (diff)
Refactor BigInt
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/catchy/test_bigint.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/tests/catchy/test_bigint.cpp b/src/tests/catchy/test_bigint.cpp
new file mode 100644
index 000000000..5f4c960cf
--- /dev/null
+++ b/src/tests/catchy/test_bigint.cpp
@@ -0,0 +1,74 @@
+// (C) 2015 Simon Warta (Kullo GmbH)
+// Botan is released under the Simplified BSD License (see license.txt)
+
+#include "catch.hpp"
+
+#include <botan/build.h>
+
+#if defined(BOTAN_HAS_BIGINT)
+
+#include <botan/bigint.h>
+
+using namespace Botan;
+
+TEST_CASE("Bigint basics", "[bigint]")
+ {
+ SECTION("in 0-bit border")
+ {
+ BigInt a(0u);
+ CHECK(( a.bits() == 0 ));
+ CHECK(( a.bytes() == 0 ));
+ CHECK(( a.to_u32bit() == 0 ));
+ }
+ SECTION("above 0-bit border")
+ {
+ BigInt a(1u);
+ CHECK(( a.bits() == 1 ));
+ CHECK(( a.bytes() == 1 ));
+ CHECK(( a.to_u32bit() == 1 ));
+ }
+ SECTION("in 8-bit border")
+ {
+ BigInt a(255u);
+ CHECK(( a.bits() == 8 ));
+ CHECK(( a.bytes() == 1 ));
+ CHECK(( a.to_u32bit() == 255 ));
+ }
+ SECTION("above 8-bit border")
+ {
+ BigInt a(256u);
+ CHECK(( a.bits() == 9 ));
+ CHECK(( a.bytes() == 2 ));
+ CHECK(( a.to_u32bit() == 256 ));
+ }
+ SECTION("in 16-bit border")
+ {
+ BigInt a(65535u);
+ CHECK(( a.bits() == 16 ));
+ CHECK(( a.bytes() == 2 ));
+ CHECK(( a.to_u32bit() == 65535 ));
+ }
+ SECTION("above 16-bit border")
+ {
+ BigInt a(65536u);
+ CHECK(( a.bits() == 17 ));
+ CHECK(( a.bytes() == 3 ));
+ CHECK(( a.to_u32bit() == 65536 ));
+ }
+ SECTION("in 32-bit border")
+ {
+ BigInt a(4294967295u);
+ CHECK(( a.bits() == 32 ));
+ CHECK(( a.bytes() == 4 ));
+ CHECK(( a.to_u32bit() == 4294967295u ));
+ }
+ SECTION("above 32-bit border")
+ {
+ BigInt a(4294967296u);
+ CHECK(( a.bits() == 33 ));
+ CHECK(( a.bytes() == 5 ));
+ CHECK_THROWS( a.to_u32bit() );
+ }
+ }
+
+#endif