def test_player_validate_valid(): game_valid = GameValidation() sm = StateManager() new_state = sm.create({"game_id": "debug_testing"}) result = game_valid.validate_player(new_state, new_state.player_ids[0]) assert result.success == True assert result.errors == []
def test_player_validate_non_existent(): game_valid = GameValidation() sm = StateManager() new_state = sm.create({"game_id": "debug_testing"}) result = game_valid.validate_player(new_state, "LOGIC") assert result.success == False assert result.errors == ["There is no player with that ID in this game."]
def test_player_validate_invalid(): game_valid = GameValidation() sm = StateManager() new_state = sm.create({"game_id": "debug_testing"}) result = game_valid.validate_player(new_state, new_state.player_ids[1]) assert result.success == False assert result.errors == ["It is not Player 2's turn to play."]
def test_new_state(): sm = StateManager() new_state = sm.create({"game_id": "debug_testing"}) assert new_state.board == {'size': 3, 'status': [[0, 0, 0], [0, 0, 0], [0, 0, 0]]} assert new_state.player_turn == 1 assert new_state.player_count == 2 assert new_state.history == []
def test_update_state_three_times(): sm = StateManager() new_state = sm.create({"game_id": "debug_testing"}) updated_state = sm.update(new_state, {"coordinates": [1, 1]}) assert updated_state.board == {'size': 3, 'status': [[0, 0, 0], [0, 1, 0], [0, 0, 0]]} assert updated_state.player_turn == 2 updated_state = sm.update(updated_state, {"coordinates": [0, 1]}) assert updated_state.board == {'size': 3, 'status': [[0, 2, 0], [0, 1, 0], [0, 0, 0]]} assert updated_state.player_turn == 1
def test_read_state(): sr = StateRepo() sm = StateManager() new_state = sm.create({"game_id": "debug_testing"}) sr.write_state(new_state) read_data = sr.read_state("debug_testing") assert read_data.board == { "size": 3, "status": [[0, 0, 0], [0, 0, 0], [0, 0, 0]] }
def test_validation_big_board_one_off_cases(): cli_valid = CLIValidation() sm = StateManager() new_state = sm.create({"board_size": 8, "game_id": "debug_testing"}) validation_errors = cli_valid.validate_move_text(new_state, "I9") assert validation_errors.success == False assert validation_errors.errors[0] == str( "\"I\" is not one of the valid selctions in position 1... (A - H)") assert validation_errors.errors[1] == str( "\"9\" is not one of the valid selctions in position 2... (1 - 8)")
def test_position_validation_valid(): game_valid = GameValidation() sm = StateManager() new_state = sm.create({ "board_size": 3, "board_status": [[1, 1, 1], [1, 1, 1], [1, 0, 1]] }) result = game_valid.validate_position(new_state, [2, 1]) assert result.success == True assert result.errors == []
def test_position_validation_invalid(): game_valid = GameValidation() sm = StateManager() new_state = sm.create({ "board_size": 3, "board_status": [[0, 0, 0], [0, 0, 0], [0, 1, 0]] }) result = game_valid.validate_position(new_state, [2, 1]) assert result.success == False assert result.errors == ["This position is already populated..."]
def test_input_invalid_second_character(): cli_valid = CLIValidation() sm = StateManager() new_state = sm.create({"game_id": "debug_testing"}) text_input = "A4" text_input = list(text_input.upper()) board_size = new_state.board["size"] validation_errors = cli_valid.has_invalid_character_second_position( board_size, text_input) assert validation_errors[0] == str( "\"4\" is not one of the valid selctions in position 2... (1 - 3)")
def test_validation_multi_error(): cli_valid = CLIValidation() sm = StateManager() new_state = sm.create({"game_id": "debug_testing"}) validation_errors = cli_valid.validate_move_text(new_state, "RESPECT") assert validation_errors.success == False assert validation_errors.errors[0] == str( "Input is 5 characters too long...") assert validation_errors.errors[1] == str( "\"R\" is not one of the valid selctions in position 1... (A - C)") assert validation_errors.errors[2] == str( "\"E\" is not one of the valid selctions in position 2... (1 - 3)")
def test_delete_state(): sr = StateRepo() sm = StateManager() current_dir = os.getcwd() data_folder_path = os.path.join(current_dir, r'data') new_state = sm.create({"game_id": "debug_testing"}) state_file_location = os.path.join(data_folder_path, str(new_state.game_id) + ".dat") sr.write_state(new_state) sr.delete_state(new_state.game_id) assert os.path.exists(state_file_location) == False
def test_write_state(): sr = StateRepo() sm = StateManager() new_state = sm.create({ "game_id": "debug_testing", "board_size": 5, "board_status": [[1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 5, 1, 2], [4, 5, 1, 2, 3], [5, 1, 2, 3, 4]] }) sr.write_state(new_state) read_data = sr.read_state("debug_testing") assert read_data.board == { "size": 5, "status": [[1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 5, 1, 2], [4, 5, 1, 2, 3], [5, 1, 2, 3, 4]] }
def test_overwrite_state(): sr = StateRepo() sm = StateManager() new_state = sm.create({ "game_id": "debug_testing", "board_size": 5, "board_status": [[1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 5, 1, 2], [4, 5, 1, 2, 3], [5, 1, 2, 3, 4]] }) sr.write_state(new_state) read_data = sr.read_state("debug_testing") assert read_data.board == { "size": 5, "status": [[1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 5, 1, 2], [4, 5, 1, 2, 3], [5, 1, 2, 3, 4]] } overwrite_state = sm.update(read_data, { "coordinates": [2, 2], "player_ids": ["debug", "testing"] }) sr.write_state(overwrite_state) overwritten_read_data = sr.read_state("debug_testing") assert overwritten_read_data.board == { "size": 5, "status": [[1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 1, 1, 2], [4, 5, 1, 2, 3], [5, 1, 2, 3, 4]] } print(overwritten_read_data.history) assert overwritten_read_data.history[0].board == { "size": 5, "status": [[1, 2, 3, 4, 5], [2, 3, 4, 5, 1], [3, 4, 5, 1, 2], [4, 5, 1, 2, 3], [5, 1, 2, 3, 4]] }
def test_dynamic_board(): sm = StateManager() new_state = sm.create({"board_size": 5, "game_id": "debug_testing"}) assert new_state.board["status"] == [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
def test_update_board(): sm = StateManager() new_state = sm.create({"game_id": "debug_testing"}) updated_board = sm.update_board(new_state, [1,1]) assert updated_board["board"] == {'size': 3, 'status': [[0, 0, 0], [0, 1, 0], [0, 0, 0]]}