def test_knights_fight_on_move(arena): knight = Knight('Marcus Junius', (0, 0), ARBITRARY_STATS) other_knight = Knight('Gaius Julius', (1, 0), ARBITRARY_STATS) arena.set_pieces(knight, other_knight) with patch.object(knight, 'attack_knight'): arena.run_instruction(knight, Direction.SOUTH) knight.attack_knight.assert_called_with(other_knight)
def test_knight_falls_off_edge_and_drowns(): origin, limits = (0, 0), (7, 7) towards_water = { Direction.NORTH: origin, Direction.EAST: limits, Direction.SOUTH: limits, Direction.WEST: origin, } for direction, position in towards_water.items(): knight = Knight('Sterling', position, ARBITRARY_STATS) knight.move(direction, limits) assert knight.status == Status.DROWNED assert knight.position is None
def make_pieces(): knights = { 'R': Knight('red', (0, 0), BASE_STATS), 'B': Knight('blue', (7, 0), BASE_STATS), 'G': Knight('green', (7, 7), BASE_STATS), 'Y': Knight('yellow', (0, 7), BASE_STATS), } items = [ # in priority order Item('axe', (2, 2), (2, 0)), Item('magic_staff', (5, 2), (1, 1)), Item('dagger', (2, 5), (1, 0)), Item('helmet', (5, 5), (1, 1)), ] return knights, items
def test_knight_position_updates_on_move(): row, col = original_position = (0, 0) knight = Knight('Moves', original_position, ARBITRARY_STATS) knight.move(Direction.EAST) assert knight.position.row == 0 assert knight.position.col == 1 knight.move(Direction.SOUTH) assert knight.position.row == 1 assert knight.position.col == 1 knight.move(Direction.WEST) assert knight.position.row == 1 assert knight.position.col == 0 knight.move(Direction.NORTH) assert knight.position.row == row assert knight.position.col == col
def test_knight_equips_item_on_move(arena): starting_position = (0, 0) knight = Knight('Merciless Ming', starting_position, ARBITRARY_STATS) item = Item('Ming Vase', (0, 1), ARBITRARY_STATS) arena.set_pieces(knight, item) arena.run_instruction(knight, Direction.EAST) assert knight.item is item
def test_tile_holds_only_one_knight(arena): position = (2, 3) knights = {Knight(str(i), position, ARBITRARY_STATS) for i in range(2)} arena.set_pieces(*knights) with pytest.raises(InvalidGameStateException): tile = arena.tile(position) tile.knight
def test_empty_tile_holds_no_pieces(arena): position = (2, 3) empty_position = (3, 4) tile = arena.tile(empty_position) knight = Knight('Starboy', position, ARBITRARY_STATS) items = {Item(str(i), position, ARBITRARY_STATS) for i in range(2)} arena.set_pieces(knight, *items) assert not tile.items assert tile.knight is None
def test_tile_holds_pieces(arena): """Since pieces fetched dynamically, tile creation time wont matter.""" position = (2, 3) tile = arena.tile(position) knight = Knight('Starboy', position, ARBITRARY_STATS) items = {Item(str(i), position, ARBITRARY_STATS) for i in range(2)} arena.set_pieces(knight, *items) assert tile.knight is knight assert len(tile.items) == len(items) for item in items: assert item in tile.items
def test_knight_throws_item_to_bank_after_falling_off(): original_position = limits = (7, 7) knight = Knight('Sterling', original_position, ARBITRARY_STATS) item = Item('Luckies', original_position, ARBITRARY_STATS) knight.equip(item) knight.move(Direction.SOUTH, limits) assert knight.item is None assert item.knight is None assert item.position == original_position assert (knight.attack, knight.defense) == (0, 0)
def test_equipped_item_moves_with_knight(): position = (0, 0) knight = Knight('Hunter', position, ARBITRARY_STATS) item = Item('Fist', position, ARBITRARY_STATS) knight.equip(item) knight.move(Direction.EAST) assert knight.position == item.position knight.move(Direction.SOUTH) assert knight.position == item.position knight.move(Direction.WEST) assert knight.position == item.position knight.move(Direction.NORTH) assert knight.position == item.position
def test_attacking_knight_kills_equal_knight(knight): """The suprise bonus should win out.""" inverted_stats = (knight.defense, knight.attack) equal_knight = Knight('Nalamayhs', ARBITRARY_POSITION, inverted_stats) knight.attack_knight(equal_knight) _test_battle_outcome(winner=knight, loser=equal_knight)
def test_attacking_knight_killed_by_stronger_knight(knight): stronger_stats = (knight.defense, knight.attack + 1) stronger_knight = Knight('Robin', ARBITRARY_POSITION, stronger_stats) knight.attack_knight(stronger_knight) _test_battle_outcome(winner=stronger_knight, loser=knight)
def test_attacking_knight_kills_weaker_knight(knight): weaker_stats = (knight.defense, knight.attack - 1) weaker_knight = Knight('Robin', ARBITRARY_POSITION, weaker_stats) knight.attack_knight(weaker_knight) _test_battle_outcome(winner=knight, loser=weaker_knight)
def knight(): return Knight('Shyamalan', ARBITRARY_POSITION, ARBITRARY_STATS)
def test_knight_moves_on_instruction(arena): starting_position = (0, 0) knight = Knight('Merciless Ming', starting_position, ARBITRARY_STATS) arena.set_pieces(knight) arena.run_instruction(knight, Direction.SOUTH) assert knight.position == (1, 0)