-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_use_item.py
More file actions
39 lines (30 loc) · 1.45 KB
/
test_use_item.py
File metadata and controls
39 lines (30 loc) · 1.45 KB
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
from main import Player
def test_use_item():
# Create a player
player = Player("TestPlayer", "normal")
# Add items to inventory
player.inventory = ["Health Potion", "Strength Potion", "Iron Sword", "Shield"]
# Test using a health potion (capped at 100 HP in normal mode)
initial_health = player.health
player.use_item("Health Potion")
expected_health = min(100, initial_health + 30)
assert player.health == expected_health, f"Expected {expected_health}, got {player.health}"
# Test using a strength potion
initial_attack = player.attack
player.use_item("Strength Potion")
assert player.attack == initial_attack + 5, f"Expected {initial_attack + 5}, got {player.attack}"
# Test using an iron sword
initial_attack = player.attack
player.use_item("Iron Sword")
assert player.attack == initial_attack + 10, f"Expected {initial_attack + 10}, got {player.attack}"
# Test using a shield
initial_defense = player.defense
player.use_item("Shield")
assert player.defense == initial_defense + 5, f"Expected {initial_defense + 5}, got {player.defense}"
# Test using an item not in inventory
initial_health = player.health
player.use_item("Nonexistent Item") # Should not be in inventory
assert player.health == initial_health, f"Expected {initial_health}, got {player.health}"
print("All tests passed!")
if __name__ == "__main__":
test_use_item()