-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_float_extensions.rb
More file actions
33 lines (27 loc) · 893 Bytes
/
test_float_extensions.rb
File metadata and controls
33 lines (27 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require File.dirname(__FILE__) + '/test_helper.rb'
class TestFloatExtensions < Test::Unit::TestCase
context "fractional_part?" do
should "return true for a number with a fractional part" do
n = 1.249
assert n.fractional_part?
end
should "return true for a number without a fractional part" do
n = 1.0
assert !n.fractional_part?
end
end
context "fractional_part" do
should "return the decimal parts for a number" do
n = 12.2456
assert_in_delta 0.2456, n.fractional_part, 0.00000001
end
should "return the decimal parts, even if they are 0" do
n = 12.0
assert_equal 0.0, n.fractional_part
end
should "return the decimal as a positive number, even if the original float is negative" do
n = -12.2399
assert_in_delta 0.2399, n.fractional_part, 0.00000001
end
end
end