def test_find_distance_to_right_sprite(self): test_player = Player(pygame.sprite.LayeredUpdates()) test_net_group = pygame.sprite.Group() test_car = Player(pygame.sprite.LayeredUpdates()) expected = Window.WIDTH - test_player.rect.center[0] actual = test_player.find_distance_to_sprite("right", test_net_group) self.assertEqual(expected, actual) # Move the test car to the right side of the player test_car.rect.y = test_player.rect.y test_car.rect.x = test_player.rect.x + 50 test_car.add(test_net_group) expected = test_car.rect.x - test_player.rect.center[0] actual = test_player.find_distance_to_sprite("right", test_net_group) self.assertEqual(expected, actual) test_car.rect.y += 10 actual = test_player.find_distance_to_sprite("right", test_net_group) self.assertEqual(expected, actual) test_car.rect.y -= 10 actual = test_player.find_distance_to_sprite("right", test_net_group) self.assertEqual(expected, actual) test_car.rect.y -= 1000 expected = Window.WIDTH - test_player.rect.center[0] actual = test_player.find_distance_to_sprite("right", test_net_group) self.assertEqual(expected, actual) test_car.rect.x -= 150 test_car2 = Player(pygame.sprite.LayeredUpdates()) test_net_group.add(test_car2) test_car2.rect.y = test_player.rect.y test_car2.rect.x = test_player.rect.x + 50 expected = test_car2.rect.x - test_player.rect.center[0] actual = test_player.find_distance_to_sprite("right", test_net_group) self.assertEqual(expected, actual) test_car.rect.y = test_player.rect.y test_car.rect.x = Window.WIDTH expected = test_car2.rect.x - test_player.rect.center[0] actual = test_player.find_distance_to_sprite("right", test_net_group) self.assertEqual(expected, actual)
def test_find_distance_to_left_sprite(self): test_player = Player(pygame.sprite.LayeredUpdates()) test_net_group = pygame.sprite.Group() test_car = Player(pygame.sprite.LayeredUpdates()) expected = test_player.rect.center[0] actual = test_player.find_distance_to_sprite("left", test_net_group) self.assertEqual(expected, actual) # Move the test car to the left side of the player test_car.rect.y = test_player.rect.y test_car.rect.x = test_player.rect.x - 50 test_car.add(test_net_group) expected = test_player.rect.center[0] - (test_car.rect.x + test_car.rect.width) actual = test_player.find_distance_to_sprite("left", test_net_group) self.assertEqual(expected, actual) test_car.rect.y += 10 actual = test_player.find_distance_to_sprite("left", test_net_group) self.assertEqual(expected, actual) test_car.rect.y -= 10 actual = test_player.find_distance_to_sprite("left", test_net_group) self.assertEqual(expected, actual) test_car.rect.y -= 1000 expected = test_player.rect.center[0] actual = test_player.find_distance_to_sprite("left", test_net_group) self.assertEqual(expected, actual) test_car.rect.x += 150 test_car2 = Player(pygame.sprite.LayeredUpdates()) test_net_group.add(test_car2) test_car2.rect.y = test_player.rect.y test_car2.rect.x = test_player.rect.x - 50 expected = test_player.rect.center[0] - (test_car2.rect.x + test_car.rect.width) actual = test_player.find_distance_to_sprite("left", test_net_group) self.assertEqual(expected, actual) test_car.rect.y = test_player.rect.y test_car.rect.x = 0 expected = test_player.rect.center[0] - (test_car2.rect.x + test_car.rect.width) actual = test_player.find_distance_to_sprite("left", test_net_group) self.assertEqual(expected, actual)