games_dice 0.4.0 → 0.4.2

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/spec/readme_spec.rb CHANGED
@@ -6,34 +6,35 @@ require 'helpers'
6
6
  describe GamesDice do
7
7
  describe '#create' do
8
8
  it "converts a string such as '3d6+6' into a GamesDice::Dice object" do
9
- d = GamesDice.create '3d6+6'
9
+ d = described_class.create '3d6+6'
10
10
  expect(d).to be_a GamesDice::Dice
11
11
  end
12
12
 
13
13
  it "takes a parameter 'dice_description', which is a string such as '3d6' or '2d4-1'" do
14
- d = GamesDice.create '3d6'
14
+ d = described_class.create '3d6'
15
15
  expect(d).to be_a GamesDice::Dice
16
- d = GamesDice.create '2d4-1'
16
+ d = described_class.create '2d4-1'
17
17
  expect(d).to be_a GamesDice::Dice
18
18
  end
19
19
 
20
20
  it "takes an optional parameter 'prng', which should be an object that has a method 'rand( integer )'" do
21
21
  prng = TestPRNG.new
22
22
 
23
- d = GamesDice.create '3d6', prng
23
+ d = described_class.create '3d6', prng
24
24
  expect(d).to be_a GamesDice::Dice
25
25
 
26
26
  (0..5).each do |dresult|
27
27
  allow(prng).to receive(:rand).and_return(dresult)
28
- expect(prng).to receive(:rand).with(6)
29
- expect(d.roll).to eql (dresult + 1) * 3
28
+ result = d.roll
29
+ expect(prng).to have_received(:rand).with(6).at_least(:once)
30
+ expect(result).to eql (dresult + 1) * 3
30
31
  end
31
32
  end
32
33
  end
33
34
  end
34
35
 
35
36
  describe GamesDice::Dice do
36
- before :each do
37
+ before do
37
38
  srand(67_809)
38
39
  end
39
40
 
@@ -57,7 +58,7 @@ describe GamesDice::Dice do
57
58
  end
58
59
  end
59
60
 
60
- it 'will be nil if no roll has been made yet' do
61
+ it 'is nil if no roll has been made yet' do
61
62
  expect(dice.result).to be_nil
62
63
  end
63
64
  end
@@ -76,20 +77,20 @@ describe GamesDice::Dice do
76
77
  end
77
78
  end
78
79
 
79
- it 'will be nil if no roll has been made yet' do
80
+ it 'is nil if no roll has been made yet' do
80
81
  expect(dice.explain_result).to be_nil
81
82
  end
82
83
  end
83
84
 
84
85
  describe '#max' do
85
86
  it 'returns the maximum possible value from a roll of the dice' do
86
- expect(dice.max).to eql 18
87
+ expect(dice.max).to be 18
87
88
  end
88
89
  end
89
90
 
90
91
  describe '#min' do
91
92
  it 'returns the minimum possible value from a roll of the dice' do
92
- expect(dice.min).to eql 3
93
+ expect(dice.min).to be 3
93
94
  end
94
95
  end
95
96
 
@@ -123,34 +124,34 @@ describe GamesDice::Probabilities do
123
124
 
124
125
  describe '#max' do
125
126
  it 'returns maximum result in the probability distribution' do
126
- expect(probs.max).to eql 18
127
+ expect(probs.max).to be 18
127
128
  end
128
129
  end
129
130
 
130
131
  describe '#min' do
131
132
  it 'returns minimum result in the probability distribution' do
132
- expect(probs.min).to eql 3
133
+ expect(probs.min).to be 3
133
134
  end
134
135
  end
135
136
 
136
137
  describe '#p_eql( n )' do
137
138
  it 'returns the probability of a result equal to the integer n' do
138
139
  expect(probs.p_eql(3)).to be_within(1e-10).of 1.0 / 216
139
- expect(probs.p_eql(2)).to eql 0.0
140
+ expect(probs.p_eql(2)).to be 0.0
140
141
  end
141
142
  end
142
143
 
143
144
  describe '#p_gt( n )' do
144
145
  it 'returns the probability of a result greater than the integer n' do
145
146
  expect(probs.p_gt(17)).to be_within(1e-10).of 1.0 / 216
146
- expect(probs.p_gt(2)).to eql 1.0
147
+ expect(probs.p_gt(2)).to be 1.0
147
148
  end
148
149
  end
149
150
 
150
151
  describe '#p_ge( n )' do
151
152
  it 'returns the probability of a result greater than the integer n' do
152
153
  expect(probs.p_ge(17)).to be_within(1e-10).of 4.0 / 216
153
- expect(probs.p_ge(3)).to eql 1.0
154
+ expect(probs.p_ge(3)).to be 1.0
154
155
  end
155
156
  end
156
157
 
@@ -164,13 +165,13 @@ describe GamesDice::Probabilities do
164
165
  describe '#p_lt( n )' do
165
166
  it 'returns the probability of a result less than the integer n' do
166
167
  expect(probs.p_lt(17)).to be_within(1e-10).of 212.0 / 216
167
- expect(probs.p_lt(3)).to eql 0.0
168
+ expect(probs.p_lt(3)).to be 0.0
168
169
  end
169
170
  end
170
171
  end
171
172
 
172
173
  describe 'String Dice Description' do
173
- before :each do
174
+ before do
174
175
  srand(35_241)
175
176
  end
176
177
 
@@ -245,7 +246,7 @@ describe 'String Dice Description' do
245
246
  end
246
247
 
247
248
  describe "'1d6r:1.'" do
248
- it "should return same as '1d6r1'" do
249
+ it "return same as '1d6r1'" do
249
250
  srand(235_241)
250
251
  d = GamesDice.create '1d6r:1.'
251
252
  results1 = (1..50).map { d.roll }
@@ -259,7 +260,7 @@ describe 'String Dice Description' do
259
260
  end
260
261
 
261
262
  describe "'1d10r:10,replace,1.'" do
262
- it 'should roll a 10-sided die, re-roll a result of 10 and take the value of the second roll' do
263
+ it 'roll a 10-sided die, re-roll a result of 10 and take the value of the second roll' do
263
264
  d = GamesDice.create '1d10r:10,replace,1.'
264
265
  expect((1..27).map do
265
266
  d.roll
@@ -268,7 +269,7 @@ describe 'String Dice Description' do
268
269
  end
269
270
 
270
271
  describe "'1d20r:<=10,use_best,1.'" do
271
- it 'should roll a 20-sided die, re-roll a result if 10 or lower, and use best result' do
272
+ it 'roll a 20-sided die, re-roll a result if 10 or lower, and use best result' do
272
273
  d = GamesDice.create '1d20r:<=10,use_best,1.'
273
274
  expect((1..20).map do
274
275
  d.roll
@@ -277,7 +278,7 @@ describe 'String Dice Description' do
277
278
  end
278
279
 
279
280
  describe "'5d10r:10,add.k2', '5d10xk2' and '5d10x.k2'" do
280
- it 'should all be equivalent' do
281
+ it 'all be equivalent' do
281
282
  srand(135_241)
282
283
  d = GamesDice.create '5d10r:10,add.k2'
283
284
  results1 = (1..50).map { d.roll }
@@ -307,6 +308,7 @@ describe 'String Dice Description' do
307
308
  d = GamesDice.create '9d6x.m:10.'
308
309
  expect((1..5).map { |_n| d.roll }).to eql [1, 2, 1, 1, 1]
309
310
  end
311
+
310
312
  it 'can be explained as number of exploding dice scoring 10+' do
311
313
  d = GamesDice.create '9d6x.m:10.'
312
314
  expect((1..5).map do |_n|
@@ -327,6 +329,7 @@ describe 'String Dice Description' do
327
329
  d = GamesDice.create '9d6x.m:10,1,S.'
328
330
  expect((1..5).map { |_n| d.roll }).to eql [1, 2, 1, 1, 1]
329
331
  end
332
+
330
333
  it "includes the string 'S' next to each success" do
331
334
  d = GamesDice.create '9d6x.m:10,1,S.'
332
335
  expect((1..5).map do |_n|
@@ -347,6 +350,7 @@ describe 'String Dice Description' do
347
350
  d = GamesDice.create '5d10m:>=6,1,S.m:==1,-1,F.'
348
351
  expect((1..10).map { |_n| d.roll }).to eql [2, 2, 4, 3, 2, 1, 1, 3, 3, 0]
349
352
  end
353
+
350
354
  it "includes the string 'S' next to each success, and 'F' next to each 'fumble'" do
351
355
  d = GamesDice.create '5d10m:>=6,1,S.m:==1,-1,F.'
352
356
  expect((1..5).map do |_n|
@@ -367,6 +371,7 @@ describe 'String Dice Description' do
367
371
  d = GamesDice.create '4d6k:3.r:1,replace,1.'
368
372
  expect((1..10).map { |_n| d.roll }).to eql [12, 14, 14, 18, 11, 17, 11, 15, 14, 14]
369
373
  end
374
+
370
375
  it 'includes re-rolls and keeper choice in explanations' do
371
376
  d = GamesDice.create '4d6k:3.r:1,replace,1.'
372
377
  expect((1..5).map do |_n|
@@ -387,6 +392,7 @@ describe 'String Dice Description' do
387
392
  d = GamesDice.create '2d20k:1,worst.'
388
393
  expect((1..10).map { |_n| d.roll }).to eql [18, 6, 2, 3, 5, 10, 15, 1, 7, 10]
389
394
  end
395
+
390
396
  it 'includes keeper choice in explanations' do
391
397
  d = GamesDice.create '2d20k:1,worst.'
392
398
  expect((1..5).map do |_n|
@@ -4,36 +4,36 @@ require 'helpers'
4
4
 
5
5
  describe GamesDice::RerollRule do
6
6
  describe '#new' do
7
- it 'should accept self-consistent operator/value pairs as a trigger' do
8
- GamesDice::RerollRule.new(5, :>, :reroll_subtract)
9
- GamesDice::RerollRule.new((1..5), :member?, :reroll_replace)
7
+ it 'accept self-consistent operator/value pairs as a trigger' do
8
+ expect { described_class.new(5, :>, :reroll_subtract) }.not_to raise_error
9
+ expect { described_class.new(1..5, :member?, :reroll_replace) }.not_to raise_error
10
10
  end
11
11
 
12
- it 'should reject inconsistent operator/value pairs for a trigger' do
13
- expect(-> { GamesDice::RerollRule.new(5, :member?, :reroll_subtract) }).to raise_error(ArgumentError)
14
- expect(-> { GamesDice::RerollRule.new((1..5), :>, :reroll_replace) }).to raise_error(ArgumentError)
12
+ it 'reject inconsistent operator/value pairs for a trigger' do
13
+ expect { described_class.new(5, :member?, :reroll_subtract) }.to raise_error(ArgumentError)
14
+ expect { described_class.new(1..5, :>, :reroll_replace) }.to raise_error(ArgumentError)
15
15
  end
16
16
 
17
- it 'should reject bad re-roll types' do
18
- expect(-> { GamesDice::RerollRule.new(5, :>, :reroll_again) }).to raise_error(ArgumentError)
19
- expect(-> { GamesDice::RerollRule.new((1..5), :member?, 42) }).to raise_error(ArgumentError)
17
+ it 'reject bad re-roll types' do
18
+ expect { described_class.new(5, :>, :reroll_again) }.to raise_error(ArgumentError)
19
+ expect { described_class.new(1..5, :member?, 42) }.to raise_error(ArgumentError)
20
20
  end
21
21
  end
22
22
 
23
23
  describe '#applies?' do
24
- it 'should return true if a trigger condition is met' do
25
- rule = GamesDice::RerollRule.new(5, :>, :reroll_subtract)
24
+ it 'return true if a trigger condition is met' do
25
+ rule = described_class.new(5, :>, :reroll_subtract)
26
26
  expect(rule.applies?(4)).to be true
27
27
 
28
- rule = GamesDice::RerollRule.new((1..5), :member?, :reroll_subtract)
28
+ rule = described_class.new(1..5, :member?, :reroll_subtract)
29
29
  expect(rule.applies?(4)).to be true
30
30
  end
31
31
 
32
- it 'should return false if a trigger condition is not met' do
33
- rule = GamesDice::RerollRule.new(5, :>, :reroll_subtract)
32
+ it 'return false if a trigger condition is not met' do
33
+ rule = described_class.new(5, :>, :reroll_subtract)
34
34
  expect(rule.applies?(7)).to be false
35
35
 
36
- rule = GamesDice::RerollRule.new((1..5), :member?, :reroll_subtract)
36
+ rule = described_class.new(1..5, :member?, :reroll_subtract)
37
37
  expect(rule.applies?(6)).to be false
38
38
  end
39
39
  end
metadata CHANGED
@@ -1,143 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: games_dice
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neil Slater
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-09-19 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: coveralls
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.6.7
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.6.7
27
- - !ruby/object:Gem::Dependency
28
- name: json
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.7.7
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 1.7.7
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 1.9.1
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 1.9.1
55
- - !ruby/object:Gem::Dependency
56
- name: rake-compiler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 0.8.3
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: 0.8.3
69
- - !ruby/object:Gem::Dependency
70
- name: rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: 2.13.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: 2.13.0
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: 1.2.1
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 1.2.1
97
- - !ruby/object:Gem::Dependency
98
- name: yard
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: 0.8.6
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: 0.8.6
111
- - !ruby/object:Gem::Dependency
112
- name: redcarpet
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: 3.5.1
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: 3.5.1
125
12
  - !ruby/object:Gem::Dependency
126
13
  name: parslet
127
14
  requirement: !ruby/object:Gem::Requirement
128
15
  requirements:
129
- - - ">="
16
+ - - "~>"
130
17
  - !ruby/object:Gem::Version
131
- version: 1.5.0
18
+ version: '2.0'
132
19
  type: :runtime
133
20
  prerelease: false
134
21
  version_requirements: !ruby/object:Gem::Requirement
135
22
  requirements:
136
- - - ">="
23
+ - - "~>"
137
24
  - !ruby/object:Gem::Version
138
- version: 1.5.0
139
- description: A library for simulating dice. Use it to construct dice-rolling systems
25
+ version: '2.0'
26
+ description: 'A library for simulating dice. Use it to construct dice-rolling systems
140
27
  used in role-playing and board games.
28
+
29
+ '
141
30
  email:
142
31
  - slobo777@gmail.com
143
32
  executables: []
@@ -145,9 +34,9 @@ extensions:
145
34
  - ext/games_dice/extconf.rb
146
35
  extra_rdoc_files: []
147
36
  files:
37
+ - ".github/workflows/ci.yml"
148
38
  - ".gitignore"
149
39
  - ".rubocop.yml"
150
- - ".travis.yml"
151
40
  - ".yardopts"
152
41
  - CHANGELOG.md
153
42
  - Gemfile
@@ -161,6 +50,7 @@ files:
161
50
  - games_dice.gemspec
162
51
  - lib/games_dice.rb
163
52
  - lib/games_dice/bunch.rb
53
+ - lib/games_dice/bunch_helpers.rb
164
54
  - lib/games_dice/complex_die.rb
165
55
  - lib/games_dice/complex_die_helpers.rb
166
56
  - lib/games_dice/constants.rb
@@ -187,8 +77,8 @@ files:
187
77
  homepage: https://github.com/neilslater/games_dice
188
78
  licenses:
189
79
  - MIT
190
- metadata: {}
191
- post_install_message:
80
+ metadata:
81
+ rubygems_mfa_required: 'true'
192
82
  rdoc_options: []
193
83
  require_paths:
194
84
  - lib
@@ -196,28 +86,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
196
86
  requirements:
197
87
  - - ">="
198
88
  - !ruby/object:Gem::Version
199
- version: 2.6.0
89
+ version: 3.3.0
200
90
  required_rubygems_version: !ruby/object:Gem::Requirement
201
91
  requirements:
202
92
  - - ">="
203
93
  - !ruby/object:Gem::Version
204
94
  version: '0'
205
95
  requirements: []
206
- rubygems_version: 3.2.3
207
- signing_key:
96
+ rubygems_version: 4.0.1
208
97
  specification_version: 4
209
98
  summary: Simulates and explains dice rolls from simple "1d6" to complex "roll 7 ten-sided
210
99
  dice, take best 3, results of 10 roll again and add on".
211
- test_files:
212
- - spec/bunch_spec.rb
213
- - spec/complex_die_spec.rb
214
- - spec/dice_spec.rb
215
- - spec/die_result_spec.rb
216
- - spec/die_spec.rb
217
- - spec/fixtures/probs_fair_die_6.dat
218
- - spec/helpers.rb
219
- - spec/map_rule_spec.rb
220
- - spec/parser_spec.rb
221
- - spec/probability_spec.rb
222
- - spec/readme_spec.rb
223
- - spec/reroll_rule_spec.rb
100
+ test_files: []
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
-
3
- before_install:
4
- - gem install bundler
5
-
6
- os:
7
- - linux
8
-
9
- rvm:
10
- - "2.7.1"
11
- - "3.0.0"