1 require File.dirname(__FILE__) + '/../../spec_helper'
4 describe "BigDecimal#>" do
6 @zero = BigDecimal("0")
7 @zero_pos = BigDecimal("+0")
8 @zero_neg = BigDecimal("-0")
9 @mixed = BigDecimal("1.23456789")
10 @pos_int = BigDecimal("2E5555")
11 @neg_int = BigDecimal("-2E5555")
12 @pos_frac = BigDecimal("2E-9999")
13 @neg_frac = BigDecimal("-2E-9999")
15 @int_mock = mock('123')
18 return [other, BigDecimal('123')]
21 BigDecimal('123') > other
25 @values = [@mixed, @pos_int, @neg_int, @pos_frac, @neg_frac,
26 -2**32, -2**31, -2**30, -2**16, -2**8, -100, -10, -1,
27 @zero , 1, 2, 10, 2**8, 2**16, 2**32, @int_mock, @zero_pos, @zero_neg]
29 @infinity = BigDecimal("Infinity")
30 @infinity_neg = BigDecimal("-Infinity")
31 @nan = BigDecimal("NaN")
34 it "returns true if a > b" do
38 frac_1 = BigDecimal("1E-99999")
39 frac_2 = BigDecimal("0.9E-99999")
40 (@zero > one).should == false
41 (two > @zero).should == true
42 (frac_2 > frac_1).should == false
44 (@neg_int > @pos_int).should == false
45 (@pos_int > @neg_int).should == true
46 (@neg_int > @pos_frac).should == false
47 (@pos_frac > @neg_int).should == true
48 (@zero > @zero_pos).should == false
49 (@zero > @zero_neg).should == false
50 (@zero_neg > @zero_pos).should == false
51 (@zero_pos > @zero_neg).should == false
54 it "properly handles infinity values" do
56 (val > @infinity).should == false
57 (@infinity > val).should == true
58 (val > @infinity_neg).should == true
59 (@infinity_neg > val).should == false
61 (@infinity > @infinity).should == false
62 (@infinity_neg > @infinity_neg).should == false
63 (@infinity > @infinity_neg).should == true
64 (@infinity_neg > @infinity).should == false
67 it "properly handles NaN values" do
68 @values += [@infinity, @infinity_neg, @nan]
72 (@nan > val).should == nil
75 lambda { 10 > @nan }.should raise_error(ArgumentError)
76 (10.5 > @nan).should == false
78 (@infinity > @nan).should == nil
79 (@infinity_neg > @nan).should == nil
80 (@zero > @nan).should == nil
83 it "returns nil if the argument is nil" do
84 (@zero > nil).should == nil
85 (@infinity > nil).should == nil
86 (@infinity_neg > nil).should == nil
87 (@mixed > nil).should == nil
88 (@pos_int > nil).should == nil
89 (@neg_frac > nil).should == nil