def setUp(self): self.i = SimpleVector([R(1), R(0), R(0)]) self.j = SimpleVector([R(0), R(1), R(0)]) self.k = SimpleVector([R(0), R(0), R(1)]) self.x = VectorSpace([self.i]) self.y = VectorSpace([self.j]) self.z = VectorSpace([self.k]) self.xy = VectorSpace([self.i, self.j]) self.yz = VectorSpace([self.j, self.k]) self.zx = VectorSpace([self.k, self.i]) self.xyz = VectorSpace([self.i, self.j, self.k])
def test_pow2(self): a = PolyHomBivar([R(0), R(1), R(2), R(1)]) b = PolyHomBivar([R(1), R(1)]) c = PolyHomBivar([R(0), R(1), R(3), R(3), R(1)]) e = PolyHomBivar([R(1), R(3), R(3), R(1)]) self.assertEqual(c, a**b) self.assertNotEqual(e, a**b)
def test_linearlyIndependent(self): a = PolyUnivar([R(1), R(2), R(3)]) b = PolyUnivar([R(2), R(3), R(4)]) c = PolyUnivar([R(3), R(4), R(5)]) d = PolyUnivar([R(3), R(5), R(5)]) self.assertTrue(a.linearlyIndependent([a, b, d])) self.assertFalse(a.linearlyIndependent([a, b, c])) self.assertFalse(a.linearlyIndependent([a, b, PolyUnivar([])]))
def test_eq(self): a = PolyUnivar([R(1), R(2), R(3)]) b = PolyUnivar([R(1), R(2), R(3)]) c = PolyUnivar([R(1), R(1), R(2), R(3)]) self.assertEqual(a, b) self.assertNotEqual(a, c)
def test_add(self): a = PolyUnivar([R(1), R(2), R(3)]) b = PolyUnivar([R(-1), R(2), R(3)]) c = PolyUnivar([R(4), R(6)]) d = PolyUnivar([R(4), R(6), R(6)]) self.assertEqual(c, a + b) self.assertNotEqual(d, a + b)
def test_rmul(self): a = PolyUnivar([R(1), R(2), R(3)]) b = PolyUnivar([R(2), R(4), R(6)]) c = PolyUnivar([R(2), R(4), R(7)]) self.assertEqual(b, R(2) * a) self.assertEqual(PolyUnivar([]), R(0) * a) self.assertNotEqual(c, R(2) * a) self.assertNotEqual(c, R(0) * a)
def test_add(self): self.assertEqual(R(42), R(29) + R(13))
def test_vector_add(self): self.assertEqual(SimpleVector([R(1), R(1), R(1)]), self.i + self.j + self.k)
def test_lt(self): self.assertTrue(R(20) < R(21)) self.assertFalse(R(21) < R(21))
def test_le(self): self.assertTrue(R(20) <= R(20)) self.assertFalse(R(22) <= R(21))
def test_ge(self): self.assertTrue(R(20) >= R(20)) self.assertFalse(R(21) >= R(22))
def test_gt(self): self.assertTrue(R(21) > R(20)) self.assertFalse(R(21) > R(21))
def test_eq(self): self.assertEqual(R(21), R(21)) self.assertNotEqual(R(20), R(21))
def test_vector_rmul(self): self.assertEqual(SimpleVector([R(2), R(2), R(2)]), R(2) * SimpleVector([R(1), R(1), R(1)]))
def test_zero(self): self.assertEqual(R(10), R(10) + self.c.zero())
def test_vector_mul(self): self.assertEqual(R(10), SimpleVector([R(1), R(2), R(3)]) * SimpleVector([R(3), R(2), R(1)]))
def test_mul(self): self.assertEqual(R(10), R(5) * R(2))
def test_vector_linearlyIndependent(self): self.assertTrue(SimpleVector.linearlyIndependent([self.i, self.j, self.k])) self.assertFalse(SimpleVector.linearlyIndependent([SimpleVector([R(1), R(2), R(3)]), SimpleVector([R(1), R(4), R(9)]), SimpleVector([R(3), R(8), R(15)])])) self.assertFalse(SimpleVector.linearlyIndependent([SimpleVector([R(2), R(3), R(4)]), SimpleVector([R(5), R(6), R(3)]), SimpleVector([R(14), R(32), R(54)]), SimpleVector([R(9), R(8), R(7)])]))
def test_rmul(self): self.assertEqual(R(10), 2 * R(5))
def test_mul(self): a = PolyUnivar([R(1), R(2), R(3)]) b = PolyUnivar([R(1), R(2), R(3), R(4)]) self.assertEqual(R(20), a * b) self.assertNotEqual(R(21), a * b)
def test_sub(self): self.assertEqual(R(10), R(12) - R(2))
def test_zero(self): a = PolyUnivar([R(1), R(2), R(3)]) self.assertEqual(a.zero() + a, a) self.assertEqual(a.zero(), R(0) * a)
def test_div(self): self.assertEqual(R(4), R(16) / R(4))
def test_pow(self): a = PolyUnivar([R(1), R(2), R(3)]) b = PolyUnivar([R(2), R(3), R(4)]) c = PolyUnivar([R(2), R(7), R(16), R(17), R(12)]) d = PolyUnivar([R(2), R(7), R(16), R(17), R(13)]) self.assertEqual(c, a ** b) self.assertEqual(c, b ** a) self.assertNotEqual(d, a ** b)
def setUp(self): # Set up unit vectors in R3 self.i = SimpleVector([R(1), R(0), R(0)]) self.j = SimpleVector([R(0), R(1), R(0)]) self.k = SimpleVector([R(0), R(0), R(1)]) self.c = R(0)
def test_pow(self): a = PolyHomBivar([R(1), R(2), R(1)]) b = PolyHomBivar([R(1), R(1)]) self.assertEqual(a, b**b)
def test_inv(self): self.assertEqual(R(10) + R.inv(R(10)), self.c.zero())
def test_add(self): a = PolyHomBivar([R(1), R(2), R(3)]) b = PolyHomBivar([R(4), R(5), R(6)]) c = PolyHomBivar([R(5), R(7), R(9)]) self.assertEqual(c, a + b)
def test_contains(self): # Check that the i + 2j lies in the xy plane self.assertIn(self.i + R(2) * self.j, self.xy) # Check that i + 2k does not lie in the xy planes self.assertNotIn(self.i + R(2) * self.k, self.xy)