def test_vector_mul(self): self.assertEqual( Zm(10, self.m), SimpleVector([Zm(1, self.m), Zm(2, self.m), Zm(3, self.m)]) * SimpleVector([Zm(3, self.m), Zm(2, self.m), Zm(1, self.m)]))
def test_add(self): a = PolyUnivar([Zm(1, 31), Zm(2, 31), Zm(3, 31)]) b = PolyUnivar([Zm(30, 31), Zm(29, 31), Zm(28, 31)]) d = PolyUnivar([Zm(4, 31), Zm(6, 31), Zm(6, 31)]) self.assertEqual(a.zero(), a + b) self.assertNotEqual(d, a + b)
def test_eq(self): a = PolyUnivar([Zm(1, 31), Zm(2, 31), Zm(3, 31)]) b = PolyUnivar([Zm(1, 31), Zm(2, 31), Zm(34, 31)]) c = PolyUnivar([Zm(1, 31), Zm(1, 31), Zm(2, 31), Zm(3, 31)]) self.assertEqual(a, b) self.assertNotEqual(a, c)
def test_pow(self): a = PolyUnivar([Zm(1, 7), Zm(2, 7), Zm(3, 7)]) b = PolyUnivar([Zm(2, 7), Zm(3, 7), Zm(4, 7)]) c = PolyUnivar([Zm(2, 7), Zm(0, 7), Zm(2, 7), Zm(3, 7), Zm(5, 7)]) d = PolyUnivar([Zm(2, 7), Zm(0, 7), Zm(2, 7), Zm(3, 7), Zm(6, 7)]) self.assertEqual(c, a ** b) self.assertEqual(c, b ** a) self.assertNotEqual(d, a ** b)
def test_vector_linearlyIndependent(self): self.assertTrue( SimpleVector.linearlyIndependent([self.i, self.j, self.k])) self.assertFalse( SimpleVector.linearlyIndependent([ SimpleVector([Zm(1, self.m), Zm(2, self.m), Zm(3, self.m)]), SimpleVector([Zm(1, self.m), Zm(35, self.m), Zm(9, self.m)]), SimpleVector([Zm(34, self.m), Zm(-23, self.m), Zm(15, self.m)]) ])) self.assertFalse( SimpleVector.linearlyIndependent([ SimpleVector([Zm(2, self.m), Zm(34, self.m), Zm(4, self.m)]), SimpleVector([Zm(5, self.m), Zm(6, self.m), Zm(3, self.m)]), SimpleVector([Zm(14, self.m), Zm(32, self.m), Zm(54, self.m)]), SimpleVector([Zm(9, self.m), Zm(8, self.m), Zm(7, self.m)]) ]))
def test_eq(self): self.assertEqual(Zm(4, 3), Zm(1, 3)) self.assertEqual(Zm(-1, 3), Zm(2, 3))
def test_mul(self): self.assertEqual(Zm(5, 31), Zm(9, 31) * Zm(4, 31))
def test_zero(self): a = PolyUnivar([Zm(1, 7), Zm(2, 7), Zm(3, 7)]) self.assertEqual(a.zero() + a, a) self.assertEqual(a.zero(), Zm(0, 7) * a)
def test_vector_rmul(self): self.assertEqual( SimpleVector([Zm(2, self.m), Zm(0, self.m), Zm(0, self.m)]), Zm(2, self.m) * self.i)
def setUp(self): self.m = 31 self.i = SimpleVector([Zm(1, self.m), Zm(0, self.m), Zm(0, self.m)]) self.j = SimpleVector([Zm(0, self.m), Zm(1, self.m), Zm(0, self.m)]) self.k = SimpleVector([Zm(0, self.m), Zm(0, self.m), Zm(1, self.m)]) self.c = Zm(0, self.m)
def test_inv(self): x = Zm(4, self.m) self.assertEqual(self.c.zero(), Zm.inv(x) + x)
def test_zero(self): self.assertEqual(Zm(4, self.m), Zm(4, self.m) + self.c.zero())
def test_div(self): self.assertEqual(Zm(4, 7), Zm(5, 7) / Zm(3, 7))
def test_sub(self): self.assertEqual(Zm(1, 4), Zm(9, 4), Zm(12, 4))
def test_rmul(self): self.assertEqual(Zm(5, 31), 9 * Zm(4, 31))
def test_mul(self): a = PolyUnivar([Zm(1, 7), Zm(2, 7), Zm(3, 7)]) b = PolyUnivar([Zm(1, 7), Zm(2, 7), Zm(3, 7), Zm(4, 7)]) self.assertEqual(Zm(6, 7), a * b) self.assertNotEqual(Zm(0, 7), a * b)
def test_rmul(self): a = PolyUnivar([Zm(1, 7), Zm(2, 7), Zm(3, 7)]) b = PolyUnivar([Zm(2, 7), Zm(4, 7), Zm(-1, 7)]) c = PolyUnivar([Zm(2, 7), Zm(4, 7), Zm(0, 7)]) self.assertEqual(b, Zm(2, 7) * a) self.assertEqual(PolyUnivar([]), Zm(0, 7) * a) self.assertNotEqual(c, Zm(2, 7) * a) self.assertNotEqual(c, Zm(0, 7) * a)
def test_vector_add(self): self.assertEqual( SimpleVector([Zm(1, self.m), Zm(1, self.m), Zm(1, self.m)]), self.i + self.j + self.k)
def test_linearlyIndependent(self): a = PolyUnivar([Zm(1, 5), Zm(2, 5), Zm(3, 5)]) b = PolyUnivar([Zm(2, 5), Zm(3, 5), Zm(4, 5)]) c = PolyUnivar([Zm(3, 5), Zm(4, 5), Zm(0, 5)]) d = PolyUnivar([Zm(3, 5), Zm(0, 5), Zm(0, 5)]) self.assertTrue(a.linearlyIndependent([a, b, d])) self.assertFalse(a.linearlyIndependent([a, b, c])) self.assertFalse(a.linearlyIndependent([a, b, PolyUnivar([])]))
def test_add(self): self.assertEqual(Zm(5, 4), Zm(6, 4) + Zm(3, 4))