def test_trapseed_does_not_become_venus_after_10_moves_on_top_of_only_flower(): turn_num = 12345 game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=((), ), flowers=((Flower(9, 5, DEFAULT_GAME_PARAMETERS, expires=20000), ), ), turn_num=turn_num, game_length=sentinel.game_length) game.boards[0].inflight[sentinel.seed_1] = TrapSeed( 9, 8, 0, mock_game_params.trap_seed_lifespan) for _ in range(DEFAULT_GAME_PARAMETERS.trap_seed_lifespan + 1): game.turn([None]) assert { vid: volant for (vid, volant) in game.boards[0].inflight.items() if not isinstance(volant, Bee) } == { sentinel.seed_1: TrapSeed(9, 5, 0, -1) } assert game.boards[0].flowers == (Flower(9, 5, DEFAULT_GAME_PARAMETERS, expires=20000), ) assert game.boards[0].hives == ()
def test_flowers_remain_if_unexpired(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[sentinel.hives], flowers=[[ Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=100) ]], turn_num=0, game_length=sentinel.game_length) game.remove_dead_flowers() assert game.boards[0].flowers == (Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=100), )
def test_apply_venus_command_over_existing_flower(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=((Hive(9, 9), ), ), flowers=((Flower(0, 0, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits), Flower(9, 9, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits)), ), turn_num=12345, game_length=sentinel.game_length) game.boards[0].inflight[sentinel.seed_1] = TrapSeed( 0, 0, 0, DEFAULT_GAME_PARAMETERS.trap_seed_lifespan) game.apply_commands([dict(entity=sentinel.seed_1, command="flower")]) assert game.boards[0].inflight == {} assert sorted(map(str, game.boards[0].flowers)) == sorted( map(str, (VenusBeeTrap( 0, 0, DEFAULT_GAME_PARAMETERS, 1, 0, expires=12345 + DEFAULT_GAME_PARAMETERS.flower_lifespan), Flower(9, 9, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits)))) assert game.boards[0].hives == (Hive(9, 9), )
def test_visit_flowers_two_bees_two_flowers(): game = GameState( game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=(sentinel.hives, ), flowers=((Flower(5, 5, DEFAULT_GAME_PARAMETERS, 1, expires=DEFAULT_GAME_PARAMETERS.flower_lifespan), Flower(5, 4, DEFAULT_GAME_PARAMETERS, 1, expires=DEFAULT_GAME_PARAMETERS.flower_lifespan)), ), game_length=sentinel.game_length) game.boards[0].inflight[sentinel.bee_1] = Bee(5, 5, 0, 10, DEFAULT_GAME_PARAMETERS, 0) game.boards[0].inflight[sentinel.bee_2] = Bee(5, 4, 0, 10, DEFAULT_GAME_PARAMETERS, 0) game.visit_flowers() assert game.boards[0].inflight == { sentinel.bee_1: Bee(5, 5, 0, 10 + DEFAULT_GAME_PARAMETERS.bee_energy_boost_per_nectar, DEFAULT_GAME_PARAMETERS, 1), sentinel.bee_2: Bee(5, 4, 0, 10 + DEFAULT_GAME_PARAMETERS.bee_energy_boost_per_nectar, DEFAULT_GAME_PARAMETERS, 1), }
def test_only_expired_flowers_removed_from_mixed_bunch(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[sentinel.hives], flowers=[[ Flower(sentinel.x1, sentinel.y1, DEFAULT_GAME_PARAMETERS, sentinel.potency1, sentinel.visits1, expires=10), Flower(sentinel.x2, sentinel.y2, DEFAULT_GAME_PARAMETERS, sentinel.potency2, sentinel.visits2, expires=50), Flower(sentinel.x3, sentinel.y3, DEFAULT_GAME_PARAMETERS, sentinel.potency3, sentinel.visits3, expires=100), VenusBeeTrap(sentinel.x3, sentinel.y3, DEFAULT_GAME_PARAMETERS, sentinel.potency3, sentinel.visits3, expires=50), VenusBeeTrap(sentinel.x3, sentinel.y3, DEFAULT_GAME_PARAMETERS, sentinel.potency3, sentinel.visits3, expires=100), ]], turn_num=75, game_length=sentinel.game_length) game.remove_dead_flowers() assert game.boards[0].flowers == ( Flower(sentinel.x3, sentinel.y3, DEFAULT_GAME_PARAMETERS, sentinel.potency3, sentinel.visits3, expires=100), VenusBeeTrap(sentinel.x3, sentinel.y3, DEFAULT_GAME_PARAMETERS, sentinel.potency3, sentinel.visits3, expires=100), )
def test_keep_one_healthy_flower_if_all_expired(): healthy_flower = Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=99) venus = VenusBeeTrap(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=99) flowers = [healthy_flower, venus] game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[sentinel.hives], flowers=[flowers], turn_num=100, game_length=sentinel.game_length) game.remove_dead_flowers() assert len(game.boards[0].flowers) == 1 assert game.boards[0].flowers[0] == healthy_flower
def detail_advance(board_width, board_height, hives, flowers, inflight, turn_num, cmd): board = Board(game_params=DEFAULT_GAME_PARAMETERS, board_width=board_width, board_height=board_height, hives=[Hive(*i) for i in hives], flowers=[Flower.from_json(i) for i in flowers], neighbours={ 'N': 1, 'S': 1, 'E': 1, 'W': 1, 'NW': 1, 'SE': 1, }, inflight={ volant_id: volant_from_json(volant) for volant_id, volant in inflight.items() }, dead_bees=0) board._connect_to_neighbours([board, _OtherBoard()]) board.apply_command(cmd, turn_num) board.remove_dead_flowers(turn_num) board.move_volants() lost = set(board.send_volants()) received = set(board.receive_volants()) board.visit_flowers(Random()) landed = set(board.land_bees()) crashed = {k: set(v) for k, v in board.detect_crashes().items()} return board.hives, board.flowers, board.inflight, crashed, landed, lost, received
def test_create_hive_deletes_flower(): queen_bee = QueenBee(1, 2, 0, 10, DEFAULT_GAME_PARAMETERS, nectar=sentinel.nectar) game = GameState( game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[[]], flowers=[[Flower(queen_bee.x, queen_bee.y, DEFAULT_GAME_PARAMETERS)]], game_length=sentinel.game_length) game.boards[0].inflight[sentinel.queenbee_1] = queen_bee game.apply_commands( [dict(entity=sentinel.queenbee_1, command="create_hive")]) assert game.boards[0].hives[0] == Hive(queen_bee.x, queen_bee.y, queen_bee.nectar) assert len(game.boards[0].inflight) == 0 assert len(game.boards[0].flowers) == 0
def test_only_queenbees_can_create_hive(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[[]], flowers=[[Flower(1, 2, DEFAULT_GAME_PARAMETERS)]], game_length=sentinel.game_length) queen_bee = QueenBee(4, 4, 0, 10, DEFAULT_GAME_PARAMETERS, nectar=sentinel.nectar) game.boards[0].inflight[sentinel.bee_1] = Bee(4, 5, 0, 10, DEFAULT_GAME_PARAMETERS) game.boards[0].inflight[sentinel.queenbee_1] = queen_bee game.boards[0].inflight[sentinel.seed_1] = Seed(3, 3, 0) with pytest.raises(RuntimeError): game.apply_commands( [dict(entity=sentinel.bee_1, command="create_hive")]) with pytest.raises(RuntimeError): game.apply_commands( [dict(entity=sentinel.seed_1, command="create_hive")]) game.apply_commands( [dict(entity=sentinel.queenbee_1, command="create_hive")]) assert game.boards[0].hives[0] == Hive(queen_bee.x, queen_bee.y, queen_bee.nectar) assert len(game.boards[0].inflight) == 2
def test_apply_flower_command_empty_tile(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=((Hive(9, 9), ), ), flowers=((Flower(0, 0, DEFAULT_GAME_PARAMETERS), ), ), turn_num=12345, game_length=sentinel.game_length) game.boards[0].inflight[sentinel.seed_1] = Seed(4, 5, 0) game.apply_commands([dict(entity=sentinel.seed_1, command="flower")]) assert game.boards[0].inflight == {} assert game.boards[0].flowers == (Flower(0, 0, DEFAULT_GAME_PARAMETERS), Flower(4, 5, DEFAULT_GAME_PARAMETERS, expires=12645)) assert game.boards[0].hives == (Hive(9, 9), )
def test_apply_venus_command_over_existing_single_hive(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=((Hive(9, 9), ), ), flowers=((Flower(0, 0, DEFAULT_GAME_PARAMETERS), ), ), turn_num=12345, game_length=sentinel.game_length) game.boards[0].inflight[sentinel.seed_1] = TrapSeed( 9, 9, 0, DEFAULT_GAME_PARAMETERS.trap_seed_lifespan) game.apply_commands([dict(entity=sentinel.seed_1, command="flower")]) assert game.boards[0].inflight == { sentinel.seed_1: TrapSeed(9, 9, 0, DEFAULT_GAME_PARAMETERS.trap_seed_lifespan) } assert game.boards[0].flowers == (Flower(0, 0, DEFAULT_GAME_PARAMETERS), ) assert game.boards[0].hives == (Hive(9, 9), )
def test_flowers_and_venus_removed_if_expired(): flowers = [ Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=99), Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=102), VenusBeeTrap(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=99), VenusBeeTrap(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=102) ] game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[sentinel.hives], flowers=[flowers], turn_num=100, game_length=sentinel.game_length) game.remove_dead_flowers() assert game.boards[0].flowers == (flowers[1], flowers[3])
def test_visit_flowers_two_bees_two_flowers_more_potent_and_live_longer(): flower1 = Flower(5, 5, DEFAULT_GAME_PARAMETERS, 3, expires=DEFAULT_GAME_PARAMETERS.flower_lifespan) flower2 = Flower(5, 4, DEFAULT_GAME_PARAMETERS, 2, expires=DEFAULT_GAME_PARAMETERS.flower_lifespan) game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=(sentinel.hives, ), flowers=((flower1, flower2), ), game_length=sentinel.game_length) game.boards[0].inflight[sentinel.bee_1] = Bee(5, 5, 0, 10, DEFAULT_GAME_PARAMETERS, 3) game.boards[0].inflight[sentinel.bee_2] = Bee(5, 4, 0, 10, DEFAULT_GAME_PARAMETERS, 2) game.visit_flowers() assert flower1.expires == flower2.expires == DEFAULT_GAME_PARAMETERS.flower_lifespan + DEFAULT_GAME_PARAMETERS.flower_lifespan_visit_impact assert game.boards[0].inflight == { sentinel.bee_1: Bee(5, 5, 0, 10 + 3 * DEFAULT_GAME_PARAMETERS.bee_energy_boost_per_nectar, DEFAULT_GAME_PARAMETERS, 5), sentinel.bee_2: Bee(5, 4, 0, 10 + 2 * DEFAULT_GAME_PARAMETERS.bee_energy_boost_per_nectar, DEFAULT_GAME_PARAMETERS, 4), }
def test_trapseed_becomes_venus_after_10_moves_on_top_of_a_flower(): turn_num = 12345 game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=((), ), flowers=((Flower(9, 5, DEFAULT_GAME_PARAMETERS, expires=20000), Flower(5, 5, DEFAULT_GAME_PARAMETERS, expires=20000)), ), turn_num=turn_num, game_length=sentinel.game_length) game.boards[0].inflight[sentinel.seed_1] = TrapSeed( 9, 8, 0, mock_game_params.trap_seed_lifespan) for _ in range(DEFAULT_GAME_PARAMETERS.trap_seed_lifespan + 1): game.turn([None]) assert not [(_, volant) for (_, volant) in game.boards[0].inflight.items() if isinstance(volant, TrapSeed)] assert sorted(map(str, game.boards[0].flowers)) == sorted( map(str, (VenusBeeTrap( 9, 5, DEFAULT_GAME_PARAMETERS, expires=turn_num + DEFAULT_GAME_PARAMETERS.trap_seed_lifespan + DEFAULT_GAME_PARAMETERS.flower_lifespan), Flower(5, 5, DEFAULT_GAME_PARAMETERS, expires=20000)))) assert game.boards[0].hives == ()
def test_remove_over_expired_flowers_if_new_are_made(): flowers = [ Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=99) ] game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[sentinel.hives], flowers=[flowers], turn_num=100, game_length=sentinel.game_length) game.remove_dead_flowers() assert len(game.boards[0].flowers) == 1 assert game.boards[0].flowers[0] in flowers flower = Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=203) game.boards[0].flowers += (flower, ) game.remove_dead_flowers() assert len(game.boards[0].flowers) == 1 assert game.boards[0].flowers[0] == flower
def apply_command_and_advance(board_width, board_height, hives, flowers, inflight, turn_num, cmd): """ You can use this function to try out a potential move and test what happens. Parameters ---------- board_width: int The number of tiles in each row of the board board_height: int The number of tiles in each column of the board hives: tuple[`Hive`+] Hives present on player's board flowers: tuple[`Flower`+] Flowers present on player's board inflight: dict [str, `Volant`] A dictionary of volant identifiers to volant turn_num: int The number of the current turn Returns ------- crashed: dict [str, set[str]] A dictionary of causes to Volant identifiers which have been removed landed: set[`str`] A set of Bee identifiers which have landed back on a hive and are no longer active on the board lost: set[`str`] A set of Volant identifiers which have moved over the boundary into a neighbouring board """ board = Board(game_params=DEFAULT_GAME_PARAMETERS, board_width=board_width, board_height=board_height, hives=[Hive(*i) for i in hives], flowers=[Flower.from_json(i) for i in flowers], neighbours={'N':1, 'S':1, 'E':1, 'W':1, 'NW':1, 'SE':1, }, inflight={volant_id: volant_from_json(volant) for volant_id, volant in inflight.items()}, dead_bees=0) board._connect_to_neighbours([board, _OtherBoard()]) board.apply_command(cmd, turn_num) board.remove_dead_flowers(turn_num) board.move_volants() lost = set(board.send_volants()) board.visit_flowers(Random()) landed = set(board.land_bees()) crashed = {k: set(v) for k, v in board.detect_crashes().items()} return crashed, landed, lost
def test_queenbees_cant_create_hive_on_top_of_existing_hive(): game = initialise_game(DEFAULT_GAME_PARAMETERS, 1, 10, 10, 1, 0, 23) board = game.boards[0] board.hives = (Hive(4, 4, 10), ) board.flowers = (Flower(1, 1, DEFAULT_GAME_PARAMETERS, expires=9999), ) # create queen bee on top of existing hive, like it has just launched board.inflight = { sentinel.queenbee_id: QueenBee(4, 4, 180, 10, DEFAULT_GAME_PARAMETERS) } # immediately create hive game.turn([{"entity": sentinel.queenbee_id, "command": "create_hive"}]) # should only be one hive (not two) assert len(board.hives) == 1 # it should be the new hive not the original (with 10 nectar) assert board.hives[0].nectar == 0 # queen bee should be gone as she has 'hived' assert sentinel.queenbee_id not in board.inflight
def test_seed_does_not_visit_flower(): game = GameState( game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=(sentinel.hives, ), flowers=((Flower( 5, 5, DEFAULT_GAME_PARAMETERS, 1, DEFAULT_GAME_PARAMETERS.flower_lifespan_visit_impact), ), ), game_length=sentinel.game_length) game.boards[0].inflight[sentinel.seed_1] = Seed(5, 5, 0) game.visit_flowers() assert game.boards[0].inflight == {sentinel.seed_1: Seed(5, 5, 0)}
def test_queenbees_die_immediately_when_landing_on_hives(): game = initialise_game(DEFAULT_GAME_PARAMETERS, 1, 10, 10, 1, 0, 23) game.boards[0].hives = (Hive(4, 4, 0), ) game.boards[0].flowers = (Flower(1, 1, DEFAULT_GAME_PARAMETERS, expires=9999), ) # create queen bee that will land on hive on the next move game.boards[0].inflight = { sentinel.queenbee_id: QueenBee(4, 5, 180, 10, DEFAULT_GAME_PARAMETERS) } # with no command, queen bee should land and die game.turn([None]) # make sure the queen is gone and can't execute a hive command on top of existing hive with pytest.raises(RuntimeError) as err: game.turn([{"entity": sentinel.queenbee_id, "command": "create_hive"}]) assert "Unknown entity" in str(err.value)
def test_apply_command_and_advance_no_command_bee_saved_from_exhaustion_by_flower( ): crashed, landed, lost = apply_command_and_advance( board_width=10, board_height=10, hives=[], flowers=[Flower(0, 1, DEFAULT_GAME_PARAMETERS, 1, 0, 1000).to_json()], inflight={ "abee": ("Bee", 0, 0, 0, 0, DEFAULT_GAME_PARAMETERS._asdict(), 0) }, turn_num=0, cmd=None) assert not crashed['collided'] assert not crashed['exhausted'] assert not crashed['headon'] assert not crashed['seeds'] assert not landed assert not lost
def test_no_expiry_causes_error(): game = GameState(game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=[sentinel.hives], flowers=[[ Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, expires=None) ]], turn_num=0, game_length=sentinel.game_length) with pytest.raises(RuntimeError): game.remove_dead_flowers()
def test_visiting_flower_does_not_create_seeds_when_not_seed_threshold(visits): game = GameState( game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=(sentinel.hives, ), flowers=((Flower( 5, 5, DEFAULT_GAME_PARAMETERS, 3, visits - 1, DEFAULT_GAME_PARAMETERS.flower_lifespan_visit_impact), ), ), game_length=sentinel.game_length) game.boards[0].inflight[sentinel.bee_1] = Bee(5, 5, 0, 10, DEFAULT_GAME_PARAMETERS) game.visit_flowers() assert game.boards[0].inflight == { sentinel.bee_1: Bee(5, 5, 0, 85, DEFAULT_GAME_PARAMETERS, 3) }
def test_visiting_flower_creates_seed_every_ten_visits(_, visits): game = GameState( game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=(sentinel.hives, ), flowers=((Flower( 5, 5, DEFAULT_GAME_PARAMETERS, 3, visits - 1, DEFAULT_GAME_PARAMETERS.flower_lifespan_visit_impact), ), ), game_length=sentinel.game_length) game.boards[0].inflight[sentinel.bee_1] = Bee(5, 5, 0, 10, DEFAULT_GAME_PARAMETERS) game.visit_flowers() assert game.boards[0].inflight == { sentinel.bee_1: Bee(5, 5, 0, 85, DEFAULT_GAME_PARAMETERS, 3), 'sentinel.uuid': Seed(5, 5, ANY) }
def test_serialise_deserialise_game_state_to_json(nboards): params = GameParameters(launch_probability=1.0, initial_energy=10, dead_bee_score_factor=-5, hive_score_factor=100, flower_score_factor=100, nectar_score_factor=2, queen_bee_nectar_threshold=20, bee_nectar_capacity=5, bee_energy_boost_per_nectar=25, flower_seed_visit_initial_threshold=10, flower_seed_visit_subsequent_threshold=10, flower_visit_potency_ratio=10, flower_lifespan=100, flower_lifespan_visit_impact=30, trap_seed_probability=1, venus_score_factor=-50, trap_seed_lifespan=10) game = GameState( game_params=params, game_id=sentinel.game_id, boards=nboards, board_width=sentinel.board_width, board_height=sentinel.board_height, hives=[(Hive(sentinel.hive_x, sentinel.hive_y, 23 * nboards), )] * nboards, flowers=[(Flower(sentinel.fx, sentinel.fy, DEFAULT_GAME_PARAMETERS, sentinel.flower_size), )] * nboards, game_length=sentinel.game_length) # make sure there are some bees on the boards, and some of them will be queens # as the nectar in the hives should be over the queen making threshold with patch("hiveminder.game_state.rngs", {sentinel.game_id: Random(0)}): game.launch_bees(sentinel.turn_num) game_state_json = game.to_json() game_state_bounce = game.from_json(game_state_json) assert game == game_state_bounce
def test_visit_flowers_does_not_feed_bee_if_not_on_flower(): game = GameState( game_params=DEFAULT_GAME_PARAMETERS, game_id=sentinel.game_id, boards=1, board_width=10, board_height=10, hives=(sentinel.hives, ), flowers=((Flower( 5, 5, DEFAULT_GAME_PARAMETERS, 1, expires=DEFAULT_GAME_PARAMETERS.flower_lifespan), ), ), game_length=sentinel.game_length) game.boards[0].inflight[sentinel.bee_1] = Bee(5, 4, 0, 10, DEFAULT_GAME_PARAMETERS, 1) game.visit_flowers() assert game.boards[0].inflight == { sentinel.bee_1: Bee(5, 4, 0, 10, DEFAULT_GAME_PARAMETERS, 1) }
def test_can_not_hash_a_flower(): h = Flower(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency) with pytest.raises(TypeError) as err: hash(h) assert str(err.value) == "unhashable type: 'Flower'"
def test_str(): assert str(Flower(1337, 2000, DEFAULT_GAME_PARAMETERS, 54321, 1234, 3000)) == "Flower(1337, 2000, %s, 54321, 1234, 3000)" % DEFAULT_GAME_PARAMETERS._asdict()
def test_can_convert_flower_to_from_json(flower_type): flower = flower_type(sentinel.x, sentinel.y, DEFAULT_GAME_PARAMETERS, sentinel.potency, sentinel.visits, sentinel.expires) bounce_flower = Flower.from_json(flower.to_json()) assert flower == bounce_flower
def test_Flowers_equality(x1, y1, size1, x2, y2, size2, are_equal): h1 = Flower(x1, y1, DEFAULT_GAME_PARAMETERS, size1) h2 = Flower(x2, y2, DEFAULT_GAME_PARAMETERS, size2) assert (h1 == h2) == are_equal assert (h1 != h2) == (not are_equal)