def test_collide_animals(): """Collide two animals together""" animal1 = Animal() animal2 = Animal() animal1.velocity = [1, 1] animal2.velocity = [-1, -1] animal1.put(0, 0) animal2.put(1, 1) collide_animals(animal1, animal2) assert_array_almost_equal(animal1.velocity, [-1, -1]) assert_array_almost_equal(animal2.velocity, [1, 1])
def test_game(): animal1 = Animal(shape="Y", max_health=2, size=40) animal2 = Animal(shape="X", max_health=2, size=40) animal1.also_likes_to_eat(animal2) animal2.also_likes_to_eat(animal1) screen = pygame.display.set_mode((600, 600)) animal1.put_relative(30, 30, screen) animal2.put_relative(60, 60, screen) engine = Engine(screen) engine.add_animals(animal1, animal2) engine.start()
def test_find_collisions(): group = Group() animal1 = Animal() animal2 = Animal() animal1.put(30, 30) animal2.put(50, 50) group.add(animal1, animal2) collisions = find_collisions(group) assert not collisions assert group animal1.put(50, 50) animal2.put(50, 50) collisions = find_collisions(group) assert len(collisions) == 1 collision = collisions[0] np.testing.assert_array_equal((collision.animal1, collision.animal2), (animal1, animal2)) assert group.has(animal1, animal2) and len(group) == 2
def sample_1(): animal1 = Animal(shape="E", color="red", size=45, mass=2, exertion_magnitude=40, max_health=50) animal2 = Animal(shape="W", color="orange", size=30, mass=1, exertion_magnitude=20, max_health=40, damage_infliction_magnitude=.2) animal3 = Animal(shape="W", color="orange", size=30, mass=1, exertion_magnitude=20, max_health=40, damage_infliction_magnitude=.2) animal1.put_relative(5, 5, screen) animal2.put_relative(95, 95, screen) animal3.put_relative(90, 90, screen) animal1.velocity = [0, 30] animal2.velocity = [0, -30] animal3.velocity = [0, -30] animal1.also_likes_to_eat(animal2, animal3) animal2.also_likes_to_eat(animal1) animal3.also_likes_to_eat(animal1) engine.add_animals(animal1, animal2, animal3)
def test_pin_groups_against_each_other(): animal1 = Animal() animal2 = Animal() animal3 = Animal() group1 = [animal1, animal2] group2 = [animal3] pin_groups_against_each_other((group1, group2)) assert animal1.eats == {animal3} assert animal2.eats == {animal3} assert animal3.eats == {animal1, animal2} assert animal1.wants_to_eat(animal3) assert animal2.wants_to_eat(animal3) assert animal3.wants_to_eat(animal1) assert animal3.wants_to_eat(animal2) assert not animal1.wants_to_eat(animal2) assert not animal2.wants_to_eat(animal1)
def test_off_screen(): screen = pygame.Surface((100, 100)) animal = Animal() animal.put(100, 100) assert animal.off_screen(screen) == False animal.put(100, 101 + animal.height + 1) assert animal.off_screen(screen) == True animal.put(101 + animal.width, 50) assert animal.off_screen(screen) == True animal.put(-1 - animal.width, 50) assert animal.off_screen(screen) == True animal.put(50, -1 - animal.height) assert animal.off_screen(screen) == True animal.put(50, 50) assert animal.off_screen(screen) == False animal.put(0, 0) assert animal.off_screen(screen) == False
def create_animals(df): """Create some animals given a list of LintErrorGroups and add them to global set of animals""" map = pd.DataFrame([ ["C", "Convention", "green", 0.2, 0.3, 0.1, 0.1, 0.1], ["R", "Refactor", "magenta", 0.3, 0.1, 0.2, 0.3, 0.5], ["W", "Warning", "yellow", 0.4, 0.2, 0.4, 0.3, 0.5], ["E", "Error", "orange", 0.8, 0.8, 0.8, 1.0, 1.0], ["F", "Fatal", "red", 1.0, 4.0, 1.0, 1.0, 1.0], ], columns=[ "error_category", "shape", "color", "size", "max_health", "mass", "exertion_magnitude", "damage_infliction_magnitude" ]) map = map.set_index("error_category") animal_groups = [] for name, group in df.groupby(["error_category"]): animals = [] for i, row in group.iterrows(): animals.append( Animal( error=row, shape=map.loc[row.error_category, "shape"], color=map.loc[row.error_category, "color"], max_health=math.ceil( map.loc[row.error_category, "max_health"] * 50) + 1, size=math.ceil(map.loc[row.error_category, "size"] * 40) + 15, mass=map.loc[row.error_category, "mass"] * 10 + 0.3, exertion_magnitude=map.loc[row.error_category, "exertion_magnitude"] * 100 + 10, damage_infliction_magnitude=map.loc[ row.error_category, "damage_infliction_magnitude"], )) animal_groups.append(animals) pin_groups_against_each_other(animal_groups) return animal_groups
def test_collide_animal_into_wall(): animal = Animal() screen = pygame.Surface((600, 600)) gameboard = GameBoard(screen) # Send the animal shooting into the top left corner animal.velocity = [-10, -10] collide_animal_into_wall(animal, gameboard.walls["top"]) assert_array_almost_equal(animal.velocity, [-10, 10]) # Toward the left wall now collide_animal_into_wall(animal, gameboard.walls["left"]) assert_array_almost_equal(animal.velocity, [10, 10]) # Toward the bottom wall now collide_animal_into_wall(animal, gameboard.walls["bottom"]) assert_array_almost_equal(animal.velocity, [10, -10]) # Toward the right wall now collide_animal_into_wall(animal, gameboard.walls["right"]) assert_array_almost_equal(animal.velocity, [-10, -10])
def evaluate(self): animal_type = animal_types.get(self.animal_type_name) animals[self.animal_name] = Animal(animal_type)