games_dice 0.3.11 → 0.3.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -4
- data/README.md +5 -5
- data/lib/games_dice/bunch.rb +1 -1
- data/lib/games_dice/die_result.rb +1 -1
- data/lib/games_dice/version.rb +1 -1
- data/spec/complex_die_spec.rb +1 -1
- data/spec/die_result_spec.rb +16 -16
- data/spec/die_spec.rb +1 -1
- data/spec/helpers.rb +5 -5
- data/spec/map_rule_spec.rb +3 -3
- data/spec/probability_spec.rb +1 -1
- data/spec/readme_spec.rb +5 -5
- data/spec/reroll_rule_spec.rb +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d19dba764a16a41817baaa3ccfd957f79433c9b0
|
4
|
+
data.tar.gz: 29037036e7fe3d1f5456e66bec3d8675a2434eaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8420089013a0439dd92199fc276bdb718ab4abb9e5cef872542b1d87d545ab53a9c382bb8ebb3d2fe7226816e3a1cd9b4a071e6659cc0ad7d0fbd959ef5135e8
|
7
|
+
data.tar.gz: 69c75770fc39c5d4ada410cf16397105e6020380a320a6023380786591b80a3a7f1ace3a00c3e0a21b665f1b6260303db5bfce223bc23d9712142ac3042190d1
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/games_dice.png)](http://badge.fury.io/rb/games_dice)
|
3
3
|
[![Build Status](https://travis-ci.org/neilslater/games_dice.png?branch=master)](http://travis-ci.org/neilslater/games_dice)
|
4
4
|
[![Coverage Status](https://coveralls.io/repos/neilslater/games_dice/badge.png?branch=master)](https://coveralls.io/r/neilslater/games_dice?branch=master)
|
5
|
+
[![Inline docs](http://inch-ci.org/github/neilslater/games_dice.png?branch=master)](http://inch-ci.org/github/neilslater/games_dice)
|
5
6
|
[![Code Climate](https://codeclimate.com/github/neilslater/games_dice.png)](https://codeclimate.com/github/neilslater/games_dice)
|
6
7
|
[![Dependency Status](https://gemnasium.com/neilslater/games_dice.png)](https://gemnasium.com/neilslater/games_dice)
|
7
8
|
|
@@ -29,12 +30,11 @@ gem as-is, and add them as features within your project code.
|
|
29
30
|
|
30
31
|
## Supported Ruby Versions
|
31
32
|
|
32
|
-
GamesDice is tested routinely on
|
33
|
+
GamesDice is tested routinely on MRI Rubies 1.9.3, 2.0.0, 2.1.0, 2.1.1 and JRuby, and the
|
34
|
+
"build passing" badge is based on those tests.
|
33
35
|
|
34
|
-
*
|
35
|
-
|
36
|
-
* JRuby in 1.8 and 1.9 modes
|
37
|
-
* Ruby Enterprise Edition
|
36
|
+
It *should* also work in versions from 1.8.7, in Ruby Enterprise and in Rubinius, but it
|
37
|
+
is not tested routinely on those Rubies.
|
38
38
|
|
39
39
|
## Installation
|
40
40
|
|
data/lib/games_dice/bunch.rb
CHANGED
@@ -98,7 +98,7 @@ class GamesDice::Bunch
|
|
98
98
|
# @return [Array<GamesDice::DieResult>, nil] Sequence of GamesDice::DieResult objects.
|
99
99
|
def result_details
|
100
100
|
return nil unless @raw_result_details
|
101
|
-
@raw_result_details.map { |r| r.is_a?(
|
101
|
+
@raw_result_details.map { |r| r.is_a?(Integer) ? GamesDice::DieResult.new(r) : r }
|
102
102
|
end
|
103
103
|
|
104
104
|
# @!attribute [r] min
|
data/lib/games_dice/version.rb
CHANGED
data/spec/complex_die_spec.rb
CHANGED
@@ -153,7 +153,7 @@ describe GamesDice::ComplexDie do
|
|
153
153
|
die = GamesDice::ComplexDie.new(10, :rerolls => [GamesDice::RerollRule.new(10, :<=, :reroll_add)] )
|
154
154
|
probs = die.probabilities.to_h
|
155
155
|
probs[8].should be_within(1e-10).of 0.1
|
156
|
-
probs[10].should
|
156
|
+
probs[10].should be_nil
|
157
157
|
probs[13].should be_within(1e-10).of 0.01
|
158
158
|
probs[27].should be_within(1e-10).of 0.001
|
159
159
|
probs.values.inject(:+).should be_within(1e-9).of 1.0
|
data/spec/die_result_spec.rb
CHANGED
@@ -223,25 +223,25 @@ describe GamesDice::DieResult do
|
|
223
223
|
it "should support comparison with >,<,>=,<= as if it were an integer, based on #value" do
|
224
224
|
die_result = GamesDice::DieResult.new(7)
|
225
225
|
|
226
|
-
(die_result > 3).should
|
227
|
-
(14 > die_result).should
|
228
|
-
(die_result >= 7).should
|
229
|
-
(9.5 >= die_result).should
|
230
|
-
(die_result < 3).should
|
231
|
-
(14 < die_result).should
|
232
|
-
(die_result <= 8).should
|
233
|
-
(14 <= die_result).should
|
226
|
+
(die_result > 3).should == true
|
227
|
+
(14 > die_result).should == true
|
228
|
+
(die_result >= 7).should == true
|
229
|
+
(9.5 >= die_result).should == true
|
230
|
+
(die_result < 3).should == false
|
231
|
+
(14 < die_result).should == false
|
232
|
+
(die_result <= 8).should == true
|
233
|
+
(14 <= die_result).should == false
|
234
234
|
|
235
235
|
other_die_result = GamesDice::DieResult.new(6)
|
236
236
|
other_die_result.add_roll(6,:reroll_add)
|
237
|
-
(die_result > other_die_result).should
|
238
|
-
(other_die_result > die_result).should
|
239
|
-
(die_result >= other_die_result).should
|
240
|
-
(other_die_result >= die_result).should
|
241
|
-
(die_result < other_die_result).should
|
242
|
-
(other_die_result < die_result).should
|
243
|
-
(die_result <= other_die_result).should
|
244
|
-
(other_die_result <= die_result).should
|
237
|
+
(die_result > other_die_result).should == false
|
238
|
+
(other_die_result > die_result).should == true
|
239
|
+
(die_result >= other_die_result).should == false
|
240
|
+
(other_die_result >= die_result).should == true
|
241
|
+
(die_result < other_die_result).should == true
|
242
|
+
(other_die_result < die_result).should == false
|
243
|
+
(die_result <= other_die_result).should == true
|
244
|
+
(other_die_result <= die_result).should == false
|
245
245
|
|
246
246
|
end
|
247
247
|
|
data/spec/die_spec.rb
CHANGED
@@ -47,7 +47,7 @@ describe GamesDice::Die do
|
|
47
47
|
it "should return the die's probability distribution as a GamesDice::Probabilities object" do
|
48
48
|
die = GamesDice::Die.new(6)
|
49
49
|
probs = die.probabilities
|
50
|
-
probs.
|
50
|
+
probs.should be_a GamesDice::Probabilities
|
51
51
|
|
52
52
|
probs.to_h.should be_valid_distribution
|
53
53
|
|
data/spec/helpers.rb
CHANGED
@@ -44,9 +44,9 @@ RSpec::Matchers.define :be_valid_distribution do
|
|
44
44
|
@error = nil
|
45
45
|
if ! given.is_a?(Hash)
|
46
46
|
@error = "distribution should be a Hash, but it is a #{given.class}"
|
47
|
-
elsif given.keys.any? { |k| ! k.is_a?(
|
48
|
-
bad_key = given.keys.first { |k| ! k.is_a?(
|
49
|
-
@error = "all keys should be
|
47
|
+
elsif given.keys.any? { |k| ! k.is_a?(Integer) }
|
48
|
+
bad_key = given.keys.first { |k| ! k.is_a?(Integer) }
|
49
|
+
@error = "all keys should be Integers, but found '#{bad_key.inspect}' which is a #{bad_key.class}"
|
50
50
|
elsif given.values.any? { |v| ! v.is_a?(Float) }
|
51
51
|
bad_value = given.values.find { |v| ! v.is_a?(Float) }
|
52
52
|
@error = "all values should be Floats, but found '#{bad_value.inspect}' which is a #{bad_value.class}"
|
@@ -60,11 +60,11 @@ RSpec::Matchers.define :be_valid_distribution do
|
|
60
60
|
! @error
|
61
61
|
end
|
62
62
|
|
63
|
-
|
63
|
+
failure_message do |given|
|
64
64
|
@error ? @error : 'Distribution is valid and complete'
|
65
65
|
end
|
66
66
|
|
67
|
-
|
67
|
+
failure_message_when_negated do |given|
|
68
68
|
@error ? @error : 'Distribution is valid and complete'
|
69
69
|
end
|
70
70
|
|
data/spec/map_rule_spec.rb
CHANGED
@@ -31,12 +31,12 @@ describe GamesDice::MapRule do
|
|
31
31
|
rule.map_from(4).should == 3
|
32
32
|
end
|
33
33
|
|
34
|
-
it "should return
|
34
|
+
it "should return nil for no match" do
|
35
35
|
rule = GamesDice::MapRule.new( 5, :>, -1 )
|
36
|
-
rule.map_from(6).should
|
36
|
+
rule.map_from(6).should be_nil
|
37
37
|
|
38
38
|
rule = GamesDice::MapRule.new( (1..5), :member?, 3 )
|
39
|
-
rule.map_from(6).should
|
39
|
+
rule.map_from(6).should be_nil
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
data/spec/probability_spec.rb
CHANGED
@@ -163,7 +163,7 @@ describe GamesDice::Probabilities do
|
|
163
163
|
it "should be either :c or :ruby" do
|
164
164
|
lang = GamesDice::Probabilities.implemented_in
|
165
165
|
lang.should be_a Symbol
|
166
|
-
[:c, :ruby].member?( lang ).should
|
166
|
+
[:c, :ruby].member?( lang ).should == true
|
167
167
|
end
|
168
168
|
end
|
169
169
|
end # describe "class methods"
|
data/spec/readme_spec.rb
CHANGED
@@ -6,21 +6,21 @@ describe GamesDice do
|
|
6
6
|
describe '#create' do
|
7
7
|
it "converts a string such as '3d6+6' into a GamesDice::Dice object" do
|
8
8
|
d = GamesDice.create '3d6+6'
|
9
|
-
d.
|
9
|
+
d.should be_a GamesDice::Dice
|
10
10
|
end
|
11
11
|
|
12
12
|
it "takes a parameter 'dice_description', which is a string such as '3d6' or '2d4-1'" do
|
13
13
|
d = GamesDice.create '3d6'
|
14
|
-
d.
|
14
|
+
d.should be_a GamesDice::Dice
|
15
15
|
d = GamesDice.create '2d4-1'
|
16
|
-
d.
|
16
|
+
d.should be_a GamesDice::Dice
|
17
17
|
end
|
18
18
|
|
19
19
|
it "takes an optional parameter 'prng', which if provided it should be an object that has a method 'rand( integer )'" do
|
20
20
|
prng = TestPRNG.new
|
21
21
|
|
22
22
|
d = GamesDice.create '3d6', prng
|
23
|
-
d.
|
23
|
+
d.should be_a GamesDice::Dice
|
24
24
|
|
25
25
|
(0..5).each do |dresult|
|
26
26
|
prng.stub( :rand ) { dresult }
|
@@ -103,7 +103,7 @@ describe GamesDice::Dice do
|
|
103
103
|
describe "#probabilities" do
|
104
104
|
it "calculates probability distribution for the dice" do
|
105
105
|
pd = dice.probabilities
|
106
|
-
pd.
|
106
|
+
pd.should be_a GamesDice::Probabilities
|
107
107
|
pd.p_eql( 3).should be_within(1e-10).of 1.0/216
|
108
108
|
pd.p_eql( 11 ).should be_within(1e-10).of 27.0/216
|
109
109
|
end
|
data/spec/reroll_rule_spec.rb
CHANGED
@@ -25,18 +25,18 @@ describe GamesDice::RerollRule do
|
|
25
25
|
|
26
26
|
it "should return true if a trigger condition is met" do
|
27
27
|
rule = GamesDice::RerollRule.new( 5, :>, :reroll_subtract )
|
28
|
-
rule.applies?(4).should
|
28
|
+
rule.applies?(4).should == true
|
29
29
|
|
30
30
|
rule = GamesDice::RerollRule.new( (1..5), :member?, :reroll_subtract )
|
31
|
-
rule.applies?(4).should
|
31
|
+
rule.applies?(4).should == true
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should return false if a trigger condition is not met" do
|
35
35
|
rule = GamesDice::RerollRule.new( 5, :>, :reroll_subtract )
|
36
|
-
rule.applies?(7).should
|
36
|
+
rule.applies?(7).should == false
|
37
37
|
|
38
38
|
rule = GamesDice::RerollRule.new( (1..5), :member?, :reroll_subtract )
|
39
|
-
rule.applies?(6).should
|
39
|
+
rule.applies?(6).should == false
|
40
40
|
end
|
41
41
|
|
42
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: games_dice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil Slater
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
requirements: []
|
193
193
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.
|
194
|
+
rubygems_version: 2.6.12
|
195
195
|
signing_key:
|
196
196
|
specification_version: 4
|
197
197
|
summary: Simulates and explains dice rolls from simple "1d6" to complex "roll 7 ten-sided
|