-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_game.py
58 lines (44 loc) · 1.5 KB
/
test_game.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
from pyrsistent import pmap
from core import Thing, Location, GameState, take, move
key = Thing(name="rusty key")
home = Location(
name="Home",
description="Home is where the heart is!",
exits={
"east": (None, "Street"),
"down": (key, "Basement")
}
)
street = Location(
name="Street",
description="The street next to your house.",
exits={"west": (None, "Home")},
items={key.name: key}
)
basement = Location(
name="Basement",
description="You found the basement!",
exits={"up": (None, "Home")}
)
world = pmap({x.name: x for x in [home, street, basement]})
initial_state = GameState(location_name="Home", world=world)
in_street = initial_state.set(location_name="Street")
in_street_with_key = in_street.transform(
["world", "Street", "items"], lambda _: {},
["inventory"], lambda _: [key]
)
def test_take_not_found():
assert take(initial_state, "some item") is None
def test_take_something():
in_street = initial_state.set(location_name="Street")
assert take(in_street, "rusty key") == in_street_with_key
def test_move_invalid():
assert move(initial_state, "inward") is None
def test_move_without_key():
assert move(initial_state, "down") is None
def test_move():
assert move(initial_state, "east") == in_street
def test_move_with_key():
in_home_with_key = in_street_with_key.set(location_name="Home")
expected_state = in_home_with_key.set(location_name="Basement")
assert move(in_home_with_key, "down") == expected_state