Sha256: 201276bc54d0b1b304d00e8a6380f5d2244bf3059c7087f35eb915608a688713

Contents?: true

Size: 1.77 KB

Versions: 14

Compression:

Stored size: 1.77 KB

Contents

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

describe Gecode::Set::Cardinality, ' (constraint)' do
  before do
    @model = Gecode::Model.new
    @set = @model.set_var([], 0..10)
    @model.branch_on @model.wrap_enum([@set])
    @range = 1..2
    @three_dot_range = 1...2
    
    @invoke = lambda do |rhs| 
      @set.size.must_be.in(rhs) 
      @model.solve!
    end
    @expect = lambda do |rhs|
      @model.allow_space_access do
        Gecode::Raw.should_receive(:cardinality).once.with(
          an_instance_of(Gecode::Raw::Space), 
          an_instance_of(Gecode::Raw::SetVar), rhs.first, rhs.last)
      end
    end
  end
  
  it 'should translate cardinality constraints with ranges' do
    @expect.call(@range)
    @invoke.call(@range)
  end

  it 'should translate cardinality constraints with three dot range domains' do
    @expect.call(@three_dot_range)
    @invoke.call(@three_dot_range)
  end
  
  it 'should constrain the cardinality of a set' do
    @set.size.must_be.in @range
    @model.solve!
    @range.should include(@set.value.size)
  end
  
  it 'should raise error if the right hand side is not a range' do
    lambda{ @set.size.must_be.in 'hello' }.should raise_error(TypeError)
  end
  
  it 'should not shadow the integer variable domain constrain' do
    Gecode::Raw.should_receive(:dom).with(
      an_instance_of(Gecode::Raw::Space), 
      an_instance_of(Gecode::Raw::IntVar), 0, 11, Gecode::Raw::ICL_DEF, 
      Gecode::Raw::PK_DEF)
    Gecode::Raw.should_receive(:dom).with(
      an_instance_of(Gecode::Raw::Space), 
      an_instance_of(Gecode::Raw::IntVar), an_instance_of(Gecode::Raw::IntSet), 
      an_instance_of(Gecode::Raw::BoolVar), Gecode::Raw::ICL_DEF, 
      Gecode::Raw::PK_DEF)
    @set.size.must_not_be.in [1,3]
    @model.solve!
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
gecoder-with-gecode-1.1.1.1 specs/constraints/set/cardinality.rb
gecoder-with-gecode-1.1.1 specs/constraints/set/cardinality.rb
gecoder-1.1.1 specs/constraints/set/cardinality.rb
gecoder-with-gecode-1.1.0 specs/constraints/set/cardinality.rb
gecoder-1.1.0 specs/constraints/set/cardinality.rb
gecoder-0.9.1 specs/constraints/set/cardinality.rb
gecoder-0.9.0 specs/constraints/set/cardinality.rb
gecoder-1.0.0 specs/constraints/set/cardinality.rb
gecoder-with-gecode-0.9.0-x86-mswin32-60 specs/constraints/set/cardinality.rb
gecoder-with-gecode-0.9.0 specs/constraints/set/cardinality.rb
gecoder-with-gecode-0.9.1-x86-mswin32-60 specs/constraints/set/cardinality.rb
gecoder-with-gecode-0.9.1 specs/constraints/set/cardinality.rb
gecoder-with-gecode-1.0.0-x86-mswin32-60 specs/constraints/set/cardinality.rb
gecoder-with-gecode-1.0.0 specs/constraints/set/cardinality.rb