#!/usr/bin/ruby $:.unshift File.join(File.dirname(__FILE__), "..", "lib") require 'test/unit' require 'Variable' require 'Domain' module ConstraintSolver class VariableTest < Test::Unit::TestCase def setup @variable = Variable.new("test", Domain.new([ 3, 4, 5 ].to_set)) end def testConstructor assert_raise(ArgumentError) { Variable.new } assert_raise(ArgumentError) { Variable.new(nil) } assert_raise(ArgumentError) { Variable.new(3) } assert_raise(ArgumentError) { Variable.new("name", Domain.new([ 3 ].to_set), 4) } assert_nothing_raised { var = Variable.new("name", nil, 3) assert_equal([ 3 ].to_set, var.domain.values) } assert_nothing_raised { Variable.new("name", Domain.new([ 3 ].to_set)) } assert_nothing_raised { Variable.new("name", Domain.new([ 3 ].to_set), 3) } end def testAssignment assert_raise(ArgumentError) { @variable.value = 2 } assert_nothing_raised { @variable.value = nil } assert_nothing_raised { @variable.value = 3 } assert(@variable.assigned?) assert_equal(3, @variable.value) @variable.reset assert_equal(false, @variable.assigned?) assert_equal(nil, @variable.value) end def testEquals assert_equal(@variable, Variable.new("test", Domain.new([ 3, 4, 5 ].to_set))) assert_equal(@variable, Variable.new("test", Domain.new(Set.new))) assert_not_equal(@variable, Variable.new("test", nil, 3)) assert_not_equal(@variable, Variable.new("test", Domain.new([ 3, 4, 5 ].to_set), 3)) assert_not_equal(@variable, Variable.new("tester", Domain.new([ 3, 4, 5 ].to_set))) end end end