| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- //
- // biginteger_test.cpp
- // bigdecimal
- //
- // Created by Sam Jaffe on 5/18/18.
- //
- #include "bignumber_test_printers.h"
- #include "xcode_gtest_helper.h"
- TEST(BigIntegerTest, ModuloZeroThrows) {
- math::biginteger bi{1000};
- EXPECT_THROW(bi % 0, std::domain_error);
- }
- TEST(BigIntegerTest, ModuloBiggerIsSameValue) {
- math::biginteger bi{1000};
- EXPECT_THAT(bi % 2000, bi);
- }
- TEST(BigIntegerTest, ModuloSameNumberIsZero) {
- math::biginteger bi{1000};
- EXPECT_THAT(bi % 1000, 0);
- }
- TEST(BigIntegerTest, ModuloDivisorIsZero) {
- math::biginteger bi{1000};
- EXPECT_THAT(bi % 100, 0);
- }
- TEST(BigIntegerTest, ModuloDiffSignIsInverseElement) {
- math::biginteger bi{1000};
- math::biginteger mod{13};
- EXPECT_THAT((bi % mod) + ((-bi) % mod), mod);
- }
- TEST(BigIntegerTest, ModuloNegativesIsNegative) {
- math::biginteger bi{1000};
- math::biginteger mod{13};
- EXPECT_THAT((bi % mod), -((-bi) % (-mod)));
- }
- class BigIntModuloTest : public testing::TestWithParam<BigIntPair> {};
- TEST_P(BigIntModuloTest, IsZero) {
- auto & ZERO = math::biginteger::ZERO;
- auto pair = GetParam();
- EXPECT_THAT(std::get<0>(pair) % std::get<1>(pair), ZERO);
- }
- class LtTest : public testing::TestWithParam<BigIntPair> {};
- TEST_P(LtTest, IsLessThan) {
- auto pair = GetParam();
- EXPECT_THAT(std::get<0>(pair), testing::Lt(std::get<1>(pair)));
- }
- INSTANTIATE_TEST_SUITE_P(BigInteger, LtTest,
- testing::Values(BigIntPair{-1, 1}, BigIntPair{0, 1},
- BigIntPair{-2, -1},
- BigIntPair{1000000000, 1000000001},
- BigIntPair{-1000000001, -1000000000}));
- INSTANTIATE_TEST_SUITE_P(ZeroModAny, BigIntModuloTest,
- testing::Combine(testing::Values(0),
- testing::Values(1, 2, 10, 100, -4,
- 1000000000,
- -1000000000)));
- INSTANTIATE_TEST_SUITE_P(AnyModOne, BigIntModuloTest,
- testing::Combine(testing::Values(1, 2, 10, 100, -4,
- 1000000000,
- -1000000000),
- testing::Values(1)));
|