Untitled
unknown
plain_text
2 years ago
2.4 kB
13
Indexable
from project.tennis_player import TennisPlayer
from unittest import TestCase, main
class TestTennisPlayer(TestCase):
def setUp(self):
self.player = TennisPlayer("Player", 25, 100)
def test_initialization(self):
self.assertEqual("Player", self.player.name)
self.assertEqual(25, self.player.age)
self.assertEqual(100, self.player.points)
self.assertEqual([], self.player.wins)
def test_name(self):
with self.assertRaises(ValueError) as ve:
self.player.name = "Ai"
self.assertEqual("Name should be more than 2 symbols!", str(ve.exception))
def test_age(self):
with self.assertRaises(ValueError) as ve:
self.player.age = 10
self.assertEqual("Players must be at least 18 years of age!", str(ve.exception))
def test_add_new_win_when_tournament_exist(self):
self.player.wins = ["Tournament_one"]
result = self.player.add_new_win("Tournament_one")
self.assertEqual("Tournament_one has been already added to the list of wins!", result)
def test_add_new_win_when_tournament_does_not_exist(self):
self.player.wins = ["Tournament_one"]
self.player.add_new_win("Tournament_two")
self.assertEqual("['Tournament_one', 'Tournament_two']", str(self.player.wins))
def test_points_when_player_has_more(self):
another_player_name = "Player_two"
another_player = TennisPlayer(another_player_name, 30, -100)
first_result = self.player < another_player
expected_result = f'{self.player.name} is a better player than {another_player_name}'
self.assertEqual(expected_result, first_result)
def test_points_when_player_has_less(self):
another_player_name = "Player_two"
another_player = TennisPlayer(another_player_name, 30, 150)
second_result = another_player > self.player
expected_result = f'{another_player_name} is a top seeded player and he/she is better than {self.player.name}'
self.assertEqual(expected_result, second_result)
def test_correct_str(self):
self.assertEqual(f"Tennis Player: Player\n" +
"Age: 25\n" +
"Points: 100.0\n" +
"Tournaments won: ", str(self.player))
Editor is loading...
Leave a Comment