Class ConstraintSolver::BinaryConstraintTest
In: test/BinaryConstraintTest.rb
Parent: Test::Unit::TestCase
Test::Unit::TestCase AllDifferentConstraintTest SolutionTest ConstraintSolverTest ConstraintListTest VariableTest DomainTest BinaryConstraintTest ProblemTest BinaryRelationTest Exception DomainWipeoutException UndoStackEmptyException AbstractConstraint BinaryConstraint AllDifferentConstraint Array ConstraintList BinaryRelation Variable Solution ConstraintSolver Problem Domain test/DomainTest.rb test/SolutionTest.rb lib/BinaryConstraint.rb lib/Variable.rb test/ConstraintListTest.rb lib/ConstraintList.rb test/ProblemTest.rb lib/Solution.rb test/BinaryConstraintTest.rb lib/ConstraintSolver.rb test/VariableTest.rb test/AllDifferentConstraintTest.rb lib/AllDifferentConstraint.rb lib/Problem.rb test/ConstraintSolverTest.rb lib/Domain.rb lib/AbstractConstraint.rb ConstraintSolver dot/m_19_0.png

Methods

Public Instance methods

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Validate]