Sha256: f460b5c40412a65a1aff9d451df9de6f3f44f7ba72080c66a14f9ebb540f56f0

Contents?: true

Size: 1.49 KB

Versions: 20

Compression:

Stored size: 1.49 KB

Contents

require 'games_dice'

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 be_true

      rule = GamesDice::RerollRule.new( (1..5), :member?, :reroll_subtract )
      rule.applies?(4).should be_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 be_false

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

  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
games_dice-0.3.9 spec/reroll_rule_spec.rb
games_dice-0.3.8 spec/reroll_rule_spec.rb
games_dice-0.3.7 spec/reroll_rule_spec.rb
games_dice-0.3.6 spec/reroll_rule_spec.rb
games_dice-0.3.5 spec/reroll_rule_spec.rb
games_dice-0.3.3 spec/reroll_rule_spec.rb
games_dice-0.3.2 spec/reroll_rule_spec.rb
games_dice-0.3.1 spec/reroll_rule_spec.rb
games_dice-0.3.0 spec/reroll_rule_spec.rb
games_dice-0.2.4 spec/reroll_rule_spec.rb
games_dice-0.2.3 spec/reroll_rule_spec.rb
games_dice-0.2.2 spec/reroll_rule_spec.rb
games_dice-0.2.1 spec/reroll_rule_spec.rb
games_dice-0.2.0 spec/reroll_rule_spec.rb
games_dice-0.1.3 spec/reroll_rule_spec.rb
games_dice-0.1.2 spec/reroll_rule_spec.rb
games_dice-0.1.1 spec/reroll_rule_spec.rb
games_dice-0.0.6 spec/reroll_rule_spec.rb
games_dice-0.0.5 spec/reroll_rule_spec.rb
games_dice-0.0.3 spec/reroll_rule_spec.rb