C0 code coverage information
Generated on Thu Jun 07 11:34:00 -0400 2007 with rcov 0.8.0
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.
Name |
Total lines |
Lines of code |
Total coverage |
Code coverage |
lib/round_to.rb
|
73
|
16
|
|
|
1
2
3 class Float
4
5 # Rounds to the nearest _n_th degree.
6 #
7 # 4.555.round_to(1) #=> 5.0
8 # 4.555.round_to(0.1) #=> 4.6
9 # 4.555.round_to(0.01) #=> 4.56
10 # 4.555.round_to(0) #=> 4.555
11 #
12 def round_to( n ) #n=1
13 return self if n == 0
14 (self * (1.0 / n)).round_off.to_f / (1.0 / n)
15 end
16 end
17
18 class Numeric
19 # To properly support Float's rounding methods,
20 # Numeric must also be augmented.
21 def round_to(*args)
22 self.to_f.round_to(*args)
23 end
24 end
25
26 class Integer
27 # To properly support Float's rounding methods,
28 # Integer must also be augmented.
29 def round_to(*args)
30 self.to_f.round_to(*args)
31 end
32 end
33
34
35 # _____ _
36 # |_ _|__ ___| |_
37 # | |/ _ \/ __| __|
38 # | | __/\__ \ |_
39 # |_|\___||___/\__|
40 #
41 =begin
42
43 require 'test/unit'
44
45 class TCFloat < Test::Unit::TestCase
46
47 def setup
48 @f0 = [ 0, 10, 15, 105 ]
49 @f1 = [ 10.1, 10.01, 10.9, 10.09, 10.5, 10.05, 10.49 ]
50 end
51
52 def test_round_to_arg1
53 fr = @f0.collect { |f| f.round_to(0.1) }
54 assert_equal( [0,10,15,105], fr )
55 fr = @f1.collect { |f| f.round_to(0.1) }
56 assert_equal( [10.1,10.0,10.9,10.1,10.5,10.1,10.5], fr )
57 end
58
59 def test_round_to_arg10
60 fr = @f0.collect { |f| f.round_to(10) }
61 assert_equal( [0,10,20,110], fr )
62 fr = @f1.collect { |f| f.round_to(10) }
63 assert_equal( [10,10,10,10,10,10,10], fr )
64 end
65
66 def test_round_off
67 assert_equal( 1.0, 1.2.round_off )
68 assert_equal( 2.0, 1.8.round_off )
69 end
70
71 end
72
73 =end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.