biginteger.t.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // biginteger.t.h
  3. // bigdecimal
  4. //
  5. // Created by Sam Jaffe on 6/30/17.
  6. //
  7. #pragma once
  8. #include "biginteger.h"
  9. #include <cxxtest/TestSuite.h>
  10. class biginteger_TestSuite : public CxxTest::TestSuite {
  11. public:
  12. void testAddPastBounds() {
  13. math::biginteger bi{999999999ULL};
  14. TS_ASSERT_EQUALS((bi+1).to_string(), "1000000000");
  15. }
  16. void testAddReciprocalIsZero() {
  17. math::biginteger bi{1000};
  18. TS_ASSERT_EQUALS((bi+(-bi)).to_string(), "0");
  19. }
  20. void testAddNegativeLargerGivesNegative() {
  21. math::biginteger bi{1000};
  22. TS_ASSERT_EQUALS((bi+(-1001)).to_string(), "-1");
  23. }
  24. void testAddNegativeSmallerGivesPositive() {
  25. math::biginteger bi{1000};
  26. TS_ASSERT_EQUALS((bi+(-999)).to_string(), "1");
  27. }
  28. void testSubSelfIsZero() {
  29. math::biginteger bi{1000};
  30. TS_ASSERT_EQUALS((bi-bi).to_string(), "0");
  31. }
  32. void testNegativeMinusNegativeIncreateAbs() {
  33. math::biginteger bi{-1000};
  34. TS_ASSERT_EQUALS((bi-100).to_string(), "-1100");
  35. }
  36. void testSubLargerGivesNegative() {
  37. math::biginteger bi{1000};
  38. TS_ASSERT_EQUALS((bi-1001).to_string(), "-1");
  39. }
  40. void testSubSmallerGivesPositive() {
  41. math::biginteger bi{1000};
  42. TS_ASSERT_EQUALS((bi-999).to_string(), "1");
  43. }
  44. };