def test_increase_food(set_up_nest): position, color, size, health = set_up_nest food_amount = 3.5 nest = Nest(position, color, size, health) nest.increase_food(food_amount) amount_tested = nest.food assert food_amount == amount_tested
def test_nest_creation(nest_creation_fixed): position, player, size, health = nest_creation_fixed nest = Nest(position, player, size, health) assert (nest.position == position).all() assert nest.owner == player assert nest.size == size assert nest.health == health
def test_update(set_up_nest): health1 = 5 health2 = -3 position, color, size, health = set_up_nest nest1 = Nest(position, color, size, health1) new_position1 = nest1.update(health1) assert ((new_position1 == position).all()) nest2 = Nest(position, color, size, health2) new_position2 = nest2.update(health2) assert new_position2 is None
from src.model.ant import Ant from src.model.nest import Nest from src.utils import array import numpy as np nest = Nest(position=array([0, 0]), color='red', size=10, health=100) ant = Ant(color='red', home_nest=nest) def test_move_has_food(): ant.has_food = True ant.position = array([10, 0]) position = ant.move([]) # asserting that y-move is towards the nest assert np.isclose(position, array([9, 0])).all(), 'incorrect y-move direction' # asserting that the position is updated assert np.isclose(ant.position, position).all(), 'position not updated' ant.position = array([0, 10]) position = ant.move([]) # asserting that x-move is towards the nest assert np.isclose(position, array([0, 9])).all(), 'incorrect x-move direction' def test_move_randomly(): ant.has_food = False ant.position = array([0, 0]) ant.momentum = array([0, 0]) previous_position = array(ant.position) position = ant.move([])
def test_increase_food(increase_food_fixed): food_amount = increase_food_fixed position = array.array('f', [0.5, 0.5]) nest = Nest(position, "red", 2, 1) amount_tested = nest.increase_food(0.5) assert food_amount == amount_tested
def test_nest_creation(nest_creation_fixed): position, color, size, health = nest_creation_fixed nest = Nest(position, color, size, health) assert nest.position[:] == position[:] and nest.color == color and nest.size == size and nest.health == health
def test_decrease_health(set_up_nest): position, color, size, health = set_up_nest damage = 5 nest = Nest(position, color, size, health) nest.decrease_health(damage) assert nest.health == health - damage
def set_up_environment(): player = Player(name="Nobody", color=(178, 58, 238)) nest = Nest(position=array([0., 0.]), player=player, size=10., health=100.) ant = Worker(player=player, home_nest=nest, speed=1) return player, nest, ant