예제 #1
0
class TestSmallBigInt(TestCase):
    def setUp(self) -> None:
        self.a = BigInt(1)
        self.b = BigInt(2)

    def test_add(self):
        c = self.a.add(self.b)
        self.assertEqual(c.equals(BigInt(3)), True)

    def test_sub(self):
        c = self.a.sub(self.b)
        self.assertEqual(c.equals(BigInt('-1')), True)

    def test_mul(self):
        c = self.a.mul(self.b)
        self.assertEqual(c.equals(BigInt(2)), True)

    def test_divide(self):
        c = self.a.divide(2)
        self.assertEqual(c[0].equals(BigInt(0)), True)
        self.assertEqual(c[1].equals(BigInt(1)), True)

    def test_mod(self):
        c = self.a.mod(self.b)
        self.assertEqual(c.equals(BigInt(1)), True)
예제 #2
0
class TestPosNegBigInt(TestCase):
    def setUp(self) -> None:
        self.pos_a = BigInt('1245356356356356353635634888')
        self.neg_b = BigInt(-1)

    def test_add(self):
        c = self.pos_a.add(self.neg_b)
        self.assertEqual(c.equals(BigInt('1245356356356356353635634887')), True)

    def test_sub(self):
        c = self.pos_a.sub(self.neg_b)
        self.assertEqual(c.equals(BigInt('1245356356356356353635634889')), True)

    def test_mul(self):
        c = self.pos_a.mul(self.neg_b)
        self.assertEqual(c.equals(BigInt('1245356356356356353635634888')), True)
        self.assertTrue(c.sign)

    def test_divide(self):
        c = self.pos_a.divide(-1)
        self.assertEqual(c[0].equals(BigInt('1245356356356356353635634888')), True)
        self.assertTrue(c[0].sign)
        self.assertEqual(c[1].equals(BigInt(0)), True)

    def test_mod(self):
        c = self.pos_a.mod(self.neg_b)
        self.assertEqual(c.equals(BigInt(0)), True)
예제 #3
0
def rand():
    while True:
        p = prime(int(random.uniform(10, 1000)))
        if not passed(p):
            continue
        else:
            return BigInt(p)
예제 #4
0
 def test_mul(self):
     c = self.pos_a.mul(self.neg_b)
     self.assertEqual(c.equals(BigInt('1245356356356356353635634888')), True)
     self.assertTrue(c.sign)
예제 #5
0
 def test_sub(self):
     c = self.pos_a.sub(self.neg_b)
     self.assertEqual(c.equals(BigInt('1245356356356356353635634889')), True)
예제 #6
0
 def test_add(self):
     c = self.pos_a.add(self.neg_b)
     self.assertEqual(c.equals(BigInt('1245356356356356353635634887')), True)
예제 #7
0
 def setUp(self) -> None:
     self.pos_a = BigInt('1245356356356356353635634888')
     self.neg_b = BigInt(-1)
예제 #8
0
 def test_mod(self):
     c = self.neg_a.mod(self.neg_b)
     self.assertEqual(c.equals(BigInt(0)), True)
예제 #9
0
 def test_divide(self):
     c = self.neg_a.divide(-1)
     self.assertEqual(c[0].equals(BigInt('1245356356356356353635634888')), True)
     self.assertEqual(c[1].equals(BigInt(0)), True)
예제 #10
0
 def setUp(self) -> None:
     self.a = BigInt(1)
     self.b = BigInt(2)
예제 #11
0
 def test_mod(self):
     c = self.a.mod(self.b)
     self.assertEqual(c.equals(BigInt(1)), True)
예제 #12
0
 def test_divide(self):
     c = self.a.divide(2)
     self.assertEqual(c[0].equals(BigInt(0)), True)
     self.assertEqual(c[1].equals(BigInt(1)), True)
예제 #13
0
 def test_mul(self):
     c = self.a.mul(self.b)
     self.assertEqual(c.equals(BigInt(2)), True)
예제 #14
0
 def test_sub(self):
     c = self.a.sub(self.b)
     self.assertEqual(c.equals(BigInt('-1')), True)
예제 #15
0
 def test_add(self):
     c = self.a.add(self.b)
     self.assertEqual(c.equals(BigInt(3)), True)