File tree Expand file tree Collapse file tree 1 file changed +45
-0
lines changed
spec/ruby/library/bigdecimal Expand file tree Collapse file tree 1 file changed +45
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments