def test_save_game(self): test_character = Character('Test_save', 10, [1, 3], 0) save_game(test_character) test_file = 'Test_save.json' with open(test_file) as file_object: test_stats = json.load(file_object) self.assertEqual(['Test_save', 10, [1, 3], 0], [test_stats['name'], test_stats['health'], test_stats['coordinates'], test_stats['kills']]) do_not_save(test_character)
def test_load_game(self): test_character = Character('Test_load', 10, [1, 3], 0) save_game(test_character) test_load_character = load_game('Test_load') self.assertEqual(['Test_load', 10, [1, 3], 0], [ test_load_character.get_name(), test_load_character.get_health(), test_load_character.get_coordinate(), test_load_character.get_kill_count() ]) do_not_save(test_character)
def test_create_character_no_saved_file_found(self, mock_input): expected_test_character = Character('Bob_New', 10, [1, 3], 0) actual_character = create_character() self.assertEqual(expected_test_character.get_name(), actual_character.get_name()) self.assertEqual(expected_test_character.get_health(), actual_character.get_health()) self.assertEqual(expected_test_character.get_coordinate(), actual_character.get_coordinate()) self.assertEqual(expected_test_character.get_kill_count(), actual_character.get_kill_count()) do_not_save(actual_character)
def test_create_character_saved_file_found(self, mock_input): expected_test_character = Character('Bob_Old', 7, [2, 4], 1) save_game(expected_test_character) actual_character = create_character() self.assertEqual(expected_test_character.get_name(), actual_character.get_name()) self.assertEqual(expected_test_character.get_health(), actual_character.get_health()) self.assertEqual(expected_test_character.get_coordinate(), actual_character.get_coordinate()) self.assertEqual(expected_test_character.get_kill_count(), actual_character.get_kill_count()) do_not_save(actual_character)
def test_start_game_start_new_game(self, mock_input, mock_character): test_character = Character('Kevin', 10, [1, 3], 0) save_game(test_character) actual_character = comp_1510_a1.start_game() self.assertEqual(test_character.get_name(), actual_character.get_name()) self.assertEqual(test_character.get_health(), actual_character.get_health()) self.assertEqual(test_character.get_coordinate(), actual_character.get_coordinate()) self.assertEqual(test_character.get_kill_count(), actual_character.get_kill_count()) do_not_save(test_character)
def test_existing_character_detected_load(self): expected_test_character = Character('Peter', 10, [1, 3], 0) save_and_load.save_game(expected_test_character) actual_character = character_creation.existing_character_detected( 'Peter', 'L') self.assertEqual(expected_test_character.get_name(), actual_character.get_name()) self.assertEqual(expected_test_character.get_health(), actual_character.get_health()) self.assertEqual(expected_test_character.get_coordinate(), actual_character.get_coordinate()) self.assertEqual(expected_test_character.get_kill_count(), actual_character.get_kill_count()) save_and_load.do_not_save(expected_test_character)
def test_start_game_start_load_game(self, mock_stdout, mock_input): test_character = Character('Kevin', 10, [1, 3], 0) save_game(test_character) actual_character = comp_1510_a1.start_game() expected_stdout = 'I see you could not resist your lust for blood.' self.assertIn(expected_stdout, mock_stdout.getvalue()) self.assertEqual(test_character.get_name(), actual_character.get_name()) self.assertEqual(test_character.get_health(), actual_character.get_health()) self.assertEqual(test_character.get_coordinate(), actual_character.get_coordinate()) self.assertEqual(test_character.get_kill_count(), actual_character.get_kill_count()) do_not_save(test_character)
def test_do_not_save(self): test_character = Character('Test_do_not_save', 10, [1, 3], 0) save_game(test_character) do_not_save(test_character) test_loaded_character = load_game('Test_do_not_save') self.assertEqual(False, test_loaded_character)