Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/gecoder/interface/constraints/fixnum_enum/element.rb | 63 | 44 | 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::FixnumEnum |
2 module FixnumEnumOperand |
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(enum_mod) #:nodoc: |
7 enum_mod.module_eval do |
8 # Now we enter the module FixnumEnumOperands is mixed into. |
9 class << self |
10 alias_method :pre_element_included, :included |
11 def included(mod) #:nodoc: |
12 mod.module_eval do |
13 if instance_methods.include? '[]' |
14 alias_method :pre_element_access, :[] |
15 end |
16 |
17 # Produces an IntOperand representing the |
18 # i:th constant integer in the enumeration, where i is the |
19 # value of the integer operand used as index. Think of it |
20 # as array access in the world of constraint programming. |
21 # |
22 # ==== Examples |
23 # |
24 # # The price of +selected_item+ as described by +prices+ . |
25 # prices = wrap_enum([500, 24, 4711, 412, 24]) |
26 # prices[selected_item] |
27 # |
28 def [](*vars) |
29 if vars.first.respond_to? :to_int_var |
30 return Element::ElementIntOperand.new( |
31 self, vars.first, model) |
32 else |
33 pre_element_access(*vars) if respond_to? :pre_element_access |
34 end |
35 end |
36 end |
37 pre_element_included(mod) |
38 end |
39 end |
40 end |
41 end |
42 end |
43 |
44 module Element #:nodoc: |
45 class ElementIntOperand < Gecode::Int::ShortCircuitEqualityOperand #:nodoc: |
46 def initialize(enum_op, position_int_var_op, model) |
47 super model |
48 @enum = enum_op |
49 @position = position_int_var_op |
50 end |
51 |
52 def constrain_equal(int_operand, constrain, propagation_options) |
53 if constrain |
54 int_operand.must_be.in @enum |
55 end |
56 |
57 Gecode::Raw::element(@model.active_space, @enum, |
58 @position.to_int_var.bind, int_operand.to_int_var.bind, |
59 *propagation_options) |
60 end |
61 end |
62 end |
63 end |
Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0