Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from project.tennis_player import TennisPlayer
- from unittest import TestCase, main
- class TestTennisPlayer(TestCase):
- def setUp(self) -> None:
- self.tennis_player = TennisPlayer('Georgi', 37, 200)
- def test_init(self):
- self.assertEqual('Georgi', self.tennis_player.name)
- self.assertEqual(37, self.tennis_player.age)
- self.assertEqual(200, self.tennis_player.points)
- self.assertEqual([], self.tennis_player.wins)
- def test_name_is_less_than_two_characters_raise(self):
- with self.assertRaises(ValueError) as ve:
- self.tennis_player.name = 'a'
- self.assertEqual("Name should be more than 2 symbols!", str(ve.exception))
- def test_age_under_18_raises(self):
- with self.assertRaises(ValueError) as ve:
- self.tennis_player.age = 14
- self.assertEqual("Players must be at least 18 years of age!", str(ve.exception))
- def test_add_tournament_name_successfully(self):
- result = self.tennis_player.add_new_win('Wimbeldon')
- self.assertEqual(['Wimbeldon'], self.tennis_player.wins)
- def test_tournament_name_is_already_added_raises(self):
- self.tennis_player.add_new_win('Wimbeldon')
- result = self.tennis_player.add_new_win('Wimbeldon')
- expected_result = "Wimbeldon has been already added to the list of wins!"
- self.assertEqual(expected_result, result)
- def test_points_first_tennis_player_are_less_second_player(self):
- second_player = TennisPlayer('Peter', 36, 300)
- result = self.tennis_player < second_player
- expected_result = 'Peter is a top seeded player and he/she is better than Georgi'
- self.assertEqual(expected_result, result)
- def test_points_second_tennis_player_are_less_first_player(self):
- second_player = TennisPlayer('Peter', 36, 300)
- result = second_player < self.tennis_player
- expected_result = 'Peter is a better player than Georgi'
- self.assertEqual(expected_result, result)
- def test_str(self):
- self.tennis_player.add_new_win('Wimbeldon')
- self.tennis_player.add_new_win('Australian open')
- result = f"Tennis Player: Georgi\n" \
- f"Age: 37\n" \
- f"Points: 200.0\n" \
- f"Tournaments won: Wimbeldon, Australian open"
- self.assertEqual(result, self.tennis_player.__str__())
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement