Ejemplo n.º 1
0
 def test_the_players_counter(self):
     game = trivia.Game()
     game.add('Alex')
     game.add('Kelly')
     self.assertEqual(game.how_many_players, 2)
     logging.info(
         "Check the numbers of players is counted correctly or not\n")
Ejemplo n.º 2
0
    def test_one(self):
        sys.stdout = open('reference/test_result.txt', 'w')

        idomero=trivia.Idomero(30)
        
        game = trivia.Game(None, None)

        game.add('Chet')
        game.add('Pat')
        game.add('Sue')

        dice_trows =    [6,6,6,1,3,1,6,4,1,2,4,6,1,2,3,4,2,3,1,1,6,1,6,6,3,4,6,4,4,2,6,4,2,5,5,4,6,4,1,6,5,5,5,5,1,2,3,3,4,4]
        given_answers = [6,9,2,4,7,0,5,1,0,2,8,4,2,3,8,1,2,5,1,7,8,4,5,7,8,1,3,1,9,2,9,6,2,2,1,0,2,6,1,2,8,9,7,1,3,5,2,5,1,3]
        given_time =    [1,2,3,4,5,4,3,3,9,9,9,1,1,9,9,9,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]

        test_game_states = zip(dice_trows, given_answers, given_time)

        for (throw, answer, time) in test_game_states:
            game.roll(throw)

            timeout = idomero.addanswertime(time)
            if answer == 7:
                not_a_winner = game.wrong_answer()
            else:
                not_a_winner = game.was_correctly_answered()

            ## nyert valaki / lejart az ido / megy tovabb
            if timeout:
                game.close_game('Winner on timeout: ')
                # gyoztes kihirdetese
            elif not not_a_winner:
                # uj jatek a vesztesekkel + az uj jatekossal
                # Erre meg nem keszult teszt
                game.close_game('Winner on max points: ')
                game = trivia.Game(None, None)
                game.add('Sue')
                game.add('Pat')
                game.add('Bob')
                
                

        sys.stdout.close()

        test_file   = open('reference/result.txt', 'r').read()
        test_result = open('reference/test_result.txt', 'r').read()

        self.assertEqual(test_file, test_result)
Ejemplo n.º 3
0
 def test_game_is_playable_with_more_players(self):
     game = trivia.Game()
     game.add('Alex')
     game.add('Kelly')
     game.add('Susan')
     game.add('Carl')
     self.assertTrue(game.is_playable())
     logging.info("The game is playable with more players\n")
Ejemplo n.º 4
0
 def test_current_category_is_rock(self):
     game = trivia.Game()
     game.add('Alex')
     game.add('Kelly')
     game.places[0] = 3
     actual_result_of_current_category = game._current_category
     self.assertEqual(actual_result_of_current_category, 'Rock')
     logging.info("The current category is: " +
                  actual_result_of_current_category + "\n")
Ejemplo n.º 5
0
 def test_the_answer_is_correct(self):
     game = trivia.Game()
     game.add('Alex')
     game.add('Kelly')
     game.places[0] = 3
     actual_result_of_current_category = game._current_category
     game._did_player_win()
     result = game.was_correctly_answered()
     self.assertTrue(game._did_player_win)
     logging.info("The answer is: " + str(result) + "\n")
Ejemplo n.º 6
0
 def test_current_category_is_science(self):
     game = trivia.Game()
     game.add('Alex')
     game.add('Kelly')
     game.places[game.current_player] = 5
     actual_result_of_current_category = game._current_category
     self.assertEqual(actual_result_of_current_category, "Science")
     logging.info("The current category is: " +
                  actual_result_of_current_category + " for " +
                  game.players[game.current_player] + "\n")
Ejemplo n.º 7
0
 def test_not_winner_with_less_coin(self):
     game = trivia.Game()
     game.add('Alex')
     game.add('Kelly')
     game.current_player = 1
     game.places[1] = 3
     game.purses[1] = 5
     winner = game._did_player_win()
     self.assertFalse(
         winner, "The correct answer should be: " +
         game.players[game.current_player] + " is not a winner with " +
         str(game.purses[game.current_player]) + "\n")
Ejemplo n.º 8
0
 def test_the_player_is_winner(self):
     game = trivia.Game()
     game.add('Alex')
     game.add('Kelly')
     game.places[0] = 3
     game.purses[0] = 7
     winner = game._did_player_win()
     self.assertTrue(
         winner,
         game.players[game.current_player] + " should be the winner with " +
         str(game.purses[game.current_player]) + "\n")
     logging.info("The winner is: " + game.players[game.current_player] +
                  " with " + str(game.purses[game.current_player]) + "\n")
Ejemplo n.º 9
0
 def test_game_is_playable_with_two_players(self):
     game = trivia.Game()
     game.add('Alex')
     game.add('Kelly')
     self.assertTrue(game.is_playable())
     logging.info("The game is playable with two players\n")
Ejemplo n.º 10
0
 def test_game_is_not_playable_with_one_player(self):
     game = trivia.Game()
     game.add('Susan')
     self.assertFalse(game.is_playable())
     logging.info("The game is not playable with one player\n")
Ejemplo n.º 11
0
 def test_game_is_not_playable(self):
     game = trivia.Game()
     self.assertFalse(game.is_playable())
     logging.info("\nThe game is not playable without any player\n")