specs/constraints/cardinality.rb in gecoder-0.6.0 vs specs/constraints/cardinality.rb in gecoder-0.6.1
- old
+ new
@@ -19,11 +19,11 @@
end
@expect = lambda do |rhs|
@model.allow_space_access do
Gecode::Raw.should_receive(:cardinality).once.with(
an_instance_of(Gecode::Raw::Space),
- @set.bind, rhs.first, rhs.last)
+ an_instance_of(Gecode::Raw::SetVar), rhs.first, rhs.last)
end
end
end
it 'should translate cardinality constraints with ranges' do
@@ -45,12 +45,15 @@
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).once.with(
+ 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.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)
@set.size.must_not_be.in [1,3]
@model.solve!
end
@@ -70,33 +73,37 @@
@set.size.must == rhs
@model.solve!
end
@expect = lambda do |relation, rhs, strength, reif_var, negated|
@model.allow_space_access do
- rhs = rhs.bind if rhs.respond_to? :bind
+ rhs = an_instance_of(Gecode::Raw::IntVar) if rhs.respond_to? :bind
if reif_var.nil?
if !negated and relation == Gecode::Raw::IRT_EQ and
- rhs.kind_of? Gecode::Raw::IntVar
+ !rhs.kind_of? Fixnum
Gecode::Raw.should_receive(:cardinality).once.with(
- an_instance_of(Gecode::Raw::Space), @set.bind, rhs)
+ an_instance_of(Gecode::Raw::Space),
+ an_instance_of(Gecode::Raw::SetVar), rhs)
Gecode::Raw.should_receive(:rel).exactly(0).times
else
Gecode::Raw.should_receive(:cardinality).once.with(
- an_instance_of(Gecode::Raw::Space), @set.bind,
+ an_instance_of(Gecode::Raw::Space),
+ an_instance_of(Gecode::Raw::SetVar),
an_instance_of(Gecode::Raw::IntVar))
Gecode::Raw.should_receive(:rel).once.with(
an_instance_of(Gecode::Raw::Space),
an_instance_of(Gecode::Raw::IntVar), relation, rhs,
strength)
end
else
Gecode::Raw.should_receive(:cardinality).once.with(
an_instance_of(Gecode::Raw::Space),
- @set.bind, an_instance_of(Gecode::Raw::IntVar))
+ an_instance_of(Gecode::Raw::SetVar),
+ an_instance_of(Gecode::Raw::IntVar))
Gecode::Raw.should_receive(:rel).once.with(
an_instance_of(Gecode::Raw::Space),
- an_instance_of(Gecode::Raw::IntVar), relation, rhs, reif_var.bind,
+ an_instance_of(Gecode::Raw::IntVar), relation, rhs,
+ an_instance_of(Gecode::Raw::BoolVar),
strength)
end
end
end
@@ -125,9 +132,22 @@
it 'should constrain the cardinality of a set' do
@set.size.must == @var
@model.solve!
@set.value.size.should == @var.value
+ end
+
+ it 'should constrain the cardinality of a set (2)' do
+ @set.size.must == 2
+ @model.solve!.should_not be_nil
+ @set.value.size.should == 2
+ end
+
+ it 'should constrain the cardinality of a set (3)' do
+ @set.size.must == @var
+ @var.must == 2
+ @model.solve!
+ @set.value.size.should == 2
end
it_should_behave_like 'constraint with options'
it_should_behave_like 'composite constraint'
end