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 { class BigNum {
public: public:
explicit BigNum(std::int64_t number); explicit BigNum(std::int64_t number = 0);
friend std::ostream& operator<<(std::ostream& out, BigNum const& num) { friend std::ostream& operator<<(std::ostream& out, BigNum const& num) {
return num.dump(out); return num.dump(out);

View file

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