class TestStatusBarFactory: m_test_coordinate = Coordinate(0, 0) def test_creating_factory(self): status_bar_factory = StatusBarFactory() assert isinstance(status_bar_factory, StatusBarFactory) def test_creating_health(self): status_bar_factory = StatusBarFactory() health_bar = status_bar_factory.get_status_bar( "health", TestStatusBarFactory.m_test_coordinate) assert isinstance(health_bar, HealthBar) def test_creating_energy(self): status_bar_factory = StatusBarFactory() energy_bar = status_bar_factory.get_status_bar( "energy", TestStatusBarFactory.m_test_coordinate) assert isinstance(energy_bar, EnergyBar) def test_creating_throws(self): status_bar_factory = StatusBarFactory() with pytest.raises(ValueError): no_object = status_bar_factory.get_status_bar( "none", TestStatusBarFactory.m_test_coordinate)
def test_creating_pet(self): frames_per_second, x_coordinate, y_coordinate = 30, 0, 0 pet = Pet(frames_per_second, Coordinate(x_coordinate, y_coordinate)) assert pet.max_health == 100 assert pet.get_position() == (x_coordinate, y_coordinate)
def test_pet_is_not_doing_action(self): frames_per_second, x_coordinate, y_coordinate = 30, 0, 0 pet = Pet(frames_per_second, Coordinate(x_coordinate, y_coordinate)) pet.set_state(ActorState.AWAKE) assert pet.is_doing_action() == False
def test_pet_is_not_alive(self): frames_per_second, x_coordinate, y_coordinate = 30, 0, 0 pet = Pet(frames_per_second, Coordinate(x_coordinate, y_coordinate)) pet.set_state(ActorState.DEAD) assert pet.is_alive() == False
def test_add_multiple_different_food(self): food_list = FoodInventory([], Coordinate(0, 0)) food_list.add_food(ExampleFood()) food_list.add_food(ExampleFoodTwo()) assert len(food_list.food_list) is 2 assert len(food_list.get_available_food()) is 2
def test_eat_food(self): food_list = FoodInventory([ExampleFood()], Coordinate(0, 0)) food_to_eat = food_list.eat_food() print(food_to_eat) assert len(food_list.food_list) is 0 assert food_to_eat.get_consumable_name() == "ExampleFood"
def test_pet_run_sleeping(self): frames_per_second, x_coordinate, y_coordinate = 30, 0, 0 pet = Pet(frames_per_second, Coordinate(x_coordinate, y_coordinate)) pet.energy = 10 pet.run_turn() assert pet.get_state() == ActorState.ASLEEP
def test_pet_run_poop(self): frames_per_second, x_coordinate, y_coordinate = 30, 0, 0 pet = Pet(frames_per_second, Coordinate(x_coordinate, y_coordinate)) pet.fullness = 70 pet.run_turn() assert pet.get_state() == ActorState.POOPING
def test_pet_run_die_hunger(self): frames_per_second, x_coordinate, y_coordinate = 30, 0, 0 pet = Pet(frames_per_second, Coordinate(x_coordinate, y_coordinate)) pet.health = 0 pet.run_turn() assert pet.is_alive() == False
def test_pet_run_die_age(self): frames_per_second, x_coordinate, y_coordinate = 30, 0, 0 pet = Pet(frames_per_second, Coordinate(x_coordinate, y_coordinate)) pet.age = 100 pet.run_turn() assert pet.is_alive() == False
def test_pet_eating_max_health(self): frames_per_second, x_coordinate, y_coordinate = 30, 0, 0 pet = Pet(frames_per_second, Coordinate(x_coordinate, y_coordinate)) example_food = ExampleFood() pet.eat(example_food) assert pet.fullness == example_food.get_consumable_weight() assert pet.get_health() == pet.max_health
def test_add_multiple_same_food(self): food_list = FoodInventory([], Coordinate(0, 0)) food_list.add_food(ExampleFood()) food_list.add_food(ExampleFood()) assert len(food_list.food_list) is 2 assert len(food_list.get_available_food()) is 1 assert food_list.get_available_food()["ExampleFood"] is 2
def test_pet_awake(self): frames_per_second, x_coordinate, y_coordinate = 30, 0, 0 pet = Pet(frames_per_second, Coordinate(x_coordinate, y_coordinate)) pet.set_state(ActorState.ASLEEP) assert pet.get_state() == ActorState.ASLEEP pet.awake() assert pet.get_state() == ActorState.AWAKE
def test_pet_eating_low_health(self): frames_per_second, x_coordinate, y_coordinate = 30, 0, 0 pet = Pet(frames_per_second, Coordinate(x_coordinate, y_coordinate)) new_health = 10 pet.health = new_health example_food = ExampleFood() pet.eat(example_food) assert pet.fullness == example_food.get_consumable_weight() assert pet.get_health( ) == ExampleFood().get_consumable_value() + new_health
def test_coordinate_get_coordinate(self): coordinate = Coordinate(10, 20) assert coordinate.get_coordinate() == (10, 20)
def test_create_coordinate(self): coordinate = Coordinate(0, 0) assert isinstance(coordinate, Coordinate) assert coordinate.x_position == 0 assert coordinate.y_position == 0
def test_coordinate_get_x(self): coordinate = Coordinate(10, 0) assert coordinate.get_x() == 10
def test_coordinate_get_y(self): coordinate = Coordinate(0, 10) assert coordinate.get_y() == 10
def test_creating_non_empty_inventory(self): food_list = FoodInventory([ExampleFood()], Coordinate(0, 0)) assert len(food_list.food_list) is 1
def test_eat_empty_food_list(self): food_list = FoodInventory([], Coordinate(0, 0)) food_to_eat = food_list.eat_food() assert food_to_eat is None
def test_add_food(self): food_list = FoodInventory([], Coordinate(0, 0)) food_list.add_food(ExampleFood()) assert len(food_list.food_list) is 1
def test_creating_empty_inventory(self): food_list = FoodInventory([], Coordinate(0, 0)) assert len(food_list.food_list) is 0
def test_pet_is_alive(self): frames_per_second, x_coordinate, y_coordinate = 30, 0, 0 pet = Pet(frames_per_second, Coordinate(x_coordinate, y_coordinate)) assert pet.is_alive() == True