def test_remove_single_tiles_by_index(self): p_state = gs.PlayerState("Test Player", [1, 2, 3]) added_tile_indexes = [] for _i in range(self.num_adds): random_indx = random.randint(0, len(p_state.get_player_collection()) - 1) added_tile_indexes.append(random_indx) p_state.add_tiles(added_tile_indexes) current_collection = p_state.get_player_collection() # sanity check that tiles were added correctly self.assertEqual(sum(current_collection), self.num_adds) # check that removing tiles one at a time works for added_tile in added_tile_indexes: p_state.remove_single_tiles_by_index([added_tile], log = False) current_collection[added_tile] -= 1 self.assertEqual(current_collection, p_state.get_player_collection()) # check that removing tiles all at once works p_state.add_tiles(added_tile_indexes) self.assertEqual(sum(p_state.get_player_collection()), self.num_adds) p_state.remove_single_tiles_by_index(added_tile_indexes, log = False) self.assertEqual(sum(p_state.get_player_collection()), 0) # check that removing tiles when there are none does nothing empty_collection = p_state.get_player_collection() for added_tile in added_tile_indexes: p_state.remove_single_tiles_by_index([added_tile], log = False) self.assertEqual(empty_collection, p_state.get_player_collection())
def test_exchange_sun(self): test_sun = [] for i in range(self.num_sun): test_sun.append(random.randint(self.min_sun, self.max_sun)) test_sun.sort() p_state = gs.PlayerState("Test Player", test_sun) # check that starting sun is correct and unusable sun is empty self.assertEqual(p_state.get_usable_sun(), test_sun) self.assertEqual(sum(p_state.get_unusable_sun()), 0) # check that exchanging sun works properly shuffled_test_sun = test_sun[:] random.shuffle(shuffled_test_sun) removed_sun = [] added_sun = [] for old_sun in test_sun: new_sun = random.randint(self.min_sun, self.max_sun) p_state.exchange_sun(old_sun, new_sun) removed_sun.append(old_sun) added_sun.append(new_sun) self.assertEqual(sorted(p_state.get_usable_sun() + removed_sun), test_sun) self.assertEqual(p_state.get_unusable_sun(), sorted(added_sun))
def test_add_points(self): p_state = gs.PlayerState("Test Player", [1, 2, 3]) current_points = p_state.get_player_points() # check num_iterations times that adding points works properly for _i in range(self.num_iterations): diff = random.randint(-self.max_magnitude, self.max_magnitude) current_points += diff p_state.add_points(diff) self.assertEqual(current_points, p_state.get_player_points())
def test_add_tiles(self): p_state = gs.PlayerState("Test Player", [1, 2, 3]) current_collection = p_state.get_player_collection() # assert that collection starts empty self.assertEqual(sum(current_collection), 0) # check that adding tiles one at a time works for _i in range(self.num_adds): random_indx = random.randint(0, len(current_collection) - 1) current_collection[random_indx] += 1 p_state.add_tiles([random_indx]) self.assertEqual(current_collection, p_state.get_player_collection()) # check that adding tiles 3 at at ime works for _i in range(self.num_adds): random_indx_1 = random.randint(0, len(current_collection) - 1) random_indx_2 = random.randint(0, len(current_collection) - 1) random_indx_3 = random.randint(0, len(current_collection) - 1) current_collection[random_indx_1] += 1 current_collection[random_indx_2] += 1 current_collection[random_indx_3] += 1 p_state.add_tiles([random_indx_1, random_indx_2, random_indx_3]) self.assertEqual(current_collection, p_state.get_player_collection())
def test_make_all_suns_usable(self): test_sun = [] for i in range(self.num_sun): test_sun.append(random.randint(self.min_sun, self.max_sun)) test_sun.sort() p_state = gs.PlayerState("Test Player", test_sun) # make all sun unusable added_suns = [] for old_sun in test_sun: new_sun = random.randint(self.min_sun, self.max_sun) p_state.exchange_sun(old_sun, new_sun) added_suns.append(new_sun) added_suns.sort() # sanity check that all suns are unusable self.assertEqual(sum(p_state.get_usable_sun()), 0) self.assertEqual(p_state.get_unusable_sun(), added_suns) # check that all suns are made usable properly p_state.make_all_suns_usable() self.assertEqual(p_state.get_usable_sun(), added_suns) self.assertEqual(sum(p_state.get_unusable_sun()), 0)