Sha256: 7c8ffea92bc9d1256bf199ea5297e4664b6eeb9740a2c77bb497f9f817610b97

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'helpers'

describe GamesDice::RerollRule do

  describe "#new" do

    it "should accept self-consistent operator/value pairs as a trigger" do
      GamesDice::RerollRule.new( 5, :>, :reroll_subtract )
      GamesDice::RerollRule.new( (1..5), :member?, :reroll_replace )
    end

    it "should reject inconsistent operator/value pairs for a trigger" do
      lambda { GamesDice::RerollRule.new( 5, :member?, :reroll_subtract ) }.should raise_error( ArgumentError )
      lambda { GamesDice::RerollRule.new( (1..5), :>, :reroll_replace ) }.should raise_error( ArgumentError )
    end

    it "should reject bad re-roll types" do
      lambda { GamesDice::RerollRule.new( 5, :>, :reroll_again ) }.should raise_error( ArgumentError )
      lambda { GamesDice::RerollRule.new( (1..5), :member?, 42 ) }.should raise_error( ArgumentError )
    end

  end

  describe '#applies?' do

    it "should return true if a trigger condition is met" do
      rule = GamesDice::RerollRule.new( 5, :>, :reroll_subtract )
      rule.applies?(4).should == true

      rule = GamesDice::RerollRule.new( (1..5), :member?, :reroll_subtract )
      rule.applies?(4).should == true
    end

    it "should return false if a trigger condition is not met" do
      rule = GamesDice::RerollRule.new( 5, :>, :reroll_subtract )
      rule.applies?(7).should == false

      rule = GamesDice::RerollRule.new( (1..5), :member?, :reroll_subtract )
      rule.applies?(6).should == false
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
games_dice-0.3.12 spec/reroll_rule_spec.rb