class WorldTestCase(unittest.TestCase): def setUp(self): self.w = World([]) self.w.load_and_build_map(Map("multi/m2.txt")) self.w2 = World([]) self.w2.load_and_build_map(Map("multi/jl2.txt")) def tearDown(self): pass def testShortestPath(self): g = self.w.grid self.assertEqual(g["a1"].shortest_path_distance_to(g["a2"]), g["a1"].shortest_path_distance_to(g["b1"])) self.assertIn(g["a1"].shortest_path_to(g["e5"]).other_side.place.name, ("a2", "b1")) self.assertEqual(g["b1"].shortest_path_to(g["e5"]).other_side.place.name, "b2") self.assertEqual(g["b1"].shortest_path_to(g["d2"]).other_side.place.name, "c1") g2 = self.w2.grid self.assertEqual(g2["a1"].shortest_path_to(g2["c1"]), None) self.assertEqual(g2["c1"].shortest_path_to(g2["a1"]), None) def testCheckString(self): World([]).get_digest() self.assertEqual(self.w.get_digest(), self.w.get_digest()) self.assertNotEqual(self.w.get_digest(), self.w2.get_digest()) self.w.get_objects_string()
class WorldTestCase(unittest.TestCase): def setUp(self): self.w = World([]) self.w.load_and_build_map(Map("multi/m2.txt")) self.w2 = World([]) self.w2.load_and_build_map(Map("multi/jl2.txt")) def tearDown(self): pass def testShortestPath(self): g = self.w.grid self.assertEqual( g["a1"].shortest_path_distance_to(g["a2"]), g["a1"].shortest_path_distance_to(g["b1"]), ) self.assertIn( g["a1"].shortest_path_to(g["e5"]).other_side.place.name, ("a2", "b1") ) self.assertEqual(g["b1"].shortest_path_to(g["e5"]).other_side.place.name, "b2") self.assertEqual(g["b1"].shortest_path_to(g["d2"]).other_side.place.name, "c1") g2 = self.w2.grid self.assertEqual(g2["a1"].shortest_path_to(g2["c1"]), None) self.assertEqual(g2["c1"].shortest_path_to(g2["a1"]), None) def testCheckString(self): World([]).get_digest() self.assertEqual(self.w.get_digest(), self.w.get_digest()) self.assertNotEqual(self.w.get_digest(), self.w2.get_digest()) self.w.get_objects_string()
def set_up(self, alliance=(1, 2), cloak=False, map_name="jl1_extended"): self.w = World([]) self.w.introduction = [] self.w.load_and_build_map(Map("soundrts/tests/%s.txt" % map_name)) if cloak: self.w.unit_class("new_flyingmachine").dct["is_a_cloaker"] = True self.w.populate_map([DummyClient(), DummyClient()], alliance) self.cp, self.cp2 = self.w.players
def set_up(self, alliance=(1, 2), cloak=False, map_name="jl1_extended", ai=("easy", "easy")): self.w = World([]) self.w.load_and_build_map(Map("soundrts/tests/%s.txt" % map_name)) if cloak: self.w.unit_class("new_flyingmachine").dct["is_a_cloaker"] = True cp = DummyClient(ai[0]) cp2 = DummyClient(ai[1]) cp.alliance, cp2.alliance = alliance self.w.populate_map([cp, cp2], random_starts=False) self.cp, self.cp2 = self.w.players self.cp.is_perceiving = is_perceiving_method(self.cp) self.cp2.is_perceiving = is_perceiving_method(self.cp2) self.w._update_buckets()
class _PlayerBaseTestCase(unittest.TestCase): def set_up(self, alliance=(1, 2), cloak=False, map_name="jl1_extended"): self.w = World([]) self.w.introduction = [] self.w.load_and_build_map(Map("soundrts/tests/%s.txt" % map_name)) if cloak: self.w.unit_class("new_flyingmachine").dct["is_a_cloaker"] = True self.w.populate_map([DummyClient(), DummyClient()], alliance) self.cp, self.cp2 = self.w.players def find_player_unit(self, p, cls_name, index=0): for u in p.units: if u.type_name == cls_name: if index: index -= 1 else: return u
def set_up(self, alliance=(1, 2), cloak=False): w = World([]) w.introduction = [] w.load_and_build_map(Map("soundrts/tests/jl1.txt")) w.players_starts[1][1].append(("b4", w.unit_class("lumbermill"))) cl = DummyClient() cl2 = DummyClient() w.populate_map([cl, cl2], alliance) cp, self.cp2 = w.players return w, cl, cp
class _PlayerBaseTestCase(unittest.TestCase): def set_up(self, alliance=(1, 2), cloak=False, map_name="jl1_extended", ai=("easy", "easy")): self.w = World([]) self.w.load_and_build_map(Map("soundrts/tests/%s.txt" % map_name)) if cloak: self.w.unit_class("new_flyingmachine").dct["is_a_cloaker"] = True cp = DummyClient(ai[0]) cp2 = DummyClient(ai[1]) cp.alliance, cp2.alliance = alliance self.w.populate_map([cp, cp2], random_starts=False) self.cp, self.cp2 = self.w.players self.cp.is_perceiving = is_perceiving_method(self.cp) self.cp2.is_perceiving = is_perceiving_method(self.cp2) self.w._update_buckets() def find_player_unit(self, p, cls_name, index=0): for u in p.units: if u.type_name == cls_name: if index: index -= 1 else: return u
def set_up(self, alliance=(1, 2), cloak=False, map_name="jl1_extended"): w = World([]) w.introduction = [] w.load_and_build_map(Map("soundrts/tests/%s.txt" % map_name)) if cloak: w.unit_class("new_flyingmachine").dct["is_a_cloaker"] = True cl = DummyClient() cl2 = DummyClient() w.populate_map([cl, cl2], alliance) cp, self.cp2 = w.players return w, cl, cp
def testSyncError(self): c = Coordinator(None, None, None) c.world = World([]) c.world.load_and_build_map(Map("multi/m2.txt")) c.world.update() c.get_sync_debug_msg_1() c.get_sync_debug_msg_2() c.world.update() c.get_sync_debug_msg_1() c.get_sync_debug_msg_2()
def test_is_ok_for_warehouse(): w = World([]) c = Computer(w, DummyClient()) a1 = Square(w, 0, 0, 12) assert a1.name == "a1" assert not c.is_ok_for_warehouse(a1, 0) a1.objects.append(Deposit(0)) assert c.is_ok_for_warehouse(a1, 0) a1.objects.append(Warehouse([1])) assert c.is_ok_for_warehouse(a1, 0) a1.objects.append(Warehouse([0])) assert not c.is_ok_for_warehouse(a1, 0)
def world(): w = World([]) w.load_and_build_map(Map("soundrts/tests/jl1_cyclic.txt")) return w
def set_up(self, alliance=(1, 2), cloak=False): w = World([]) w.introduction = [] w.load_and_build_map(Map("soundrts/tests/jl1.txt")) w.players_starts[0][1].append(("b1", w.unit_class("new_flyingmachine"))) w.players_starts[0][1].append(("b1", w.unit_class("flyingmachine"))) w.players_starts[0][1].append(("b1", w.unit_class("dragon"))) w.players_starts[0][1].append(("b1", w.unit_class("castle"))) w.players_starts[1][1].append(("b4", w.unit_class("new_flyingmachine"))) w.players_starts[1][1].append(("b4", w.unit_class("flyingmachine"))) w.players_starts[1][1].append(("b4", w.unit_class("dragon"))) w.players_starts[1][1].append(("b4", w.unit_class("castle"))) if cloak: w.unit_class("new_flyingmachine").dct["is_a_cloaker"] = True cl = DummyClient() cl2 = DummyClient() w.populate_map([cl, cl2], alliance) cp, self.cp2 = w.players return w, cl, cp
def world(): w = World([]) w.load_and_build_map(Map("soundrts/tests/height.txt")) return w
def setUp(self): self.w = World([]) self.w.load_and_build_map(Map("multi/m2.txt")) self.w2 = World([]) self.w2.load_and_build_map(Map("multi/jl2.txt"))
def testCheckString(self): World([]).get_digest() self.assertEqual(self.w.get_digest(), self.w.get_digest()) self.assertNotEqual(self.w.get_digest(), self.w2.get_digest()) self.w.get_objects_string()