Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/jldrill/model/Quiz/Counter.rb | 92 | 81 | 86.96%
|
85.19%
|
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 'jldrill/model/Quiz/Schedule' |
2 |
3 module JLDrill |
4 class Counter |
5 attr_reader :ranges, :table |
6 |
7 def initialize |
8 @ranges = makeRanges |
9 @table = initializeTable |
10 end |
11 |
12 def initializeTable |
13 retVal = [] |
14 0.upto(7) do |level| |
15 retVal.push(0) |
16 end |
17 return retVal |
18 end |
19 |
20 def makeRanges |
21 retVal = [] |
22 0.upto(6) do |level| |
23 retVal.push(Counter.findRange(level)) |
24 end |
25 return retVal |
26 end |
27 |
28 def Counter.findRange(level) |
29 low = Duration.new(0) |
30 high = Duration.new |
31 high.days = 5.0 |
32 1.upto(level) do |
33 low.assign(high) |
34 high.seconds = Schedule.backoff(low.seconds) |
35 end |
36 return low.seconds...high.seconds |
37 end |
38 |
39 def Counter.getLevel(item) |
40 level = 0 |
41 found = false |
42 while (level <= 6) && !found |
43 range = Counter.findRange(level) |
44 if item.schedule.durationWithin?(range) |
45 found = true |
46 else |
47 level += 1 |
48 end |
49 end |
50 return level |
51 end |
52 |
53 # Returns the rounded number of days from seconds |
54 def toDays(seconds) |
55 d = Duration.new(seconds) |
56 return d.days.round |
57 end |
58 |
59 def levelString(level) |
60 if level == 0 |
61 return "Less than #{toDays(@ranges[0].end)} days" |
62 elsif level == 7 |
63 return "More than #{toDays(@ranges[6].end)} days" |
64 else |
65 return "#{toDays(@ranges[level].begin)} to #{toDays(@ranges[level].end)} days" |
66 end |
67 end |
68 |
69 def to_s |
70 retVal = "" |
71 0.upto(7) do |i| |
72 retVal = retVal + levelString(i) + " #{@table[i]}\n" |
73 end |
74 return retVal |
75 end |
76 end |
77 |
78 class DurationCounter < Counter |
79 def count(item) |
80 found = false |
81 0.upto(6) do |level| |
82 if !found && item.schedule.durationWithin?(@ranges[level]) |
83 @table[level] += 1 |
84 found = true |
85 end |
86 end |
87 if !found |
88 @table[7] += 1 |
89 end |
90 end |
91 end |
92 end |
Generated on Mon May 23 16:17:46 +0900 2011 with rcov 0.9.8