def test(path): flo = Flo(path) game = Game(flo._mock_roller) game.play() flo._exit()
def test(path): flo = Flo(path) game = Game(flo._mock_roller) try: game.play() except SystemExit: flo.old_print("no problemo") finally: flo._exit()
def test_cheat_and_fix(): """Cheating (or typos) should not be allowed. Therefore the user’s input must be validated If invalid prompt user for re-entry """ errors = diff(Game().play, path="tests/version_one/cheat_and_fix.sim.txt") assert not errors, errors[0]
def test_repeat_roller(): """Plays 1 round game and confirms proper exit IMPORTANT: pass 1 for num_rounds """ diffs = diff(Game(num_rounds=1).play, path="tests/version_4/complete.sim.txt") assert not diffs, diffs
def test_zilcher(): """ No scoring dice results in a ‘zilch’ which wipes away shelved points and ends turn """ errors = diff(Game().play, path="tests/version_one/zilcher.sim.txt") assert not errors, errors[0]
def test_zilcher(): """ No scoring dice results in a 'zilch' which wipes away shelved points and ends turn """ diffs = diff(Game().play, path="tests/version_3/zilcher.sim.txt") assert not diffs, diffs
def play(cls, num_games=1): mega_total = 0 for i in range(num_games): player = cls() game = Game() # doesn't pass a mock roller try: game.play() except SystemExit: # in game system exit is fine # because that's how they quit. pass mega_total += player.total_score player.reset() print( f"{num_games} games (maybe) played with average score of {mega_total // num_games}" )
def test(path): flo = Flo(path) game = Game(flo._mock_roller) try: game.start_game() except SystemExit: pass flo._exit()
def play(cls, num_games=1): """Tell Bot play game a given number of times. Will report average score""" mega_total = 0 for _ in range(num_games): player = cls() game = Game() try: game.play() except SystemExit: # in game system exit is fine # because that's how they quit. pass mega_total += player.total_score player.reset() print( f"{cls.__name__}: {num_games} games played with average score of {mega_total // num_games}" )
def _enter_dice(self): """simulate user entering which dice to keep. Defaults to all scoring dice""" roll = Game.get_scorers(self.last_roll) roll_string = "" for value in roll: roll_string += str(value) self.report("> " + roll_string) return roll_string
def test_one_and_done(): game = Game() errors = diff( game.play, path="tests/user_acc_test/sim_txt_files/one_and_done.sim.txt") assert not errors, errors[0] # def test_single_bank(): # game = Game() # errors = diff(game.play, path="tests/user_acc_test/bank_one_roll_then_quit.sim.txt") # assert not errors, errors[0] # def test_bank_first_for_two_rounds(): # game = Game() # errors = diff(game.play, path="tests/user_acc_test/bank_first_for_two_rounds.sim.txt") # assert not errors, errors[0]
def play(cls, num_games=1): mega_total = 0 for i in range(num_games): player = cls() game = Game() try: game.start_game() except SystemExit: pass mega_total += player.total_score player.reset() print( f"{cls.__name__}: {num_games} games played with average score of {mega_total // (num_games * game.NUMBER_OF_ROUNDS)} per game" )
def test_single_five(): actual = Game.calculate_score((5,)) expected = 50 assert actual == expected
def test_repeat_roller(): """Allow setting aside scoring dice and rolling the rest """ diffs = diff(Game().play, path="tests/version_3/repeat_roller.sim.txt") assert not diffs, diffs
def test_two_fives(): actual = Game.calculate_score((5, 5)) expected = 100 assert actual == expected
def test_hot_dice(): """When all dice are used without a zilch then user gets 6 fresh dice and continues turn. """ diffs = diff(Game().play, path="tests/version_3/hot_dice.sim.txt") assert not diffs, diffs
def test_two_ones(): actual = Game.calculate_score((1, 1)) expected = 200 assert actual == expected
def test_zilch(): actual = Game.calculate_score((2,)) expected = 0 assert actual == expected
def test_one_and_five(): actual = Game.calculate_score((1, 5)) expected = 150 assert actual == expected
def test_three_fives(): actual = Game.calculate_score((5, 5, 5, 2, 2, 3)) expected = 500 assert actual == expected
def test_quitter(): game = Game() diffs = diff(game.play, path="tests/flow/quitter.txt") assert not diffs, diffs
def test_single_bank(): game = Game() diffs = diff(game.play, path="tests/flow/bank_one_roll_then_quit.txt") assert not diffs, diffs
def test_three_ones(): actual = Game.calculate_score((1, 1, 1, 2, 3, 4)) expected = 1000 assert actual == expected
def test_three_ones_and_a_five(): actual = Game.calculate_score((1, 1, 1, 5)) expected = 1050 assert actual == expected
def test_one_and_done(): game = Game() diffs = diff(game.play, path="tests/flow/one_and_done.sim.txt") assert not diffs, diffs
def test_straight(): actual = Game.calculate_score((1, 6, 3, 2, 5, 4)) expected = 1500 assert actual == expected
def test_bank_first_for_two_rounds(): game = Game() diffs = diff(game.play, path="tests/flow/bank_first_for_two_rounds.txt") assert not diffs, diffs
def test_six_of_a_kind(): actual = Game.calculate_score((2, 2, 2, 2, 2, 2)) expected = 800 assert actual == expected
def test_get_scorers(test_input, expected): actual = Game.get_scores(test_input) assert sorted(actual) == sorted(expected)
def test_six_ones(): actual = Game.calculate_score((1, 1, 1, 1, 1, 1)) expected = 4000 assert actual == expected