예제 #1
0
def test_end_of_line_called(monkeypatch):
    """Test that the Path calls end_of_line when it comes to the end of the line."""
    class ArgCollector:
        """Class used for mocking that just collects the arguments from a method call"""
        def __init__(self):
            self.args = None

        def collect_args(self, *args):
            """Used for mocking a method call; collect the arguments for later use."""
            self.args = args

    collector = ArgCollector()
    monkeypatch.setattr(Grid, "end_of_line", collector.collect_args)

    factory = Factory(x=0, y=0, creates=Resource.BLUE, max_capacity=1)
    factory.resources = [Resource.BLUE]

    path = Path(Point(1, 1))
    path.append(Point(0, 1))

    grid = Grid(3, 3)
    grid.add(factory)
    grid.add_path(path)

    grid.update(1.1)

    assert collector.args == (path, Point(0, 1))
예제 #2
0
def test_agent_reversing_adjacent_to_no_stations():
    """If the agent reverses next to no stations, it should keep its resources"""
    path = Path(Point(1, 1))
    path.append(Point(0, 1))
    path.resource = Resource.BLUE

    grid = Grid(3, 3)
    grid.add_path(path)

    grid.update(1.1)

    assert path.resource == Resource.BLUE
예제 #3
0
def test_agent_continues_when_stopping_by_empty_factory():
    """If the station that the agent reverses by is empty, nothing shall happen"""
    factory = Factory(x=0, y=0, max_capacity=1)

    path = Path(Point(1, 1))
    path.append(Point(0, 1))

    grid = Grid(3, 3)
    grid.add(factory)
    grid.add_path(path)

    grid.update(1.1)

    assert factory.resources == []
    assert path.resources == []
예제 #4
0
def test_agent_does_not_drop_off_resource_at_wrong_factory():
    """Assert that when an agent reaches end of the line, if there is a type of factory
    that is not the same as the resource the agent is carrying, nothing happens."""
    factory = Factory(x=0, y=0, consumes=Resource.RED, max_capacity=1)

    path = Path(Point(1, 1))
    path.append(Point(0, 1))
    path.resource = Resource.BLUE

    grid = Grid(3, 3)
    grid.add(factory)
    grid.add_path(path)

    grid.update(1.1)

    assert path.resource is Resource.BLUE
예제 #5
0
def test_agent_drops_off_resource():
    """Assert that when an agent reaches end of the line, it drops off a resource
    to a nearby accepting factory"""
    factory = Factory(x=0, y=0, consumes=Resource.BLUE, max_capacity=1)

    path = Path(Point(1, 1))
    path.append(Point(0, 1))
    path.resources = [Resource.BLUE]

    grid = Grid(3, 3)
    grid.add(factory)
    grid.add_path(path)

    grid.update(1.1)

    assert path.resources == []
예제 #6
0
def test_agent_does_not_pick_up_resource_if_already_carrying():
    """Assert that when an agent reaches end of the line, it does not pick up a resource
    from an adjacent factory if it is already carrying something."""
    factory = Factory(x=0, y=0, max_capacity=1)
    factory.resources = [Resource.BLUE]

    path = Path(Point(1, 1))
    path.append(Point(0, 1))
    path.resources = [Resource.BLUE]

    grid = Grid(3, 3)
    grid.add(factory)
    grid.add_path(path)

    grid.update(1.1)

    assert factory.resources == [Resource.BLUE]
예제 #7
0
def test_agent_picks_up_resource():
    """Assert that when an agent reaches end of the line, it picks up a resource
    from an adjacent factory"""
    factory = Factory(x=0, y=0, max_capacity=1)
    factory.resources = [Resource.BLUE]

    path = Path(Point(1, 1))
    path.append(Point(0, 1))

    grid = Grid(3, 3)
    grid.add(factory)
    grid.add_path(path)

    grid.update(1.1)

    assert factory.resources == []
    assert path.resources == [Resource.BLUE]
예제 #8
0
def test_update():
    """ Test. just so that nothing crashes when calling the update method."""
    grid = Grid(2, 2)
    grid.add_path(Path(Point(0, 0)))
    grid.add(Factory(x=1, y=1))
    widget = GridWidget(2)
    widget.paths = [InstructionGroup()]
    widget.factories = [InstructionGroup()]
    controller = Controller(grid, TransportAppView(widget))

    controller.update(0.1)
예제 #9
0
def test_path_created_on_touch_move():
    """ Test that a touch in location A and dragged to B creates a Path starting at A
        and ending at B.
        -----------------
        |       |       |
        |   B   |       |
        |       |       |
        -----------------
        |       |       |
        |   A   |       |
        |       |       |
        -----------------
    """
    grid = Grid(2, 2)
    widget = GridWidget(2)
    Controller(grid, TransportAppView(widget))

    widget.on_touch_down(Touch(widget.width * 1 / 4, widget.height * 1 / 3))
    widget.on_touch_move(Touch(widget.width * 1 / 4, widget.height * 3 / 4))
    widget.on_touch_up(Touch(widget.width * 1 / 4, widget.height * 3 / 4))

    expected = Path(Point(0, 0))
    expected.append(Point(0, 1))
    assert grid.paths == [expected]
예제 #10
0
 def touch_down(self, x_index, y_index):
     """Called when the user touches an index in the grid."""
     self._model.add_path(Path(Point(x_index, y_index)))