Example #1
0
 def test_starving(self):
     client = SimulationClient('sqlite:///:memory:')
     grid = SimulationGrid(persistence=client,
                           simulation_parameters=sim_config)
     turn_to_starve = sim_config['shark_starving']
     # set turn to more...
     grid._sim_turn = turn_to_starve + 1
     grid._check_deads()
     assert len(
         grid._persistence.get_animals_by_type(grid._sid,
                                               Animal.Shark)) == 0
Example #2
0
    def test_empty(self):
        '''
        Tests that an empty grid throws an exception of no sharks
        '''
        client = SimulationClient('sqlite:///:memory:')
        grid = SimulationGrid(persistence=client,
                              simulation_parameters=sim_config_empty)

        with pytest.raises(EndOfSimulatioError):
            grid._check_deads()

        with pytest.raises(EndOfSimulatioError):
            grid.play_turn()
Example #3
0
    def test_fish_only(self):
        '''
        Test if non-empty, but fish only: the simulation should end
        Make two cases:
            (1) add manually the fish to empty grid
            (2) use the config with updated value for corresponding key
        '''
        # No. 1
        client = SimulationClient('sqlite:///:memory:')
        grid = SimulationGrid(persistence=client,
                              simulation_parameters=sim_config_empty)
        a_list = [
            (Animal.Fish, SquareGridCoordinate(x=1, y=1)),
        ]

        for t, c in a_list:
            client.init_animal(sim_id=grid._sid,
                               current_turn=0,
                               animal_type=t,
                               coordinate=c)

        with pytest.raises(EndOfSimulatioError):
            grid._check_deads()

        with pytest.raises(EndOfSimulatioError):
            grid.play_turn()

        # repeat the same for No. 2
        del client, grid, a_list

        sim_config_empty_local = copy.deepcopy(sim_config_empty)
        sim_config_empty_local['init_nb_fish'] = 1

        client = SimulationClient('sqlite:///:memory:')
        grid = SimulationGrid(persistence=client,
                              simulation_parameters=sim_config_empty_local)
        with pytest.raises(EndOfSimulatioError):
            grid._check_deads()

        with pytest.raises(EndOfSimulatioError):
            grid.play_turn()
Example #4
0
    def test_starving(self):
        client = SimulationClient('sqlite:///:memory:')
        grid = SimulationGrid(persistence=client,
                              simulation_parameters=sim_config)
        turn_to_starve = sim_config['shark_starving']
        # set turn to more...
        grid._sim_turn = turn_to_starve + 1
        grid._check_deads()
        assert len(
            grid._persistence.get_animals_by_type(grid._sid,
                                                  Animal.Shark)) == 0

        # amend this test by adding further checks
        # after the first turn we should have killed the sharks
        with pytest.raises(EndOfSimulatioError):
            grid.check_simulation_ends()

        with pytest.raises(EndOfSimulatioError):
            grid._check_deads()

        with pytest.raises(EndOfSimulatioError):
            grid.play_turn()