def test_world_with_tiles_inits__with_tiles_to_empty_data(self): world = World(None, "1", "0", 3, 3, [(1, 1, 0)], []) expected_tile_data = [ [1, 1, 1], [1, 0, 1], [1, 1, 1], ] self.assertEqual(expected_tile_data, world.get_tile_data()) self.assertEqual(3, world.get_size_x()) self.assertEqual(3, world.get_size_y())
def create_game(self, host, game_id=None): if game_id is None: game_id = str(uuid.uuid4()) world_uuid = str(uuid.uuid4()) world = World(self.db, world_uuid, "0", 0, 0, [], []) world.insert_to_db() game = Game(self.db, game_id, host, {}, 0, world_uuid, generate_invite_code(), True, False) game.insert_to_db() game.add_player(host) return game
def test_set_size_with_smaller_x_y_removes_data(self): world = World(None, "1", "0", 0, 0, [], []) world.set_size(3, 3) world.set_size(2, 2) expected_tile_data = [ [1, 1], [1, 1], ] self.assertEqual(expected_tile_data, world.get_tile_data()) self.assertEqual(2, world.get_size_x()) self.assertEqual(2, world.get_size_y())
def test_set_size_with_larger_y_pads_with_forest(self): world = World(None, "1", "0", 0, 0, [], []) world.set_size(3, 2) world.set_size(3, 3) expected_tile_data = [ [1, 1, 1], [1, 1, 1], [1, 1, 1], ] self.assertEqual(expected_tile_data, world.get_tile_data()) self.assertEqual(3, world.get_size_x()) self.assertEqual(3, world.get_size_y())
def test_set_size_with_same_x_y_does_nothing(self): world = World(None, "1", "0", 0, 0, [], []) world.set_size(3, 3) world.set_size(3, 3) expected_tile_data = [ [1, 1, 1], [1, 1, 1], [1, 1, 1], ] self.assertEqual(expected_tile_data, world.get_tile_data()) self.assertEqual(3, world.get_size_x()) self.assertEqual(3, world.get_size_y())
def test_set_tile_changes_tile_data(self): world = World(None, "1", "0", 0, 0, [], []) world.set_size(5, 5) world.set_tile_at(2, 3, 0) self.assertEqual(0, world.get_tile_at(2, 3)) expected_tile_data = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 0, 1, 1], [1, 1, 1, 1, 1]] self.assertEqual(expected_tile_data, world.get_tile_data())
def test_set_size_from_zero_initialsies_from_forest(self): world = World(None, "1", "0", 0, 0, [], []) world.set_size(3, 3) expected_tile_data = [ [1, 1, 1], [1, 1, 1], [1, 1, 1], ] self.assertEqual(expected_tile_data, world.get_tile_data()) self.assertEqual(3, world.get_size_x()) self.assertEqual(3, world.get_size_y())
def get_world(self): db_result = self.db.query( "SELECT map_id, size_x, size_y FROM world WHERE uuid=%s", (self.world_uuid, )) tile_db_results = self.db.query( "SELECT x, y, tile_id FROM world_tile WHERE world_uuid=%s", (self.world_uuid, )) building_db_results = self.db.query( "SELECT x, y, building_id, owner_id FROM world_building WHERE world_uuid=%s", (self.world_uuid, )) buildings = [{ "in_db": True, "x": b[0], "y": b[1], "id": b[2], "owner_id": b[3] } for b in building_db_results] row = db_result[0] return World(self.db, self.world_uuid, row[0], row[1], row[2], tile_db_results, buildings)
def test_world_inits_to_empty_data(self): world = World(None, "1", "0", 0, 0, [], []) self.assertEqual(0, world.get_size_x()) self.assertEqual(0, world.get_size_y()) self.assertEqual([], world.get_tile_data())