Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/gecoder/interface/constraints/set_elements/relation.rb | 116 | 53 | 100.00%
|
100.00%
|
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.
1 module Gecode::SetElements |
2 class SetElementsConstraintReceiver |
3 # Constrains the set elements to equal +operand+ (either a |
4 # constant integer or an integer operand). |
5 # |
6 # ==== Examples |
7 # |
8 # # The elements of +set+ must equal +int+ |
9 # set.elements.must == int |
10 # |
11 # # The elements of +set+ must equal 17 |
12 # set.elements.must == 17 |
13 def ==(operand, options = {}) |
14 comparison(:==, operand, options) |
15 end |
16 |
17 # Constrains the set elements to be strictly greater than |
18 # +operand+ (either a constant integer or an integer operand). |
19 # |
20 # ==== Examples |
21 # |
22 # # The elements of +set+ must be strictly greater than +int+ |
23 # set.elements.must > int |
24 # |
25 # # The elements of +set+ must be strictly greater than 17 |
26 # set.elements.must > 17 |
27 def >(operand, options = {}) |
28 comparison(:>, operand, options) |
29 end |
30 |
31 # Constrains the set elements to be greater than or equal to |
32 # +operand+ (either a constant integer or an integer operand). |
33 # |
34 # ==== Examples |
35 # |
36 # # The elements of +set+ must be greater than or equal to +int+ |
37 # set.elements.must >= int |
38 # |
39 # # The elements of +set+ must be greater than or equal to 17 |
40 # set.elements.must >= 17 |
41 def >=(operand, options = {}) |
42 comparison(:>=, operand, options) |
43 end |
44 |
45 # Constrains the set elements to be strictly less than |
46 # +operand+ (either a constant integer or an integer operand). |
47 # |
48 # ==== Examples |
49 # |
50 # # The elements of +set+ must be strictly less than +int+ |
51 # set.elements.must < int |
52 # |
53 # # The elements of +set+ must be strictly less than 17 |
54 # set.elements.must < 17 |
55 def <(operand, options = {}) |
56 comparison(:<, operand, options) |
57 end |
58 |
59 # Constrains the set elements to be less than or equal to |
60 # +operand+ (either a constant integer or an integer operand). |
61 # |
62 # ==== Examples |
63 # |
64 # # The elements of +set+ must be less than or equal to +int+ |
65 # set.elements.must <= int |
66 # |
67 # # The elements of +set+ must be less than or equal to 17 |
68 # set.elements.must <= 17 |
69 def <=(operand, options = {}) |
70 comparison(:<=, operand, options) |
71 end |
72 |
73 alias_comparison_methods |
74 |
75 private |
76 |
77 # Helper for the comparison methods. The reason that they are not |
78 # generated in a loop is that it would mess up the RDoc. |
79 def comparison(name, operand, options) |
80 unless operand.respond_to?(:to_int_var) or |
81 operand.kind_of?(Fixnum) |
82 raise TypeError, "Expected int operand or integer, got " + |
83 "#{operand.class}." |
84 end |
85 unless options[:reify].nil? |
86 raise ArgumentError, 'Reification is not supported by the elements ' + |
87 'relation constraint.' |
88 end |
89 |
90 unless @params[:negate] |
91 relation_type = Gecode::Util::RELATION_TYPES[name] |
92 else |
93 relation_type = Gecode::Util::NEGATED_RELATION_TYPES[name] |
94 end |
95 @params.update Gecode::Set::Util.decode_options(options) |
96 @model.add_constraint Relation::RelationConstraint.new(@model, |
97 @params.update(:relation_type => relation_type, :rhs => operand)) |
98 end |
99 end |
100 |
101 module Relation #:nodoc: |
102 class RelationConstraint < Gecode::Constraint #:nodoc: |
103 def post |
104 set_elements, rhs, type = @params.values_at(:lhs, :rhs, :relation_type) |
105 set = set_elements.to_set_elements |
106 |
107 if rhs.kind_of? Fixnum |
108 # Use a proxy int variable to cover. |
109 rhs = @model.int_var(rhs) |
110 end |
111 Gecode::Raw::rel(@model.active_space, set.to_set_var.bind, |
112 type, rhs.to_int_var.bind) |
113 end |
114 end |
115 end |
116 end |
Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0