File: split_spec.rb

package info (click to toggle)
jruby 1.7.26-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 84,572 kB
  • sloc: ruby: 669,910; java: 253,056; xml: 35,152; ansic: 9,187; yacc: 7,267; cpp: 5,244; sh: 1,036; makefile: 345; jsp: 48; tcl: 40
file content (88 lines) | stat: -rw-r--r-- 3,258 bytes parent folder | download
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require File.expand_path('../../../spec_helper', __FILE__)
require 'bigdecimal'

describe "BigDecimal#split" do

  before(:each) do
    @arr = BigDecimal("0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1").split
    @arr_neg = BigDecimal("-0.314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043E1").split
    @digits = "922337203685477580810101333333333333333333333333333"
    @arr_big = BigDecimal("00#{@digits}000").split
    @arr_big_neg = BigDecimal("-00#{@digits}000").split
    @huge = BigDecimal('100000000000000000000000000000000000000000001E90000000').split

    @infinity = BigDecimal("Infinity")
    @infinity_neg = BigDecimal("-Infinity")
    @nan = BigDecimal("NaN")
    @zero = BigDecimal("0")
    @zero_neg = BigDecimal("-0")
  end

  it "splits BigDecimal in an array with four values" do
    @arr.size.should == 4
  end

  it "First value: 1 for numbers > 0" do
    @arr[0].should == 1
    @arr_big[0].should == 1
    @zero.split[0].should == 1
    @huge[0].should == 1
    BigDecimal("+0").split[0].should == 1
    BigDecimal("1E400").split[0].should == 1
    @infinity.split[0].should == 1
  end

  it "First value: -1 for numbers < 0" do
    @arr_neg[0].should == -1
    @arr_big_neg[0].should == -1
    @zero_neg.split[0].should == -1
    BigDecimal("-1E400").split[0].should == -1
    @infinity_neg.split[0].should == -1
  end

  it "First value: 0 if BigDecimal is NaN" do
    BigDecimal("NaN").split[0].should == 0
  end

  it "Second value: a string with the significant digits" do
    string = "314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593014782083152134043"
    @arr[1].should == string
    @arr_big[1].should == @digits
    @arr_big_neg[1].should == @digits
    @huge[1].should == "100000000000000000000000000000000000000000001"
    @infinity.split[1].should == @infinity.to_s
    @nan.split[1].should == @nan.to_s
    @infinity_neg.split[1].should == @infinity.to_s
    @zero.split[1].should == "0"
    BigDecimal("-0").split[1].should == "0"
  end

  it "Third value: the base (currently always ten)" do
   @arr[2].should == 10
   @arr_neg[2].should == 10
   @arr_big[2].should == 10
   @arr_big_neg[2].should == 10
   @huge[2].should == 10
   @infinity.split[2].should == 10
   @nan.split[2].should == 10
   @infinity_neg.split[2].should == 10
   @zero.split[2].should == 10
   @zero_neg.split[2].should == 10
  end

  it "Fourth value: The exponent" do
    @arr[3].should == 1
    @arr_neg[3].should == 1
    @arr_big[3].should == 54
    @arr_big_neg[3].should == 54
    @huge[3].should == 90000045
    @infinity.split[3].should == 0
    @nan.split[3].should == 0
    @infinity_neg.split[3].should == 0
    @zero.split[3].should == 0
    @zero_neg.split[3].should == 0
  end

end