コード例 #1
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)
コード例 #2
0
ファイル: acceptance_test.py プロジェクト: txomon/trivia
    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)
コード例 #3
0
ファイル: acceptance_test.py プロジェクト: txomon/trivia
    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)
コード例 #4
0
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
コード例 #5
0
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])
コード例 #6
0
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
コード例 #7
0
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())