oc-mint/test/test_big_int.cpp

38 lines
684 B
C++
Raw Normal View History

2022-12-05 23:39:56 +01:00
#include "big_int.hpp"
#include <catch2/catch_test_macros.hpp>
TEST_CASE("BigInt::from_string", "[big_int]") {
2023-04-20 22:55:17 +02:00
const std::string VALID [] = {
2022-12-05 23:39:56 +01:00
"1",
"12",
"123",
"1234",
"12345",
"123456",
"120456",
"123056",
"120345",
"1234560abc",
"aabbcc",
"abcdef1"
};
2023-04-20 22:55:17 +02:00
for (const auto & i : VALID) {
auto b = BigInt::from_string(i);
2022-12-05 23:39:56 +01:00
REQUIRE(b.has_value());
2023-04-20 22:55:17 +02:00
REQUIRE(b->to_string() == i);
2022-12-05 23:39:56 +01:00
}
auto invalid_hex = "aabbcc..";
{
auto b = BigInt::from_string(invalid_hex);
REQUIRE(!b);
}
}
TEST_CASE("BigInt::from_int", "[big_int]") {
auto b = BigInt::from_int(0xaabbccdd);
REQUIRE(b.to_string()=="aabbccdd");
}