Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/gecoder/interface/constraints/set_enum/element.rb | 79 | 50 | 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::SetEnum |
2 module SetEnumOperand |
3 # This adds the adder for the methods in the modules including it. The |
4 # reason for doing it so indirect is that the first #[] won't be defined |
5 # before the module that this is mixed into is mixed into an enum. |
6 def self.included(mod) #:nodoc: |
7 mod.module_eval do |
8 # Now we enter the module SetEnumOperands is mixed into. |
9 class << self |
10 alias_method :pre_set_element_included, :included |
11 def included(mod) #:nodoc: |
12 mod.module_eval do |
13 # Now we enter the module that the module possibly defining #[] |
14 # is mixed into. |
15 if instance_methods.include?('[]') and |
16 not instance_methods.include?('pre_set_element_access') |
17 alias_method :pre_set_element_access, :[] |
18 end |
19 |
20 # Produces a SetOperand representing the i:th set |
21 # operand in the enumeration, where i is the value of the |
22 # int operand used as index. |
23 # |
24 # A set can also be used as index, in which case a |
25 # SelectedSetOperand is produced. |
26 # |
27 # ==== Examples |
28 # |
29 # # The set operand at the +x+:th position in +set_enum+, |
30 # # where +x+ is a int operand. |
31 # set_enum[x] |
32 # |
33 # # The SelectedSetOperand representing sets at positions |
34 # # included in the value of +set+ in +set_enum+, |
35 # set_enum[set] |
36 # |
37 def [](*vars) |
38 # Hook in an element constraint if a operand is used for array |
39 # access. |
40 if vars.first.respond_to? :to_int_var |
41 Element::ElementSetOperand.new( |
42 model, self, vars.first) |
43 elsif vars.first.respond_to? :to_set_var |
44 Gecode::SelectedSet::SelectedSetOperand.new( |
45 self, vars.first) |
46 else |
47 if respond_to? :pre_set_element_access |
48 pre_set_element_access(*vars) |
49 end |
50 end |
51 end |
52 end |
53 pre_set_element_included(mod) |
54 end |
55 end |
56 end |
57 end |
58 end |
59 |
60 module Element #:nodoc: |
61 class ElementSetOperand < Gecode::Set::ShortCircuitEqualityOperand #:nodoc: |
62 def initialize(model, enum_op, position_int_op) |
63 super model |
64 @enum = enum_op |
65 @position = position_int_op |
66 end |
67 |
68 def constrain_equal(set_operand, constrain, propagation_options) |
69 enum = @enum.to_set_enum |
70 if constrain |
71 set_operand.must_be.subset_of enum.upper_bound_range |
72 end |
73 |
74 Gecode::Raw::element(@model.active_space, enum.bind_array, |
75 @position.to_int_var.bind, set_operand.to_set_var.bind) |
76 end |
77 end |
78 end |
79 end |
Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0