def test_build_agent_for_needarg(self): # Here we test the entire sequence of becoming blocked for a missing # argument, posting a FillParamScout to fill it in, and running # successfully with the filled-in argument. g = NumboGraph(Numble([4, 5, 6], 15)) bricks = g.find_all(OfClass(Brick)) glom = g.add_node(Glom, g.find_all(OfClass(Brick))) noticer = g.add_node(NoticeAllBricksAreAvail, member_of=g.ws) assert len(bricks) == 3 # First, the Noticer tries to run, but can't, because it's missing # a 'focal_point' argument. So, it posts a Blocked tag about it: g.do_timestep(actor=noticer) problem_tag = g.neighbor(noticer, neighbor_class=Blocked) assert problem_tag, 'Noticer did not create problem tag.' # Next, the Noticer should build an agent to fix the problem. self.assertCountEqual(as_iter(g.actions(noticer)), [BuildAgent(noticer, problem_tag)]) g.do_timestep(actor=noticer) scout = g.neighbor(noticer, 'agents') self.assertTrue(g.is_of_class(scout, FillParamScout), 'Noticer did not build a FillParamScout') # Now the Noticer should be blocked: self.assertTrue(g.is_blocked(noticer)) ## and have nothing to do: #self.assertFalse(g.actions(noticer)) # and should only want to boost the scout: self.assertEqual(g.actions(noticer), BoostFromTo({scout})) # The Scout should find the Glom, override the Noticer's 'focal_point' # arg with it, and remove the Blocked tag. g.do_timestep(actor=scout) # Therefore the Noticer should no longer be blocked: self.assertFalse(g.is_blocked(noticer)) # and the Noticer should be able to act: self.assertTrue(g.actions(noticer)) # Finally, the Noticer notices what it's looking for: g.do_timestep(actor=noticer) self.assertTrue(g.has_tag(bricks, AllBricksAvail)) self.assertTrue(g.is_sleeping(noticer))
def test_ac_selfdestruct_on_update(self): g = NumboGraph(Numble([4, 5, 6], 15)) bricks = g.find_all(OfClass(Brick)) tag = g.add_tag(AllBricksAvail, bricks) self.assertFalse(tag.needs_update) self.assertCountEqual(as_iter(g.actions(tag)), []) g.remove_tag(bricks[0], Avail) # now all Bricks are no longer Avail g.do_touches() # UGLY: calling .do_timestep() clears the touch made # by .remove_tag(), so we force .do_touches() here. self.assertTrue(tag.needs_update) g.do_timestep(actor=tag) self.assertFalse(g.has_node(tag), 'AllBricksAvail did not SelfDestruct.') # Trying to run the tag after it no longer exists should not cause # an exception. g.do_timestep(actor=tag)