示例#1
0
 def test_components(self):
     self.assertEqual(Vector(1, 2).components, [1, 2])
示例#2
0
 def test_mul_with_vector(self):
     self.assertEqual(Vector(1, 2) * Vector(2, 3), Vector(2, 6))
示例#3
0
 def test_mul_incompatible_type_error(self):
     with self.assertRaises(TypeError):
         Vector(1, 2) * 'incompatible'
示例#4
0
 def test_sub_with_vector(self):
     self.assertEqual(Vector(3, 5) - Vector(2, 3), Vector(1, 2))
示例#5
0
 def test_mul_with_int(self):
     self.assertEqual(Vector(1, 2) * 2, Vector(2, 4))
示例#6
0
 def test_add_incompatible_vector_error(self):
     with self.assertRaises(TypeError):
         Vector(1, 2) + Vector(1, 2, 3)
示例#7
0
 def test_sub_with_int(self):
     self.assertEqual(Vector(1, 2) - 1, Vector(0, 1))
示例#8
0
 def test_contract(self):
     self.assertEqual(Vector(3, 2).contract(Vector(1, 3)), Vector(1, 2))
示例#9
0
 def test_contract_incompatible_type_error(self):
     with self.assertRaises(TypeError):
         Vector(3, 2).contract('incompatible')
示例#10
0
 def test_expand_incompatible_type_error(self):
     with self.assertRaises(TypeError):
         Vector(1, 2).expand('incompatible')
示例#11
0
 def test_expand_incompatible_vector_error(self):
     with self.assertRaises(TypeError):
         Vector(1, 2).expand(Vector(3, 1, 0))
示例#12
0
 def test_expand(self):
     self.assertEqual(Vector(1, 2).expand(Vector(3, 1)), Vector(3, 2))
示例#13
0
 def test_magnitude(self):
     self.assertEqual(Vector(2, 3, 0.5).magnitude, 3)
示例#14
0
 def test_to_int_list(self):
     self.assertEqual(Vector(1, 2.5).to_int_list(), [1, 2])
示例#15
0
 def test_add_with_float(self):
     self.assertEqual(Vector(1, 2) + 0.5, Vector(1.5, 2.5))
示例#16
0
 def test_contract_incompatible_vector_error(self):
     with self.assertRaises(TypeError):
         Vector(3, 2).contract(Vector(1, 2, 0))
示例#17
0
 def test_add_with_vector(self):
     self.assertEqual(Vector(1, 2) + Vector(2, 3), Vector(3, 5))
示例#18
0
 def test_to_float_list(self):
     self.assertEqual(Vector(1, 2.5).to_float_list(), [1.0, 2.5])
示例#19
0
 def test_repr(self):
     self.assertEqual(repr(Vector(1, 2)), 'Vector(1.0, 2.0)')
示例#20
0
 def test_eq(self):
     self.assertEqual(Vector(1, 2), Vector(1.0, 2.0))
示例#21
0
 def test_sub_with_float(self):
     self.assertEqual(Vector(1, 2) - 0.5, Vector(0.5, 1.5))
示例#22
0
 def test_really_not_eq(self):
     self.assertNotEqual(Vector(1, 2), Vector(2.0, 1.0))
示例#23
0
 def test_sub_incompatible_vector_error(self):
     with self.assertRaises(TypeError):
         Vector(3, 5) - Vector(2, 3, 4)
示例#24
0
 def test_definitely_not_eq(self):
     self.assertNotEqual(Vector(1, 2), Vector(1, 2, 3))
示例#25
0
 def test_mul_with_float(self):
     self.assertEqual(Vector(1, 2) * 0.5, Vector(0.5, 1))
示例#26
0
 def test_really_definitely_not_eq(self):
     self.assertNotEqual(Vector(1, 2), 'incompatible')
示例#27
0
 def test_str(self):
     self.assertEqual(str(Vector(1, 2)), '1 2')
示例#28
0
 def test_add_with_int(self):
     self.assertEqual(Vector(1, 2) + 1, Vector(2, 3))
示例#29
0
 def test_mul_incompatible_vector_error(self):
     with self.assertRaises(TypeError):
         Vector(1, 2) * Vector(2, 3, 4)
示例#30
0
 def test_iter(self):
     self.assertEqual([c for c in Vector(1, 2, 3)], [1, 2, 3])