Sha256: 72f7596d013aa25dec480ff73e3512bfd663a3c849d5fbfa1321ea74777777d3

Contents?: true

Size: 1.32 KB

Versions: 20

Compression:

Stored size: 1.32 KB

Contents

require 'games_dice'

describe GamesDice::MapRule do

  describe "#new" do

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

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

    it "should reject non-Integer map results" do
      lambda { GamesDice::MapRule.new( 5, :>, :reroll_again ) }.should raise_error( TypeError )
      lambda { GamesDice::MapRule.new( (1..5), :member?, 'foo' ) }.should raise_error( TypeError )
    end

  end

  describe '#map_from' do

    it "should return the mapped value for a match" do
      rule = GamesDice::MapRule.new( 5, :>, -1 )
      rule.map_from(4).should == -1

      rule = GamesDice::MapRule.new( (1..5), :member?, 3 )
      rule.map_from(4).should == 3
    end

    it "should return false for no match" do
      rule = GamesDice::MapRule.new( 5, :>, -1 )
      rule.map_from(6).should be_false

      rule = GamesDice::MapRule.new( (1..5), :member?, 3 )
      rule.map_from(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/map_rule_spec.rb
games_dice-0.3.8 spec/map_rule_spec.rb
games_dice-0.3.7 spec/map_rule_spec.rb
games_dice-0.3.6 spec/map_rule_spec.rb
games_dice-0.3.5 spec/map_rule_spec.rb
games_dice-0.3.3 spec/map_rule_spec.rb
games_dice-0.3.2 spec/map_rule_spec.rb
games_dice-0.3.1 spec/map_rule_spec.rb
games_dice-0.3.0 spec/map_rule_spec.rb
games_dice-0.2.4 spec/map_rule_spec.rb
games_dice-0.2.3 spec/map_rule_spec.rb
games_dice-0.2.2 spec/map_rule_spec.rb
games_dice-0.2.1 spec/map_rule_spec.rb
games_dice-0.2.0 spec/map_rule_spec.rb
games_dice-0.1.3 spec/map_rule_spec.rb
games_dice-0.1.2 spec/map_rule_spec.rb
games_dice-0.1.1 spec/map_rule_spec.rb
games_dice-0.0.6 spec/map_rule_spec.rb
games_dice-0.0.5 spec/map_rule_spec.rb
games_dice-0.0.3 spec/map_rule_spec.rb