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_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_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_decay(self, decay, prob, time, output): agent = Agent(output=output) memory = Memory(agent, decay) chunk = Chunk(isa='cat', name='Whiskers', owner='Jane') memory.store(chunk) agent.wait(.5) memory.rehearse(chunk) agent.wait(2.5) memory.rehearse(chunk) agent.wait(3.7) memory.rehearse(chunk) agent.wait(6.2) memory.activation_noise = 0.5 if prob: self.assertAlmostEqual(prob, memory.compute_prob_recall(chunk), 2) self.assertAlmostEqual(memory.compute_recall_time(chunk), time, 2)