Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 556adaf

Browse files
committed
WKT: updated enums
Signed-off-by: Serhii Horodilov <sgorodil@gmail.com>
1 parent 99550bf commit 556adaf

File tree

4 files changed

+66
-65
lines changed

4 files changed

+66
-65
lines changed

src/wtk/enums.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def __str__(self) -> str:
2222
class FightChoice(enum.Enum):
2323
"""Fight choice enumeration model"""
2424

25-
WARRIOR = enum.auto()
26-
ROBBER = enum.auto()
25+
KNIGHT = enum.auto()
26+
THIEF = enum.auto()
2727
WIZARD = enum.auto()
2828

2929
def __str__(self) -> str:
@@ -58,20 +58,21 @@ def get_fight_result(attack: FightChoice, defence: FightChoice) -> FightResult:
5858

5959
# perform type validation
6060
if not isinstance(attack, FightChoice) or \
61-
not isinstance(defence, FightChoice):
61+
not isinstance(defence, FightChoice):
62+
attack_cls = attack.__class__.__name__
63+
defence_cls = defence.__class__.__name__
6264
raise TypeError(
63-
f"unsupported argument type(s): "
64-
f"'{attack.__class__.__name__}' and '{defence.__class__.__name__}'"
65+
f"unsupported argument type(s): '{attack_cls}' and '{defence_cls}'"
6566
)
6667

6768
# calculate result
6869
if attack == defence:
6970
return FightResult.DRAW
7071

7172
successful_attacks = (
72-
(FightChoice.WARRIOR, FightChoice.ROBBER),
73-
(FightChoice.ROBBER, FightChoice.WIZARD),
74-
(FightChoice.WIZARD, FightChoice.WARRIOR),
73+
(FightChoice.KNIGHT, FightChoice.THIEF),
74+
(FightChoice.THIEF, FightChoice.WIZARD),
75+
(FightChoice.WIZARD, FightChoice.KNIGHT),
7576
)
7677
if (attack, defence) in successful_attacks:
7778
return FightResult.SUCCESS

tests/wtk/integration/models_test.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ def setUp(self) -> None:
1515
# noinspection PyUnusedLocal
1616
@mock.patch(
1717
"wtk.models.Player.select_attack",
18-
return_value=enums.FightChoice.WARRIOR
18+
return_value=enums.FightChoice.KNIGHT
1919
)
2020
@mock.patch(
2121
"wtk.models.Enemy.select_defence",
22-
return_value=enums.FightChoice.ROBBER
22+
return_value=enums.FightChoice.THIEF
2323
)
2424
def test_decrease_health(self, *mocks):
2525
self.enemy.decrease_health = mock.Mock()
@@ -29,11 +29,11 @@ def test_decrease_health(self, *mocks):
2929
# noinspection PyUnusedLocal
3030
@mock.patch(
3131
"wtk.models.Player.select_attack",
32-
return_value=enums.FightChoice.WARRIOR
32+
return_value=enums.FightChoice.KNIGHT
3333
)
3434
@mock.patch(
3535
"wtk.models.Enemy.select_defence",
36-
return_value=enums.FightChoice.ROBBER
36+
return_value=enums.FightChoice.THIEF
3737
)
3838
def test_score_assignment(self, *mocks):
3939
self.player.add_score_points = mock.Mock()
@@ -43,11 +43,11 @@ def test_score_assignment(self, *mocks):
4343
# noinspection PyUnusedLocal
4444
@mock.patch(
4545
"wtk.models.Player.select_attack",
46-
return_value=enums.FightChoice.WARRIOR
46+
return_value=enums.FightChoice.KNIGHT
4747
)
4848
@mock.patch(
4949
"wtk.models.Enemy.select_defence",
50-
return_value=enums.FightChoice.ROBBER
50+
return_value=enums.FightChoice.THIEF
5151
)
5252
def test_score_assignment_enemy_down(self, *mocks):
5353
self.player.add_score_points = mock.Mock()
@@ -58,11 +58,11 @@ def test_score_assignment_enemy_down(self, *mocks):
5858
# noinspection PyUnusedLocal
5959
@mock.patch(
6060
"wtk.models.Player.select_attack",
61-
return_value=enums.FightChoice.WARRIOR
61+
return_value=enums.FightChoice.KNIGHT
6262
)
6363
@mock.patch(
6464
"wtk.models.Enemy.select_defence",
65-
return_value=enums.FightChoice.ROBBER
65+
return_value=enums.FightChoice.THIEF
6666
)
6767
def test_messages(self, *mocks):
6868
message = f"INFO:PlayerModel:{settings.MSG_SUCCESS_ATTACK}"
@@ -79,7 +79,7 @@ def setUp(self) -> None:
7979
# noinspection PyUnusedLocal
8080
@mock.patch(
8181
"wtk.models.Player.select_attack",
82-
return_value=enums.FightChoice.WARRIOR
82+
return_value=enums.FightChoice.KNIGHT
8383
)
8484
@mock.patch(
8585
"wtk.models.Enemy.select_defence",
@@ -93,7 +93,7 @@ def test_decrease_health(self, *mocks):
9393
# noinspection PyUnusedLocal
9494
@mock.patch(
9595
"wtk.models.Player.select_attack",
96-
return_value=enums.FightChoice.WARRIOR
96+
return_value=enums.FightChoice.KNIGHT
9797
)
9898
@mock.patch(
9999
"wtk.models.Enemy.select_defence",
@@ -107,7 +107,7 @@ def test_score_assignment(self, *mocks):
107107
# noinspection PyUnusedLocal
108108
@mock.patch(
109109
"wtk.models.Player.select_attack",
110-
return_value=enums.FightChoice.WARRIOR
110+
return_value=enums.FightChoice.KNIGHT
111111
)
112112
@mock.patch(
113113
"wtk.models.Enemy.select_defence",
@@ -128,11 +128,11 @@ def setUp(self) -> None:
128128
# noinspection PyUnusedLocal
129129
@mock.patch(
130130
"wtk.models.Enemy.select_attack",
131-
return_value=enums.FightChoice.ROBBER
131+
return_value=enums.FightChoice.THIEF
132132
)
133133
@mock.patch(
134134
"wtk.models.Player.select_defence",
135-
return_value=enums.FightChoice.WARRIOR
135+
return_value=enums.FightChoice.KNIGHT
136136
)
137137
def test_decrease_health(self, *mocks):
138138
self.player.decrease_health = mock.MagicMock()
@@ -142,11 +142,11 @@ def test_decrease_health(self, *mocks):
142142
# noinspection PyUnusedLocal
143143
@mock.patch(
144144
"wtk.models.Enemy.select_attack",
145-
return_value=enums.FightChoice.ROBBER
145+
return_value=enums.FightChoice.THIEF
146146
)
147147
@mock.patch(
148148
"wtk.models.Player.select_defence",
149-
return_value=enums.FightChoice.WARRIOR
149+
return_value=enums.FightChoice.KNIGHT
150150
)
151151
def test_score_assignment(self, *mocks):
152152
self.player.add_score_points = mock.Mock()
@@ -156,11 +156,11 @@ def test_score_assignment(self, *mocks):
156156
# noinspection PyUnusedLocal
157157
@mock.patch(
158158
"wtk.models.Enemy.select_attack",
159-
return_value=enums.FightChoice.ROBBER
159+
return_value=enums.FightChoice.THIEF
160160
)
161161
@mock.patch(
162162
"wtk.models.Player.select_defence",
163-
return_value=enums.FightChoice.WARRIOR
163+
return_value=enums.FightChoice.KNIGHT
164164
)
165165
def test_messages(self, mock_print, *mocks):
166166
message = f"INFO:PlayerModel:{settings.MSG_SUCCESS_DEFENCE}"
@@ -181,7 +181,7 @@ def setUp(self) -> None:
181181
)
182182
@mock.patch(
183183
"wtk.models.Player.select_defence",
184-
return_value=enums.FightChoice.WARRIOR
184+
return_value=enums.FightChoice.KNIGHT
185185
)
186186
def test_decrease_health(self, *mocks):
187187
self.player.decrease_health = mock.MagicMock()
@@ -195,7 +195,7 @@ def test_decrease_health(self, *mocks):
195195
)
196196
@mock.patch(
197197
"wtk.models.Player.select_defence",
198-
return_value=enums.FightChoice.WARRIOR
198+
return_value=enums.FightChoice.KNIGHT
199199
)
200200
def test_messages(self, *mocks):
201201
message = f"INFO:PlayerModel:{settings.MSG_FAILURE_DEFENCE}"
@@ -212,11 +212,11 @@ def setUp(self) -> None:
212212
# noinspection PyUnusedLocal
213213
@mock.patch(
214214
"wtk.models.Player.select_defence",
215-
return_value=enums.FightChoice.WARRIOR
215+
return_value=enums.FightChoice.KNIGHT
216216
)
217217
@mock.patch(
218218
"wtk.models.Enemy.select_attack",
219-
return_value=enums.FightChoice.WARRIOR
219+
return_value=enums.FightChoice.KNIGHT
220220
)
221221
def test_player_decrease_health(self, *mocks):
222222
self.player.decrease_health = mock.Mock()
@@ -226,11 +226,11 @@ def test_player_decrease_health(self, *mocks):
226226
# noinspection PyUnusedLocal
227227
@mock.patch(
228228
"wtk.models.Player.select_attack",
229-
return_value=enums.FightChoice.WARRIOR
229+
return_value=enums.FightChoice.KNIGHT
230230
)
231231
@mock.patch(
232232
"wtk.models.Enemy.select_defence",
233-
return_value=enums.FightChoice.WARRIOR
233+
return_value=enums.FightChoice.KNIGHT
234234
)
235235
def test_enemy_decrease_health(self, *mocks):
236236
self.enemy.decrease_health = mock.Mock()
@@ -240,11 +240,11 @@ def test_enemy_decrease_health(self, *mocks):
240240
# noinspection PyUnusedLocal
241241
@mock.patch(
242242
"wtk.models.Player.select_attack",
243-
return_value=enums.FightChoice.WARRIOR
243+
return_value=enums.FightChoice.KNIGHT
244244
)
245245
@mock.patch(
246246
"wtk.models.Enemy.select_defence",
247-
return_value=enums.FightChoice.WARRIOR
247+
return_value=enums.FightChoice.KNIGHT
248248
)
249249
def test_score_assignment_attack(self, *mocks):
250250
self.player.attack(self.enemy)
@@ -253,11 +253,11 @@ def test_score_assignment_attack(self, *mocks):
253253
# noinspection PyUnusedLocal
254254
@mock.patch(
255255
"wtk.models.Enemy.select_attack",
256-
return_value=enums.FightChoice.WARRIOR
256+
return_value=enums.FightChoice.KNIGHT
257257
)
258258
@mock.patch(
259259
"wtk.models.Player.select_defence",
260-
return_value=enums.FightChoice.WARRIOR
260+
return_value=enums.FightChoice.KNIGHT
261261
)
262262
def test_score_assignment_defence(self, *mocks):
263263
self.player.defence(self.enemy)
@@ -266,11 +266,11 @@ def test_score_assignment_defence(self, *mocks):
266266
# noinspection PyUnusedLocal
267267
@mock.patch(
268268
"wtk.models.Player.select_attack",
269-
return_value=enums.FightChoice.WARRIOR
269+
return_value=enums.FightChoice.KNIGHT
270270
)
271271
@mock.patch(
272272
"wtk.models.Enemy.select_defence",
273-
return_value=enums.FightChoice.WARRIOR
273+
return_value=enums.FightChoice.KNIGHT
274274
)
275275
def test_attack_message(self, *mocks):
276276
message = f"INFO:PlayerModel:{settings.MSG_DRAW}"
@@ -281,11 +281,11 @@ def test_attack_message(self, *mocks):
281281
# noinspection PyUnusedLocal
282282
@mock.patch(
283283
"wtk.models.Player.select_defence",
284-
return_value=enums.FightChoice.WARRIOR
284+
return_value=enums.FightChoice.KNIGHT
285285
)
286286
@mock.patch(
287287
"wtk.models.Enemy.select_attack",
288-
return_value=enums.FightChoice.WARRIOR
288+
return_value=enums.FightChoice.KNIGHT
289289
)
290290
def test_defence_message(self, *mocks):
291291
message = f"INFO:PlayerModel:{settings.MSG_DRAW}"

tests/wtk/unit/fight_test.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55

66
class TestFightChoice(unittest.TestCase):
77
def test_warrior_str(self):
8-
self.assertEqual(str(FightChoice.WARRIOR), "WARRIOR")
8+
self.assertEqual(str(FightChoice.KNIGHT), "KNIGHT")
99

1010
def test_robber_str(self):
11-
self.assertEqual(str(FightChoice.ROBBER), "ROBBER")
11+
self.assertEqual(str(FightChoice.THIEF), "THIEF")
1212

1313
def test_wizard_str(self):
1414
self.assertEqual(str(FightChoice.WIZARD), "WIZARD")
1515

1616
def test_equality(self):
17-
self.assertNotEqual(FightChoice.WARRIOR, FightChoice.ROBBER)
18-
self.assertNotEqual(FightChoice.WARRIOR, FightChoice.WIZARD)
19-
self.assertNotEqual(FightChoice.ROBBER, FightChoice.WIZARD)
17+
self.assertNotEqual(FightChoice.KNIGHT, FightChoice.THIEF)
18+
self.assertNotEqual(FightChoice.KNIGHT, FightChoice.WIZARD)
19+
self.assertNotEqual(FightChoice.THIEF, FightChoice.WIZARD)
2020

2121

2222
class TestFightResult(unittest.TestCase):
@@ -32,43 +32,43 @@ def test_draw_str(self):
3232

3333
class TestFights(unittest.TestCase):
3434
def test_draw_warrior(self):
35-
fight_result = get_fight_result(FightChoice.WARRIOR,
36-
FightChoice.WARRIOR)
35+
fight_result = get_fight_result(FightChoice.KNIGHT,
36+
FightChoice.KNIGHT)
3737
self.assertEqual(FightResult.DRAW, fight_result)
3838

3939
def test_draw_robber(self):
40-
fight_result = get_fight_result(FightChoice.ROBBER, FightChoice.ROBBER)
40+
fight_result = get_fight_result(FightChoice.THIEF, FightChoice.THIEF)
4141
self.assertEqual(FightResult.DRAW, fight_result)
4242

4343
def test_draw_wizard(self):
4444
fight_result = get_fight_result(FightChoice.WIZARD, FightChoice.WIZARD)
4545
self.assertEqual(FightResult.DRAW, fight_result)
4646

4747
def test_success_warrior(self):
48-
fight_result = get_fight_result(FightChoice.WARRIOR, FightChoice.ROBBER)
48+
fight_result = get_fight_result(FightChoice.KNIGHT, FightChoice.THIEF)
4949
self.assertEqual(FightResult.SUCCESS, fight_result)
5050

5151
def test_success_robber(self):
52-
fight_result = get_fight_result(FightChoice.ROBBER, FightChoice.WIZARD)
52+
fight_result = get_fight_result(FightChoice.THIEF, FightChoice.WIZARD)
5353
self.assertEqual(FightResult.SUCCESS, fight_result)
5454

5555
def test_success_wizard(self):
56-
fight_result = get_fight_result(FightChoice.WIZARD, FightChoice.WARRIOR)
56+
fight_result = get_fight_result(FightChoice.WIZARD, FightChoice.KNIGHT)
5757
self.assertEqual(FightResult.SUCCESS, fight_result)
5858

5959
def test_failure_warrior(self):
60-
fight_result = get_fight_result(FightChoice.WARRIOR, FightChoice.WIZARD)
60+
fight_result = get_fight_result(FightChoice.KNIGHT, FightChoice.WIZARD)
6161
self.assertEqual(FightResult.FAILURE, fight_result)
6262

6363
def test_failure_robber(self):
64-
fight_result = get_fight_result(FightChoice.ROBBER, FightChoice.WARRIOR)
64+
fight_result = get_fight_result(FightChoice.THIEF, FightChoice.KNIGHT)
6565
self.assertEqual(FightResult.FAILURE, fight_result)
6666

6767
def test_failure_wizard(self):
68-
fight_result = get_fight_result(FightChoice.WIZARD, FightChoice.ROBBER)
68+
fight_result = get_fight_result(FightChoice.WIZARD, FightChoice.THIEF)
6969
self.assertEqual(FightResult.FAILURE, fight_result)
7070

7171
def test_exception(self):
7272
self.assertRaises(TypeError, get_fight_result, None, None)
73-
self.assertRaises(TypeError, get_fight_result, FightChoice.WARRIOR, 1)
74-
self.assertRaises(TypeError, get_fight_result, 1, FightChoice.WARRIOR)
73+
self.assertRaises(TypeError, get_fight_result, FightChoice.KNIGHT, 1)
74+
self.assertRaises(TypeError, get_fight_result, 1, FightChoice.KNIGHT)

0 commit comments

Comments
 (0)