示例#1
0
 def test_can_get_angle_between_vectors_when_zero(self, mock_dot, mock_mag):
     mock_dot.return_value = 1
     mock_mag.return_value = 0
     vector1 = Vector(7, 1)
     vector2 = Mock(Vector)
     vector2.magnitude.return_value = 0.5
     vector2.length.return_value = 2
     self.assertAlmostEqual(vector1.angle_with(vector2), math.pi / 4, delta=0.0005)
     vector2.magnitude.return_value = 0
     mock_mag.return_value = 9
     self.assertAlmostEqual(vector1.angle_with(vector2), math.pi / 4, delta=0.0005)
示例#2
0
 def test_can_get_angle_between_vectors(self, mock_dot, mock_mag):
     mock_dot.return_value = 1
     mock_mag.return_value = 4
     vector1 = Vector(7, 1)
     vector2 = Mock(Vector)
     vector2.magnitude.return_value = 0.5
     vector2.length.return_value = 2
     self.assertAlmostEqual(vector1.angle_with(vector2), 1.0471, delta=0.0005)
示例#3
0
 def test_angle_requires_equal_length(self):
     vector1 = Vector(-6, 8)
     vector2 = Mock(Vector)
     vector2.length.return_value = 3
     with self.assertRaises(ValueError):
         vector1.angle_with(vector2)
示例#4
0
 def test_angle_requires_vector(self):
     vector1 = Vector(-6, -8)
     with self.assertRaises(TypeError):
         vector1.angle_with("vector")