Module: Gecode::Util::Extensional
- Defined in:
- lib/gecoder/interface/constraints.rb
Overview
A module that contains utility-methods for extensional constraints.
Class Method Summary collapse
-
.perform_tuple_checks(tuples, expected_size, &additional_test) ⇒ Object
Checks that the specified enumeration is an enumeration containing one or more tuples of the specified size.
Class Method Details
.perform_tuple_checks(tuples, expected_size, &additional_test) ⇒ Object
Checks that the specified enumeration is an enumeration containing one or more tuples of the specified size. It also allows the caller to define additional tests by providing a block, which is given each tuple. If a test fails then an appropriate error is raised.
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
# File 'lib/gecoder/interface/constraints.rb', line 434 def perform_tuple_checks(tuples, expected_size, &additional_test) unless tuples.respond_to?(:each) raise TypeError, 'Expected an enumeration with tuples, got ' + "#{tuples.class}." end if tuples.empty? raise ArgumentError, 'One or more tuples must be specified.' end tuples.each do |tuple| unless tuple.respond_to?(:each) raise TypeError, 'Expected an enumeration containing enumeraions, ' + "got #{tuple.class}." end unless tuple.size == expected_size raise ArgumentError, 'All tuples must be of the same size as the ' + 'number of operands in the array.' end yield tuple end end |