def test_report(): class MockAgent(): def __init__(self): self.coords = random.randint(10, 500), random.randint(10, 500) class MockEngine(): def __init__(self): self.agents = [MockAgent() for _ in range(10)] self.agents = [] def add_command(self, command): print('Engine receive', command) def agents_with(self, whatever): return self.agents def agents_at(self, coords, precision=1.0): try: return iter([random.choice(self.agents)]) except IndexError: return None engine = MockEngine() engine.space_width = 800 engine.space_height= 600 # create and test the world view object wv = WorldView(engine) wv.start() for _ in range(10): wv.update({ 'new_report': MockAgent() }) time.sleep(0.4)
def test_report(): class MockAgent(): def __init__(self): self.coords = random.randint(10, 500), random.randint(10, 500) class MockEngine(): def __init__(self): self.agents = [MockAgent() for _ in range(10)] self.agents = [] def add_command(self, command): print('Engine receive', command) def agents_with(self, whatever): return self.agents def agents_at(self, coords, precision=1.0): try: return iter([random.choice(self.agents)]) except IndexError: return None engine = MockEngine() engine.space_width = 800 engine.space_height = 600 # create and test the world view object wv = WorldView(engine) wv.start() for _ in range(10): wv.update({'new_report': MockAgent()}) time.sleep(0.4)
def test_whole(): # initialization engine = Engine(Coords(800, 600)) engine.start() # thread start gui = WorldView(engine) term = TerminalManagementInterface(engine, 'lucas') engine.register_observer(gui) engine.add_command(AddAgentCommand(Squad(Coords(100, 100), player=1))) engine.add_command(AddAgentCommand(Squad(Coords(150, 150), player=2))) engine.add_command(AddAgentCommand(Squad(Coords(150, 100), player=3))) engine.add_command(AddAgentCommand(Squad(Coords(100, 150), player=4))) gui.start() term.run() # block gui.join() engine.join() # wait the end