@@ -69,121 +69,71 @@ describe('dnd', function()
69
69
end )
70
70
71
71
describe (' ability' , function ()
72
- it (' uses 3 largest numbers from scores in descending order' , function ()
73
- assert .equal (9 , dnd .ability ({ 4 , 3 , 2 , 1 }))
74
- end )
75
-
76
- it (' uses 3 largest numbers from scores in ascending order' , function ()
77
- assert .equal (9 , dnd .ability ({ 1 , 2 , 3 , 4 }))
78
- end )
79
-
80
- it (' uses 3 largest numbers from scores in random order' , function ()
81
- assert .equal (9 , dnd .ability ({ 2 , 4 , 3 , 1 }))
82
- end )
83
-
84
- it (' returns 3 with lowest equal numbers' , function ()
85
- assert .equal (3 , dnd .ability ({ 1 , 1 , 1 , 1 }))
86
- end )
87
-
88
- it (' returns 18 with highest equal numbers' , function ()
89
- assert .equal (18 , dnd .ability ({ 6 , 6 , 6 , 6 }))
90
- end )
91
- end )
92
-
93
- describe (' roll_dice' , function ()
94
- it (' returns 4 numbers, each in the range 1 to 6' , function ()
95
- for _ = 1 , 10 do
96
- local scores = dnd .roll_dice ()
97
- assert .equal (4 , # scores )
98
- for _ , score in ipairs (scores ) do
99
- assert .equal (" integer" , math.type (score ))
100
- assert .lteq (1 , score )
101
- assert .lteq (score , 6 )
102
- end
72
+ it (' random ability is within range' , function ()
73
+ for i = 1 , 10 do
74
+ local ability_score = dnd .ability ()
75
+ assert .equal (' integer' , math.type (ability_score ))
76
+ assert .lteq (3 , ability_score )
77
+ assert .lteq (ability_score , 18 )
103
78
end
104
79
end )
105
80
end )
106
81
107
82
describe (' Character' , function ()
108
83
it (' creates a character with the supplied name' , function ()
109
84
local names = {
110
- " Alice" ,
111
- " Bob" ,
112
- " Charlie" ,
113
- " David" ,
114
- " Eve" ,
115
- " Fred" ,
116
- " Ginny" ,
117
- " Harriet" ,
118
- " Ileana" ,
119
- " Joseph" ,
120
- " Kincaid" ,
121
- " Larry"
85
+ ' Alice' ,
86
+ ' Bob' ,
87
+ ' Charlie' ,
88
+ ' David' ,
89
+ ' Eve' ,
90
+ ' Fred' ,
91
+ ' Ginny' ,
92
+ ' Harriet' ,
93
+ ' Ileana' ,
94
+ ' Joseph' ,
95
+ ' Kincaid' ,
96
+ ' Larry'
122
97
}
123
98
for _ , name in ipairs (names ) do
124
99
assert .equal (name , dnd .Character :new (name ).name )
125
100
end
126
101
end )
127
102
128
- it (' creates a character with valid strength' , function ()
129
- local character = dnd .Character :new (" Alice" )
130
- local strength = character .strength
131
- assert .equal (" integer" , math.type (strength ))
132
- assert .lteq (3 , strength )
133
- assert .lteq (strength , 18 )
134
- assert .equal (strength , character .strength )
135
- end )
103
+ it (' random character is valid' , function ()
104
+ local character = dnd .Character :new (' Alice' )
136
105
137
- it (' creates a character with valid dexterity' , function ()
138
- local character = dnd .Character :new (" Bob" )
139
- local dexterity = character .dexterity
140
- assert .equal (" integer" , math.type (dexterity ))
141
- assert .lteq (3 , dexterity )
142
- assert .lteq (dexterity , 18 )
143
- assert .equal (dexterity , character .dexterity )
144
- end )
106
+ assert .lteq (3 , character .strength )
107
+ assert .lteq (character .strength , 18 )
145
108
146
- it (' creates a character with valid constitution' , function ()
147
- local character = dnd .Character :new (" Charlie" )
148
- local constitution = character .constitution
149
- assert .equal (" integer" , math.type (constitution ))
150
- assert .lteq (3 , constitution )
151
- assert .lteq (constitution , 18 )
152
- assert .equal (constitution , character .constitution )
153
- end )
109
+ assert .lteq (3 , character .dexterity )
110
+ assert .lteq (character .dexterity , 18 )
154
111
155
- it (' creates a character with valid intelligence' , function ()
156
- local character = dnd .Character :new (" David" )
157
- local intelligence = character .intelligence
158
- assert .equal (" integer" , math.type (intelligence ))
159
- assert .lteq (3 , intelligence )
160
- assert .lteq (intelligence , 18 )
161
- assert .equal (intelligence , character .intelligence )
162
- end )
112
+ assert .lteq (3 , character .constitution )
113
+ assert .lteq (character .constitution , 18 )
163
114
164
- it (' creates a character with valid wisdom' , function ()
165
- local character = dnd .Character :new (" Eve" )
166
- local wisdom = character .wisdom
167
- assert .equal (" integer" , math.type (wisdom ))
168
- assert .lteq (3 , wisdom )
169
- assert .lteq (wisdom , 18 )
170
- assert .equal (wisdom , character .wisdom )
171
- end )
115
+ assert .lteq (3 , character .intelligence )
116
+ assert .lteq (character .intelligence , 18 )
172
117
173
- it ( ' creates a character with valid charisma ' , function ( )
174
- local character = dnd . Character : new ( " Fred " )
175
- local charisma = character . charisma
176
- assert .equal ( " integer " , math.type ( charisma ) )
177
- assert .lteq (3 , charisma )
178
- assert . lteq ( charisma , 18 )
179
- assert .equal (charisma , character .charisma )
118
+ assert . lteq ( 3 , character . wisdom )
119
+ assert . lteq ( character . wisdom , 18 )
120
+
121
+ assert .lteq ( 3 , character . charisma )
122
+ assert .lteq (character . charisma , 18 )
123
+
124
+ assert .equal (10 + dnd . modifier ( character . constitution ) , character .hitpoints )
180
125
end )
181
126
182
- it (' creates a character with valid hitpoints' , function ()
183
- for i = 1 , 10 do
184
- local character = dnd .Character :new (tostring (i ))
185
- assert .equal (10 + dnd .modifier (character .constitution ), character .hitpoints )
186
- end
127
+ it (' each ability is calculated once' , function ()
128
+ local character = dnd .Character :new (' Bob' )
129
+
130
+ assert .equal (character .strength , character .strength )
131
+ assert .equal (character .dexterity , character .dexterity )
132
+ assert .equal (character .constitution , character .constitution )
133
+ assert .equal (character .intelligence , character .intelligence )
134
+ assert .equal (character .wisdom , character .wisdom )
135
+ assert .equal (character .charisma , character .charisma )
136
+ assert .equal (character .hitpoints , character .hitpoints )
187
137
end )
188
138
end )
189
139
end )
0 commit comments