| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- //
- // biginteger.t.h
- // bigdecimal
- //
- // Created by Sam Jaffe on 6/30/17.
- //
- #pragma once
- #include "biginteger.h"
- #include <cxxtest/TestSuite.h>
- 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");
- }
-
- void testMultiplyNoOverflow() {
- math::biginteger bi{1000};
- TS_ASSERT_EQUALS((bi*bi).to_string(), "1000000");
- }
- };
|