Beispiel #1
0
def test_no_progress_while_at_max_capacity():
    """While the factory is at max capacity, no work on creating the next resource
    shall be done."""
    factory = Factory(0, 0, creates=Resource.RED, interval=1, max_capacity=1)
    factory.resources = [Resource.RED]
    factory.update(0.5)
    assert factory.time_to_next_production > 0.99
Beispiel #2
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))
Beispiel #3
0
def test_start_production_when_free_capacity():
    """Once there is free capacity, production shall resume."""
    factory = Factory(0, 0, creates=Resource.RED, interval=1, max_capacity=1)
    factory.resources = [Resource.RED]
    factory.update(1.1)
    factory.pop()
    factory.update(1.1)
    factory.resources = [Resource.RED]
Beispiel #4
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]
Beispiel #5
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]
Beispiel #6
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)
Beispiel #7
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 == []
Beispiel #8
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
Beispiel #9
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 == []
Beispiel #10
0
"""Main entry point for the program"""

# pragma: no cover
from transport.controller import Controller
from transport.model.factory import Factory
from transport.model.grid import Grid
from transport.model.resource import Resource
from transport.view.app import TransportAppView
from transport.view.grid_widget import GridWidget

if __name__ == "__main__":  # pragma: no cover
    WIDTH = 16
    GRID = Grid(WIDTH, WIDTH)
    GRID.add(Factory(x=5, y=5, creates=Resource.BLUE, max_capacity=5))
    GRID.add(Factory(x=10, y=10, consumes=Resource.BLUE, max_capacity=5))
    Controller(GRID, TransportAppView(GridWidget(WIDTH))).run()
Beispiel #11
0
def test_create_one_resource():
    """One resource shall be created after the specified interval has passed."""
    factory = Factory(0, 0, creates=Resource.RED, interval=1, max_capacity=1)
    factory.update(1.1)
    assert factory.resources == [Resource.RED]
Beispiel #12
0
def test_a_factory_producing_none_shall_not_produce_anything():
    """If it produces None, nothing shall be produced."""
    factory = Factory(0, 0, creates=None, interval=1, max_capacity=1)
    factory.update(1.1)
    assert factory.resources == []
Beispiel #13
0
def test_max_capacity():
    """The number of resources cannot exceed max capacity."""
    factory = Factory(0, 0, creates=Resource.RED, interval=1, max_capacity=1)
    factory.update(1.1)
    factory.update(1.1)
    assert factory.resources == [Resource.RED]
Beispiel #14
0
def test_create_two_resources():
    """Two resources shall be crated after the specified interval has passed twice."""
    factory = Factory(0, 0, creates=Resource.RED, interval=1, max_capacity=2)
    factory.update(1.1)
    factory.update(1.1)
    assert factory.resources == [Resource.RED, Resource.RED]