Gecoder C0 Coverage Information - RCov

lib/gecoder/interface/constraints/bool_enum/extensional.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/gecoder/interface/constraints/bool_enum/extensional.rb 106 59
100.00%
100.00%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 module Gecode::BoolEnum
2   class BoolEnumConstraintReceiver
3     # Constrains all the operands in this enumeration to be equal to
4     # one of the specified tuples. Neither negation nor reification is
5     # supported.
6     #
7     # ==== Examples 
8     # 
9     #   # Constrains the three boolean operands in +bools+ to either
10     #   # be true, false, true, or false, false, true.
11     #   bools.must_be.in [[true, false, true], [false, false, true]]
12     #
13     #   # The same as above, but preferring speed over low memory usage.
14     #   bools.must_be.in([[true, false, true], [false, false, true]], 
15     #     :kind => :speed)
16     def in(tuples, options = {})
17       if @params[:negate]
18         raise Gecode::MissingConstraintError, 'A negated tuple constraint is ' +
19           'not implemented.'
20       end
21       unless options[:reify].nil?
22         raise ArgumentError, 'Reification is not supported by the tuple ' + 
23           'constraint.'
24       end
25       
26       util = Gecode::Util
27       
28       # Check that the tuples are correct.
29       expected_size = @params[:lhs].size
30       util::Extensional.perform_tuple_checks(tuples, expected_size) do |tuple|
31         unless tuple.all?{ |x| x.kind_of?(TrueClass) or x.kind_of?(FalseClass) }
32           raise TypeError, 'All tuples must contain booleans.'
33         end
34       end
35       
36       @params[:tuples] = tuples
37       @model.add_constraint Extensional::TupleConstraint.new(@model, 
38         @params.update(Gecode::Util.decode_options(options)))
39     end
40 
41     # Constrains the sequence of operands in this enumeration to match
42     # a specified regexp in the boolean domain. Neither negation nor
43     # reification is supported.
44     #
45     # The regular expressions are specified as described in 
46     # IntEnumConstraintReceiver#match but true and false can be
47     # used instead of integers.
48     #
49     # ==== Examples 
50     #
51     #   # Constrains the two boolean operands in +bools+ to be false
52     #   # and true respectively.
53     #   bools.must.match [false, true]
54     #
55     #   # Constrains the boolean operands in +bools+ to be false,
56     #   # except for three consecutive operands which should be true
57     #   # followed by false followed by true.
58     #   bools.must.match [repeat(false), true, false, true, repeat(false)]]
59     #
60     def match(regexp, options = {})
61       if @params[:negate]
62         raise Gecode::MissingConstraintError, 'A negated regexp constraint ' +
63           'is not implemented.'
64       end
65       unless options[:reify].nil?
66         raise ArgumentError, 'Reification is not supported by the regexp ' + 
67           'constraint.'
68       end
69 
70       @params[:regexp] = 
71         Gecode::Util::Extensional.parse_regexp regexp
72       @params.update Gecode::Util.decode_options(options)
73       @model.add_constraint Extensional::RegexpConstraint.new(@model, @params)
74     end
75   end
76   
77   # A module that gathers the classes and modules used in extensional 
78   # constraints.
79   module Extensional #:nodoc:
80     class TupleConstraint < Gecode::Constraint #:nodoc:
81       def post
82         # Bind lhs.
83         lhs = @params[:lhs].to_bool_enum.bind_array
84 
85         # Create the tuple set.
86         tuple_set = Gecode::Raw::TupleSet.new
87         @params[:tuples].each do |tuple|
88           tuple_set.add tuple.map{ |b| b ? 1 : 0 }
89         end
90         tuple_set.finalize
91 
92         # Post the constraint.
93         Gecode::Raw::extensional(@model.active_space, lhs, tuple_set, 
94           *propagation_options)
95       end
96     end
97 
98     class RegexpConstraint < Gecode::Constraint #:nodoc:
99       def post
100         lhs, regexp = @params.values_at(:lhs, :regexp)
101         Gecode::Raw::extensional(@model.active_space, 
102           lhs.to_bool_enum.bind_array, regexp, *propagation_options)
103       end
104     end
105   end
106 end

Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0