def test_current_category_is_rock(): test_game = Game() test_game.add('Chet') test_game.add('Pat') test_game.roll(7) for i in range(2): test_game.roll(4) assert test_game._current_category == "Rock"
def test_current_category_is_science(): test_game = Game() test_game.add('Chet') test_game.add('Pat') test_game.roll(5) for i in range(2): test_game.roll(4) assert test_game._current_category == "Science"
def test_current_category_is_sports(): test_game = Game() test_game.add('Chet') test_game.add('Pat') test_game.roll(6) for i in range(2): test_game.roll(4) assert test_game._current_category == "Sports"
def test_current_category_is_pop(): test_game = Game() test_game.add('Chet') test_game.add('Pat') test_game.roll(4) for i in range(2): test_game.roll(4) assert test_game._current_category == "Pop"
def test_is_playable(): g = Game() assert not g.is_playable() g.add('one') assert not g.is_playable() g.add('two') assert g.is_playable()
def test_is_playable(self): game = Game() assert game.is_playable() == False game.add("Player1") assert game.is_playable() == False game.add("Player2") assert game.is_playable() == True
def test_foo(self): # Given # When Game() # Then assert True == True
def test_three(self, stdout): randrange = [0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 2, 2, 0, 0, 2, 0, 0, 2] game = Game() game.add('Chet') game.add('Pat') game.add('Sue') game.is_playable() while randrange: game.roll(randrange.pop() + 1) not_a_winner = game.wrong_answer() if not not_a_winner: break Approvals.verify(stdout.getvalue(), reporter)
def main(): random.seed(1) not_a_winner = False game = Game() game.add('Chet') game.add('Pat') game.add('Sue') while True: game.roll(random.randrange(5) + 1) if random.randrange(9) == 7: not_a_winner = game.wrong_answer() else: not_a_winner = game.was_correctly_answered() if not not_a_winner: break
class CorrectlyAnsweredTest(unittest.TestCase): def setUp(self): self.game = Game() self.game.add('Chet') def test_player_not_in_penalty(self): self.game.was_correctly_answered() self.assertEqual(self.game.purses[0], 1) def test_player_in_penalty_not_getting_out(self): self.game.in_penalty_box[0] = True self.game.is_getting_out_of_penalty_box = False self.game.was_correctly_answered() self.assertEqual(self.game.purses[0], 0) def test_player_in_penalty_and_getting_out(self): self.game.in_penalty_box[0] = True self.game.is_getting_out_of_penalty_box = True self.game.was_correctly_answered() self.assertEqual(self.game.purses[0], 1)
def test(self, stdout): game = Game() game.add('one') game.add('two') Approvals.verify(stdout.getvalue(), reporter)
class TestGame(unittest.TestCase): def setUp(self): self.game = Game() def test_game(self): result = """Chet was added They are player number 1 Pat was added They are player number 2 Sue was added They are player number 3 Chet is the current player They have rolled a 5 Chet's new location is 5 The category is Science Science Question 0 Answer was corrent!!!! Chet now has 1 Gold Coins. Pat is the current player They have rolled a 5 Pat's new location is 5 The category is Science Science Question 1 Answer was corrent!!!! Pat now has 1 Gold Coins. Sue is the current player They have rolled a 5 Sue's new location is 5 The category is Science Science Question 2 Answer was corrent!!!! Sue now has 1 Gold Coins. Chet is the current player They have rolled a 3 Chet's new location is 8 The category is Pop Pop Question 0 Answer was corrent!!!! Chet now has 2 Gold Coins. Pat is the current player They have rolled a 4 Pat's new location is 9 The category is Science Science Question 3 Answer was corrent!!!! Pat now has 2 Gold Coins. Sue is the current player They have rolled a 2 Sue's new location is 7 The category is Rock Rock Question 0 Answer was corrent!!!! Sue now has 2 Gold Coins. Chet is the current player They have rolled a 4 Chet's new location is 0 The category is Pop Pop Question 1 Answer was corrent!!!! Chet now has 3 Gold Coins. Pat is the current player They have rolled a 5 Pat's new location is 2 The category is Sports Sports Question 0 Answer was corrent!!!! Pat now has 3 Gold Coins. Sue is the current player They have rolled a 1 Sue's new location is 8 The category is Pop Pop Question 2 Answer was corrent!!!! Sue now has 3 Gold Coins. Chet is the current player They have rolled a 2 Chet's new location is 2 The category is Sports Sports Question 1 Answer was corrent!!!! Chet now has 4 Gold Coins. Pat is the current player They have rolled a 4 Pat's new location is 6 The category is Sports Sports Question 2 Answer was corrent!!!! Pat now has 4 Gold Coins. Sue is the current player They have rolled a 5 Sue's new location is 1 The category is Science Science Question 4 Answer was corrent!!!! Sue now has 4 Gold Coins. Chet is the current player They have rolled a 4 Chet's new location is 6 The category is Sports Sports Question 3 Answer was corrent!!!! Chet now has 5 Gold Coins. Pat is the current player They have rolled a 2 Pat's new location is 8 The category is Pop Pop Question 3 Answer was corrent!!!! Pat now has 5 Gold Coins. Sue is the current player They have rolled a 4 Sue's new location is 5 The category is Science Science Question 5 Answer was corrent!!!! Sue now has 5 Gold Coins. Chet is the current player They have rolled a 3 Chet's new location is 9 The category is Science Science Question 6 Answer was corrent!!!! Chet now has 6 Gold Coins. """ temp_output = StringIO() origin = sys.stdout sys.stdout = temp_output self.game.add('Chet') self.game.add('Pat') self.game.add('Sue') random.seed(30) while True: self.game.roll(random.randrange(5) + 1) if random.randrange(9) == 7: not_a_winner = self.game.wrong_answer() else: not_a_winner = self.game.was_correctly_answered() if not not_a_winner: break sys.stdout = origin self.assertEqual(result, temp_output.getvalue()) def test_second_seed(self): result = """Chet was added They are player number 1 Pat was added They are player number 2 Sue was added They are player number 3 Chet is the current player They have rolled a 2 Chet's new location is 2 The category is Sports Sports Question 0 Question was incorrectly answered Chet was sent to the penalty box Pat is the current player They have rolled a 3 Pat's new location is 3 The category is Rock Rock Question 0 Answer was corrent!!!! Pat now has 1 Gold Coins. Sue is the current player They have rolled a 2 Sue's new location is 2 The category is Sports Sports Question 1 Answer was corrent!!!! Sue now has 1 Gold Coins. Chet is the current player They have rolled a 1 Chet is getting out of the penalty box Chet's new location is 3 The category is Rock Rock Question 1 Answer was correct!!!! Chet now has 1 Gold Coins. Pat is the current player They have rolled a 4 Pat's new location is 7 The category is Rock Rock Question 2 Answer was corrent!!!! Pat now has 2 Gold Coins. Sue is the current player They have rolled a 2 Sue's new location is 4 The category is Pop Pop Question 0 Answer was corrent!!!! Sue now has 2 Gold Coins. Chet is the current player They have rolled a 2 Chet is not getting out of the penalty box Pat is the current player They have rolled a 5 Pat's new location is 0 The category is Pop Pop Question 1 Answer was corrent!!!! Pat now has 3 Gold Coins. Sue is the current player They have rolled a 2 Sue's new location is 6 The category is Sports Sports Question 2 Answer was corrent!!!! Sue now has 3 Gold Coins. Chet is the current player They have rolled a 1 Chet is getting out of the penalty box Chet's new location is 4 The category is Pop Pop Question 2 Question was incorrectly answered Chet was sent to the penalty box Pat is the current player They have rolled a 5 Pat's new location is 5 The category is Science Science Question 0 Answer was corrent!!!! Pat now has 4 Gold Coins. Sue is the current player They have rolled a 1 Sue's new location is 7 The category is Rock Rock Question 3 Answer was corrent!!!! Sue now has 4 Gold Coins. Chet is the current player They have rolled a 4 Chet is not getting out of the penalty box Question was incorrectly answered Chet was sent to the penalty box Pat is the current player They have rolled a 3 Pat's new location is 8 The category is Pop Pop Question 3 Answer was corrent!!!! Pat now has 5 Gold Coins. Sue is the current player They have rolled a 3 Sue's new location is 10 The category is Sports Sports Question 3 Answer was corrent!!!! Sue now has 5 Gold Coins. Chet is the current player They have rolled a 5 Chet is getting out of the penalty box Chet's new location is 9 The category is Science Science Question 1 Answer was correct!!!! Chet now has 2 Gold Coins. Pat is the current player They have rolled a 4 Pat's new location is 0 The category is Pop Pop Question 4 Answer was corrent!!!! Pat now has 6 Gold Coins. """ temp_output = StringIO() origin = sys.stdout sys.stdout = temp_output self.game.add('Chet') self.game.add('Pat') self.game.add('Sue') random.seed(485214524) while True: self.game.roll(random.randrange(5) + 1) if random.randrange(9) == 7: not_a_winner = self.game.wrong_answer() else: not_a_winner = self.game.was_correctly_answered() if not not_a_winner: break sys.stdout = origin self.assertEqual(result, temp_output.getvalue()) def test_un_joueur(self): result = """Chet was added They are player number 1 Chet is the current player They have rolled a 5 Chet's new location is 5 The category is Science Science Question 0 Answer was corrent!!!! Chet now has 1 Gold Coins. Chet is the current player They have rolled a 5 Chet's new location is 10 The category is Sports Sports Question 0 Answer was corrent!!!! Chet now has 2 Gold Coins. Chet is the current player They have rolled a 5 Chet's new location is 3 The category is Rock Rock Question 0 Answer was corrent!!!! Chet now has 3 Gold Coins. Chet is the current player They have rolled a 3 Chet's new location is 6 The category is Sports Sports Question 1 Answer was corrent!!!! Chet now has 4 Gold Coins. Chet is the current player They have rolled a 4 Chet's new location is 10 The category is Sports Sports Question 2 Answer was corrent!!!! Chet now has 5 Gold Coins. Chet is the current player They have rolled a 2 Chet's new location is 0 The category is Pop Pop Question 0 Answer was corrent!!!! Chet now has 6 Gold Coins. """ temp_output = StringIO() origin = sys.stdout sys.stdout = temp_output self.game.add('Chet') random.seed(30) while True: self.game.roll(random.randrange(5) + 1) if random.randrange(9) == 7: not_a_winner = self.game.wrong_answer() else: not_a_winner = self.game.was_correctly_answered() if not not_a_winner: break sys.stdout = origin self.assertEqual(result, temp_output.getvalue())
def setUp(self): self.game = Game()
def test_create_rock_question(self): game = Game() res = game.create_rock_question(5) assert res == "Rock Question 5"
def test_add_player(self, stdout): game = Game() res = game.add("Player") assert res assert stdout.getvalue() == "Player was added\nThey are player number 1\n"
def test_ask_question(): test_game = Game() test_game.add('Chet') test_game.add('Pat') test_game.roll(7) assert test_game.questions['Rock'] == 1
def setUp(self): self.game = Game() self.game.add('Chet')
class GameTest(unittest.TestCase): def setUp(self): self.game = Game() self.game.add('Chet') def test_player_put_in_penalty_box(self): self.game.wrong_answer() self.assertTrue(self.game.in_penalty_box[0]) def test_player_gets_out_of_penalty_box_on_odd_roll(self): self.game.wrong_answer() self.game.roll(1) self.game.was_correctly_answered() self.assertFalse(self.game.in_penalty_box[0]) def test_player_does_not_gets_out_of_penalty_box_on_even_roll(self): self.game.wrong_answer() self.game.roll(2) self.game.was_correctly_answered() self.assertTrue(self.game.in_penalty_box[0])
class TimeTest(unittest.TestCase): def setUp(self): self.game = Game() self.game.add('Chet') self.game.add('Pat') def test_game_has_timer(self): self.assertIsNotNone(self.game.timer) def test_game_timer_changes_after_correct_answer(self): timer = self.game.timer self.game.roll(4) self.game.was_correctly_answered() self.assertNotEquals(timer, self.game.timer) def test_game_timer_changes_after_wrong_answer(self): timer = self.game.timer self.game.roll(4) self.game.wrong_answer() self.assertNotEquals(timer, self.game.timer)
class GameAddTest(unittest.TestCase): def setUp(self): self.game = Game() def test_6_players_can_play(self): self.game.add('1') self.game.add('2') self.game.add('3') self.game.add('4') self.game.add('5') self.game.add('6') def test_8_players_can_play(self): self.game.add('1') self.game.add('2') self.game.add('3') self.game.add('4') self.game.add('5') self.game.add('6') self.game.add('7') self.game.add('8')
def test_it(self): game = Game() game.add('Chet') assert len(game.players) == 2
def game(): g = Game() g.add('a') g.add('b') return g
from trivia import Game with open('randomSeq.txt') as f: f.readline() winner_range = f.readline().strip().split(',')[:-1] winner_range.reverse() f.readline() f.readline() rolls = f.readline().strip().split(',')[:-1] rolls.reverse() game = Game() game.add('Chet') game.add('Pat') game.add('Sue') while True: game.roll(int(rolls.pop())) if int(winner_range.pop()) == 7: not_a_winner = game.wrong_answer() else: not_a_winner = game.was_correctly_answered() if not not_a_winner: break
def test_two(self, stdout): randrange = [1, 6, 7, 1, 2, 3, 4, 5, 3, 1, 2, 3, 6, 2, 4, 7, 4, 2, 1, 3, 6, 4, 3, 2, 4, 7, 2, 4] game = Game() game.add('Chet') game.add('Pat') game.add('Sue') game.is_playable() while randrange: game.roll(randrange.pop() + 1) if randrange.pop() == 7: not_a_winner = game.wrong_answer() else: not_a_winner = game.was_correctly_answered() if not not_a_winner: break Approvals.verify(stdout.getvalue(), reporter)