Sha256: 23ec50b965fe4f008724130f0d574b9ad6320453d09c9fee5d674b5a6ea56348

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require 'helpers'

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

2 entries across 2 versions & 1 rubygems

Version Path
games_dice-0.3.11 spec/map_rule_spec.rb
games_dice-0.3.10 spec/map_rule_spec.rb