Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/gecoder/interface/enum_matrix.rb | 64 | 48 | 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 require 'matrix' |
2 |
3 module Gecode::Util #:nodoc: |
4 # Methods that make a matrix an enumerable. |
5 module MatrixEnumMethods #:nodoc: |
6 include Enumerable |
7 |
8 # Iterates over every element in the matrix. |
9 def each(&block) |
10 row_size.times do |i| |
11 column_size.times do |j| |
12 yield self[i,j] |
13 end |
14 end |
15 end |
16 end |
17 |
18 # Extends Matrix so that it's an enumerable. |
19 class EnumMatrix < Matrix #:nodoc: |
20 include MatrixEnumMethods |
21 |
22 def row(i) |
23 wrap_if_wrapped make_vector_enumerable(super) |
24 end |
25 |
26 def column(i) |
27 wrap_if_wrapped make_vector_enumerable(super) |
28 end |
29 |
30 def minor(*args) |
31 matrix = super |
32 class <<matrix |
33 include MatrixEnumMethods |
34 end |
35 return wrap_if_wrapped(matrix) |
36 end |
37 |
38 private |
39 |
40 # Makes the specified vector enumerable. |
41 def make_vector_enumerable(vector) |
42 class <<vector |
43 include Enumerable |
44 |
45 # Iterates over every element in the matrix. |
46 def each(&block) |
47 size.times do |i| |
48 yield self[i] |
49 end |
50 end |
51 end |
52 return vector |
53 end |
54 |
55 # Wraps the specified enumerable if the matrix itself is already wrapped. |
56 def wrap_if_wrapped(enum) |
57 if respond_to? :model |
58 model.wrap_enum(enum) |
59 else |
60 enum |
61 end |
62 end |
63 end |
64 end |
Generated on Thu Jan 08 13:27:03 +0100 2015 with rcov 1.0.0