// // biginteger.t.h // bigdecimal // // Created by Sam Jaffe on 6/30/17. // #pragma once #include "biginteger.h" #include class biginteger_TestSuite : public CxxTest::TestSuite { public: void testAddPastBounds() { math::biginteger bi{999999999ULL}; TS_ASSERT_EQUALS((bi+1).to_string(), "1000000000"); } void testAddReciprocalIsZero() { math::biginteger bi{1000}; TS_ASSERT_EQUALS((bi+(-bi)).to_string(), "0"); } void testAddNegativeLargerGivesNegative() { math::biginteger bi{1000}; TS_ASSERT_EQUALS((bi+(-1001)).to_string(), "-1"); } void testAddNegativeSmallerGivesPositive() { math::biginteger bi{1000}; TS_ASSERT_EQUALS((bi+(-999)).to_string(), "1"); } void testSubSelfIsZero() { math::biginteger bi{1000}; TS_ASSERT_EQUALS((bi-bi).to_string(), "0"); } void testNegativeMinusNegativeIncreateAbs() { math::biginteger bi{-1000}; TS_ASSERT_EQUALS((bi-100).to_string(), "-1100"); } void testSubLargerGivesNegative() { math::biginteger bi{1000}; TS_ASSERT_EQUALS((bi-1001).to_string(), "-1"); } void testSubSmallerGivesPositive() { math::biginteger bi{1000}; TS_ASSERT_EQUALS((bi-999).to_string(), "1"); } void testSubUnderflowBorrows() { math::biginteger bi{1000000000ULL}; TS_ASSERT_EQUALS((bi-1).to_string(), "999999999"); } void testMultiplyZeroReturnsZero() { auto &ZERO = math::biginteger::ZERO; math::biginteger bi{999999999ULL}; TS_ASSERT_EQUALS((bi*ZERO).to_string(), "0"); TS_ASSERT_EQUALS((ZERO*bi).to_string(), "0"); } void testMultiplyOneReturnsValue() { auto &ONE = math::biginteger::ONE; math::biginteger bi{999999999ULL}; TS_ASSERT_EQUALS((bi*ONE).to_string(), "999999999"); TS_ASSERT_EQUALS((ONE*bi).to_string(), "999999999"); } void testMultiplyNegativeOneReturnsInverse() { auto &NEGATIVE_ONE = math::biginteger::NEGATIVE_ONE; math::biginteger bi{999999999ULL}; TS_ASSERT_EQUALS((bi*NEGATIVE_ONE).to_string(), "-999999999"); TS_ASSERT_EQUALS((NEGATIVE_ONE*bi).to_string(), "-999999999"); } void testMultiplyOverflowsIntoNextCell() { math::biginteger bi{999999999ULL}; TS_ASSERT_EQUALS((bi*bi).to_string(), "999999998000000001"); } void testMultiplyCarryIntoNextCell() { math::biginteger bi{999999999ULL}; math::biginteger big{bi*bi}; TS_ASSERT_EQUALS((big*big).to_string(), "999999996000000005999999996000000001"); } };