def test_move_to_occupied_position(self, mover, obstacle): positions = {Point(0, 0): mover, Point(1, 1): obstacle} roster = Roster.for_mapping(positions, area_containing(positions)) move = Move(mover, Point(0, 0), Point(1, 1)) with pytest.raises(ValueError): move.next_roster(roster)
def test_move_of_non_existent_character(self, character, non_existent_character): roster = Roster.for_mapping({Point(0, 0): character}, Area(Point(0, 0), Point(5, 5))) move = Move(non_existent_character, Point(1, 1), Point(2, 1)) with pytest.raises(ValueError): move.next_roster(roster)
def test_preserves_instigator(self, instigator, target): positions = {Point(0, 0): instigator, Point(1, 1): target} roster = Roster.for_mapping(positions, area_containing(positions)) paint = ChangeCharacter(instigator, Point(1, 1), paint_blue) new_roster = paint.next_roster(roster) assert new_roster.character_at(Point(0, 0)) is instigator
def test_move_out_of_bounds(self, area_and_positions, new_position): area, positions = area_and_positions position, character = next(iter(positions.items())) assume(new_position not in area) roster = Roster.for_mapping(positions, area) move = Move(character, position, new_position) with pytest.raises(ValueError): move.next_roster(roster)
def test_changes_target(self, instigator): target = Character(colour="red") positions = {Point(0, 0): instigator, Point(1, 1): target} roster = Roster.for_mapping(positions, area_containing(positions)) paint = ChangeCharacter(instigator, Point(1, 1), paint_blue) new_roster = paint.next_roster(roster) new_character = new_roster.character_at(Point(1, 1)) assert new_character is not None assert new_character.colour == "blue"
def test_character_moves(self, positions_and_item, move_vector): positions, (position, character) = positions_and_item new_position = position + move_vector all_positions = list(positions) + [new_position] assume(not any(pos == new_position for pos, _ in positions.items())) roster = Roster.for_mapping(positions, area_containing(all_positions)) move = Move(character, position, new_position) next_roster = move.next_roster(roster) assert next_roster.character_at(new_position) == character
def test_viewpoint_multiple_characters(self, char1, char2): roster = Roster.for_mapping( { Point(1, 1): char1, Point(2, 0): char2 }, area=Area(Point(0, 0), Point(3, 3)), ) viewpoint = Viewpoint(Point(0, 1), roster) assert viewpoint.occupied_points_in( BoundingBox.range(1)) == {Vector(1, 0)} assert viewpoint.occupied_points_in(BoundingBox.range(5)) == { Vector(1, 0), Vector(2, -1), }
def test_fails_if_instigator_not_in_roster(self, instigator, target): roster = Roster.for_mapping({Point(0, 0): target}, Area(Point(0, 0), Point(5, 5))) action = ChangeCharacter(instigator, target, paint_blue) with pytest.raises(ValueError): action.next_roster(roster)
def test_zero_move_preserves_roster(self, positions_and_item): positions, (position, character) = positions_and_item roster = Roster.for_mapping(positions, area_containing(positions)) assert Move(character, position, position).next_roster(roster) == roster
def test_characters_outside_area(self, positions, area): assume(not all(p in area for p in positions)) with pytest.raises(ValueError) as e: Roster.for_mapping(positions, area)
def test_move_preserves_non_moving_character(self, mover, non_mover): positions = {Point(0, 0): mover, Point(1, 1): non_mover} roster = Roster.for_mapping(positions, area_containing(positions)) move = Move(mover, Point(0, 0), Point(0, 1)) assert move.next_roster(roster).character_at(Point(1, 1)) is non_mover
def test_empty_roster(self): characters: Mapping[Point, Any] = {} roster = Roster.for_mapping(characters, Area(Point(0, 0), Point(5, 5))) assert not roster
def test_value_equality(self, positions): area = area_containing(positions) assert Roster.for_mapping(positions, area) == Roster.for_mapping( positions.copy(), area)
def test_non_empty_roster(self, positions): roster = Roster.for_mapping(positions, area_containing(positions)) assert roster
def test_rejects_duplicate_character(self, character): positions = {Point(0, 0): character, Point(1, 1): character} with pytest.raises(ValueError) as e: Roster.for_mapping(positions, area_containing(positions))
def test_no_nearest_character(self, character): roster = Roster.for_mapping( {Point(1, 1): character}, area=Area(Point(0, 0), Point(2, 2)), ) assert roster.nearest_to(Point(1, 1), key=()) is None
def test_viewpoint_single_character(self, character): roster = Roster.for_mapping({Point(1, 1): character}, area=Area(Point(0, 0), Point(2, 2))) viewpoint = Viewpoint(Point(1, 1), roster) assert viewpoint.occupied_points_in( BoundingBox.range(2)) == {Vector.ZERO}
def test_empty_viewpoint(self): characters: Mapping[Point, Any] = {} roster = Roster.for_mapping(characters, area=Area(Point(0, 0), Point(2, 2))) viewpoint = Viewpoint(Point(1, 1), roster) assert viewpoint.occupied_points_in(BoundingBox.range(2)) == set()
def test_takes_position_character_map(self, positions): Roster.for_mapping(positions, area_containing(positions))
def test_character_at_position(self, positions_and_item): positions, (position, character) = positions_and_item roster = Roster.for_mapping(positions, area_containing(positions)) assert roster.character_at(position) == character