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]
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))
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
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]
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]