def setUp(self): self.team_name = 'The Team' self.team = Team(self.team_name) self.player_name = 'A Player' self.player = Player(self.player_name) self.another_player_name = 'Another Player' self.another_player = Player(self.another_player_name)
class TestTeam(unittest.TestCase): """ Test functionality of the cricket team """ def setUp(self): self.team_name = 'The Team' self.team = Team(self.team_name) self.player_name = 'A Player' self.player = Player(self.player_name) self.another_player_name = 'Another Player' self.another_player = Player(self.another_player_name) def test_creation(self): otago_name = 'Otago' team = Team(otago_name) self.assertEqual(otago_name, team.name) self.assertEqual(0, team.num_players) def test_adding_player(self): self.assertEqual(0, self.team.num_players) self.team.add_player(self.player) self.assertEqual(1, self.team.num_players) def test_adding_2_player(self): self.assertEqual(0, self.team.num_players) self.team.add_player(self.player) self.team.add_player(self.another_player) self.assertEqual(2, self.team.num_players) def test_removing_2_player(self): self.assertEqual(0, self.team.num_players) self.team.add_player(self.player) self.team.add_player(self.another_player) self.team.remove_player(self.player) self.team.remove_player(self.another_player) self.assertEqual(0, self.team.num_players)