specs/model.rb in gecoder-0.8.2 vs specs/model.rb in gecoder-0.8.3
- old
+ new
@@ -7,11 +7,11 @@
it 'should allow the creation of int variables with range' do
range = 0..3
@model.int_var(range).should have_domain(range)
end
-
+
it 'should allow the creation of int variables without specified domain' do
var = @model.int_var
var.should be_range
var.min.should == Gecode::Raw::IntLimits::MIN
var.max.should == Gecode::Raw::IntLimits::MAX
@@ -41,10 +41,21 @@
vars = @model.int_var_array(count, domain)
vars.size.should equal(count)
vars.each{ |var| var.should have_domain(domain) }
end
+ it 'should allow the creation of int-var arrays without specified domain' do
+ count = 5
+ vars = @model.int_var_array(count)
+ vars.size.should equal(count)
+ vars.each do |var|
+ var.should be_range
+ var.min.should == Gecode::Raw::IntLimits::MIN
+ var.max.should == Gecode::Raw::IntLimits::MAX
+ end
+ end
+
it 'should allow the creation of int-var matrices with range domains' do
range = 0..3
rows = 5
columns = 4
vars = @model.int_var_matrix(rows, columns, range)
@@ -60,10 +71,36 @@
vars = @model.int_var_matrix(rows, columns, domain)
vars.row_size.should equal(rows)
vars.column_size.should equal(columns)
vars.each{ |var| var.should have_domain(domain) }
end
+
+ it 'should allow the creation of int-var matrices without specified domain' do
+ rows = 5
+ columns = 4
+ vars = @model.int_var_matrix(rows, columns)
+ vars.row_size.should equal(rows)
+ vars.column_size.should equal(columns)
+ vars.each do |var|
+ var.should be_range
+ var.min.should == Gecode::Raw::IntLimits::MIN
+ var.max.should == Gecode::Raw::IntLimits::MAX
+ end
+ end
+
+ it 'should raise error if the domain is of incorrect type' do
+ lambda do
+ @model.int_var(nil)
+ end.should raise_error(TypeError)
+ end
+
+ it 'should gracefully GC a variable that was never accessed' do
+ lambda do
+ @model.int_var 0
+ GC.start
+ end.should_not raise_error
+ end
end
describe Gecode::Model, ' (bool creation)' do
before do
@model = Gecode::Model.new
@@ -80,10 +117,17 @@
it 'should allow the creation of matrices of boolean variables' do
matrix = @model.bool_var_matrix(3, 4)
matrix.row_size.should equal(3)
matrix.column_size.should equal(4)
end
+
+ it 'should gracefully GC a variable that was never accessed' do
+ lambda do
+ @model.bool_var
+ GC.start
+ end.should_not raise_error
+ end
end
describe Gecode::Model, ' (set creation)' do
before do
@model = Gecode::Model.new
@@ -141,10 +185,19 @@
var.cardinality.end.should <= @upper_card
var.cardinality.begin.should >= @lower_card
end
end
+ it 'should allow the creation of arrays of set variables without specified bounds' do
+ vars = @model.set_var_array(3)
+ vars.each do |var|
+ var.lower_bound.size.should == 0
+ var.upper_bound.min.should == Gecode::Raw::SetLimits::MIN
+ var.upper_bound.max.should == Gecode::Raw::SetLimits::MAX
+ end
+ end
+
it 'should allow the creation of matrices of set variables' do
matrix = @model.set_var_matrix(4, 5, @glb_enum, @lub_enum,
@lower_card..@upper_card)
matrix.row_size.should == 4
matrix.column_size.should == 5
@@ -152,23 +205,48 @@
var.should have_bounds(@glb_enum, @lub_enum)
var.cardinality.end.should <= @upper_card
var.cardinality.begin.should >= @lower_card
end
end
+
+ it 'should allow the creation of matrices of set variables without specified bounds' do
+ matrix = @model.set_var_matrix(4, 5)
+ matrix.each do |var|
+ var.lower_bound.size.should == 0
+ var.upper_bound.min.should == Gecode::Raw::SetLimits::MIN
+ var.upper_bound.max.should == Gecode::Raw::SetLimits::MAX
+ end
+ end
it 'should raise error if glb and lub are not valid when they are given as range' do
- lambda{ @model.set_var(@lub_range, @glb_range).should }.should raise_error(
- ArgumentError)
+ lambda do
+ @model.set_var(@lub_range, @glb_range)
+ end.should raise_error(ArgumentError)
end
it 'should raise error if glb and lub are not valid when one is given as enum' do
- lambda{ @model.set_var(@lub_range, @glb_enum).should }.should raise_error(
- ArgumentError)
+ lambda do
+ @model.set_var(@lub_range, @glb_enum)
+ end.should raise_error(ArgumentError)
end
it 'should raise error if glb and lub are not valid when both are given as enums' do
- lambda{ @model.set_var(@lub_enum, @glb_enum).should }.should raise_error(
- ArgumentError)
+ lambda do
+ @model.set_var(@lub_enum, @glb_enum)
+ end.should raise_error(ArgumentError)
+ end
+
+ it 'should raise error if the glb and lub are of incorrect type' do
+ lambda do
+ @model.set_var("foo\n", "foo\ns")
+ end.should raise_error(TypeError)
+ end
+
+ it 'should gracefully GC a variable that was never accessed' do
+ lambda do
+ @model.set_var(@glb_range, @lub_range)
+ GC.start
+ end.should_not raise_error
end
end
describe Gecode::Model, ' (space access restriction)' do
before do
\ No newline at end of file