Advertisement
horozov86

Tennis player Unit Tests

Aug 3rd, 2023
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. from project.tennis_player import TennisPlayer
  2.  
  3. from unittest import TestCase, main
  4.  
  5.  
  6. class TestTennisPlayer(TestCase):
  7.     def setUp(self) -> None:
  8.         self.tennis_player = TennisPlayer('Georgi', 37, 200)
  9.  
  10.     def test_init(self):
  11.         self.assertEqual('Georgi', self.tennis_player.name)
  12.         self.assertEqual(37, self.tennis_player.age)
  13.         self.assertEqual(200, self.tennis_player.points)
  14.         self.assertEqual([], self.tennis_player.wins)
  15.  
  16.     def test_name_is_less_than_two_characters_raise(self):
  17.         with self.assertRaises(ValueError) as ve:
  18.             self.tennis_player.name = 'a'
  19.         self.assertEqual("Name should be more than 2 symbols!", str(ve.exception))
  20.  
  21.     def test_age_under_18_raises(self):
  22.         with self.assertRaises(ValueError) as ve:
  23.             self.tennis_player.age = 14
  24.  
  25.         self.assertEqual("Players must be at least 18 years of age!", str(ve.exception))
  26.  
  27.     def test_add_tournament_name_successfully(self):
  28.         result = self.tennis_player.add_new_win('Wimbeldon')
  29.         self.assertEqual(['Wimbeldon'], self.tennis_player.wins)
  30.  
  31.     def test_tournament_name_is_already_added_raises(self):
  32.         self.tennis_player.add_new_win('Wimbeldon')
  33.         result = self.tennis_player.add_new_win('Wimbeldon')
  34.         expected_result = "Wimbeldon has been already added to the list of wins!"
  35.         self.assertEqual(expected_result, result)
  36.  
  37.     def test_points_first_tennis_player_are_less_second_player(self):
  38.         second_player = TennisPlayer('Peter', 36, 300)
  39.         result = self.tennis_player < second_player
  40.         expected_result = 'Peter is a top seeded player and he/she is better than Georgi'
  41.         self.assertEqual(expected_result, result)
  42.  
  43.     def test_points_second_tennis_player_are_less_first_player(self):
  44.         second_player = TennisPlayer('Peter', 36, 300)
  45.         result = second_player < self.tennis_player
  46.         expected_result = 'Peter is a better player than Georgi'
  47.         self.assertEqual(expected_result, result)
  48.  
  49.     def test_str(self):
  50.         self.tennis_player.add_new_win('Wimbeldon')
  51.         self.tennis_player.add_new_win('Australian open')
  52.         result = f"Tennis Player: Georgi\n" \
  53.                f"Age: 37\n" \
  54.                f"Points: 200.0\n" \
  55.                f"Tournaments won: Wimbeldon, Australian open"
  56.         self.assertEqual(result, self.tennis_player.__str__())
  57.  
  58.  
  59. if __name__ == '__main__':
  60.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement