Class | ConstraintSolver::AllDifferentConstraintTest |
In: |
test/AllDifferentConstraintTest.rb
|
Parent: | Test::Unit::TestCase |
# File test/AllDifferentConstraintTest.rb, line 12 def setup domain = Domain.new([ 1, 2, 3 ].to_set) @x = Variable.new("x", domain) @y = Variable.new("y", domain.clone) @z = Variable.new("z", domain.clone) @constraint = AllDifferentConstraint.new([ @x, @y, @z ]) end
# File test/AllDifferentConstraintTest.rb, line 27 def testAssigned assert_equal(false, @constraint.allAssigned?) @y.value = 1 @z.value = 1 assert_equal(false, @constraint.allAssigned?) @x.value = 1 assert_equal(true, @constraint.allAssigned?) @x.reset @y.reset @z.reset end
# File test/AllDifferentConstraintTest.rb, line 20 def testConstructor assert_raise(ArgumentError) { AllDifferentConstraint.new } assert_raise(ArgumentError) { AllDifferentConstraint.new([]) } assert_raise(ArgumentError) { AllDifferentConstraint.new([ @x ]) } assert_nothing_raised { AllDifferentConstraint.new([ @x, @y, @z ]) } end
# File test/AllDifferentConstraintTest.rb, line 71 def testDomainWipeout domain = Domain.new([ 1 ].to_set) x = Variable.new("x", domain) y = Variable.new("y", domain.clone) z = Variable.new("z", domain.clone) constraint = AllDifferentConstraint.new([ x, y, z ]) assert_raise(DomainWipeoutException) { constraint.revise } end
# File test/AllDifferentConstraintTest.rb, line 46 def testEquals assert_not_equal(AllDifferentConstraint.new([ @x, @y ]), @constraint) assert_equal(AllDifferentConstraint.new([ @x, @y, @z ]), @constraint) end
# File test/AllDifferentConstraintTest.rb, line 51 def testHolds assert_raise(RuntimeError) { @constraint.holds? } @x.value = 1 @y.value = 2 @z.value = 2 assert_equal(false, @constraint.holds?) @z.value = 3 assert_equal(true, @constraint.holds?) @constraint.variables.each { |var| var.reset } end
# File test/AllDifferentConstraintTest.rb, line 39 def testInclude assert_equal(true, @constraint.include?(@x)) assert_equal(true, @constraint.include?(@y)) assert_equal(true, @constraint.include?(@z)) assert_equal(false, @constraint.include?(Variable.new("foobar", 1))) end