def test_distance(self): first = vec2(5, 3) second = vec2(7, 1) actual_distance = first.distance(second) expected_distance = first.copy.subtract(second).length self.assertEqual(actual_distance, expected_distance)
def test_subtract(self): first = vec2(5, 3) second = vec2(7, 1) actual_result = first.copy.subtract(second) expected_vector = vec2(first.x - second.x, first.y - second.y) self.__assert_vectors_equal(actual_result, expected_vector)
def test_add(self): first = vec2(1, 2) second = vec2(3, 4) actual_result = first.copy.add(second) expected_vector = vec2(first.x + second.x, first.y + second.y) self.__assert_vectors_equal(actual_result, expected_vector)
def test_line_line_intersect_no_intersection(self): expected_intersection = geometry.POINT_AT_INFINITY first_line = vec2(-10, -12), vec2(0, -5) second_line = vec2(15, 2), vec2(4, 3) are_intersected, intersection = geometry.line_line_intersect( first_line, second_line) self.assertFalse(are_intersected) self.assertEqual(intersection, expected_intersection)
def test_line_line_intersect(self): expected_intersection = vec2(0, 0) first_line = vec2(-1, 0), vec2(1, 0) second_line = vec2(0, -1), vec2(0, 1) are_intersected, intersection = geometry.line_line_intersect( first_line, second_line) self.assertTrue(are_intersected) self.assertTrue(expected_intersection.almost_equal(intersection))
def test_ray_intersect(self): result = geometry.ray_circle_intersect( (vec2(0, 0), vec2(0, 2)), (vec2(0, 3), 2)) valid, actual_distance, actual_point = result expected_point = vec2(0, 1) expected_distance = 1 self.assertTrue(valid) self.assertTrue(expected_point.almost_equal(actual_point)) self.assertEqual(actual_distance, expected_distance)
def test_ray_intersect_not_intersected(self): result = geometry.ray_circle_intersect( (vec2(0, 0), vec2(2, 2)), (vec2(4, 10), 2)) valid, actual_distance, actual_point = result expected_point = geometry.POINT_AT_INFINITY expected_distance = math.inf self.assertFalse(valid) self.assertEqual(actual_point, expected_point) self.assertEqual(actual_distance, expected_distance)
def test_circles_intersect_no_intersection(self): first_circle = vec2(5, 5), 3 second_circle = vec2(-1, 4), 2 self.assertFalse(geometry.circles_intersect( first_circle, second_circle))
def test_circles_intersect(self): first_circle = vec2(0, 1), 3 second_circle = vec2(0, 4), 2 self.assertTrue(geometry.circles_intersect( first_circle, second_circle))
def test_digestion(self, circle_intersect_mock): elements = [Food(vec2(1, 2), 1), ] digestion = Digestion(elements) circle_intersect_mock().return_value = True
def test_scale_to(self): vector = vec2(3, 4) actual_vector = vector.copy.scale_to(10) expected_vector = vec2(6, 8) self.__assert_vectors_equal(actual_vector, expected_vector)
def test_copy(self): vector = vec2(2, 3) copy = vector.copy self.__assert_vectors_equal(copy, vector)
def test_rotate(self): vector = vec2(3, 4) actual_vector = vector.copy.rotate(0.785398) expected_vector = vec2(-0.7071, 4.9497) self.__assert_vectors_equal(actual_vector, expected_vector)
def test_length(self): vector = vec2(3, 4) self.assertEqual(vector.length, 5)
def test_reverse(self): vector = vec2(5, 4) reversed_vector = vector.reverse expected_vector = vec2(-vector.x, -vector.y) self.__assert_vectors_equal(reversed_vector, expected_vector)