Module: Gecode::Constraints::Util::Extensional

Defined in:
lib/gecoder/interface/constraints.rb

Overview

A module that contains utility-methods for extensional constraints.

Class Method Summary collapse

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.



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/gecoder/interface/constraints.rb', line 228

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 variables in the array.'
    end
    
    yield tuple
  end
end