Class ConstraintSolver::AllDifferentConstraintTest
In: test/AllDifferentConstraintTest.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/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

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# 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

[Source]

# File test/AllDifferentConstraintTest.rb, line 62
        def testRevise
            assert_equal([ [], 0 ], @constraint.revise)
            @x.value = 1
            assert_equal([ [ @y, @z ], 0 ], @constraint.revise)
            assert_equal([ 2, 3 ].to_set, @y.values)
            assert_equal([ 2, 3 ].to_set, @z.values)
            @x.reset
        end

[Validate]