abacus: bignum: add default constructor

This commit is contained in:
Bruno BELANYI 2021-08-20 18:34:41 +02:00
parent ad5092ea8d
commit 6f7e1102db
2 changed files with 17 additions and 17 deletions

View file

@ -9,7 +9,7 @@ namespace abacus::bignum {
class BigNum {
public:
explicit BigNum(std::int64_t number);
explicit BigNum(std::int64_t number = 0);
friend std::ostream& operator<<(std::ostream& out, BigNum const& num) {
return num.dump(out);

View file

@ -18,41 +18,41 @@ TEST(BigNum, dump) {
return str.str();
};
ASSERT_EQ(to_str(zero), "0");
ASSERT_EQ(to_str(one), "1");
ASSERT_EQ(to_str(minus_one), "-1");
ASSERT_EQ(to_str(forty_two), "42");
EXPECT_EQ(to_str(zero), "0");
EXPECT_EQ(to_str(one), "1");
EXPECT_EQ(to_str(minus_one), "-1");
EXPECT_EQ(to_str(forty_two), "42");
}
TEST(BigNum, equality) {
auto const zero = BigNum(0);
auto const one = BigNum(1);
ASSERT_EQ(zero, zero);
ASSERT_EQ(one, one);
ASSERT_NE(zero, one);
EXPECT_EQ(zero, zero);
EXPECT_EQ(one, one);
EXPECT_NE(zero, one);
}
TEST(BigNum, comparisons) {
auto const zero = BigNum(0);
auto const one = BigNum(1);
ASSERT_LT(zero, one);
ASSERT_LE(zero, one);
ASSERT_LE(zero, zero);
EXPECT_LT(zero, one);
EXPECT_LE(zero, one);
EXPECT_LE(zero, zero);
ASSERT_GT(one, zero);
ASSERT_GE(one, zero);
ASSERT_GE(one, one);
EXPECT_GT(one, zero);
EXPECT_GE(one, zero);
EXPECT_GE(one, one);
}
TEST(BigNum, unary) {
auto const zero = BigNum(0);
auto const one = BigNum(1);
ASSERT_EQ(zero, -zero);
ASSERT_NE(one, -one);
EXPECT_EQ(zero, -zero);
EXPECT_NE(one, -one);
auto const minus_one = BigNum(-1);
ASSERT_EQ(minus_one, -one);
EXPECT_EQ(minus_one, -one);
}