def test_generate_losing_team_summary(self):
        test_losing_message_string = "team2 lost by 1 wicket  Kirat Boli - 36* (6 balls ) N S Nodhi - 0* (0 balls )"

        team2 = Team("team2")

        p3 = Player('Kirat Boli', batting_order=1, probability_distribution=[0, 0, 0, 0, 0, 0, 100, 0])
        p4 = Player('N S Nodhi', batting_order=2, probability_distribution=[0, 0, 0, 0, 0, 0, 100, 0])

        team2.add_players(p3)
        team2.add_players(p4)

        team2.play(overs=1, balls_per_over=6, target=40)

        losing_message_string = Commentary.generate_team_summary(team2, is_winner=0)

        self.assertEqual(test_losing_message_string, losing_message_string)

        print("Generate Summary for losing team test case executed successfully", end='\n\n')
    def test_generate_winning_team_summary(self):
        test_winning_message_string = "team1 won by 1 wicket and 3 over 0 balls remaining Kirat Boli - 36* (6 balls ) N S Nodhi - 0* (0 balls )"

        team1 = Team("team1")

        p1 = Player('Kirat Boli', batting_order=1, probability_distribution=[0, 0, 0, 0, 0, 0, 100, 0])
        p2 = Player('N S Nodhi', batting_order=2, probability_distribution=[0, 0, 0, 0, 0, 0, 100, 0])

        team1.add_players(p1)
        team1.add_players(p2)

        team1.play(overs=4, balls_per_over=6, target=35)

        winning_message_string = Commentary.generate_team_summary(team1, is_winner=1)

        self.assertEqual(test_winning_message_string, winning_message_string)

        print("Generate Summary for winning team test case executed successfully", end='\n\n')
Example #3
0
team1 = Team('Bengaluru')

team2 = Team('Chennai')
team2.set_runs(40)

p1 = Player('Kirat Boli',
            batting_order=1,
            probability_distribution=[5, 30, 25, 10, 15, 1, 9, 5])
p2 = Player('N S Nodhi',
            batting_order=2,
            probability_distribution=[10, 40, 20, 5, 10, 1, 4, 10])
p3 = Player('R Rumrah',
            batting_order=3,
            probability_distribution=[20, 30, 15, 5, 5, 1, 4, 20])
p4 = Player('Shashi Henra',
            batting_order=4,
            probability_distribution=[30, 25, 5, 0, 5, 1, 4, 30])

team1.add_players(p1)
team1.add_players(p2)
team1.add_players(p3)
team1.add_players(p4)

game.add_team(team1)
game.add_team(team2)

result_object = game.play()

Commentary.generate_summary(result_object["winning_team"],
                            result_object["losing_team"])
class TeamTestCase(TestCase):
    def setUp(self):
        print("", end='\n\n')
        print("Running test cases for Team", end="\n\n")
        self.t1 = Team('team1')

    def test_create_team(self):

        self.assertEqual('team1', self.t1.name)
        print("Create Team test case executed successfully", end='\n\n')

    def test_add_player(self):
        players = copy.copy(self.t1.get_players())

        p1 = Player('Kirat Boli',
                    batting_order=1,
                    probability_distribution=[5, 30, 25, 10, 15, 1, 9, 5])
        self.t1.add_players(p1)

        self.assertEqual(len(players) + 1, len(self.t1.total_players))

        print("Add Player to the Team test case executed successfully",
              end='\n\n')

    def test_get_next_player(self):
        p1 = Player('Kirat Boli',
                    batting_order=1,
                    probability_distribution=[5, 30, 25, 10, 15, 1, 9, 5])
        p2 = Player('N S Nodhi',
                    batting_order=2,
                    probability_distribution=[10, 40, 20, 5, 10, 1, 4, 10])

        self.t1.add_players(p1)
        self.t1.add_players(p2)

        next_player = self.t1.get_next_player()
        self.assertEqual(p2.name, next_player.name)

        print("Get Next Player of the Team test case executed successfully",
              end='\n\n')

    def test_set_active_players(self):
        active_players = self.t1.active_players

        p1 = Player('Kirat Boli',
                    batting_order=1,
                    probability_distribution=[5, 30, 25, 10, 15, 1, 9, 5])
        p2 = Player('N S Nodhi',
                    batting_order=2,
                    probability_distribution=[10, 40, 20, 5, 10, 1, 4, 10])

        self.t1.add_players(p1)
        self.t1.add_players(p2)

        self.t1.set_active_players()

        self.assertEqual(len(active_players) + 2, len(self.t1.active_players))

        print("Set Active Players of the Team test case executed successfully",
              end='\n\n')

    def test_play(self):
        p1 = Player('Kirat Boli',
                    batting_order=1,
                    probability_distribution=[5, 30, 25, 10, 15, 1, 9, 5])
        p2 = Player('N S Nodhi',
                    batting_order=2,
                    probability_distribution=[10, 40, 20, 5, 10, 1, 4, 10])
        p3 = Player('R Rumrah',
                    batting_order=3,
                    probability_distribution=[20, 30, 15, 5, 5, 1, 4, 20])
        p4 = Player('Shashi Henra',
                    batting_order=4,
                    probability_distribution=[30, 25, 5, 0, 5, 1, 4, 30])

        self.t1.add_players(p1)
        self.t1.add_players(p2)
        self.t1.add_players(p3)
        self.t1.add_players(p4)

        self.t1.play(overs=4, balls_per_over=6, target=40)

        self.assertTrue(0 <= self.t1.runs_scored <= 46)

        print("Play of the Team test case executed successfully", end='\n\n')

    def tearDown(self):
        print("Test cases executed successfully for Team", end="\n\n")