Gecoder C0 Coverage Information - RCov

lib/gecoder/interface/constraints/set/domain.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/gecoder/interface/constraints/set/domain.rb 156 65
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::Set
2   class SetConstraintReceiver
3     # Constrains the set operand to have a domain equal to +constant_set+.
4     # 
5     # ==== Examples 
6     # 
7     #   # +set+ must equal [1,2,5]
8     #   set.must == [1,2,5]
9     #   
10     #   # +set+ must not equal 1..67
11     #   set.must_not == 1..67
12     #   
13     #   # +set+ must equal the singleton set 0. The constraint is reified with
14     #   # the boolean operand +is_singleton_zero+.
15     #   set.must.equal(0, :reify => is_singleton_zero)
16     def ==(constant_set, options = {})
17       add_domain_constraint(:==, constant_set, options)
18     end
19 
20     # Constrains the set operand to be a superset of +constant_set+.
21     #
22     # ==== Examples 
23     # 
24     #   # +set+ must be a superset of [1,2,5]
25     #   set.must_be.superset_of [1,2,5]
26     #   
27     #   # +set+ must be a superset of 1..67
28     #   set.must_be.superset_of 1..67
29     #   
30     #   # +set+ must not be a superset of [0].
31     #   set.must_not_be.superset_of 0
32     #   
33     #   # +set+ must be a superset of [1,3,5,7]. The constraint is reified with
34     #   # the boolean operand +bool+.
35     #   set.must_be.superset_of([1.3.5.7], :reify => bool) 
36     def superset(constant_set, options = {})
37       add_domain_constraint(:superset, constant_set, options)
38     end
39 
40     # Constrains the set operand to be a subset of +constant_set+.
41     # 
42     # ==== Examples 
43     # 
44     #   # +set+ must be a subset of [1,2,5]
45     #   set.must_be.subset_of [1,2,5]
46     #   
47     #   # +set+ must be a subset of 1..67
48     #   set.must_be.subset_of 1..67
49     #   
50     #   # +set+ must not be a subset of [0].
51     #   set.must_not_be.subset_of 0
52     #   
53     #   # +set+ must be a subset of [1,3,5,7]. The constraint is reified with
54     #   # the boolean operand +bool+.
55     #   set.must_be.subset_of([1.3.5.7], :reify => bool) 
56     def subset(constant_set, options = {})
57       add_domain_constraint(:subset, constant_set, options)
58     end
59 
60     # Constrains the set operand to be disjoint with +constant_set+.
61     # 
62     # ==== Examples 
63     # 
64     #   # +set+ must be disjoint with [1,2,5]
65     #   set.must_be.disjoint_with [1,2,5]
66     #   
67     #   # +set+ must be disjoint with 1..67
68     #   set.must_be.disjoint_with 1..67
69     #   
70     #   # +set+ must not be disjoint with [0].
71     #   set.must_not_be.disjoint_with 0
72     #   
73     #   # +set+ must be disjoint with [1,3,5,7]. The constraint is reified with
74     #   # the boolean operand +bool+.
75     #   set.must_be.disjoint_with([1.3.5.7], :reify => bool) 
76     def disjoint(constant_set, options = {})
77       add_domain_constraint(:disjoint, constant_set, options)
78     end
79 
80     # Constrains the set operand to be the complement of +constant_set+.
81     #
82     # ==== Examples 
83     # 
84     #   # +set+ must be the complement of [1,2,5]
85     #   set.must_be.complement_of [1,2,5]
86     #   
87     #   # +set+ must be the complement of 1..67
88     #   set.must_be.complement_of 1..67
89     #   
90     #   # +set+ must not be the complement of [0].
91     #   set.must_not_be.complement_of 0
92     #   
93     #   # +set+ must be the complement of [1,3,5,7]. The constraint is 
94     #   # reified with the boolean operand +bool+.
95     #   set.must_be.complement_of([1.3.5.7], :reify => bool) 
96     def complement(constant_set, options = {})
97       add_domain_constraint(:complement, constant_set, options)
98     end
99 
100     alias_set_methods
101     
102     private
103     
104     # Adds a domain constraint for the specified relation name, constant set
105     # and options.
106     def add_domain_constraint(relation_name, constant_set, options)
107       unless Gecode::Util.constant_set? constant_set
108         raise TypeError, "Expected constant set, got #{constant_set.class}."
109       end
110       @params[:rhs] = constant_set
111       @params[:relation] = relation_name
112       @params.update Gecode::Set::Util.decode_options(options)
113       if relation_name == :==
114         @model.add_constraint Domain::EqualityDomainConstraint.new(@model, 
115           @params)
116       else
117         @model.add_constraint Domain::DomainConstraint.new(@model, @params)
118       end
119     end
120   end
121   
122   # A module that gathers the classes and modules used in domain constraints.
123   module Domain #:nodoc:
124     class EqualityDomainConstraint < Gecode::ReifiableConstraint #:nodoc:
125       def post
126         var, domain, reif_var, negate = @params.values_at(:lhs, :rhs, :reif, 
127           :negate)
128         if negate
129           rel_type = Gecode::Util::NEGATED_SET_RELATION_TYPES[:==]
130         else
131           rel_type = Gecode::Util::SET_RELATION_TYPES[:==]
132         end
133         
134         (params = []) << var.to_set_var.bind
135         params << rel_type
136         params << Gecode::Util.constant_set_to_params(domain)
137         params << reif_var.to_bool_var.bind if reif_var.respond_to? :to_bool_var
138         Gecode::Raw::dom(@model.active_space, *params.flatten)
139       end
140     end
141   
142     class DomainConstraint < Gecode::ReifiableConstraint #:nodoc:
143       def post
144         var, domain, reif_var, relation = @params.values_at(:lhs, :rhs, :reif, 
145           :relation)
146         
147         (params = []) << var.to_set_var.bind
148         params << Gecode::Util::SET_RELATION_TYPES[relation]
149         params << Gecode::Util.constant_set_to_params(domain)
150         params << reif_var.to_bool_var.bind if reif_var.respond_to? :to_bool_var
151         Gecode::Raw::dom(@model.active_space, *params.flatten)
152       end
153       negate_using_reification
154     end
155   end
156 end

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