Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 124 lines (97 sloc) 2.404 kB
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
1 ##
2 # Float ISO Test
3
4 assert('Float', '15.2.9') do
5 Float.class == Class
6 end
7
0c2d740 @bovi Add more superclass tests
bovi authored
8 assert('Float superclass', '15.2.9.2') do
9 Float.superclass == Numeric
10 end
11
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
12 assert('Float#+', '15.2.9.3.1') do
13 a = 3.123456788 + 0.000000001
14 b = 3.123456789 + 1
15
52b2d09 @matz test t/*.rb spacing fix
matz authored
16 check_float(a, 3.123456789) and
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
17 check_float(b, 4.123456789)
18 end
19
20 assert('Float#-', '15.2.9.3.2') do
21 a = 3.123456790 - 0.000000001
22 b = 5.123456789 - 1
23
52b2d09 @matz test t/*.rb spacing fix
matz authored
24 check_float(a, 3.123456789) and
25 check_float(b, 4.123456789)
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
26 end
27
28 assert('Float#*', '15.2.9.3.3') do
0270d11 @matz float do not have enough precision to round if MRB_USE_FLOAT is set
matz authored
29 a = 3.125 * 3.125
30 b = 3.125 * 1
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
31
0270d11 @matz float do not have enough precision to round if MRB_USE_FLOAT is set
matz authored
32 check_float(a, 9.765625) and
33 check_float(b, 3.125)
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
34 end
35
36 assert('Float#/', '15.2.9.3.4') do
37 a = 3.123456789 / 3.123456789
38 b = 3.123456789 / 1
39
40 check_float(a, 1.0) and
41 check_float(b, 3.123456789)
42 end
43
44 assert('Float#%', '15.2.9.3.5') do
0270d11 @matz float do not have enough precision to round if MRB_USE_FLOAT is set
matz authored
45 a = 3.125 % 3.125
46 b = 3.125 % 1
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
47
48 check_float(a, 0.0) and
0270d11 @matz float do not have enough precision to round if MRB_USE_FLOAT is set
matz authored
49 check_float(b, 0.125)
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
50 end
51
52 assert('Float#<=>', '15.2.9.3.6') do
0270d11 @matz float do not have enough precision to round if MRB_USE_FLOAT is set
matz authored
53 a = 3.125 <=> 3.123
54 b = 3.125 <=> 3.125
55 c = 3.125 <=> 3.126
56 a2 = 3.125 <=> 3
57 c2 = 3.125 <=> 4
52b2d09 @matz test t/*.rb spacing fix
matz authored
58
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
59 a == 1 and b == 0 and c == -1 and
60 a2 == 1 and c2 == -1
61 end
62
63 assert('Float#==', '15.2.9.3.7') do
52b2d09 @matz test t/*.rb spacing fix
matz authored
64 3.1 == 3.1 and not 3.1 == 3.2
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
65 end
66
67 assert('Float#ceil', '15.2.9.3.8') do
9dd3ac3 @akuroda add test cases for floor, inifinite?, truncate, ceil, and round
akuroda authored
68 a = 3.123456789.ceil
69 b = 3.0.ceil
70 c = -3.123456789.ceil
71 d = -3.0.ceil
72 a == 4 and b == 3 and c == -3 and d == -3
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
73 end
74
75 assert('Float#finite?', '15.2.9.3.9') do
76 3.123456789.finite? and
77 not (1.0 / 0.0).finite?
78 end
79
80 assert('Float#floor', '15.2.9.3.10') do
9dd3ac3 @akuroda add test cases for floor, inifinite?, truncate, ceil, and round
akuroda authored
81 a = 3.123456789.floor
82 b = 3.0.floor
83 c = -3.123456789.floor
84 d = -3.0.floor
85 a == 3 and b == 3 and c == -4 and d == -3
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
86 end
87
88 assert('Float#infinite?', '15.2.9.3.11') do
9dd3ac3 @akuroda add test cases for floor, inifinite?, truncate, ceil, and round
akuroda authored
89 a = 3.123456789.infinite?
90 b = (1.0 / 0.0).infinite?
91 c = (-1.0 / 0.0).infinite?
92
93 a == nil and b == 1 and c == -1
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
94 end
95
96 assert('Float#round', '15.2.9.3.12') do
97 a = 3.123456789.round
98 b = 3.5.round
0270d11 @matz float do not have enough precision to round if MRB_USE_FLOAT is set
matz authored
99 c = 3.4999.round
9dd3ac3 @akuroda add test cases for floor, inifinite?, truncate, ceil, and round
akuroda authored
100 d = (-3.123456789).round
101 e = (-3.5).round
102 f = 12345.67.round(-1)
0270d11 @matz float do not have enough precision to round if MRB_USE_FLOAT is set
matz authored
103 g = 3.423456789.round(0)
104 h = 3.423456789.round(1)
105 i = 3.423456789.round(3)
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
106
9dd3ac3 @akuroda add test cases for floor, inifinite?, truncate, ceil, and round
akuroda authored
107 a == 3 and b == 4 and c == 3 and d == -3 and e == -4 and
0270d11 @matz float do not have enough precision to round if MRB_USE_FLOAT is set
matz authored
108 f == 12350 and g == 3 and h == 3.4 and i == 3.423
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
109 end
110
111 assert('Float#to_f', '15.2.9.3.13') do
112 a = 3.123456789
113
114 check_float(a.to_f, a)
115 end
116
117 assert('Float#to_i', '15.2.9.3.14') do
118 3.123456789.to_i == 3
119 end
120
121 assert('Float#truncate', '15.2.9.3.15') do
9dd3ac3 @akuroda add test cases for floor, inifinite?, truncate, ceil, and round
akuroda authored
122 3.123456789.truncate == 3 and -3.1.truncate == -3
8bf21cd @bovi Finish all Float ISO Tests
bovi authored
123 end
Something went wrong with that request. Please try again.