lib/gecoder/interface/constraints/bool_enum/extensional.rb in gecoder-0.8.1 vs lib/gecoder/interface/constraints/bool_enum/extensional.rb in gecoder-0.8.2
- old
+ new
@@ -8,19 +8,20 @@
end
unless options[:reify].nil?
raise ArgumentError, 'Reification is not supported by the tuple ' +
'constraint.'
end
- unless tuples.respond_to?(:each) and
- tuples.all?{ |tuple| tuple.respond_to?(:each) }
- raise TypeError, 'Expected an enumeration with tuples, got ' +
- "#{tuples.class}."
+
+ util = Gecode::Constraints::Util
+
+ # Check that the tuples are correct.
+ expected_size = @params[:lhs].size
+ util::Extensional.perform_tuple_checks(tuples, expected_size) do |tuple|
+ unless tuple.all?{ |x| x.kind_of?(TrueClass) or x.kind_of?(FalseClass) }
+ raise TypeError, 'All tuples must contain booleans.'
+ end
end
- unless tuples.all?{ |tuple|
- tuple.all?{ |x| x.kind_of?(TrueClass) or x.kind_of?(FalseClass) }}
- raise TypeError, 'All tuples must contain booleans.'
- end
-
+
@params[:tuples] = tuples
@model.add_constraint Extensional::TupleConstraint.new(@model,
@params.update(Gecode::Constraints::Util.decode_options(options)))
end
end