spec/FixedOdds_spec.rb in rodders-0.1.2 vs spec/FixedOdds_spec.rb in rodders-0.2.0

- old
+ new

@@ -49,10 +49,37 @@ end it "should recognise '4-to-1 on' as '1/4'" do FixedOdds.fractional_odds('4-to-1 on').should == FixedOdds.fractional_odds('1/4') end + + it "should raise error if numerator has decimal point" do + expect { + FixedOdds.fractional_odds '1.1/4' + }.to raise_error( + RuntimeError, + /could not parse "1.1\/4" as fractional odds/ + ) + end + + it "should raise error if denominator has decimal point" do + expect { + FixedOdds.fractional_odds '1/4.1' + }.to raise_error( + RuntimeError, + /could not parse "1\/4.1" as fractional odds/ + ) + end + + it "should raise error if both numerator and denominator have decimal points" do + expect { + FixedOdds.fractional_odds '1.1/4.1' + }.to raise_error( + RuntimeError, + /could not parse "1.1\/4.1" as fractional odds/ + ) + end end describe "moneyline_odds factory" do it "should raise error if not moneyline odds" do expect { @@ -61,10 +88,19 @@ RuntimeError, /could not parse "1.25" as moneyline odds/ ) end + it "should raise error if moneyline odds has decimal point" do + expect { + FixedOdds.moneyline_odds '-100.1' + }.to raise_error( + RuntimeError, + /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 plus400 = FixedOdds.moneyline_odds('+400') plus400.profit_on_winning_stake('$100').should == '$400' end @@ -282,12 +318,10 @@ end it "should display '1.25' as '-400'" do FixedOdds.decimal_odds('1.25').to_s_moneyline.should == '-400' end - - it "should display a floating point moneyline" end describe "#to_s_decimal" do it "should display '1.25' as '1.25'" do FixedOdds.decimal_odds('1.25').to_s_decimal.should == '1.25' @@ -329,9 +363,21 @@ end 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' + end + end + + describe "#stake_needed_to_win" 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' + end + + 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' end end describe "object comparison" do it "'+915' is less likely than '-275'" do