Sha256: 4da36882c6352a5ad19e7dc8197f7ef47369b9c4fb8be8b7f730913d1f49b91e

Contents?: true

Size: 1.69 KB

Versions: 3

Compression:

Stored size: 1.69 KB

Contents

require File.dirname(__FILE__) + '/../property_helper'

class IntEnumArithmeticSampleProblem < Gecode::Model
  attr :numbers
  attr :var
  
  def initialize
    @numbers = int_var_array(4, 0..9)
    @var = int_var(-9..9)
    branch_on @numbers
    branch_on @var
  end
end

describe Gecode::IntEnum::Arithmetic, ' (max)' do
  before do
    @model = IntEnumArithmeticSampleProblem.new
    @numbers = @model.numbers
    @var = @model.var

    @property_types = [:int_enum]
    @select_property = lambda do |int_enum|
      int_enum.max
    end
    @selected_property = @numbers.max
    @constraint_class = Gecode::BlockConstraint
  end
  
  it 'should constrain the maximum value' do
    @numbers.max.must > 5
    @model.solve!.numbers.values.max.should > 5
  end

  it 'should translate into a max constraint' do
    Gecode::Raw.should_receive(:max)
    @numbers.max.must == 5
    @model.solve!
  end
  
  it_should_behave_like(
    'property that produces int operand by short circuiting equality')
end

describe Gecode::IntEnum::Arithmetic, ' (min)' do
  before do
    @model = IntEnumArithmeticSampleProblem.new
    @numbers = @model.numbers
    @var = @model.var

    @property_types = [:int_enum]
    @select_property = lambda do |int_enum|
      int_enum.min
    end
    @selected_property = @numbers.min
    @constraint_class = Gecode::BlockConstraint
  end
  
  it 'should constrain the minimum value' do
    @numbers.min.must > 5
    @model.solve!.numbers.values.min.should > 5
  end

  it 'should translate into a min constraint' do
    Gecode::Raw.should_receive(:min)
    @numbers.min.must == 5
    @model.solve!
  end
  
  it_should_behave_like(
    'property that produces int operand by short circuiting equality')
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
gecoder-0.9.0 specs/constraints/int_enum/arithmetic.rb
gecoder-with-gecode-0.9.0-x86-mswin32-60 specs/constraints/int_enum/arithmetic.rb
gecoder-with-gecode-0.9.0 specs/constraints/int_enum/arithmetic.rb