def test_pairs(self): graph = {2: [1], 3: [2], 1: [3]} visited = set([(1, 2), (2, 3), (3, 1)]) self.assertEqual(visited, set(graphs.node_pairs(graph))) graph = {1: [2, 3], 3: [4], 4: [1], 5: [6]} visited = set([(2, 1), (3, 1), (4, 3), (1, 4), (6, 5)]) self.assertEqual(visited, set(graphs.node_pairs(graph)))
def resolve_attacks(self): attacks = dict((self.coord_actors[pos], self.future_attacks[pos]) for pos in self.future_attacks if pos in self.coord_actors) pairs = graphs.node_pairs(attacks) queue = queues.PriorityQueue() queue.reset() queue.push_pairs(((a.attack_priority, d.attack_priority), (a, d)) for a, d in pairs) rounds = self.conf['rounds'] dt = self.conf['dt'] while len(queue) > 0: _, (attacker, defender) = queue.pop() fight(attacker, defender, dt, rounds) self.update_karma(attacker, defender) self.commenter.fight(attacker, defender) self.future_attacks = defdict(list)
def test_emptygraph(self): graph = {} pairs = [] self.assertEqual(pairs, graphs.node_pairs(graph))