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