-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacter_test.py
90 lines (72 loc) · 2.35 KB
/
Character_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
import ideas
defaults = {'academics': -3, 'computer': -3, 'init':'dex comp'}
def filter(self, rep, key):
if key == "defence":
return min(self['dex'], self['wits'])
if type(rep) == str:
print 'str'
try:
return sum((self[i] if i in self else int(i)) for i in rep.split())
except Exception, e:
print e
return rep
else:
return rep
def test_example_filter():
assert filter({'dex':2, 'wits':3}, 0, 'defence') == 2
assert filter({}, 3, 'pie') == 3
assert filter({'dex':2, 'str':2}, 'dex str', 'speed') == 4
assert filter({'dex':2, 'str':2}, 'dex str 5', 'speed') == 9
assert filter({'dex':2, 'str':2}, 'dex str -3', 'speed') == 1
def test_character():
char = ideas.Character(open('mel.txt'))
assert len(char['name']) == 3
assert 'Mel' in char['name']
assert char['Int'] == 2
assert char['int'] == 2
assert char['Dex'] == 3
assert char['Man'] == 2
assert char['Academics'] == 1
assert char['Craft'] == 1
assert char['attack'] == 'dex firearms pistol lightpistol'
assert char['Monky'] == 0
assert 'monky' not in char
def test_world():
world = ideas.World()
world.load(open('mel.txt'))
assert len(world) == 1
assert 'Mel' in world
assert 'Melba Brandon' in world
assert world['Mel'] is world['Melba Brandon']
char = world['Mel']
assert 'Mel' in char['name']
assert char['Int'] == 2
def test_defaults():
char = ideas.Character(open('mel.txt'), defaults)
assert char['int'] == 2
assert char['computer'] == -3
assert char['init'] == 'dex comp'
def test_world_defaults():
world = ideas.World(defaults)
world.load(open('mel.txt'))
char = world['Mel']
assert char['int'] == 2
assert char['computer'] == -3
assert char['init'] == 'dex comp'
def test_filter():
filters = [filter]
char = ideas.Character(open('mel.txt'), defaults, filters)
assert char['computer'] == -3
assert char['int'] == 2
assert char['attack'] == 7
assert char['init'] == 6
assert char['defence'] == 2
def test_world_filters():
filters = [filter]
world = ideas.World(defaults, filters)
world.load(open('mel.txt'))
char = world['Mel']
assert char['int'] == 2
assert char['attack'] == 7
assert char['computer'] == -3
assert char['init'] == 6