Skip to content

Commit a8387ae

Browse files
committed
Add specs for the various methods defined on classes when 'bigdecimal/util' is required.
1 parent 07e8e7b commit a8387ae

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require_relative '../../spec_helper'
2+
require 'bigdecimal'
3+
require 'bigdecimal/util'
4+
5+
describe "BigDecimal's util method definitions" do
6+
7+
describe "#to_d" do
8+
9+
it "should define #to_d on Integer" do
10+
42.to_d.should == BigDecimal(42)
11+
end
12+
13+
it "should define #to_d on Float" do
14+
0.5.to_d.should == BigDecimal(0.5, Float::DIG)
15+
1.234.to_d(2).should == BigDecimal(1.234, 2)
16+
end
17+
18+
it "should define #to_d on String" do
19+
"0.5".to_d.should == BigDecimal(0.5, Float::DIG)
20+
"45.67 degrees".to_d.should == BigDecimal(45.67, Float::DIG)
21+
end
22+
23+
it "should define #to_d on BigDecimal" do
24+
bd = BigDecimal("3.14")
25+
bd.to_d.should equal(bd)
26+
end
27+
28+
it "should define #to_d on Rational" do
29+
Rational(22, 7).to_d(3).should == BigDecimal(3.14, 3)
30+
end
31+
32+
it "should define #to_d on nil" do
33+
nil.to_d.should == BigDecimal(0)
34+
end
35+
36+
end
37+
38+
describe "#to_digits" do
39+
40+
it "should define #to_digits on BigDecimal" do
41+
BigDecimal("3.14").to_digits.should == "3.14"
42+
end
43+
44+
end
45+
end

0 commit comments

Comments
 (0)