| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- //
- // 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");
- }
- };
|