def test_can_convert_Bee_to_json(BeeType): assert (BeeType(sentinel.x, sentinel.y, sentinel.h, sentinel.nrg, DEFAULT_GAME_PARAMETERS, sentinel.nectar).to_json() == [ BeeType.__name__, sentinel.x, sentinel.y, sentinel.h, sentinel.nrg, DEFAULT_GAME_PARAMETERS._asdict(), sentinel.nectar ])
def test_apply_command_and_advance_command_stops_two_bees_crashing(): crashed, landed, lost = apply_command_and_advance( board_width=10, board_height=10, hives=[], flowers=[], inflight={ "abee": ("Bee", 0, 0, 0, 100, DEFAULT_GAME_PARAMETERS._asdict(), 0), "anotherbee": ("Bee", 0, 2, 180, 100, DEFAULT_GAME_PARAMETERS._asdict(), 0) }, turn_num=0, cmd=dict(entity="anotherbee", command=120)) assert not crashed['collided'] assert not crashed['exhausted'] assert not crashed['headon'] assert not crashed['seeds'] assert not landed assert not lost
def test_apply_command_and_advance_no_command_nothing_happens(): crashed, landed, lost = apply_command_and_advance( board_width=10, board_height=10, hives=[], flowers=[], inflight={ "abee": ("Bee", 1, 1, 0, 100, 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_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
from hiveminder.board import volant_from_json from hiveminder.bee import Bee, QueenBee from hiveminder.seed import Seed from hiveminder.game_params import DEFAULT_GAME_PARAMETERS from mock import sentinel import pytest @pytest.mark.parametrize("json, expected_type", [ ([ "Bee", sentinel.x, sentinel.y, sentinel.h, sentinel.e, DEFAULT_GAME_PARAMETERS._asdict(), sentinel.n ], Bee), ([ "QueenBee", sentinel.x, sentinel.y, sentinel.h, sentinel.e, DEFAULT_GAME_PARAMETERS._asdict(), sentinel.n ], QueenBee), (["Seed", sentinel.x, sentinel.y, sentinel.h], Seed), ]) def test_volant_from_json(json, expected_type): assert isinstance(volant_from_json(json), expected_type)
def test_repr(BeeType): assert repr( BeeType(1337, 2000, 123456, 71077345, DEFAULT_GAME_PARAMETERS, 1234)) == "{}(1337, 2000, 123456, 71077345, {}, 1234)".format( BeeType.__name__, DEFAULT_GAME_PARAMETERS._asdict())
def test_can_read_Bee_from_json(BeeType): assert BeeType.from_json([ sentinel.type, sentinel.x, sentinel.y, sentinel.h, sentinel.nrg, DEFAULT_GAME_PARAMETERS._asdict(), sentinel.nectar ]) == BeeType(sentinel.x, sentinel.y, sentinel.h, sentinel.nrg, DEFAULT_GAME_PARAMETERS, sentinel.nectar)
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_repr_venus_bee_trap(): assert (repr(VenusBeeTrap(1337, 2000, DEFAULT_GAME_PARAMETERS, 54321, 1234, 3000)) == "VenusBeeTrap(1337, 2000, %s, 54321, 1234, 3000)" % DEFAULT_GAME_PARAMETERS._asdict())