-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayer_test.py
110 lines (83 loc) · 2.74 KB
/
player_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# from .items import FlawedPotionItem, SimpleLeatherHelm, SimpleSwordItem, ItemAttributeModifier
# from .player import Player
# def test_should_increase_exp():
# player = Player()
# player.increase_exp(3).increase_exp(3)
# assert player.exp == 6
# def test_should_decrease_exp():
# player = Player()
# player.decrease_exp(3).decrease_exp(3)
# assert player.exp == 0
# def test_should_calculate_level():
# player = Player()
# result = player.calculate_exp_by_level(0)
# assert result == 0
# result = player.calculate_exp_by_level(1)
# assert result == 0.8
# result = player.calculate_exp_by_level(2)
# assert result == 6.4
# result = player.calculate_exp_by_level(3)
# assert result == 21.6
# def test_should_calculate_level_by_exp():
# player = Player()
# result = player.calculate_level_by_exp(6.4)
# assert result == 2
# result = player.calculate_level_by_exp(21.6)
# assert result == 3
# def test_should_level_up_to_correct_level():
# player = Player()
# assert player.increase_exp(21.6).level == 3
# def test_should_receive_inventory_item():
# player = Player()
# player.receive_item(SimpleSwordItem())
# assert len(player.get_items()) == 1
# def test_should_equip_and_unequip_item_and_apply_modifiers():
# player = Player(
# inventory=Inventory([]),
# stats={
# "curr_hp": 0,
# "max_hp": 10,
# "strength": 0,
# "defense": 0,
# })
# swordItem = SimpleSwordItem()
# leatherItem = SimpleLeatherHelm()
# player.receive_item(swordItem)
# player.receive_item(leatherItem)
# assert len(player.get_items()) == 2
# player.equip(swordItem.id)
# player.equip(leatherItem.id)
# assert len(player.get_items()) == 0
# assert player.equipments[swordItem.bodyPart] == swordItem
# assert player.get_stats() == {
# "curr_hp": 0,
# "max_hp": 10,
# "strength": 1,
# "defense": 1,
# }
# player.unequip(swordItem.bodyPart)
# assert player.equipments[swordItem.bodyPart] == None
# assert player.get_stats() == {
# "curr_hp": 0,
# "max_hp": 10,
# "strength": 0,
# "defense": 1,
# }
# def test_should_use_consumable_item():
# player = Player(
# inventory=Inventory([]),
# stats={
# "curr_hp": 5,
# "max_hp": 10,
# "strength": 0,
# "defense": 0,
# })
# potion = FlawedPotionItem()
# player.receive_item(potion).consume_item(potion.id)
# assert len(player.get_items()) == 0
# assert player.get_stats() == {
# "curr_hp": 10,
# "max_hp": 10,
# "strength": 0,
# "defense": 0,
# }