Пример #1
0
 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
Пример #2
0
    def __init__(self, name, preact=False,
                 postact=False, model_nm=None):
        super().__init__(name)
        self.graph = nx.Graph()
        pop_name = ""
        if model_nm:
            pop_name += model_nm + " "
        pop_name += "Agents"
        self.agents = ap.AgentPop(pop_name)
        self.graph.add_edge(self, self.agents)
        self.womb = []
        self.period = 0
        self.preact = preact
        self.postact = postact
        self.disp_census = False
        self.model_nm = model_nm
        if model_nm is not None:
            self.props = pa.PropArgs.get_props(model_nm)
        else:
            self.props = None

        user_nm = getpass.getuser()
        user_type = user.TERMINAL
        if self.props is not None:
            self.props.set("user_name", user_nm)
            user_type = self.props.get("user_type", user.TERMINAL)
        self.user = user.User(user_nm, user_type)
        self.graph.add_edge(self, self.user)
        self.menu = menu.MainMenu("Main Menu", self)
        self.graph.add_edge(self, self.menu)
        self.graph.add_edge(self, self.props)
        self.graph.add_edge(self, node.universals)
Пример #3
0
    def __init_unrestorables(self):
        # anything that can't be restored from JSON file init here
        pop_name = ""
        if self.model_nm:
            pop_name += self.model_nm + " "
        pop_name += "Agents"
        self.agents = ap.AgentPop(pop_name)

        self.womb = []
        self.graph = nx.Graph()
        self.graph.add_edge(self, self.agents)
        if self.props is not None:
            self.graph.add_edge(self, self.props)
        self.graph.add_edge(self, self.user)
        self.graph.add_edge(self, self.menu)
        self.graph.add_edge(self, node.universals)
Пример #4
0
    def test_restore_hist_from(self):
        report = True
        for var in self.dic_for_reference:
            for a in self.dic_for_reference[var][AGENTS]:
                self.agentpop.append(a)
            self.agentpop.set_var_color(
                var, self.dic_for_reference[var][DISP_COLOR])
        dict_to_pass_in = self.agentpop.get_pop_hist()
        dummy_ap = ap.AgentPop("dummy")
        for var in self.dic_for_reference:
            for a in self.dic_for_reference[var][AGENTS]:
                dummy_ap.append(a)
        dummy_ap.restore_hist_from(dict_to_pass_in)
        dict_to_check = dummy_ap.get_pop_hist()
        if dict_to_pass_in != dict_to_check:
            report = False

        self.assertEqual(report, True)