Sha256: 03b751731d0c8691d24001bd70662ac44e1186c02657db7c56afe6688dd4098a

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

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
      expect(-> { GamesDice::RerollRule.new(5, :member?, :reroll_subtract) }).to raise_error(ArgumentError)
      expect(-> { GamesDice::RerollRule.new((1..5), :>, :reroll_replace) }).to raise_error(ArgumentError)
    end

    it 'should reject bad re-roll types' do
      expect(-> { GamesDice::RerollRule.new(5, :>, :reroll_again) }).to raise_error(ArgumentError)
      expect(-> { GamesDice::RerollRule.new((1..5), :member?, 42) }).to 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)
      expect(rule.applies?(4)).to be true

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
games_dice-0.4.0 spec/reroll_rule_spec.rb