specs/constraints/boolean.rb in gecoder-0.8.2 vs specs/constraints/boolean.rb in gecoder-0.8.3
- old
+ new
@@ -20,32 +20,26 @@
@b2 = @model.b2
@b3 = @model.b3
# For constraint option spec.
@invoke_options = lambda do |hash|
- (@b1 | @b2).must_be.equal_to(true, hash)
+ (@b1 | @b2).must_be.true(hash)
@model.solve!
end
@expect_options = option_expectation do |strength, kind, reif_var|
@model.allow_space_access do
- Gecode::Raw.should_receive(:rel).once.with(
- an_instance_of(Gecode::Raw::Space),
- an_instance_of(Gecode::Raw::BoolVar),
- Gecode::Raw::BOT_OR,
- an_instance_of(Gecode::Raw::BoolVar),
- an_instance_of(Gecode::Raw::BoolVar),
- Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
+ # We only test the non-MiniModel parts.
unless reif_var.nil?
Gecode::Raw.should_receive(:rel).once.with(
an_instance_of(Gecode::Raw::Space),
- an_instance_of(Gecode::Raw::BoolVar), Gecode::Raw::BOT_EQV,
- an_instance_of(Gecode::Raw::BoolVar), 1, strength, kind)
+ an_instance_of(Gecode::Raw::BoolVar), Gecode::Raw::IRT_EQ,
+ an_instance_of(Gecode::Raw::BoolVar), strength, kind)
end
end
end
end
-
+
it 'should handle single variables constrainted to be true' do
@b1.must_be.true
b1 = @model.solve!.b1
b1.should be_assigned
b1.value.should be_true
@@ -77,19 +71,19 @@
(@b1 | @b2).must_be.true
sol = @model.solve!
sol.b1.value.should_not be_true
sol.b2.value.should be_true
end
-
+
it 'should handle negated disjunction' do
@b1.must_be.false
(@b1 | @b2).must_not_be.true
sol = @model.solve!
sol.b1.value.should_not be_true
sol.b2.value.should_not be_true
end
-
+
it 'should handle conjunction' do
(@b1 & @b2).must_be.true
sol = @model.solve!
sol.b1.value.should be_true
sol.b2.value.should be_true
@@ -140,11 +134,11 @@
@b1.must.imply @b2
sol = @model.solve!
sol.b1.value.should_not be_true
sol.b2.value.should_not be_true
end
-
+
it 'should handle imply after must_not' do
@b1.must_be.true
@b1.must_not.imply @b2
sol = @model.solve!
sol.b1.value.should be_true
@@ -164,73 +158,85 @@
@b2.must_be.false
sol = @model.solve!
sol.b1.value.should be_true
sol.b2.value.should_not be_true
end
-
+
it 'should handle expressions as right hand side' do
@b1.must == (@b2 | @b3)
@b2.must_be.true
sol = @model.solve!
sol.b1.value.should be_true
sol.b2.value.should be_true
end
-
+
it 'should handle nested expressions as left hand side' do
((@b1 & @b2) | @b3 | (@b1 & @b3)).must_be.true
@b1.must_be.false
sol = @model.solve!
sol.b1.value.should_not be_true
sol.b3.value.should be_true
end
-
+
it 'should handle nested expressions on both side' do
((@b1 & @b1) | @b3).must == ((@b1 & @b3) & @b2)
@b1.must_be.true
sol = @model.solve!
sol.b1.value.should be_true
sol.b2.value.should be_true
sol.b3.value.should be_true
end
-
+
+ it 'should handle nested expressions with implication' do
+ ((@b1 & @b1) | @b3).must.imply(@b1 ^ @b2)
+ @b1.must_be.true
+ sol = @model.solve!
+ sol.b1.value.should be_true
+ sol.b2.value.should be_false
+ end
+
it 'should handle nested expressions containing exclusive or' do
((@b1 ^ @b1) & @b3).must == ((@b2 | @b3) ^ @b2)
@b1.must_be.true
@b2.must_be.false
sol = @model.solve!
sol.b1.value.should be_true
sol.b2.value.should_not be_true
sol.b3.value.should_not be_true
end
-
+
it 'should handle nested expressions on both sides with negation' do
((@b1 & @b1) | @b3).must_not == ((@b1 | @b3) & @b2)
@b1.must_be.true
@b3.must_be.true
sol = @model.solve!
sol.b1.value.should be_true
sol.b2.value.should_not be_true
sol.b3.value.should be_true
end
-
+
it 'should translate reification with a variable right hand side' do
@b1.must_be.equal_to(@b2, :reify => @b3)
@b1.must_be.true
@b2.must_be.false
sol = @model.solve!
sol.b3.value.should_not be_true
end
-
- it 'should translate reification with a variable right hand side and negation' do
+
+ it 'should translate reification with a variable right hand side and negation' do
@b1.must_not_be.equal_to(@b2, :reify => @b3)
@b1.must_be.true
@b2.must_be.false
sol = @model.solve!
sol.b3.value.should be_true
end
- it 'should raise error on right hand sides of the wrong type' do
+ it 'should raise error on right hand sides of incorrect type given to #==' do
lambda{ @b1.must == 'hello' }.should raise_error(TypeError)
end
-
+
+ it 'should raise error on right hand sides of incorrect type given to #imply' do
+ lambda{ @b1.must.imply 'hello' }.should raise_error(TypeError)
+ end
+
it_should_behave_like 'reifiable constraint'
-end
\ No newline at end of file
+end