def __init__(self, methodName): super().__init__(methodName=methodName) # A dictionary for different types of dummy agents in order to test agent pop class # First we will fill this dict with various dummy agents, # then we will fill the Agent Pop class, using dict_for_reference as source # The OrderedDict in Agent Pop should be the same as dic_for_reference. That will test if append works # If append works and we have the OrderedDict in Agent Pop, # we will test rest of the functions if they return correct result, with reference of dict_for_reference # format: {var:{"agents": [], "pop_data": 0,"pop_hist": [],"my_periods": 0,"disp_color": None}} self.dic_for_reference = OrderedDict() self.agentpop = ap.AgentPop("test") # add 3 varieties for i in range(3): self.dic_for_reference[str(i)] = { AGENTS: [], POP_DATA: 0, POP_HIST: [], MY_PERIODS: 0, DISP_COLOR: None } for i in range(3): # add color to each variety self.dic_for_reference[str(i)][DISP_COLOR] = "#" + str(i) # add agents; agent type is Node for r in range(random.randint(1, 7)): self.dic_for_reference[str(i)][AGENTS].append( node.Node("agent" + str(r))) for var in self.dic_for_reference: for a in self.dic_for_reference[var][AGENTS]: a.ntype = var
def test_remove(self): report = True self.agentpop.add_variety("dummy var") dummy_node = node.Node("dummy node") dummy_node.ntype = "dummy var" self.agentpop.append(dummy_node) self.agentpop.remove(dummy_node) if dummy_node in self.agentpop.vars['dummy var'][AGENTS]: report = False self.assertEqual(report, True)
def test_get_my_pop(self): report = True for var in self.dic_for_reference: for a in self.dic_for_reference[var][AGENTS]: self.agentpop.append(a) var = str(random.randint(0, 2)) dummy_node = node.Node("dummy node") dummy_node.ntype = var self.agentpop.append(dummy_node) self.dic_for_reference[var][AGENTS].append(dummy_node) result = self.agentpop.get_my_pop(dummy_node) correct_pop = len(self.dic_for_reference[var][AGENTS]) if result != correct_pop: report = False self.assertEqual(report, True)
def test_change_agent_type(self): report = True for var in self.dic_for_reference: for a in self.dic_for_reference[var][AGENTS]: self.agentpop.append(a) agent_for_track = node.Node("agent for track") agent_for_track.ntype = "0" self.agentpop.append(agent_for_track) # print("check1 !!!", agent_for_track.ntype) new_type = "dummy type" old_type = '0' self.agentpop.change_agent_type(agent_for_track, old_type, new_type) # print("check2 !!!", agent_for_track.ntype) if agent_for_track.ntype != new_type: report = False if new_type not in self.agentpop.vars: report = False if agent_for_track not in self.agentpop.vars[new_type][AGENTS]: report = False if agent_for_track in self.agentpop.vars[old_type][AGENTS]: report = False self.assertEqual(report, True)