def test_set_recovery(self): edges = [] for i in range(1, 100): for j in range(1, 100): if i == j: continue else: edges.append((i, j)) g = Graph(edges) recovered = [] def recovery_function(n): recovered.append(n) g.set_recovery(recovery_function) g.infect_seeds([g.get_node_by_name(i) for i in range(1, 100)]) assert not recovered before = g.infected() g.recover() after = g.infected() assert not not recovered assert len(after) < len(before)
def test_set_recovery(self): edges = [] for i in range(1,100): for j in range(1,100): if i == j: continue else: edges.append((i,j)) g = Graph(edges) recovered = [] def recovery_function(n): recovered.append(n) g.set_recovery(recovery_function) g.infect_seeds([g.get_node_by_name(i) for i in range(1,100)]) assert not recovered before = g.infected() g.recover() after = g.infected() assert not not recovered assert len(after) < len(before)
def test_set_transmission_function_in_constructor(self): target = [False] def trans(a,b): target[0] = True return 1 g = Graph([(1,2)], transmission_probability=trans) g.infect_seeds([g.get_node_by_name(1)]) g.propagate() assert target[0]
def test_set_infection(self): g = Graph([(1, 2), (1, 3), (1, 4), (1, 5)]) infected = [] def callback(n): infected.append(n) g.set_infection(callback) one = g.get_node_by_name(1) two = g.get_node_by_name(2) three = g.get_node_by_name(3) g.infect_seeds([one, two, three]) assert one in infected assert two in infected assert three in infected assert one in g.infected() assert two in g.infected() assert three in g.infected()
def test_set_infection(self): g = Graph([(1,2),(1,3),(1,4),(1,5)]) infected = [] def callback(n): infected.append(n) g.set_infection(callback) one = g.get_node_by_name(1) two = g.get_node_by_name(2) three = g.get_node_by_name(3) g.infect_seeds([one, two, three]) assert one in infected assert two in infected assert three in infected assert one in g.infected() assert two in g.infected() assert three in g.infected()