def test_welcome(): prints = [ "Welcome to Game of Greed!", "Wanna play? ", "OK. Maybe another time", "Great! Check back tomorrow!", ] def print_for_testing(message): assert message == prints.pop(0) game = Game(print_for_testing, print_for_testing) game.play()
def play(cls, num_games=1): mega_total = 0 for i in range(num_games): player = cls() game = Game() game.play() mega_total += player.total_score player.reset() print( f"{num_games} games (maybe) played with average score of {mega_total // num_games}" )
def test_def_validate_roll_fail(roll, expected_keepers): prints = ['No way pal', roll, 'No way pal',roll] inputs = ['0','0', str(expected_keepers[0])] def my_print(msg, *args): assert msg == prints.pop(0) def my_input(msg, *args): assert msg == 'Enter dice to keep: ' return inputs.pop(0) game = Game(my_print, my_input) keepers = game.validate_roll(roll) assert keepers == expected_keepers
def test_def_validate_roll_success(roll, expected_keepers): def my_print(msg, *args): assert msg == roll def my_input(msg, *args): assert msg == 'Enter dice to keep: ' keeper_string = '' for val in expected_keepers: keeper_string += str(val) return keeper_string game = Game(my_print, my_input) keepers = game.validate_roll(roll) assert keepers == expected_keepers
def test_flow_no(): prints = ['Welcome to Game of Greed', 'OK. Maybe another time'] prompts = ['Wanna play? Please type y to start game Type: '] responses = ['n'] def mock_print(*args): if len(prints): current_print = prints.pop(0) assert args[0] == current_print def mock_input(*args): if len(prompts): current_prompt = prompts.pop(0) assert args[0] == current_prompt if len(responses): current_response = responses.pop(0) return current_response game = Game(mock_print, mock_input) game.play()
def test_1_and_5(): test_game = Game() actual = test_game.calculate_score((6, 5, 4, 1, 4, 2)) assert 150 == actual
def test_straigt(): test_game = Game() actual = test_game.calculate_score((6, 5, 4, 1, 3, 2)) assert 1500 == actual
def test_3_pairs(): test_game = Game() actual = test_game.calculate_score((6, 4, 4, 2, 6, 2)) assert 1500 == actual