Class | ConstraintSolver::BinaryConstraintTest |
In: |
test/BinaryConstraintTest.rb
|
Parent: | Test::Unit::TestCase |
# File test/BinaryConstraintTest.rb, line 12 def setup @lhs = Variable.new("lhs", Domain.new([ 1, 2 ].to_set)) @rhs = Variable.new("rhs", Domain.new([ 1, 2 ].to_set)) @rel = BinaryRelation.new("==") @constraint = BinaryConstraint.new(@lhs, @rhs, @rel) end
# File test/BinaryConstraintTest.rb, line 25 def testAssigned assert_equal(false, @constraint.allAssigned?) @rhs.value = 1 assert_equal(false, @constraint.allAssigned?) @lhs.value = 1 assert_equal(true, @constraint.allAssigned?) @rhs.reset @lhs.reset end
# File test/BinaryConstraintTest.rb, line 19 def testConstructor assert_raise(ArgumentError) { BinaryConstraint.new } assert_raise(ArgumentError) { BinaryConstraint.new(@lhs, @rhs, Proc.new { |a| a }) } assert_nothing_raised { BinaryConstraint.new(@lhs, @rhs, @rel) } end
# File test/BinaryConstraintTest.rb, line 52 def testEquals assert_equal(BinaryConstraint.new(@lhs, @rhs, @rel), @constraint) assert_not_equal(BinaryConstraint.new(@lhs, @rhs, BinaryRelation.new("<") {|a, b| a < b }), @constraint) assert_not_equal(BinaryConstraint.new(Variable.new("foo", [ 1 ].to_set), @rhs, @rel), @constraint) assert_not_equal(BinaryConstraint.new(@lhs, Variable.new("foo", [ 1 ].to_set), @rel), @constraint) end
# File test/BinaryConstraintTest.rb, line 41 def testHolds assert_raise(RuntimeError) { @constraint.holds? } assert_nothing_raised { @lhs.value = 1 } assert_nothing_raised { @rhs.value = 2 } assert_equal(false, @constraint.holds?) assert_nothing_raised { @rhs.value = 1 } assert_equal(true, @constraint.holds?) @lhs.reset @rhs.reset end
# File test/BinaryConstraintTest.rb, line 35 def testInclude assert_equal(true, @constraint.include?(@lhs)) assert_equal(true, @constraint.include?(@rhs)) assert_equal(false, @constraint.include?(Variable.new("2", [ 3 ].to_set))) end
# File test/BinaryConstraintTest.rb, line 59 def testRevise lhs = Variable.new("x", Domain.new([ 1 ].to_set)) rhs = Variable.new("y", Domain.new([ 1, 2, 3, 4 ].to_set)) rel = BinaryRelation.new("<") { |a, b| a < b } constraint = BinaryConstraint.new(lhs, rhs, rel) revisedVariables, checks = constraint.revise assert_equal([ rhs ], revisedVariables) assert_equal(4, checks) assert_equal([ 2, 3, 4 ].to_set, rhs.values) end