def test_mouse(self, output=False): agent = Agent(output=output) vision = Vision(agent) hands = Hands(agent) mouse = Mouse(hands, vision) self.button = None end = 20.0 def update(): if agent.time() < end: def fn(): vision.clear() agent.wait(1.0) self.button = Visual(random.randint(0, 500), random.randint(0, 500), 30, 30, 'button') vision.add(self.button, "X") agent.run_thread(fn) update() def fn(visual): if visual.equals(self.button): update() mouse.add_click_fn(fn) while agent.time() < end: visual = vision.wait_for(isa='button') mouse.point_and_click(visual) agent.wait_for_all() self.assertGreaterEqual(agent.time(), end)
def test_mouse(self, output=False): agent = Agent(output=output) env = Environment() vision = Vision(agent, env.display) motor = Motor(agent, vision, env) self.button = None end = 20.0 def update(): if agent.time() < end: def fn(): vision.clear() agent.wait(1.0) self.button = env.display.add_button( random.randint(0, 500), random.randint(0, 500), 'X') agent.run_thread(fn) update() def fn(visual): if visual.obj == 'X': update() env.mouse.add_click_fn(fn) while agent.time() < end: visual = vision.wait_for(isa='button') motor.point_and_click(visual) agent.wait_for_all() self.assertGreaterEqual(agent.time(), end)
def test_agent(self, output=False): agent = Agent(output=output) agent.wait(10.0) self.assertAlmostEqual(10.0, agent.time(), 2) agent.run_thread(lambda: agent.wait(5.0)) agent.wait(2.0) self.assertAlmostEqual(12.0, agent.time(), 2) agent.wait_for_all() self.assertAlmostEqual(15.0, agent.time(), 2)
def test_speech(self, output=False): agent = Agent(output=output) speech = Speech(agent) speech.say("Hello I am the speech module") speech.subvocalize("Goodbye all") agent.wait_for_all() self.assertAlmostEqual(agent.time(), 3.650, 2)
def test_threads(self, output=False): agent = Agent(output=output) memory = Memory(agent) memory.add(isa='item') memory.add(isa='digit', value=1) memory.add(isa='number', value='three') speech = Speech(agent) def thread2(): for _ in range(2): number = memory.recall(isa='number') speech.say(number.value) agent.run_thread(thread2) agent.wait(.100) def thread3(): for _ in range(2): memory.recall('digit') agent.run_thread(thread3) for _ in range(2): memory.recall('item') agent.wait_for_all() self.assertAlmostEqual(1.200, agent.time(), 2)
def test_typing(self, output=False): agent = Agent(output=output) env = Environment() vision = Vision(agent, env.display) motor = Motor(agent, vision, env) motor.type('Hello there. What\'s up?') agent.wait_for_all() self.assertAlmostEqual(6.597, agent.time(), 1)
def test_vision(self, output=False): agent = Agent(output=output) eyes = Eyes(agent) vision = Vision(agent, eyes) eyes.move_to(100, 100) vision.add(Visual(50, 50, 20, 20, 'text'), "Hello") vision.add(Visual(150, 150, 20, 20, 'text'), "Goodbye") self.assertEqual("Hello", vision.find_and_encode( Query(isa='text').lt('x', 100))) self.assertEqual("Goodbye", vision.find_and_encode(seen=False)) vision.start_wait_for(isa='cross') agent.wait(2.0) vision.add(Visual(200, 200, 20, 20, 'cross'), "cross") self.assertEqual("cross", vision.encode(vision.get_found())) self.assertAlmostEqual(2.7, agent.time(), 1) agent.wait_for_all()
def test_vision(self, output=False): agent = Agent(output=output) display = Environment().display eyes = Eyes(agent) vision = Vision(agent, display, eyes) eyes.move_to(100, 100) display.add_text(50, 50, 'Hello') display.add_text(150, 150, 'Goodbye') self.assertEqual( "Hello", vision.find_and_encode(Query(isa='text').lt('x', 100))) self.assertEqual("Goodbye", vision.find_and_encode(seen=False)) vision.start_wait_for(isa='cross') agent.wait(2.0) display.add(200, 200, 20, 20, 'cross', "cross") self.assertEqual("cross", vision.encode(vision.get_found())) self.assertAlmostEqual(2.7, agent.time(), 1) agent.wait_for_all()
def test_typing(self, output=False): agent = Agent(output=output) typing = Typing(Hands(agent)) typing.type("Hello there. What's up?") agent.wait_for_all() self.assertAlmostEqual(6.597, agent.time(), 1)