odds 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile +6 -0
- data/Gemfile.lock +40 -0
- data/Guardfile +33 -0
- data/VERSION +1 -1
- data/lib/odds.rb +6 -54
- data/lib/odds/bet.rb +21 -0
- data/lib/odds/ext/hash.rb +5 -0
- data/lib/odds/ext/map_special.rb +17 -0
- data/lib/odds/ext/math.rb +5 -0
- data/lib/odds/ext/numeric.rb +9 -0
- data/lib/odds/ext/rand.rb +27 -0
- data/lib/odds/ext/string.rb +6 -0
- data/lib/odds/ext/to_odds.rb +5 -0
- data/lib/odds/odds.rb +76 -0
- data/lib/odds/parlay.rb +14 -0
- data/odds.gemspec +27 -2
- data/spec/bet_spec.rb +18 -0
- data/spec/odds_spec.rb +17 -9
- data/spec/parlay_spec.rb +28 -0
- data/spec/spec_helper.rb +17 -9
- metadata +71 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTVhOWM3MDg1YmRhZTVmNDVkYzU0ZTU1YjY5MjUyOTlhYTI3YmNhMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
N2U2MzBkYTZjZmIwYzgxM2JkZmU2ZjMzN2JmNzZiMzljY2UyMDhkMg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjkxZGRhYjU0ZjQ5OTk5NjE4NmFjNDMzNzhjMjkxNDllOTgxYzU5ZTBjZGY4
|
10
|
+
ZjgxNzZhY2UzZmRjMDNjMDZiM2E4MmY5YjUyNTdjMTk4NWMwODVhNjZjYWM2
|
11
|
+
ZjMwNzBjMDYwOGEzNDIzOThiZGU2ZmRkZTIzM2I1YmE3MTUwMjg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDAxN2NjNmQxZTZjOTE5OTUyZTYxNTdhZjg0MTgyMTcwNjllMGZjNjYxNzA4
|
14
|
+
MjRhMWJlMGEwMmE4NzVmNDdkMmFjMWEyODU0NDYyYmVkNzVhNWIxZmY5ZDVj
|
15
|
+
ZWM3N2I1ODNkN2VhNTMyOWJlMmI0NTExOGY2YjRiMGUyNjU4ODM=
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -3,11 +3,18 @@ GEM
|
|
3
3
|
specs:
|
4
4
|
addressable (2.3.5)
|
5
5
|
builder (3.2.2)
|
6
|
+
celluloid (0.15.2)
|
7
|
+
timers (~> 1.1.0)
|
8
|
+
childprocess (0.3.9)
|
9
|
+
ffi (~> 1.0, >= 1.0.11)
|
10
|
+
coderay (1.1.0)
|
6
11
|
diff-lcs (1.1.3)
|
7
12
|
facets (2.9.3)
|
8
13
|
faraday (0.8.8)
|
9
14
|
multipart-post (~> 1.2.0)
|
10
15
|
fattr (2.2.1)
|
16
|
+
ffi (1.9.3)
|
17
|
+
formatador (0.2.4)
|
11
18
|
git (1.2.6)
|
12
19
|
github_api (0.10.1)
|
13
20
|
addressable
|
@@ -16,6 +23,18 @@ GEM
|
|
16
23
|
multi_json (~> 1.4)
|
17
24
|
nokogiri (~> 1.5.2)
|
18
25
|
oauth2
|
26
|
+
guard (2.2.3)
|
27
|
+
formatador (>= 0.2.4)
|
28
|
+
listen (~> 2.1)
|
29
|
+
lumberjack (~> 1.0)
|
30
|
+
pry (>= 0.9.12)
|
31
|
+
thor (>= 0.18.1)
|
32
|
+
guard-rspec (1.2.1)
|
33
|
+
guard (>= 1.1)
|
34
|
+
guard-spork (1.5.1)
|
35
|
+
childprocess (>= 0.2.3)
|
36
|
+
guard (>= 1.1)
|
37
|
+
spork (>= 0.8.4)
|
19
38
|
hashie (2.0.5)
|
20
39
|
highline (1.6.19)
|
21
40
|
httpauth (0.2.0)
|
@@ -31,6 +50,12 @@ GEM
|
|
31
50
|
json (1.8.1)
|
32
51
|
jwt (0.1.8)
|
33
52
|
multi_json (>= 1.5)
|
53
|
+
listen (2.2.0)
|
54
|
+
celluloid (>= 0.15.2)
|
55
|
+
rb-fsevent (>= 0.9.3)
|
56
|
+
rb-inotify (>= 0.9)
|
57
|
+
lumberjack (1.0.4)
|
58
|
+
method_source (0.8.2)
|
34
59
|
mharris_ext (1.7.1)
|
35
60
|
facets
|
36
61
|
fattr
|
@@ -45,8 +70,15 @@ GEM
|
|
45
70
|
multi_json (~> 1.0)
|
46
71
|
multi_xml (~> 0.5)
|
47
72
|
rack (~> 1.2)
|
73
|
+
pry (0.9.12.4)
|
74
|
+
coderay (~> 1.0)
|
75
|
+
method_source (~> 0.8)
|
76
|
+
slop (~> 3.4)
|
48
77
|
rack (1.5.2)
|
49
78
|
rake (10.1.0)
|
79
|
+
rb-fsevent (0.9.3)
|
80
|
+
rb-inotify (0.9.2)
|
81
|
+
ffi (>= 0.5.0)
|
50
82
|
rdoc (3.12.2)
|
51
83
|
json (~> 1.4)
|
52
84
|
rspec (2.8.0)
|
@@ -57,13 +89,21 @@ GEM
|
|
57
89
|
rspec-expectations (2.8.0)
|
58
90
|
diff-lcs (~> 1.1.2)
|
59
91
|
rspec-mocks (2.8.0)
|
92
|
+
slop (3.4.7)
|
93
|
+
spork (0.9.2)
|
94
|
+
thor (0.18.1)
|
95
|
+
timers (1.1.0)
|
60
96
|
|
61
97
|
PLATFORMS
|
62
98
|
ruby
|
63
99
|
|
64
100
|
DEPENDENCIES
|
65
101
|
bundler (>= 1.0)
|
102
|
+
guard
|
103
|
+
guard-rspec
|
104
|
+
guard-spork
|
66
105
|
jeweler (~> 1.8.7)
|
67
106
|
mharris_ext
|
107
|
+
rb-fsevent (~> 0.9)
|
68
108
|
rdoc (~> 3.12)
|
69
109
|
rspec (~> 2.8.0)
|
data/Guardfile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'spork', :rspec_port => 5645 do
|
5
|
+
watch('config/application.rb')
|
6
|
+
watch('config/environment.rb')
|
7
|
+
watch('config/environments/test.rb')
|
8
|
+
watch(%r{^config/initializers/.+\.rb$})
|
9
|
+
watch('Gemfile')
|
10
|
+
watch('Gemfile.lock')
|
11
|
+
watch('spec/spec_helper.rb') { :rspec }
|
12
|
+
watch('test/test_helper.rb') { :test_unit }
|
13
|
+
watch(%r{features/support/}) { :cucumber }
|
14
|
+
watch(%r{^spec/support/.+\.rb$})
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
guard 'rspec', :cli => "--drb --drb-port 5645" do
|
21
|
+
watch(%r{^spec/.+_spec\.rb$}) { "spec" }
|
22
|
+
watch(%r{^lib/(.+)\.rb$}) { "spec" } # { |m| "spec/lib/#{m[1]}_spec.rb" }
|
23
|
+
watch(%r{^lib/(.+)\.treetop$}) { "spec" }
|
24
|
+
watch(%r{^lib/(.+)\.csv$}) { "spec" }
|
25
|
+
#watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
26
|
+
watch('spec/spec_helper.rb') { "spec" }
|
27
|
+
watch(%r{^app/(.+)\.rb$}) { "spec" }
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/odds.rb
CHANGED
@@ -1,59 +1,11 @@
|
|
1
1
|
require 'mharris_ext'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
%w(to_odds string hash map_special numeric rand math).each do |f|
|
4
|
+
load File.dirname(__FILE__) + "/odds/ext/#{f}.rb"
|
5
|
+
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
else
|
11
|
-
n = (1.0 / loss_chance) - 1.0
|
12
|
-
"-" + (n * 100.0).to_i.to_s
|
13
|
-
end
|
14
|
-
end
|
7
|
+
%w(odds bet parlay).each do |f|
|
8
|
+
load File.dirname(__FILE__) + "/odds/#{f}.rb"
|
9
|
+
end
|
15
10
|
|
16
|
-
def win_amount_with_principal
|
17
|
-
1.0 / win_chance
|
18
|
-
end
|
19
|
-
def win_amount_without_principal
|
20
|
-
win_amount_with_principal - 1.0
|
21
|
-
end
|
22
|
-
def loss_chance
|
23
|
-
1.0 - win_chance
|
24
|
-
end
|
25
|
-
|
26
|
-
def to_s_to_one
|
27
|
-
if win_chance < 0.5
|
28
|
-
"#{win_amount_without_principal} to 1"
|
29
|
-
else
|
30
|
-
"1 to #{(1.0 / win_amount_without_principal).round(1)}"
|
31
|
-
end
|
32
|
-
end
|
33
11
|
|
34
|
-
def *(other)
|
35
|
-
res = win_chance * other.win_chance
|
36
|
-
self.class.new(:win_chance => res)
|
37
|
-
end
|
38
|
-
|
39
|
-
def inverse
|
40
|
-
self.class.new(:win_chance => (1.0 - win_chance))
|
41
|
-
end
|
42
|
-
|
43
|
-
class << self
|
44
|
-
def from_string(str)
|
45
|
-
sign = str[0..0]
|
46
|
-
num = str[1..-1].to_f / 100.0
|
47
|
-
if sign == '-'
|
48
|
-
from_win_amount_without_principal(1.0 / num)
|
49
|
-
elsif sign == '+'
|
50
|
-
from_win_amount_without_principal(num)
|
51
|
-
else
|
52
|
-
raise "bad #{str}"
|
53
|
-
end
|
54
|
-
end
|
55
|
-
def from_win_amount_without_principal(num)
|
56
|
-
new(:win_chance => (1.0 / (1.0 + num)))
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
data/lib/odds/bet.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class Bet
|
2
|
+
module ExpectedProfit
|
3
|
+
def expected_profit
|
4
|
+
n = (win_chance * odds.win_amount_with_principal) - 1.0
|
5
|
+
n * wagered_amount.to_f
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
include FromHash
|
10
|
+
include ExpectedProfit
|
11
|
+
attr_accessor :odds, :wagered_amount, :win_chance
|
12
|
+
|
13
|
+
def odds=(o)
|
14
|
+
o = Odds.from_string(o) if o.kind_of?(String)
|
15
|
+
@odds = o
|
16
|
+
end
|
17
|
+
|
18
|
+
def potential_profit
|
19
|
+
odds.win_amount_without_principal * wagered_amount.to_f
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Array
|
2
|
+
def map_centered_on_sum(target_sum)
|
3
|
+
self_sum = sum
|
4
|
+
map { |x| x.to_f / self_sum.to_f * target_sum.to_f }
|
5
|
+
end
|
6
|
+
def map_restrict_to_range(r)
|
7
|
+
map do |n|
|
8
|
+
if n > r.end
|
9
|
+
r.end
|
10
|
+
elsif n < r.begin
|
11
|
+
r.begin
|
12
|
+
else
|
13
|
+
n
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Range
|
2
|
+
def rand_num
|
3
|
+
num = rand * (self.end.to_f - self.begin.to_f)
|
4
|
+
num + self.begin.to_f
|
5
|
+
end
|
6
|
+
|
7
|
+
def rand_sq_num
|
8
|
+
a = self.begin**2
|
9
|
+
b = self.end**2
|
10
|
+
num = (a..b).rand_num
|
11
|
+
num.to_f**0.5
|
12
|
+
end
|
13
|
+
|
14
|
+
def rand_sqrt_num
|
15
|
+
a = self.begin.to_f**0.5
|
16
|
+
b = self.end.to_f**0.5
|
17
|
+
num = (a..b).rand_num
|
18
|
+
num.to_f**2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Array
|
23
|
+
def rand_el
|
24
|
+
i = (rand()*size.to_f).to_i
|
25
|
+
self[i]
|
26
|
+
end
|
27
|
+
end
|
data/lib/odds/odds.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
class Odds
|
2
|
+
include FromHash
|
3
|
+
attr_accessor :win_chance
|
4
|
+
|
5
|
+
def initialize(arg)
|
6
|
+
if arg.kind_of?(Hash)
|
7
|
+
from_hash(arg)
|
8
|
+
else
|
9
|
+
self.win_chance = arg
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
if win_chance < 0.5
|
15
|
+
"+" + (win_amount_without_principal * 100.0).to_i.to_s
|
16
|
+
else
|
17
|
+
n = (1.0 / loss_chance) - 1.0
|
18
|
+
"-" + (n * 100.0).to_i.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s_to_one
|
23
|
+
if win_chance < 0.5
|
24
|
+
"#{win_amount_without_principal} to 1"
|
25
|
+
else
|
26
|
+
n = (1.0 / win_amount_without_principal).round(1)
|
27
|
+
"1 to #{n}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def win_amount_with_principal
|
32
|
+
1.0 / win_chance
|
33
|
+
end
|
34
|
+
def win_amount_without_principal
|
35
|
+
win_amount_with_principal - 1.0
|
36
|
+
end
|
37
|
+
def loss_chance
|
38
|
+
1.0 - win_chance
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
def* (other)
|
44
|
+
res = win_chance * other.win_chance
|
45
|
+
self.class.new(:win_chance => res)
|
46
|
+
end
|
47
|
+
|
48
|
+
def inverse
|
49
|
+
self.class.new(:win_chance => (1.0 - win_chance))
|
50
|
+
end
|
51
|
+
|
52
|
+
def odds
|
53
|
+
win_chance / (1.0 - win_chance)
|
54
|
+
end
|
55
|
+
|
56
|
+
def log_odds
|
57
|
+
Math.log(odds)
|
58
|
+
end
|
59
|
+
|
60
|
+
class << self
|
61
|
+
def from_string(str)
|
62
|
+
sign = str[0..0]
|
63
|
+
num = str[1..-1].to_f / 100.0
|
64
|
+
if sign == '-'
|
65
|
+
from_win_amount_without_principal(1.0 / num)
|
66
|
+
elsif sign == '+'
|
67
|
+
from_win_amount_without_principal(num)
|
68
|
+
else
|
69
|
+
raise "bad #{str}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
def from_win_amount_without_principal(num)
|
73
|
+
new(:win_chance => (1.0 / (1.0 + num)))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/lib/odds/parlay.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class Parlay
|
2
|
+
include FromHash
|
3
|
+
include Bet::ExpectedProfit
|
4
|
+
attr_accessor :wagered_amount
|
5
|
+
fattr(:bets) { [] }
|
6
|
+
|
7
|
+
def odds
|
8
|
+
bets.map { |x| x.odds }.times_product
|
9
|
+
end
|
10
|
+
|
11
|
+
def win_chance
|
12
|
+
bets.map { |x| x.win_chance }.times_product
|
13
|
+
end
|
14
|
+
end
|
data/odds.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "odds"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mike Harris"]
|
12
|
-
s.date = "2014-02-
|
12
|
+
s.date = "2014-02-02"
|
13
13
|
s.description = "odds"
|
14
14
|
s.email = "mharris717@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -21,13 +21,26 @@ Gem::Specification.new do |s|
|
|
21
21
|
".rspec",
|
22
22
|
"Gemfile",
|
23
23
|
"Gemfile.lock",
|
24
|
+
"Guardfile",
|
24
25
|
"LICENSE.txt",
|
25
26
|
"README.rdoc",
|
26
27
|
"Rakefile",
|
27
28
|
"VERSION",
|
28
29
|
"lib/odds.rb",
|
30
|
+
"lib/odds/bet.rb",
|
31
|
+
"lib/odds/ext/hash.rb",
|
32
|
+
"lib/odds/ext/map_special.rb",
|
33
|
+
"lib/odds/ext/math.rb",
|
34
|
+
"lib/odds/ext/numeric.rb",
|
35
|
+
"lib/odds/ext/rand.rb",
|
36
|
+
"lib/odds/ext/string.rb",
|
37
|
+
"lib/odds/ext/to_odds.rb",
|
38
|
+
"lib/odds/odds.rb",
|
39
|
+
"lib/odds/parlay.rb",
|
29
40
|
"odds.gemspec",
|
41
|
+
"spec/bet_spec.rb",
|
30
42
|
"spec/odds_spec.rb",
|
43
|
+
"spec/parlay_spec.rb",
|
31
44
|
"spec/spec_helper.rb"
|
32
45
|
]
|
33
46
|
s.homepage = "http://github.com/mharris717/odds"
|
@@ -45,12 +58,20 @@ Gem::Specification.new do |s|
|
|
45
58
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
46
59
|
s.add_development_dependency(%q<bundler>, [">= 1.0"])
|
47
60
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.7"])
|
61
|
+
s.add_development_dependency(%q<guard>, [">= 0"])
|
62
|
+
s.add_development_dependency(%q<guard-rspec>, [">= 0"])
|
63
|
+
s.add_development_dependency(%q<guard-spork>, [">= 0"])
|
64
|
+
s.add_development_dependency(%q<rb-fsevent>, ["~> 0.9"])
|
48
65
|
else
|
49
66
|
s.add_dependency(%q<mharris_ext>, [">= 0"])
|
50
67
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
51
68
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
52
69
|
s.add_dependency(%q<bundler>, [">= 1.0"])
|
53
70
|
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
71
|
+
s.add_dependency(%q<guard>, [">= 0"])
|
72
|
+
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
73
|
+
s.add_dependency(%q<guard-spork>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rb-fsevent>, ["~> 0.9"])
|
54
75
|
end
|
55
76
|
else
|
56
77
|
s.add_dependency(%q<mharris_ext>, [">= 0"])
|
@@ -58,6 +79,10 @@ Gem::Specification.new do |s|
|
|
58
79
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
59
80
|
s.add_dependency(%q<bundler>, [">= 1.0"])
|
60
81
|
s.add_dependency(%q<jeweler>, ["~> 1.8.7"])
|
82
|
+
s.add_dependency(%q<guard>, [">= 0"])
|
83
|
+
s.add_dependency(%q<guard-rspec>, [">= 0"])
|
84
|
+
s.add_dependency(%q<guard-spork>, [">= 0"])
|
85
|
+
s.add_dependency(%q<rb-fsevent>, ["~> 0.9"])
|
61
86
|
end
|
62
87
|
end
|
63
88
|
|
data/spec/bet_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Bet" do
|
4
|
+
it 'smoke' do
|
5
|
+
bet = Bet.new(:odds => "+200", :wagered_amount => 100)
|
6
|
+
bet.potential_profit.should == 200
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'smoke' do
|
10
|
+
bet = Bet.new(:odds => "-200", :wagered_amount => 100)
|
11
|
+
bet.potential_profit.should == 50
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'ev' do
|
15
|
+
bet = Bet.new(:odds => "+200", :wagered_amount => 100, :win_chance => 0.4)
|
16
|
+
bet.expected_profit.round(4).should == 20
|
17
|
+
end
|
18
|
+
end
|
data/spec/odds_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe "Odds" do
|
|
7
7
|
odds.to_s.should == exp
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def odds(win_chance)
|
12
12
|
Odds.new(:win_chance => win_chance)
|
13
13
|
end
|
@@ -28,36 +28,44 @@ describe "Odds" do
|
|
28
28
|
it 'win_amount_with_principal' do
|
29
29
|
odds(0.9).win_amount_with_principal.round(3).should == 1.111
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it 'to_s_to_one' do
|
33
33
|
odds(0.25).to_s_to_one.should == "3.0 to 1"
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it 'to_s_to_one' do
|
37
37
|
odds(0.75).to_s_to_one.should == "1 to 3.0"
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
|
+
it 'odds' do
|
41
|
+
odds(0.25).odds.round(3).should == 0.333
|
42
|
+
end
|
43
|
+
|
40
44
|
describe 'multiply' do
|
41
45
|
it 'smoke' do
|
42
46
|
(odds(0.5) * odds(0.5)).win_chance.should == 0.25
|
43
47
|
end
|
44
48
|
end
|
45
|
-
|
49
|
+
|
46
50
|
it 'inverse' do
|
47
51
|
odds(0.25).inverse.win_chance.should == 0.75
|
48
52
|
end
|
49
|
-
|
53
|
+
|
50
54
|
describe "other creation methods" do
|
51
55
|
it 'from string' do
|
52
56
|
Odds.from_string("+300").win_chance.should == 0.25
|
53
57
|
end
|
54
|
-
|
58
|
+
|
55
59
|
it 'from string' do
|
56
60
|
Odds.from_string("-300").win_chance.should == 0.75
|
57
61
|
end
|
58
|
-
|
62
|
+
|
59
63
|
it 'from string bad' do
|
60
64
|
lambda { Odds.from_string("42") }.should raise_error
|
61
65
|
end
|
62
66
|
end
|
63
|
-
|
67
|
+
|
68
|
+
it 'to_odds - string' do
|
69
|
+
"+150".to_odds.win_chance.should == 0.4
|
70
|
+
end
|
71
|
+
end
|
data/spec/parlay_spec.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Parlay" do
|
4
|
+
describe 'basic' do
|
5
|
+
let(:bets) do
|
6
|
+
res = []
|
7
|
+
res << Bet.new(:odds => "+200", :win_chance => 0.4)
|
8
|
+
res << Bet.new(:odds => "+300", :win_chance => 0.3)
|
9
|
+
res
|
10
|
+
end
|
11
|
+
let(:parlay) do
|
12
|
+
Parlay.new(:bets => bets, :wagered_amount => 100)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'odds' do
|
16
|
+
parlay.odds.win_chance.should == (1.0/12.0)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'win_chance' do
|
20
|
+
parlay.win_chance.should == 0.12
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'expected_profit' do
|
24
|
+
parlay.expected_profit.round(4).should == 44
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rspec'
|
4
|
-
require 'odds'
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spork'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
Spork.prefork do
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
9
7
|
|
10
|
-
|
11
|
-
|
8
|
+
require 'rspec'
|
9
|
+
|
10
|
+
# Load support files
|
11
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Spork.each_run do
|
19
|
+
load File.dirname(__FILE__) + "/../lib/odds.rb"
|
12
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Harris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mharris_ext
|
@@ -80,6 +80,62 @@ dependencies:
|
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.8.7
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard-spork
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rb-fsevent
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.9'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.9'
|
83
139
|
description: odds
|
84
140
|
email: mharris717@gmail.com
|
85
141
|
executables: []
|
@@ -92,13 +148,26 @@ files:
|
|
92
148
|
- .rspec
|
93
149
|
- Gemfile
|
94
150
|
- Gemfile.lock
|
151
|
+
- Guardfile
|
95
152
|
- LICENSE.txt
|
96
153
|
- README.rdoc
|
97
154
|
- Rakefile
|
98
155
|
- VERSION
|
99
156
|
- lib/odds.rb
|
157
|
+
- lib/odds/bet.rb
|
158
|
+
- lib/odds/ext/hash.rb
|
159
|
+
- lib/odds/ext/map_special.rb
|
160
|
+
- lib/odds/ext/math.rb
|
161
|
+
- lib/odds/ext/numeric.rb
|
162
|
+
- lib/odds/ext/rand.rb
|
163
|
+
- lib/odds/ext/string.rb
|
164
|
+
- lib/odds/ext/to_odds.rb
|
165
|
+
- lib/odds/odds.rb
|
166
|
+
- lib/odds/parlay.rb
|
100
167
|
- odds.gemspec
|
168
|
+
- spec/bet_spec.rb
|
101
169
|
- spec/odds_spec.rb
|
170
|
+
- spec/parlay_spec.rb
|
102
171
|
- spec/spec_helper.rb
|
103
172
|
homepage: http://github.com/mharris717/odds
|
104
173
|
licenses:
|