From 0817dcf4b1722c772df4d7e24e12caec00059819 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Tue, 4 Oct 2022 11:37:55 -0700 Subject: [PATCH] Red... (Green, Refactor) TDD FTW! --- bigjoyints/big.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bigjoyints/big.py b/bigjoyints/big.py index c923e79..a5bd77c 100644 --- a/bigjoyints/big.py +++ b/bigjoyints/big.py @@ -41,6 +41,15 @@ class BigInt: n = -n return n + def __add__(self, other): + if not isinstance(other, BigInt): + other = BigInt(other) + if self.sign == other.sign: + return self.add_like_signs(other) + + def add_like_signs(self, other): + return BigInt(23) + class OberonInt: ''' @@ -140,6 +149,23 @@ class BigIntTest(unittest.TestCase): x = BigInt(n).to_int() self.assertEqual(n, x) + def test_2_to_100th_power(self): + digits = list(BigInt.digitize(2**100)) + self.assertEqual( + digits, + [OberonInt(0), OberonInt(0), OberonInt(0), OberonInt(128)], + ) + + def test_Addition(self): + n = 12345678901234567898090123445678990 + m = 901234567898090 + x = BigInt(n) + y = BigInt(m) + z = x + y + t = z.to_int() + self.assertEqual(t, n + m) + + if __name__ == '__main__': unittest.main()