spec/fixed_odds_spec.rb in rodders-2.1.0 vs spec/fixed_odds_spec.rb in rodders-3.0.0
- old
+ new
@@ -39,19 +39,19 @@
it "treats 'even money' as '1/1'" do
FixedOdds.fractional_odds('even money').should == FixedOdds.fractional_odds('1/1')
end
- it "recognises '4-to-1' as '4/1'" do
+ it "treats '4-to-1' as '4/1'" do
FixedOdds.fractional_odds('4-to-1').should == FixedOdds.fractional_odds('4/1')
end
- it "recognises '4-to-1 against' as '4/1'" do
+ it "treats '4-to-1 against' as '4/1'" do
FixedOdds.fractional_odds('4-to-1 against').should == FixedOdds.fractional_odds('4/1')
end
- it "recognises '4-to-1 on' as '1/4'" do
+ it "treats '4-to-1 on' as '1/4'" do
FixedOdds.fractional_odds('4-to-1 on').should == FixedOdds.fractional_odds('1/4')
end
it "raises error if numerator has decimal point" do
expect {
@@ -101,33 +101,33 @@
end
describe "positive figures" do
it "treats '+400' as meaning winning £400 on a £100 bet" do
plus400 = FixedOdds.moneyline_odds('+400')
- plus400.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(400, :GBP)
+ plus400.profit_on_stake(Money.parse '£100').should == Money.parse('£400')
end
it "treats +100 as meaning winning £100 on a £100 bet" do
plus100 = FixedOdds.moneyline_odds('+100')
- plus100.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(100, :GBP)
+ plus100.profit_on_stake(Money.parse '£100').should == Money.parse('£100')
end
end
describe "negative figures" do
it "treats '-400' as meaning you need to wager £400 to win £100" do
minus400 = FixedOdds.moneyline_odds('-400')
- minus400.profit_on_winning_stake(Money.from_fixnum(400, :GBP)).should == Money.from_fixnum(100, :GBP)
+ minus400.profit_on_stake(Money.parse '£400').should == Money.parse('£100')
end
it "treats '-100' as meaning you need to wager £100 to win £100" do
minus100 = FixedOdds.moneyline_odds('-100')
- minus100.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(100, :GBP)
+ minus100.profit_on_stake(Money.parse '£100').should == Money.parse('£100')
end
it "treats '+100' as meaning you need to wager £100 to win £100" do
plus100 = FixedOdds.moneyline_odds('+100')
- plus100.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(100, :GBP)
+ plus100.profit_on_stake(Money.parse '£100').should == Money.parse('£100')
end
end
end
describe ".decimal_odds" do
@@ -138,41 +138,41 @@
RuntimeError,
/could not parse "-400" as decimal odds/
)
end
- it "treats '2' as meaning you have to wager £100 to win £100" do
- d2 = FixedOdds.decimal_odds('2')
- d2.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(100, :GBP)
+ it "treats '2' as meaning you have to wager £1 to win £1" do
+ d2 = FixedOdds.decimal_odds '2'
+ d2.profit_on_stake(Money.parse '£1').should == Money.parse('£1')
end
- it "treats '5' as meaning you have to wager £100 to win £400" do
- d5 = FixedOdds.decimal_odds('5')
- d5.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(400, :GBP)
+ it "treats '5' as meaning you have to wager £1 to win £4" do
+ d5 = FixedOdds.decimal_odds '5'
+ d5.profit_on_stake(Money.parse '£1').should == Money.parse('£4')
end
- it "treats '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(Money.from_fixnum(400, :GBP)).should == Money.from_fixnum(100, :GBP)
+ it "treats '1.25' as meaning you have to wager £4 to win £1" do
+ d1_25 = FixedOdds.decimal_odds '1.25'
+ d1_25.profit_on_stake(Money.parse '£4').should == Money.parse('£1')
end
end
describe ".from_s" do
describe "bad input" do
it "rejects garbage" do
expect {
- FixedOdds.from_s('garbage')
+ FixedOdds.from_s 'garbage'
}.to raise_error(
ArgumentError,
/could not parse "garbage"/
)
end
end
it "rejects an empty string" do
expect {
- FixedOdds.from_s('')
+ FixedOdds.from_s ''
}.to raise_error(
ArgumentError,
/could not parse ""/
)
end
@@ -210,11 +210,11 @@
FixedOdds.from_s('4-to-1 on').should == FixedOdds.fractional_odds('1/4')
end
it "raises an error for a zero denominator" do
expect {
- FixedOdds.from_s('4/0')
+ FixedOdds.from_s '4/0'
}.to raise_error(
ZeroDivisionError
)
end
end
@@ -229,11 +229,11 @@
end
end
describe "decimal odds" do
it "parses 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 = FixedOdds.from_s '2'
decimal_odds_2.should == FixedOdds.decimal_odds('2')
decimal_odds_2.should_not == FixedOdds.fractional_odds('2/1')
end
@@ -351,51 +351,51 @@
it "is '2' for '-100'" do
FixedOdds.moneyline_odds('-100').to_s_decimal.should == '2'
end
end
- describe "#profit_on_winning_stake" do
- it "is £400 on a £100 stake on a 4/1 bet" do
+ describe "#profit_on_stake" do
+ it "is £4 on a £1 stake on a 4/1 bet" do
fourToOne = FixedOdds.fractional_odds '4/1'
- fourToOne.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(400, :GBP)
+ fourToOne.profit_on_stake(Money.parse '£1').should == Money.parse('£4')
end
- it "is £25 on a £100 stake with a 1/4 bet" do
+ it "is £0.25 on a £1 stake with a 1/4 bet" do
oneToFour = FixedOdds.fractional_odds '1/4'
- oneToFour.profit_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(25, :GBP)
+ oneToFour.profit_on_stake(Money.parse '£1').should == Money.parse('£0.25')
end
end
- describe "#total_return_on_winning_stake" do
- it "is £500 on a winning 4/1 bet with a £100 stake" do
+ describe "#total_return_on_stake" do
+ it "is £5 on a winning 4/1 bet with a £1 stake" do
fourToOne = FixedOdds.fractional_odds '4/1'
- fourToOne.total_return_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(500, :GBP)
+ fourToOne.total_return_on_stake(Money.parse '£1').should == Money.parse('£5')
end
it "is £125 on a winning 1/4 bet with a £100 stake" do
oneToFour = FixedOdds.fractional_odds '1/4'
- oneToFour.total_return_on_winning_stake(Money.from_fixnum(100, :GBP)).should == Money.from_fixnum(125, :GBP)
+ oneToFour.total_return_on_stake(Money.parse '£100').should == Money.parse('£125')
end
end
- describe "#stake_needed_to_win" do
+ describe "#stake_to_profit" do
it "is £1 on a 1/1 to win £1" do
oneToOne = FixedOdds.fractional_odds '1/1'
- oneToOne.stake_needed_to_win(Money.from_fixnum(1, :GBP)).should == Money.from_fixnum(1, :GBP)
+ oneToOne.stake_to_profit(Money.parse '£1').should == Money.parse('£1')
end
- it "is £100 on 4/1 to win £400" do
- fourToOne = FixedOdds.fractional_odds '4/1'
- fourToOne.stake_needed_to_win(Money.from_fixnum(400, :GBP)).should == Money.from_fixnum(100, :GBP)
+ it "is £1 on 2/1 to win £2" do
+ fourToOne = FixedOdds.fractional_odds '2/1'
+ fourToOne.stake_to_profit(Money.parse '£2').should == Money.parse('£1')
end
end
describe "object comparison" do
- it "'+915' is less likely than '-275'" do
- FixedOdds.from_s('+915').should be < FixedOdds.from_s('-275')
+ it "'+200' is less likely than '-200'" do
+ FixedOdds.from_s('+200').should be < FixedOdds.from_s('-200')
end
- it "'-275' is more likely than '+915'" do
- FixedOdds.from_s('-275').should be > FixedOdds.from_s('+915')
+ it "'-200' is more likely than '+200'" do
+ FixedOdds.from_s('-200').should be > FixedOdds.from_s('+200')
end
end
end