gecoder-with-gecode 0.9.0-x86-mswin32-60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. data/CHANGES +137 -0
  2. data/COPYING +17 -0
  3. data/LGPL-LICENSE +458 -0
  4. data/README +58 -0
  5. data/Rakefile +14 -0
  6. data/example/equation_system.rb +15 -0
  7. data/example/example_helper.rb +1 -0
  8. data/example/magic_sequence.rb +43 -0
  9. data/example/money.rb +36 -0
  10. data/example/queens.rb +42 -0
  11. data/example/send_more_money.rb +43 -0
  12. data/example/send_most_money.rb +58 -0
  13. data/example/square_tiling.rb +84 -0
  14. data/example/sudoku-set.rb +106 -0
  15. data/example/sudoku.rb +56 -0
  16. data/lib/gecode.dll +0 -0
  17. data/lib/gecoder.rb +5 -0
  18. data/lib/gecoder/bindings.rb +96 -0
  19. data/lib/gecoder/bindings/bindings.rb +2029 -0
  20. data/lib/gecoder/interface.rb +9 -0
  21. data/lib/gecoder/interface/binding_changes.rb +9 -0
  22. data/lib/gecoder/interface/branch.rb +163 -0
  23. data/lib/gecoder/interface/constraints.rb +471 -0
  24. data/lib/gecoder/interface/constraints/bool/boolean.rb +251 -0
  25. data/lib/gecoder/interface/constraints/bool/channel.rb +7 -0
  26. data/lib/gecoder/interface/constraints/bool/linear.rb +200 -0
  27. data/lib/gecoder/interface/constraints/bool_enum/channel.rb +68 -0
  28. data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +106 -0
  29. data/lib/gecoder/interface/constraints/bool_enum/relation.rb +55 -0
  30. data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +84 -0
  31. data/lib/gecoder/interface/constraints/bool_var_constraints.rb +155 -0
  32. data/lib/gecoder/interface/constraints/extensional_regexp.rb +101 -0
  33. data/lib/gecoder/interface/constraints/fixnum_enum/element.rb +63 -0
  34. data/lib/gecoder/interface/constraints/fixnum_enum/operation.rb +65 -0
  35. data/lib/gecoder/interface/constraints/fixnum_enum_constraints.rb +42 -0
  36. data/lib/gecoder/interface/constraints/int/arithmetic.rb +150 -0
  37. data/lib/gecoder/interface/constraints/int/channel.rb +51 -0
  38. data/lib/gecoder/interface/constraints/int/domain.rb +80 -0
  39. data/lib/gecoder/interface/constraints/int/linear.rb +143 -0
  40. data/lib/gecoder/interface/constraints/int/relation.rb +141 -0
  41. data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +63 -0
  42. data/lib/gecoder/interface/constraints/int_enum/channel.rb +86 -0
  43. data/lib/gecoder/interface/constraints/int_enum/count.rb +66 -0
  44. data/lib/gecoder/interface/constraints/int_enum/distinct.rb +64 -0
  45. data/lib/gecoder/interface/constraints/int_enum/element.rb +64 -0
  46. data/lib/gecoder/interface/constraints/int_enum/equality.rb +37 -0
  47. data/lib/gecoder/interface/constraints/int_enum/extensional.rb +187 -0
  48. data/lib/gecoder/interface/constraints/int_enum/sort.rb +135 -0
  49. data/lib/gecoder/interface/constraints/int_enum_constraints.rb +95 -0
  50. data/lib/gecoder/interface/constraints/int_var_constraints.rb +230 -0
  51. data/lib/gecoder/interface/constraints/reifiable_constraints.rb +78 -0
  52. data/lib/gecoder/interface/constraints/selected_set/select.rb +120 -0
  53. data/lib/gecoder/interface/constraints/selected_set_constraints.rb +75 -0
  54. data/lib/gecoder/interface/constraints/set/cardinality.rb +65 -0
  55. data/lib/gecoder/interface/constraints/set/channel.rb +51 -0
  56. data/lib/gecoder/interface/constraints/set/connection.rb +130 -0
  57. data/lib/gecoder/interface/constraints/set/domain.rb +156 -0
  58. data/lib/gecoder/interface/constraints/set/include.rb +36 -0
  59. data/lib/gecoder/interface/constraints/set/operation.rb +118 -0
  60. data/lib/gecoder/interface/constraints/set/relation.rb +155 -0
  61. data/lib/gecoder/interface/constraints/set_elements/relation.rb +116 -0
  62. data/lib/gecoder/interface/constraints/set_elements_constraints.rb +97 -0
  63. data/lib/gecoder/interface/constraints/set_enum/channel.rb +45 -0
  64. data/lib/gecoder/interface/constraints/set_enum/distinct.rb +43 -0
  65. data/lib/gecoder/interface/constraints/set_enum/operation.rb +69 -0
  66. data/lib/gecoder/interface/constraints/set_enum/select.rb +79 -0
  67. data/lib/gecoder/interface/constraints/set_enum_constraints.rb +84 -0
  68. data/lib/gecoder/interface/constraints/set_var_constraints.rb +243 -0
  69. data/lib/gecoder/interface/enum_matrix.rb +64 -0
  70. data/lib/gecoder/interface/enum_wrapper.rb +205 -0
  71. data/lib/gecoder/interface/model.rb +453 -0
  72. data/lib/gecoder/interface/model_sugar.rb +84 -0
  73. data/lib/gecoder/interface/search.rb +197 -0
  74. data/lib/gecoder/interface/variables.rb +306 -0
  75. data/lib/gecoder/version.rb +4 -0
  76. data/specs/bool_var.rb +81 -0
  77. data/specs/branch.rb +185 -0
  78. data/specs/constraints/bool/boolean.rb +317 -0
  79. data/specs/constraints/bool/boolean_properties.rb +51 -0
  80. data/specs/constraints/bool/linear.rb +213 -0
  81. data/specs/constraints/bool_enum/bool_enum_relation.rb +117 -0
  82. data/specs/constraints/bool_enum/channel.rb +102 -0
  83. data/specs/constraints/bool_enum/extensional.rb +225 -0
  84. data/specs/constraints/constraint_helper.rb +234 -0
  85. data/specs/constraints/constraint_receivers.rb +103 -0
  86. data/specs/constraints/constraints.rb +26 -0
  87. data/specs/constraints/fixnum_enum/element.rb +58 -0
  88. data/specs/constraints/fixnum_enum/operation.rb +67 -0
  89. data/specs/constraints/int/arithmetic.rb +149 -0
  90. data/specs/constraints/int/channel.rb +101 -0
  91. data/specs/constraints/int/domain.rb +106 -0
  92. data/specs/constraints/int/linear.rb +183 -0
  93. data/specs/constraints/int/linear_properties.rb +97 -0
  94. data/specs/constraints/int/relation.rb +84 -0
  95. data/specs/constraints/int_enum/arithmetic.rb +72 -0
  96. data/specs/constraints/int_enum/channel.rb +57 -0
  97. data/specs/constraints/int_enum/count.rb +72 -0
  98. data/specs/constraints/int_enum/distinct.rb +80 -0
  99. data/specs/constraints/int_enum/element.rb +61 -0
  100. data/specs/constraints/int_enum/equality.rb +29 -0
  101. data/specs/constraints/int_enum/extensional.rb +224 -0
  102. data/specs/constraints/int_enum/sort.rb +167 -0
  103. data/specs/constraints/operands.rb +264 -0
  104. data/specs/constraints/property_helper.rb +443 -0
  105. data/specs/constraints/reification_sugar.rb +69 -0
  106. data/specs/constraints/selected_set/select.rb +56 -0
  107. data/specs/constraints/selected_set/select_properties.rb +157 -0
  108. data/specs/constraints/set/cardinality.rb +58 -0
  109. data/specs/constraints/set/cardinality_properties.rb +46 -0
  110. data/specs/constraints/set/channel.rb +77 -0
  111. data/specs/constraints/set/connection.rb +176 -0
  112. data/specs/constraints/set/domain.rb +197 -0
  113. data/specs/constraints/set/include.rb +36 -0
  114. data/specs/constraints/set/operation.rb +132 -0
  115. data/specs/constraints/set/relation.rb +117 -0
  116. data/specs/constraints/set_elements/relation.rb +84 -0
  117. data/specs/constraints/set_enum/channel.rb +80 -0
  118. data/specs/constraints/set_enum/distinct.rb +59 -0
  119. data/specs/constraints/set_enum/operation.rb +111 -0
  120. data/specs/constraints/set_enum/select.rb +73 -0
  121. data/specs/distribution.rb +14 -0
  122. data/specs/enum_matrix.rb +43 -0
  123. data/specs/enum_wrapper.rb +179 -0
  124. data/specs/examples.rb +17 -0
  125. data/specs/int_var.rb +163 -0
  126. data/specs/logging.rb +24 -0
  127. data/specs/model.rb +325 -0
  128. data/specs/model_sugar.rb +30 -0
  129. data/specs/search.rb +383 -0
  130. data/specs/selected_set.rb +39 -0
  131. data/specs/set_elements.rb +34 -0
  132. data/specs/set_var.rb +82 -0
  133. data/specs/spec_helper.rb +265 -0
  134. data/tasks/all_tasks.rb +1 -0
  135. data/tasks/dependencies.txt +22 -0
  136. data/tasks/distribution.rake +194 -0
  137. data/tasks/rcov.rake +18 -0
  138. data/tasks/specs.rake +21 -0
  139. data/tasks/svn.rake +16 -0
  140. data/tasks/website.rake +51 -0
  141. data/vendor/gecode/win32/lib/libgecodeint.dll +0 -0
  142. data/vendor/gecode/win32/lib/libgecodekernel.dll +0 -0
  143. data/vendor/gecode/win32/lib/libgecodeminimodel.dll +0 -0
  144. data/vendor/gecode/win32/lib/libgecodesearch.dll +0 -0
  145. data/vendor/gecode/win32/lib/libgecodeset.dll +0 -0
  146. data/vendor/gecode/win32/lib/libgecodesupport.dll +0 -0
  147. data/vendor/rust/README +28 -0
  148. data/vendor/rust/bin/cxxgenerator.rb +93 -0
  149. data/vendor/rust/include/rust_checks.hh +116 -0
  150. data/vendor/rust/include/rust_conversions.hh +102 -0
  151. data/vendor/rust/rust.rb +67 -0
  152. data/vendor/rust/rust/attribute.rb +51 -0
  153. data/vendor/rust/rust/bindings.rb +172 -0
  154. data/vendor/rust/rust/class.rb +337 -0
  155. data/vendor/rust/rust/constants.rb +48 -0
  156. data/vendor/rust/rust/container.rb +110 -0
  157. data/vendor/rust/rust/cppifaceparser.rb +129 -0
  158. data/vendor/rust/rust/cwrapper.rb +72 -0
  159. data/vendor/rust/rust/cxxclass.rb +96 -0
  160. data/vendor/rust/rust/element.rb +81 -0
  161. data/vendor/rust/rust/enum.rb +63 -0
  162. data/vendor/rust/rust/function.rb +407 -0
  163. data/vendor/rust/rust/namespace.rb +61 -0
  164. data/vendor/rust/rust/templates/AttributeDefinition.rusttpl +17 -0
  165. data/vendor/rust/rust/templates/AttributeInitBinding.rusttpl +9 -0
  166. data/vendor/rust/rust/templates/BindingsHeader.rusttpl +24 -0
  167. data/vendor/rust/rust/templates/BindingsUnit.rusttpl +46 -0
  168. data/vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl +64 -0
  169. data/vendor/rust/rust/templates/ClassDeclarations.rusttpl +7 -0
  170. data/vendor/rust/rust/templates/ClassInitialize.rusttpl +6 -0
  171. data/vendor/rust/rust/templates/ConstructorStub.rusttpl +21 -0
  172. data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +100 -0
  173. data/vendor/rust/rust/templates/CxxMethodStub.rusttpl +12 -0
  174. data/vendor/rust/rust/templates/CxxStandaloneClassDefinitions.rusttpl +26 -0
  175. data/vendor/rust/rust/templates/EnumDeclarations.rusttpl +3 -0
  176. data/vendor/rust/rust/templates/EnumDefinitions.rusttpl +29 -0
  177. data/vendor/rust/rust/templates/FunctionDefinition.rusttpl +9 -0
  178. data/vendor/rust/rust/templates/FunctionInitAlias.rusttpl +5 -0
  179. data/vendor/rust/rust/templates/FunctionInitBinding.rusttpl +9 -0
  180. data/vendor/rust/rust/templates/MethodInitBinding.rusttpl +9 -0
  181. data/vendor/rust/rust/templates/ModuleDeclarations.rusttpl +3 -0
  182. data/vendor/rust/rust/templates/ModuleDefinitions.rusttpl +3 -0
  183. data/vendor/rust/rust/templates/StandaloneClassDeclarations.rusttpl +7 -0
  184. data/vendor/rust/rust/templates/VariableFunctionCall.rusttpl +14 -0
  185. data/vendor/rust/rust/type.rb +98 -0
  186. data/vendor/rust/test/Makefile +4 -0
  187. data/vendor/rust/test/constants.rb +36 -0
  188. data/vendor/rust/test/cppclass.cc +45 -0
  189. data/vendor/rust/test/cppclass.hh +67 -0
  190. data/vendor/rust/test/cppclass.rb +59 -0
  191. data/vendor/rust/test/cwrapper.c +74 -0
  192. data/vendor/rust/test/cwrapper.h +41 -0
  193. data/vendor/rust/test/cwrapper.rb +56 -0
  194. data/vendor/rust/test/dummyclass.hh +31 -0
  195. data/vendor/rust/test/lib/extension-test.rb +98 -0
  196. data/vendor/rust/test/operators.cc +41 -0
  197. data/vendor/rust/test/operators.hh +39 -0
  198. data/vendor/rust/test/operators.rb +39 -0
  199. data/vendor/rust/test/test-constants.rb +43 -0
  200. data/vendor/rust/test/test-cppclass.rb +82 -0
  201. data/vendor/rust/test/test-cwrapper.rb +80 -0
  202. data/vendor/rust/test/test-operators.rb +42 -0
  203. metadata +393 -0
@@ -0,0 +1,73 @@
1
+ require File.dirname(__FILE__) + '/../property_helper'
2
+
3
+ class SelectionSampleProblem < Gecode::Model
4
+ attr :sets
5
+ attr :set
6
+ attr :target
7
+ attr :index
8
+
9
+ def initialize
10
+ @sets = set_var_array(3, [], 0..20)
11
+ @set = set_var([], 0...3)
12
+ @target = set_var([], 0..20)
13
+ @index = int_var(0...3)
14
+ branch_on wrap_enum([@index])
15
+ branch_on @sets
16
+ end
17
+ end
18
+
19
+ # Requires everything that composite behaviour spec requires in addition to
20
+ # @stub and @expect_constrain_equal .
21
+ describe 'selection constraint', :shared => true do
22
+ it 'should not disturb normal array access' do
23
+ @sets[0].should be_kind_of(Gecode::SetVar)
24
+ end
25
+ end
26
+
27
+ describe Gecode::SetEnum::Select, ' (int operand)' do
28
+ include GecodeR::Specs::SetHelper
29
+
30
+ before do
31
+ @model = SelectionSampleProblem.new
32
+ @sets = @model.sets
33
+ @target = @set = @model.target
34
+ @index = @model.index
35
+ @model.branch_on @model.wrap_enum([@set])
36
+ @stub = @sets[@index]
37
+
38
+ @property_types = [:set_enum, :int]
39
+ @select_property = lambda do |set_enum, int|
40
+ set_enum[int]
41
+ end
42
+ @selected_property = @sets[@index]
43
+ @constraint_class = Gecode::BlockConstraint
44
+ end
45
+
46
+ it 'should constrain the specified element of an enum of sets' do
47
+ @sets[@index].must_be.superset_of([5,7,9])
48
+ @model.solve!
49
+ @sets[@index.value].value.should include(5,7,9)
50
+ end
51
+
52
+ it 'should translate into a select constraint' do
53
+ Gecode::Raw.should_receive(:selectSet)
54
+ @sets[@index].must_be.superset_of([5,7,9])
55
+ @model.solve!
56
+ end
57
+
58
+ it_should_behave_like 'selection constraint'
59
+ it_should_behave_like(
60
+ 'property that produces set operand by short circuiting equality')
61
+ end
62
+
63
+ describe Gecode::SetEnum::Select, ' (set operand)' do
64
+ before do
65
+ @model = SelectionSampleProblem.new
66
+ @sets = @model.sets
67
+ @set = @model.set
68
+ end
69
+
70
+ it 'should produce a selected set operand' do
71
+ @sets[@set].should be_respond_to(:to_selected_set)
72
+ end
73
+ end
@@ -0,0 +1,14 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'Interface installed on win32 systems' do
4
+ it 'should be able to load the libraries' do
5
+ # Admittably this is not an especially good test for the library loading
6
+ # under Windows. It only makes sure that there are no execution errors. This
7
+ # has to be tested in a proper Windows environment to tell whether library
8
+ # loading actually works.
9
+ RUBY_PLATFORM = 'i386-mswin32'
10
+ lambda do
11
+ Gecode.load_bindings_lib
12
+ end.should_not raise_error
13
+ end
14
+ end
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Gecode::Util::EnumMatrix do
4
+ before do
5
+ @matrix = Gecode::Util::EnumMatrix[[0, 1], [1, 0]]
6
+ end
7
+
8
+ it 'should be enumerable' do
9
+ @matrix.should be_kind_of(Enumerable)
10
+ end
11
+
12
+ it 'should produce rows that are enumerable' do
13
+ @matrix.row(0).should be_kind_of(Enumerable)
14
+ @matrix.row(0).inject([]){ |arr, e| arr << e }.should == [0, 1]
15
+ end
16
+
17
+ it 'should produce columns that are enumerable' do
18
+ @matrix.column(0).should be_kind_of(Enumerable)
19
+ end
20
+
21
+ it 'should produce submatrices that are enumerable' do
22
+ @matrix.minor(0,1,0,1).should be_kind_of(Enumerable)
23
+ end
24
+ end
25
+
26
+ describe Gecode::Util::EnumMatrix, ' (when wrapped)' do
27
+ before do
28
+ @model = Gecode::Model.new
29
+ @matrix = @model.wrap_enum(Gecode::Util::EnumMatrix[[0, 1], [1, 0]])
30
+ end
31
+
32
+ it 'should produce rows that are wrapped' do
33
+ @matrix.row(0).should respond_to(:model)
34
+ end
35
+
36
+ it 'should produce columns that are enumerable' do
37
+ @matrix.column(0).should respond_to(:model)
38
+ end
39
+
40
+ it 'should produce submatrices that are enumerable' do
41
+ @matrix.minor(0,1,0,1).should respond_to(:model)
42
+ end
43
+ end
@@ -0,0 +1,179 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Gecode::Model, ' (enum wrapping)' do
4
+ before do
5
+ @model = Gecode::Model.new
6
+ @bool = @model.bool_var
7
+ @int = @model.int_var(1..2)
8
+ @set = @model.set_var([], 1..2)
9
+ end
10
+
11
+ it 'should only allow enumerables to be wrapped' do
12
+ lambda do
13
+ @model.wrap_enum(17)
14
+ end.should raise_error(TypeError)
15
+ end
16
+
17
+ it 'should allow enumerables of bool variables to be wrapped' do
18
+ lambda do
19
+ enum = [@bool]
20
+ @model.wrap_enum(enum)
21
+ end.should_not raise_error
22
+ end
23
+
24
+ it 'should allow enumerables of bool operands to be wrapped' do
25
+ lambda do
26
+ enum = [@bool & @bool]
27
+ @model.wrap_enum(enum)
28
+ end.should_not raise_error
29
+ end
30
+
31
+ it 'should allow enumerables of int variables to be wrapped' do
32
+ lambda do
33
+ enum = [@int]
34
+ @model.wrap_enum(enum)
35
+ end.should_not raise_error
36
+ end
37
+
38
+ it 'should allow enumerables of int operands to be wrapped' do
39
+ lambda do
40
+ enum = [@int + @int]
41
+ @model.wrap_enum(enum)
42
+ end.should_not raise_error
43
+ end
44
+
45
+ it 'should allow enumerables of set variables to be wrapped' do
46
+ lambda do
47
+ enum = [@set]
48
+ @model.wrap_enum(enum)
49
+ end.should_not raise_error
50
+ end
51
+
52
+ it 'should allow enumerables of set operands to be wrapped' do
53
+ lambda do
54
+ enum = [@set.union(@set)]
55
+ @model.wrap_enum(enum)
56
+ end.should_not raise_error
57
+ end
58
+
59
+
60
+ it 'should allow enumerables of fixnums to be wrapped' do
61
+ lambda do
62
+ enum = [17]
63
+ @model.wrap_enum(enum)
64
+ end.should_not raise_error
65
+ end
66
+
67
+ it 'should not allow empty enumerables to be wrapped' do
68
+ lambda do
69
+ @model.wrap_enum([])
70
+ end.should raise_error(ArgumentError)
71
+ end
72
+
73
+ it 'should not allow wrapping a wrapped enumerable' do
74
+ lambda do
75
+ enum = [@bool]
76
+ @model.wrap_enum(@model.wrap_enum(enum))
77
+ end.should raise_error(ArgumentError)
78
+ end
79
+
80
+ it 'should not allow enumerables without variables or fixnums to be wrapped' do
81
+ lambda do
82
+ @model.wrap_enum(['foo'])
83
+ end.should raise_error(TypeError)
84
+ end
85
+
86
+ it 'should not allow enumerables with only some variables to be wrapped' do
87
+ lambda do
88
+ enum = [@bool, 'foo']
89
+ @model.wrap_enum(enum)
90
+ end.should raise_error(TypeError)
91
+ end
92
+
93
+ it 'should not allow enumerables with mixed types of variables to be wrapped' do
94
+ lambda do
95
+ enum = [@bool, @int]
96
+ @model.wrap_enum(enum)
97
+ end.should raise_error(TypeError)
98
+ end
99
+ end
100
+
101
+ describe Gecode::IntEnumMethods do
102
+ before do
103
+ @model = Gecode::Model.new
104
+ @int_enum = @model.int_var_array(3, 0..1)
105
+ end
106
+
107
+ it 'should convert to an int var array' do
108
+ @model.allow_space_access do
109
+ @int_enum.bind_array.should be_kind_of(Gecode::Raw::IntVarArray)
110
+ end
111
+ end
112
+
113
+ it 'should compute the smallest domain range' do
114
+ @int_enum.domain_range.should == (0..1)
115
+ (@int_enum << @model.int_var(-4..4)).domain_range.should == (-4..4)
116
+ end
117
+
118
+ it 'should define #to_int_enum' do
119
+ @int_enum.to_int_enum.should be_kind_of(
120
+ Gecode::IntEnum::IntEnumOperand)
121
+ end
122
+ end
123
+
124
+ describe Gecode::BoolEnumMethods do
125
+ before do
126
+ @model = Gecode::Model.new
127
+ @bool_enum = @model.bool_var_array(3)
128
+ end
129
+
130
+ it 'should convert to a bool var array' do
131
+ @model.allow_space_access do
132
+ @bool_enum.bind_array.should be_kind_of(Gecode::Raw::BoolVarArray)
133
+ end
134
+ end
135
+
136
+ it 'should define #to_bool_enum' do
137
+ @bool_enum.to_bool_enum.should be_kind_of(
138
+ Gecode::BoolEnum::BoolEnumOperand)
139
+ end
140
+ end
141
+
142
+ describe Gecode::SetEnumMethods do
143
+ before do
144
+ @model = Gecode::Model.new
145
+ @set_enum = @model.set_var_array(3, [0], 0..1)
146
+ end
147
+
148
+ it 'should convert to a set var array' do
149
+ @model.allow_space_access do
150
+ @set_enum.bind_array.should be_kind_of(Gecode::Raw::SetVarArray)
151
+ end
152
+ end
153
+
154
+ it 'should compute the smallest upper bound union range' do
155
+ @set_enum.upper_bound_range.should == (0..1)
156
+ (@set_enum << @model.set_var([], -4..4)).upper_bound_range.should == (-4..4)
157
+ end
158
+
159
+ it 'should define #to_set_enum' do
160
+ @set_enum.to_set_enum.should be_kind_of(
161
+ Gecode::SetEnum::SetEnumOperand)
162
+ end
163
+ end
164
+
165
+ describe Gecode::FixnumEnumMethods do
166
+ before do
167
+ @model = Gecode::Model.new
168
+ @enum = @model.instance_eval{ wrap_enum([7, 14, 17, 4711]) }
169
+ end
170
+
171
+ it 'should compute the smallest domain range' do
172
+ @enum.domain_range.should == (7..4711)
173
+ end
174
+
175
+ it 'should define #to_fixnum_enum' do
176
+ @enum.to_fixnum_enum.should be_kind_of(
177
+ Gecode::FixnumEnum::FixnumEnumOperand)
178
+ end
179
+ end
data/specs/examples.rb ADDED
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require 'open3'
3
+
4
+ # This spec checks that the examples are still working.
5
+ files = Dir["#{File.dirname(__FILE__)}/../example/*.rb"]
6
+ files.delete_if do |file|
7
+ file =~ /example_helper.rb/
8
+ end
9
+
10
+ files.each do |example|
11
+ describe "Example (#{File.basename(example)})" do
12
+ it 'should not output errors' do
13
+ _, _, stderr = Open3.popen3("ruby #{example} 1> /dev/null")
14
+ stderr.gets.should be_nil
15
+ end
16
+ end
17
+ end
data/specs/int_var.rb ADDED
@@ -0,0 +1,163 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/constraints/property_helper'
3
+
4
+ describe 'non-empty int variable', :shared => true do
5
+ it 'should have min equal to the lower domain bound' do
6
+ @var.min.should equal(@domain.min)
7
+ end
8
+
9
+ it 'should have max equal to the upper domain bound' do
10
+ @var.max.should equal(@domain.max)
11
+ end
12
+
13
+ it 'should have size equal to the domain size' do
14
+ @var.size.should equal(@domain.size)
15
+ end
16
+
17
+ it 'should contain every element in its domain' do
18
+ @domain.each do |i|
19
+ @var.should include(i)
20
+ end
21
+ end
22
+
23
+ it 'should not contain elements outside its domain' do
24
+ @var.should_not include(@domain.min - 1)
25
+ @var.should_not include(@domain.max + 1)
26
+ end
27
+
28
+ it 'should have a width equal to the domain width' do
29
+ @var.width.should equal(@domain.max - @domain.min + 1)
30
+ end
31
+
32
+ it 'should give a NoMethodError when calling a method that doesn\'t exist' do
33
+ lambda{ @var.this_method_does_not_exists }.should raise_error(NoMethodError)
34
+ end
35
+
36
+ it 'should have a zero degree' do
37
+ @var.degree.should be_zero
38
+ end
39
+
40
+ it 'should return the correct domain through #domain' do
41
+ @var.domain.to_a.should == @domain.to_a
42
+ end
43
+
44
+ it_should_behave_like 'int var operand'
45
+ end
46
+
47
+ describe Gecode::IntVar, ' (with range domain of size > 1)' do
48
+ before do
49
+ @range = -4..3
50
+ @domain = @range.to_a
51
+ @model = Gecode::Model.new
52
+ @operand = @var = @model.int_var(@range)
53
+ end
54
+
55
+ it 'should not be assigned' do
56
+ @var.should_not be_assigned
57
+ end
58
+
59
+ it 'should have a range domain' do
60
+ @var.should be_range
61
+ end
62
+
63
+ it 'should raise error when trying to access assigned value' do
64
+ lambda{ @var.value }.should raise_error(RuntimeError)
65
+ end
66
+
67
+ it_should_behave_like 'non-empty int variable'
68
+ end
69
+
70
+ describe Gecode::IntVar, ' (defined with three-dot range)' do
71
+ before do
72
+ @range = -4...3
73
+ @domain = @range.to_a
74
+ @model = Gecode::Model.new
75
+ @operand = @var = @model.int_var(@range)
76
+ end
77
+
78
+ it_should_behave_like 'non-empty int variable'
79
+ end
80
+
81
+ describe Gecode::IntVar, ' (with non-range domain of size > 1)' do
82
+ before do
83
+ @domain = [-3, -2, -1, 1]
84
+ @model = Gecode::Model.new
85
+ @operand = @var = @model.int_var(@domain)
86
+ end
87
+
88
+ it 'should not be assigned' do
89
+ @var.should_not be_assigned
90
+ end
91
+
92
+ it 'should not be a range domain' do
93
+ @var.should_not be_range
94
+ end
95
+
96
+ it 'should not contain the domain\'s holes' do
97
+ @var.should_not include(0)
98
+ end
99
+
100
+ it_should_behave_like 'non-empty int variable'
101
+ end
102
+
103
+ describe Gecode::IntVar, ' (with a domain of size 1)' do
104
+ before do
105
+ @domain = [1]
106
+ @model = Gecode::Model.new
107
+ @operand = @var = @model.int_var(*@domain)
108
+ end
109
+
110
+ it 'should be assigned' do
111
+ @var.should be_assigned
112
+ end
113
+
114
+ it 'should be a range domain' do
115
+ @var.should be_range
116
+ end
117
+
118
+ it_should_behave_like 'non-empty int variable'
119
+ end
120
+
121
+ describe Gecode::IntVar, ' (assigned)' do
122
+ before do
123
+ @domain = 1
124
+ @model = Gecode::Model.new
125
+ @operand = @var = @model.int_var(*@domain)
126
+ end
127
+
128
+ it 'should be assigned' do
129
+ @var.should be_assigned
130
+ end
131
+
132
+ it 'should give the assigned number when inspecting' do
133
+ @var.inspect.should include(" #{@domain[0]}>")
134
+ end
135
+
136
+ it 'should return the correct domain through #domain' do
137
+ @var.domain.to_a.should == [@domain]
138
+ end
139
+
140
+ it_should_behave_like 'int var operand'
141
+ end
142
+
143
+ describe Gecode::IntVar, ' (not assigned)' do
144
+ before do
145
+ @domain = 1..2
146
+ @model = Gecode::Model.new
147
+ @operand = @var = @model.int_var(@domain)
148
+ end
149
+
150
+ it 'should not be assigned' do
151
+ @var.should_not be_assigned
152
+ end
153
+
154
+ it 'should give the domain range when inspecting' do
155
+ @var.inspect.should include(" #{@domain.first}..#{@domain.last}>")
156
+ end
157
+
158
+ it 'should return the correct domain through #domain' do
159
+ @var.domain.to_a.should == @domain.to_a
160
+ end
161
+
162
+ it_should_behave_like 'int var operand'
163
+ end