math_probability 0.2.0 → 1.0.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.
- checksums.yaml +4 -4
- data/README.md +12 -3
- data/lib/math_probability.rb +1 -2
- data/lib/math_probability/version.rb +1 -1
- data/test/lib/math_probability/math_probability_test.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f9663665c75fb9d29ec90847b892da061f61130
|
4
|
+
data.tar.gz: 5daae246f7c6550558993a7ba15bc82db6853371
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1dbba8ab53c0463e905d396791cd319de513f0cb630f163b92551ede0ec096a070cd0fb9b91765cc0e32c1fbcc039563dfef632c7c696892aa69abc9f794089
|
7
|
+
data.tar.gz: 70208f2b091d28c8478b8cd16ef21ee1756380d18df45db99d941acd6ad14bcaaed996fc60fca5444d36386ce3bbc6c7b0f561f07d236dcbaa7619bb31941873
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
[](https://coveralls.io/r/polysaturate/math_probability?branch=master)
|
5
5
|
[](https://codeclimate.com/github/polysaturate/math_probability)
|
6
6
|
|
7
|
-
Quickly find factorals,
|
7
|
+
Quickly find factorals, summations, permutations, combanations and probability answers
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -47,11 +47,20 @@ Combinations | Usage combinations(objects, at_a_time)
|
|
47
47
|
prob.combinations(10,4)
|
48
48
|
=> 210
|
49
49
|
|
50
|
-
Probability | Usage probability(choices, outcomes)
|
50
|
+
Probability | Usage probability(choices, outcomes, reduce=true)
|
51
51
|
|
52
52
|
prob.probability(1,4)
|
53
|
-
=>
|
53
|
+
=> {:decimal=> 0.25, :percentage=>"25.0%", :fraction=>"1/4"}
|
54
|
+
prob.probability(2,4)
|
55
|
+
=> {:decimal=> 0.5, :percentage=>"50.0%", :fraction=>"1/2"}
|
56
|
+
prob.probability(2,4,false)
|
57
|
+
=> {:decimal=> 0.5, :percentage=>"50.0%", :fraction=>"2/4"}
|
54
58
|
|
59
|
+
## Running tests
|
60
|
+
|
61
|
+
$ git clone git://github.com/polysaturate/math_probability.git
|
62
|
+
$ bundle install
|
63
|
+
$ rake
|
55
64
|
|
56
65
|
## Contributing
|
57
66
|
|
data/lib/math_probability.rb
CHANGED
@@ -28,9 +28,8 @@ module MathProbability
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.probability(choices, outcomes, reduce=true)
|
31
|
-
answer ||= []
|
32
31
|
a = choices.to_f / outcomes
|
33
|
-
answer
|
32
|
+
answer = {decimal: a, percentage: "#{a*100}%", fraction: (reduce ? reduced_fraction(choices, outcomes) : "#{choices}/#{outcomes}")}
|
34
33
|
end
|
35
34
|
|
36
35
|
private
|
@@ -29,15 +29,15 @@ describe MathProbability::Probability do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should return all forms of Probability" do
|
32
|
-
subject.probability(1,2).must_equal(
|
32
|
+
subject.probability(1,2).must_equal({:decimal=> 0.5, :percentage=>"50.0%", :fraction=>"1/2"})
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should return a reduced fraction" do
|
36
|
-
subject.probability(2,4).must_equal(
|
36
|
+
subject.probability(2,4).must_equal({:decimal=> 0.5, :percentage=>"50.0%", :fraction=>"1/2"})
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should not return a reduced fraction if flag is set to false" do
|
40
|
-
subject.probability(2,4,false).must_equal(
|
40
|
+
subject.probability(2,4,false).must_equal({:decimal=> 0.5, :percentage=>"50.0%", :fraction=>"2/4"})
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: math_probability
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob Race
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|