| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- //
- // biginteger_test.cpp
- // bigdecimal
- //
- // Created by Sam Jaffe on 5/18/18.
- //
- #include <gmock/gmock.h>
- #include "biginteger.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)));
- }
- using BigIntPair = std::tuple<math::biginteger, math::biginteger>;
- 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)));
- }
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments"
- INSTANTIATE_TEST_CASE_P(BigInteger, LtTest,
- testing::Values(BigIntPair{-1, 1},
- BigIntPair{ 0, 1},
- BigIntPair{-2, -1},
- BigIntPair{ 1000000000, 1000000001},
- BigIntPair{-1000000001, -1000000000}));
- INSTANTIATE_TEST_CASE_P(ZeroModAny, BigIntModuloTest,
- testing::Combine(testing::Values(0),
- testing::Values(1, 2, 10, 100, -4, 1000000000, -1000000000)));
- INSTANTIATE_TEST_CASE_P(AnyModOne, BigIntModuloTest,
- testing::Combine(testing::Values(1, 2, 10, 100, -4, 1000000000, -1000000000),
- testing::Values(1)));
- #pragma clang diagnostic pop
|