spec/FixedOdds_spec.rb in rodders-0.2.0 vs spec/FixedOdds_spec.rb in rodders-0.3.0
- old
+ new
@@ -1,16 +1,17 @@
+# coding: utf-8
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "FixedOdds" do
describe "fractional_odds factory" do
it "should raise error if not fractional odds" do
expect {
- FixedOdds.fractional_odds '-400'
+ FixedOdds.fractional_odds '5'
}.to raise_error(
RuntimeError,
- /could not parse "-400" as fractional odds/
+ /could not parse "5" as fractional odds/
)
end
it "should not modify the input string with 'against'" do
value = '4/1 against'
@@ -98,30 +99,30 @@
/could not parse "-100.1" as moneyline odds/
)
end
describe "positive figures" do
- it "should treat '+400' as meaning winning $400 on a $100 bet" do
+ it "should treat '+400' as meaning winning £400 on a £100 bet" do
plus400 = FixedOdds.moneyline_odds('+400')
- plus400.profit_on_winning_stake('$100').should == '$400'
+ plus400.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(400, :GBP)
end
- it "should treat +100 as meaning winning $100 on a $100 bet" do
+ it "should treat +100 as meaning winning £100 on a £100 bet" do
plus100 = FixedOdds.moneyline_odds('+100')
- plus100.profit_on_winning_stake('$100').should == '$100'
+ plus100.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(100, :GBP)
end
end
describe "negative figures" do
- it "should treat '-400' as meaning you need to wager $400 to win $100" do
+ it "should treat '-400' as meaning you need to wager £400 to win £100" do
minus400 = FixedOdds.moneyline_odds('-400')
- minus400.profit_on_winning_stake('$400').should == '$100'
+ minus400.profit_on_winning_stake(Money.from_fixnum(400, :GBP)).should == Money.from_fixnum(100, :GBP)
end
- it "should treat '-100' as meaning you need to wager $100 to win $100 (which is identical to '+100')" do
+ it "should treat '-100' as meaning you need to wager £100 to win £100 (which is identical to '+100')" do
minus100 = FixedOdds.moneyline_odds('-100')
- minus100.profit_on_winning_stake('$100').should == '$100'
+ minus100.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(100, :GBP)
end
end
end
describe "decimal_odds factory" do
@@ -132,23 +133,23 @@
RuntimeError,
/could not parse "-400" as decimal odds/
)
end
- it "should treat '2' as meaning you have to wager $100 to win $100" do
+ it "should treat '2' as meaning you have to wager £100 to win £100" do
d2 = FixedOdds.decimal_odds('2')
- d2.profit_on_winning_stake('$100').should == '$100'
+ d2.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(100, :GBP)
end
- it "should treat '5' as meaning you have to wager $100 to win $400" do
+ it "should treat '5' as meaning you have to wager £100 to win £400" do
d5 = FixedOdds.decimal_odds('5')
- d5.profit_on_winning_stake('$100').should == '$400'
+ d5.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(400, :GBP)
end
- it "should treat '1.25' as meaning yo have to wager $400 to win $100" do
+ it "should treat '1.25' as meaning yo have to wager £400 to win £100" do
d1_25 = FixedOdds.decimal_odds('1.25')
- d1_25.profit_on_winning_stake('$400').should == '$100'
+ d1_25.profit_on_winning_stake(Money.from_fixnum(400, :GBP)).should == Money.from_fixnum(100, :GBP)
end
end
describe "#from_s" do
describe "bad input" do
@@ -222,12 +223,15 @@
FixedOdds.from_s('-400').should == FixedOdds.moneyline_odds('-400')
end
end
describe "decimal odds" do
- it "should parse integral odds" do
- FixedOdds.from_s('2').should == FixedOdds.decimal_odds('2')
+ it "should parse integral odds of '2' as decimal odds, not as fractional odds of '2/1'" do
+ decimal_odds_2 = FixedOdds.from_s('2')
+
+ decimal_odds_2.should == FixedOdds.decimal_odds('2')
+ decimal_odds_2.should_not == FixedOdds.fractional_odds('2/1')
end
it "should parse floating-point odds" do
FixedOdds.from_s('1.25').should == FixedOdds.decimal_odds('1.25')
end
@@ -343,41 +347,41 @@
FixedOdds.moneyline_odds('-100').to_s_decimal.should == '2'
end
end
describe "#profit_on_winning_stake" do
- it "should return a profit of $400 on a $100 stake on a 4/1 bet" do
+ it "should return a profit of £400 on a £100 stake on a 4/1 bet" do
fourToOne = FixedOdds.fractional_odds '4/1'
- fourToOne.profit_on_winning_stake('$100').should == '$400'
+ fourToOne.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(400, :GBP)
end
- it "should return a profit of $25 on a $110 stake with a 1/4 bet" do
+ it "should return a profit of £25 on a £100 stake with a 1/4 bet" do
oneToFour = FixedOdds.fractional_odds '1/4'
- oneToFour.profit_on_winning_stake('$100').should == '$25'
+ oneToFour.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(25, :GBP)
end
end
describe "#total_return_on_winning_stake" do
- it "should show that the full amount back on a winning 4/1 bet with a $100 stake is $500" do
+ it "should show that the full amount back on a winning 4/1 bet with a £100 stake is £500" do
fourToOne = FixedOdds.fractional_odds '4/1'
- fourToOne.total_return_on_winning_stake('$100').should == '$500'
+ fourToOne.total_return_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(500, :GBP)
end
- it "should show that the full amount back on a winning 1/4 bet with a $100 stake is $125" do
+ it "should show that the full amount back on a winning 1/4 bet with a £100 stake is £125" do
oneToFour = FixedOdds.fractional_odds '1/4'
- oneToFour.total_return_on_winning_stake('$100').should == '$125'
+ oneToFour.total_return_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(125, :GBP)
end
end
describe "#stake_needed_to_win" do
- it "should be $1 on a 1/1 to win $1" do
+ it "should be £1 on a 1/1 to win £1" do
oneToOne = FixedOdds.fractional_odds '1/1'
- oneToOne.stake_needed_to_win('$1').should == '$1'
+ oneToOne.stake_needed_to_win(Money.from_fixnum(1, :GBP)).should == Money.from_fixnum(1, :GBP)
end
- it "should be $100 on 4/1 to win $400" do
+ it "should be £100 on 4/1 to win £400" do
fourToOne = FixedOdds.fractional_odds '4/1'
- fourToOne.stake_needed_to_win('$400').should == '$100'
+ fourToOne.stake_needed_to_win(Money.from_fixnum(400, :GBP)).should == Money.from_fixnum(100, :GBP)
end
end
describe "object comparison" do
it "'+915' is less likely than '-275'" do