crapshoot 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Guardfile +4 -4
- data/README.rdoc +24 -1
- data/Rakefile +5 -0
- data/crapshoot.gemspec +1 -0
- data/lib/crapshoot.rb +6 -1
- data/lib/crapshoot/evaluator.rb +1 -0
- data/lib/crapshoot/parser/scan.rb +17 -61
- data/lib/crapshoot/parser/scan.rl +1 -1
- data/lib/crapshoot/postfixer.rb +1 -0
- data/lib/crapshoot/result.rb +14 -0
- data/lib/crapshoot/scanner.rb +1 -0
- data/lib/crapshoot/tokens/arithmetic.rb +3 -2
- data/lib/crapshoot/tokens/constant.rb +2 -1
- data/lib/crapshoot/tokens/series.rb +17 -9
- data/lib/crapshoot/version.rb +1 -1
- data/test/crapshoot_test.rb +18 -0
- data/test/evaluator_test.rb +14 -2
- data/test/result_test.rb +19 -0
- data/test/scanner_test.rb +1 -0
- metadata +20 -2
data/Guardfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
guard 'test', :runner => 'fastfail' do
|
2
|
-
watch('^lib/(.*)\.rb') { |m| "test
|
3
|
-
watch('^lib/crapshoot/(.*)\.rb') { |m| 'test
|
4
|
-
watch('^test/(.*)_test.rb')
|
5
|
-
watch('^test/
|
2
|
+
watch('^lib/(.*)\.rb') { |m| "test/#{m[1]}_test.rb" }
|
3
|
+
watch('^lib/crapshoot/(.*)\.rb') { |m| 'test/#{m[1]}_test.rb'}
|
4
|
+
watch('^test/(.*)_test.rb')
|
5
|
+
watch('^test/helper.rb') { 'rake test' }
|
6
6
|
end
|
data/README.rdoc
CHANGED
@@ -16,6 +16,29 @@ Or you might just want nine:
|
|
16
16
|
|
17
17
|
Crapshoot.roll '9'
|
18
18
|
|
19
|
+
== Rolling Dice
|
20
|
+
|
21
|
+
+Crapshoot.roll+ is the method that rolls dice and returns the result. It takes one argument,
|
22
|
+
an expression in the crapshoot language.
|
23
|
+
|
24
|
+
[67] a Constant
|
25
|
+
[4d4] a Series, rolling four four-sided dice and adding them together
|
26
|
+
[4d6v] a Series, rolling four four-sided dice, dropping the lowest one, adding them together
|
27
|
+
[17+17] adds two Constants together
|
28
|
+
[4d6v - 17] subtracts a Constant from a Series
|
29
|
+
[4d20 + 2d100 + 3d6 - 4d4 + 19] adds a whole bunch of dice, subtracts some dice, and adds nineteen
|
30
|
+
|
31
|
+
Generally, whitespace is allowed around arithmetic operations, but not inside a series.
|
32
|
+
|
33
|
+
== Describing a Roll
|
34
|
+
|
35
|
+
The return value from +Crapshoot.roll+ is a Crapshoot::Result object,
|
36
|
+
which is an Integer with a description field:
|
37
|
+
|
38
|
+
r = Crapshoot.roll '4d4^ + 6d6 - 10' # => 22
|
39
|
+
r.description # => "(2+2+2+3-3)+(1+3+5+5+6+6)-10"
|
40
|
+
r + 5 # => 27
|
41
|
+
|
19
42
|
== Developing with Ragel
|
20
43
|
|
21
44
|
I used the "Ragel" state machine compiler to generate the parser for this library. If you're changing the parser, you will need to install Ragel.
|
@@ -25,7 +48,7 @@ I've had good luck with the macports and homebrew packages for Ragel; I don't an
|
|
25
48
|
If you are modifying the parser, you may want to generate a Graphviz .dot or PDF document of the state machine produced by the scanner. The "rake scanner:pdf" task will generate this PDF, provided your installation of Graphviz allows it. If you're developing on Mac OS X, you can get a PDF-capable copy of Graphviz from http://www.graphviz.org/Download_macos.php .
|
26
49
|
|
27
50
|
== Contributing to crapshoot
|
28
|
-
|
51
|
+
|
29
52
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
30
53
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
31
54
|
* Fork the project
|
data/Rakefile
CHANGED
data/crapshoot.gemspec
CHANGED
@@ -27,5 +27,6 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.add_development_dependency(%q<guard-test>, ["~> 0.1.4"])
|
28
28
|
s.add_development_dependency(%q<shoulda>, ["~> 2.11.3"])
|
29
29
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.7"])
|
30
|
+
s.add_development_dependency(%q<yard>, ["~> 0.6.4"])
|
30
31
|
end
|
31
32
|
|
data/lib/crapshoot.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
+
require 'delegate'
|
1
2
|
require 'active_support'
|
2
|
-
%w{ scanner postfixer evaluator }.each do |f|
|
3
|
+
%w{ result scanner postfixer evaluator }.each do |f|
|
3
4
|
require File.join(File.dirname(__FILE__), 'crapshoot', f)
|
4
5
|
end
|
5
6
|
|
6
7
|
module Crapshoot
|
8
|
+
|
9
|
+
# Rolls dice for the given expression.
|
10
|
+
# @param [String] crapshoot expression to evaluate, such as '4d6v + 8'
|
11
|
+
# @return [Crapshoot::Result] the result of the expression, can be used as a normal Integer
|
7
12
|
def self.roll(expression)
|
8
13
|
scanner = Scanner.new
|
9
14
|
postfixer = Postfixer.new
|
data/lib/crapshoot/evaluator.rb
CHANGED
@@ -30,7 +30,7 @@ self._scanner_trans_keys = [
|
|
30
30
|
0, 0, 48, 57, 9, 45,
|
31
31
|
9, 57, 9, 57, 48,
|
32
32
|
57, 9, 100, 9, 118,
|
33
|
-
9, 45,
|
33
|
+
9, 45, 0
|
34
34
|
]
|
35
35
|
|
36
36
|
class << self
|
@@ -39,7 +39,7 @@ class << self
|
|
39
39
|
end
|
40
40
|
self._scanner_key_spans = [
|
41
41
|
0, 10, 37, 49, 49, 10, 92, 110,
|
42
|
-
37
|
42
|
+
37
|
43
43
|
]
|
44
44
|
|
45
45
|
class << self
|
@@ -48,7 +48,7 @@ class << self
|
|
48
48
|
end
|
49
49
|
self._scanner_index_offsets = [
|
50
50
|
0, 0, 11, 49, 99, 149, 160, 253,
|
51
|
-
364
|
51
|
+
364
|
52
52
|
]
|
53
53
|
|
54
54
|
class << self
|
@@ -101,17 +101,12 @@ self._scanner_indicies = [
|
|
101
101
|
1, 1, 15, 1, 1, 1, 1, 1,
|
102
102
|
1, 1, 1, 1, 1, 1, 1, 1,
|
103
103
|
1, 1, 1, 1, 1, 1, 1, 1,
|
104
|
-
1, 1,
|
105
|
-
|
104
|
+
1, 1, 15, 1, 16, 16, 16, 16,
|
105
|
+
16, 1, 1, 1, 1, 1, 1, 1,
|
106
106
|
1, 1, 1, 1, 1, 1, 1, 1,
|
107
|
-
1, 1, 1,
|
108
|
-
1, 1, 1, 1, 1, 1,
|
109
|
-
|
110
|
-
1, 1, 1, 1, 1, 1, 1, 1,
|
111
|
-
1, 1, 1, 1, 1, 1, 1, 1,
|
112
|
-
1, 19, 1, 1, 1, 1, 1, 1,
|
113
|
-
1, 1, 1, 1, 20, 1, 20, 1,
|
114
|
-
0
|
107
|
+
1, 1, 1, 16, 1, 1, 1, 1,
|
108
|
+
1, 1, 1, 1, 1, 1, 17, 1,
|
109
|
+
17, 1, 0
|
115
110
|
]
|
116
111
|
|
117
112
|
class << self
|
@@ -121,7 +116,7 @@ end
|
|
121
116
|
self._scanner_trans_targs = [
|
122
117
|
6, 0, 2, 3, 4, 6, 4, 7,
|
123
118
|
2, 3, 6, 5, 2, 3, 7, 8,
|
124
|
-
|
119
|
+
2, 3
|
125
120
|
]
|
126
121
|
|
127
122
|
class << self
|
@@ -131,7 +126,7 @@ end
|
|
131
126
|
self._scanner_trans_actions = [
|
132
127
|
1, 0, 0, 0, 2, 3, 0, 1,
|
133
128
|
4, 4, 0, 5, 6, 6, 0, 5,
|
134
|
-
|
129
|
+
7, 7
|
135
130
|
]
|
136
131
|
|
137
132
|
class << self
|
@@ -140,7 +135,7 @@ class << self
|
|
140
135
|
end
|
141
136
|
self._scanner_eof_actions = [
|
142
137
|
0, 0, 0, 0, 0, 0, 4, 6,
|
143
|
-
7
|
138
|
+
7
|
144
139
|
]
|
145
140
|
|
146
141
|
class << self
|
@@ -164,7 +159,7 @@ self.scanner_en_main = 1;
|
|
164
159
|
|
165
160
|
# line 52 "lib/crapshoot/parser/scan.rl"
|
166
161
|
|
167
|
-
# line
|
162
|
+
# line 163 "lib/crapshoot/parser/scan.rb"
|
168
163
|
begin
|
169
164
|
p ||= 0
|
170
165
|
pe ||= data.length
|
@@ -173,7 +168,7 @@ end
|
|
173
168
|
|
174
169
|
# line 53 "lib/crapshoot/parser/scan.rl"
|
175
170
|
|
176
|
-
# line
|
171
|
+
# line 172 "lib/crapshoot/parser/scan.rb"
|
177
172
|
begin
|
178
173
|
testEof = false
|
179
174
|
_slen, _trans, _keys, _inds, _acts, _nacts = nil
|
@@ -213,42 +208,25 @@ begin
|
|
213
208
|
# line 4 "lib/crapshoot/parser/scan.rl"
|
214
209
|
begin
|
215
210
|
@mark_num = p end
|
216
|
-
# line 4 "lib/crapshoot/parser/scan.rl"
|
217
211
|
when 5 then
|
218
212
|
# line 5 "lib/crapshoot/parser/scan.rl"
|
219
213
|
begin
|
220
214
|
@num_stack.push atos(data[@mark_num..p-1]) end
|
221
|
-
# line 5 "lib/crapshoot/parser/scan.rl"
|
222
|
-
when 7 then
|
223
|
-
# line 8 "lib/crapshoot/parser/scan.rl"
|
224
|
-
begin
|
225
|
-
|
226
|
-
drop = @drop_current
|
227
|
-
@drop_current = nil
|
228
|
-
sides = @num_stack.pop
|
229
|
-
count = @num_stack.pop
|
230
|
-
@tokens << Tokens::Series.new(count, sides, drop)
|
231
|
-
end
|
232
|
-
# line 8 "lib/crapshoot/parser/scan.rl"
|
233
215
|
when 2 then
|
234
216
|
# line 15 "lib/crapshoot/parser/scan.rl"
|
235
217
|
begin
|
236
218
|
@tokens << Tokens::Arithmetic.new(data[p-1].chr) end
|
237
|
-
# line 15 "lib/crapshoot/parser/scan.rl"
|
238
219
|
when 4 then
|
239
220
|
# line 5 "lib/crapshoot/parser/scan.rl"
|
240
221
|
begin
|
241
222
|
@num_stack.push atos(data[@mark_num..p-1]) end
|
242
|
-
# line 5 "lib/crapshoot/parser/scan.rl"
|
243
223
|
# line 7 "lib/crapshoot/parser/scan.rl"
|
244
224
|
begin
|
245
225
|
@tokens << Tokens::Constant.new(@num_stack.pop) end
|
246
|
-
# line 7 "lib/crapshoot/parser/scan.rl"
|
247
226
|
when 6 then
|
248
227
|
# line 5 "lib/crapshoot/parser/scan.rl"
|
249
228
|
begin
|
250
229
|
@num_stack.push atos(data[@mark_num..p-1]) end
|
251
|
-
# line 5 "lib/crapshoot/parser/scan.rl"
|
252
230
|
# line 8 "lib/crapshoot/parser/scan.rl"
|
253
231
|
begin
|
254
232
|
|
@@ -258,21 +236,17 @@ begin
|
|
258
236
|
count = @num_stack.pop
|
259
237
|
@tokens << Tokens::Series.new(count, sides, drop)
|
260
238
|
end
|
261
|
-
# line 8 "lib/crapshoot/parser/scan.rl"
|
262
239
|
when 3 then
|
263
240
|
# line 15 "lib/crapshoot/parser/scan.rl"
|
264
241
|
begin
|
265
242
|
@tokens << Tokens::Arithmetic.new(data[p-1].chr) end
|
266
|
-
# line 15 "lib/crapshoot/parser/scan.rl"
|
267
243
|
# line 4 "lib/crapshoot/parser/scan.rl"
|
268
244
|
begin
|
269
245
|
@mark_num = p end
|
270
|
-
|
271
|
-
when 8 then
|
246
|
+
when 7 then
|
272
247
|
# line 17 "lib/crapshoot/parser/scan.rl"
|
273
248
|
begin
|
274
249
|
@drop_current = data[p-1].chr end
|
275
|
-
# line 17 "lib/crapshoot/parser/scan.rl"
|
276
250
|
# line 8 "lib/crapshoot/parser/scan.rl"
|
277
251
|
begin
|
278
252
|
|
@@ -282,8 +256,7 @@ begin
|
|
282
256
|
count = @num_stack.pop
|
283
257
|
@tokens << Tokens::Series.new(count, sides, drop)
|
284
258
|
end
|
285
|
-
# line
|
286
|
-
# line 287 "lib/crapshoot/parser/scan.rb"
|
259
|
+
# line 260 "lib/crapshoot/parser/scan.rb"
|
287
260
|
end
|
288
261
|
end
|
289
262
|
end
|
@@ -301,31 +274,17 @@ begin
|
|
301
274
|
if _goto_level <= _test_eof
|
302
275
|
if p == eof
|
303
276
|
case _scanner_eof_actions[cs]
|
304
|
-
when 7 then
|
305
|
-
# line 8 "lib/crapshoot/parser/scan.rl"
|
306
|
-
begin
|
307
|
-
|
308
|
-
drop = @drop_current
|
309
|
-
@drop_current = nil
|
310
|
-
sides = @num_stack.pop
|
311
|
-
count = @num_stack.pop
|
312
|
-
@tokens << Tokens::Series.new(count, sides, drop)
|
313
|
-
end
|
314
|
-
# line 8 "lib/crapshoot/parser/scan.rl"
|
315
277
|
when 4 then
|
316
278
|
# line 5 "lib/crapshoot/parser/scan.rl"
|
317
279
|
begin
|
318
280
|
@num_stack.push atos(data[@mark_num..p-1]) end
|
319
|
-
# line 5 "lib/crapshoot/parser/scan.rl"
|
320
281
|
# line 7 "lib/crapshoot/parser/scan.rl"
|
321
282
|
begin
|
322
283
|
@tokens << Tokens::Constant.new(@num_stack.pop) end
|
323
|
-
# line 7 "lib/crapshoot/parser/scan.rl"
|
324
284
|
when 6 then
|
325
285
|
# line 5 "lib/crapshoot/parser/scan.rl"
|
326
286
|
begin
|
327
287
|
@num_stack.push atos(data[@mark_num..p-1]) end
|
328
|
-
# line 5 "lib/crapshoot/parser/scan.rl"
|
329
288
|
# line 8 "lib/crapshoot/parser/scan.rl"
|
330
289
|
begin
|
331
290
|
|
@@ -335,12 +294,10 @@ begin
|
|
335
294
|
count = @num_stack.pop
|
336
295
|
@tokens << Tokens::Series.new(count, sides, drop)
|
337
296
|
end
|
338
|
-
|
339
|
-
when 8 then
|
297
|
+
when 7 then
|
340
298
|
# line 17 "lib/crapshoot/parser/scan.rl"
|
341
299
|
begin
|
342
300
|
@drop_current = data[p-1].chr end
|
343
|
-
# line 17 "lib/crapshoot/parser/scan.rl"
|
344
301
|
# line 8 "lib/crapshoot/parser/scan.rl"
|
345
302
|
begin
|
346
303
|
|
@@ -350,8 +307,7 @@ begin
|
|
350
307
|
count = @num_stack.pop
|
351
308
|
@tokens << Tokens::Series.new(count, sides, drop)
|
352
309
|
end
|
353
|
-
# line
|
354
|
-
# line 355 "lib/crapshoot/parser/scan.rb"
|
310
|
+
# line 311 "lib/crapshoot/parser/scan.rb"
|
355
311
|
end
|
356
312
|
end
|
357
313
|
|
data/lib/crapshoot/postfixer.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Crapshoot
|
2
|
+
# An Integer with a description, uses DelegateClass from the stdlib to do this
|
3
|
+
class Result < DelegateClass(Integer)
|
4
|
+
# Creates a new result with the given value.
|
5
|
+
#
|
6
|
+
# Everything except the description is delegated to this value.
|
7
|
+
def initialize(value)
|
8
|
+
super value
|
9
|
+
end
|
10
|
+
|
11
|
+
# The derivation of the result, as a String.
|
12
|
+
attr_accessor :description
|
13
|
+
end
|
14
|
+
end
|
data/lib/crapshoot/scanner.rb
CHANGED
@@ -12,8 +12,9 @@ module Crapshoot
|
|
12
12
|
def eval(stack)
|
13
13
|
r = stack.pop
|
14
14
|
l = stack.pop
|
15
|
-
@result = l.send(@operation.to_sym, r)
|
16
|
-
@result
|
15
|
+
@result = Result.new l.send(@operation.to_sym, r)
|
16
|
+
@result.description = "#{l.description}#{@operation}#{r.description}"
|
17
|
+
return @result
|
17
18
|
end
|
18
19
|
|
19
20
|
def inspect
|
@@ -8,21 +8,22 @@ module Crapshoot
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def eval(stack)
|
11
|
+
raise TooManyDiceException.new(@count) if @count > 50_000
|
11
12
|
results_array = (1..@count).to_a.map{ roll_a_die }.sort
|
12
|
-
|
13
|
+
numeric_result = results_array.inject(&:+)
|
13
14
|
roll_description = results_array.join '+'
|
14
|
-
|
15
15
|
case @drop
|
16
16
|
when '^'
|
17
|
-
max = results_array
|
18
|
-
|
19
|
-
roll_description +=
|
17
|
+
max = results_array.last
|
18
|
+
numeric_result -= max
|
19
|
+
roll_description += "-#{max}"
|
20
20
|
when 'v'
|
21
|
-
min = results_array
|
22
|
-
|
23
|
-
roll_description +=
|
21
|
+
min = results_array.first
|
22
|
+
numeric_result -= min
|
23
|
+
roll_description += "-#{min}"
|
24
24
|
end
|
25
|
-
@
|
25
|
+
@result = Result.new numeric_result
|
26
|
+
@result.description = "(#{roll_description})"
|
26
27
|
|
27
28
|
return @result
|
28
29
|
end
|
@@ -37,6 +38,13 @@ module Crapshoot
|
|
37
38
|
# +1 because we can roll a zero
|
38
39
|
ActiveSupport::SecureRandom.random_number(@sides) + 1
|
39
40
|
end
|
41
|
+
|
42
|
+
class TooManyDiceException < RuntimeError
|
43
|
+
def initialize(number_of_dice)
|
44
|
+
@number_of_dice = number_of_dice
|
45
|
+
super "#{@number_of_dice} dice is too many"
|
46
|
+
end
|
47
|
+
end
|
40
48
|
end
|
41
49
|
end
|
42
50
|
end
|
data/lib/crapshoot/version.rb
CHANGED
data/test/crapshoot_test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestCrapshoot < Test::Unit::TestCase
|
4
|
+
|
4
5
|
def self.should_roll(from, options)
|
5
6
|
keys = options.keys
|
6
7
|
|
@@ -12,8 +13,25 @@ class TestCrapshoot < Test::Unit::TestCase
|
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
16
|
+
|
17
|
+
def self.should_describe(from, matcher)
|
18
|
+
should "evaluate #{from.inspect} into something resembling #{matcher.inspect}" do
|
19
|
+
result = Crapshoot.roll from
|
20
|
+
assert_match matcher, result.description
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
context 'The Crapshoot module' do
|
16
25
|
should_roll '4d6', '>='=>4, '<='=>24
|
17
26
|
should_roll '4d6 + 200', '>='=>204, '<='=>224
|
27
|
+
should_roll '10-5', '=='=>5
|
28
|
+
should_roll '5-10', '=='=>-5
|
29
|
+
|
30
|
+
should_describe '1 + 2', '1+2'
|
31
|
+
should_describe '10 - 5', '10-5'
|
32
|
+
should_describe '2d6', /\(\d\+\d\)/
|
33
|
+
should_describe '2d6 + 5', /\(\d\+\d\)\+5/
|
34
|
+
should_describe '2d6 + 5 + 4d2v', /\(\d\+\d\)\+5\+\(\d\+\d\+\d\+\d\-\d\)/
|
35
|
+
should_describe '2d6 + 5 + 4d2^', /\(\d\+\d\)\+5\+\(\d\+\d\+\d\+\d\-\d\)/
|
18
36
|
end
|
19
37
|
end
|
data/test/evaluator_test.rb
CHANGED
@@ -26,8 +26,8 @@ class TestEvaluator < Test::Unit::TestCase
|
|
26
26
|
series1 = Series.new '5', '6', nil
|
27
27
|
series2 = Series.new '4', '20', 'v'
|
28
28
|
series3 = Series.new '20', '2'
|
29
|
-
series4 = Series.new '20', 1, 'v'
|
30
|
-
series5 = Series.new '20', 1, '^'
|
29
|
+
series4 = Series.new '20', '1', 'v'
|
30
|
+
series5 = Series.new '20', '1', '^'
|
31
31
|
|
32
32
|
should_evaluate [five, six, plus], '=='=> 11
|
33
33
|
should_evaluate [series1, series1, plus], '>=' => 10, '<=' => 60
|
@@ -35,5 +35,17 @@ class TestEvaluator < Test::Unit::TestCase
|
|
35
35
|
should_evaluate [series3], '>=' => 20, '<=' => 40
|
36
36
|
should_evaluate [series4], '=='=>19
|
37
37
|
should_evaluate [series5], '=='=>19
|
38
|
+
|
39
|
+
should 'raise an exception when rolling over 50,000 dice' do
|
40
|
+
assert_raises do
|
41
|
+
@evaluator.evaluate [Series.new('50001', '6')]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
should 'not raise an exception when rolling exactly 50,000 dice' do
|
46
|
+
assert_nothing_raised do
|
47
|
+
@evaluator.evaluate [Series.new('50000', '6')]
|
48
|
+
end
|
49
|
+
end
|
38
50
|
end
|
39
51
|
end
|
data/test/result_test.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestResult < Test::Unit::TestCase
|
4
|
+
context 'a result' do
|
5
|
+
setup do
|
6
|
+
@result = Crapshoot::Result.new 5
|
7
|
+
end
|
8
|
+
|
9
|
+
should 'have a description' do
|
10
|
+
assert_respond_to @result, :description
|
11
|
+
assert_respond_to @result, :description=
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'behave like an integer' do
|
15
|
+
assert_equal 11, (@result + 6)
|
16
|
+
assert_equal 1, (@result / 5)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/test/scanner_test.rb
CHANGED
@@ -31,6 +31,7 @@ class TestScanner < Test::Unit::TestCase
|
|
31
31
|
should_parse '1+2', Constant, Arithmetic, Constant
|
32
32
|
should_parse '4d6 + 4d6', Series, Arithmetic, Series
|
33
33
|
should_parse '4d6v', Series
|
34
|
+
should_parse '4d6^', Series
|
34
35
|
should_parse '4d6 + 2', Series, Arithmetic, Constant
|
35
36
|
should_parse '15', Constant
|
36
37
|
should_parse '14d100v + 8d8 + 3', Series, Arithmetic, Series, Arithmetic, Constant
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 3
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.3.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Bryce Kerley
|
@@ -76,6 +76,21 @@ dependencies:
|
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: *id004
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: yard
|
81
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
- 6
|
89
|
+
- 4
|
90
|
+
version: 0.6.4
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: *id005
|
79
94
|
description: Crapshoot is a dice-rolling gem for most of your pen-and-paper gaming needs; roll 4d6v to find out how much time it will save.
|
80
95
|
email: bkerley@brycekerley.net
|
81
96
|
executables: []
|
@@ -99,6 +114,7 @@ files:
|
|
99
114
|
- lib/crapshoot/parser/scan.rb
|
100
115
|
- lib/crapshoot/parser/scan.rl
|
101
116
|
- lib/crapshoot/postfixer.rb
|
117
|
+
- lib/crapshoot/result.rb
|
102
118
|
- lib/crapshoot/scanner.rb
|
103
119
|
- lib/crapshoot/tokens/arithmetic.rb
|
104
120
|
- lib/crapshoot/tokens/base.rb
|
@@ -109,6 +125,7 @@ files:
|
|
109
125
|
- test/evaluator_test.rb
|
110
126
|
- test/helper.rb
|
111
127
|
- test/postfixer_test.rb
|
128
|
+
- test/result_test.rb
|
112
129
|
- test/scanner_test.rb
|
113
130
|
has_rdoc: true
|
114
131
|
homepage: http://github.com/bkerley/crapshoot
|
@@ -149,4 +166,5 @@ test_files:
|
|
149
166
|
- test/evaluator_test.rb
|
150
167
|
- test/helper.rb
|
151
168
|
- test/postfixer_test.rb
|
169
|
+
- test/result_test.rb
|
152
170
|
- test/scanner_test.rb
|