Change soft-fail to use the config, rather than env
[rbx.git] / spec / frozen / 1.8 / library / bigdecimal / gte_spec.rb
blobaa1de95121a8a842a6ca7e9e3e95e9ccf5a78bae
1 require File.dirname(__FILE__) + '/../../spec_helper'
2 require 'bigdecimal'
4 describe "BigDecimal#>=" do
5   before(:each) 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')
16     class << @int_mock
17       def coerce(other)
18         return [other, BigDecimal('123')]
19       end
20       def >= (other)
21         BigDecimal('123') >= other
22       end
23     end
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")
32   end
34   it "returns true if a >= b" do
35     one = BigDecimal("1")
36     two = BigDecimal("2")
38     frac_1 = BigDecimal("1E-99999")
39     frac_2 = BigDecimal("0.9E-99999")
41     (@zero >= one).should == false
42     (two >= @zero).should == true
44     (frac_2 >= frac_1).should == false
45     (two >= two).should == true
46     (frac_1 >= frac_1).should == true
48     (@neg_int >= @pos_int).should == false
49     (@pos_int >= @neg_int).should == true
50     (@neg_int >= @pos_frac).should == false
51     (@pos_frac >= @neg_int).should == true
52     (@zero >= @zero_pos).should == true
53     (@zero >= @zero_neg).should == true
54     (@zero_neg >= @zero_pos).should == true
55     (@zero_pos >= @zero_neg).should == true
56   end
58   it "properly handles infinity values" do
59     @values.each { |val|
60       (val >= @infinity).should == false
61       (@infinity >= val).should == true
62       (val >= @infinity_neg).should == true
63       (@infinity_neg >= val).should == false
64     }
65     (@infinity >= @infinity).should == true
66     (@infinity_neg >= @infinity_neg).should == true
67     (@infinity >= @infinity_neg).should == true
68     (@infinity_neg >= @infinity).should == false
69   end
71   it "properly handles NaN values" do
72     @values += [@infinity, @infinity_neg, @nan]
73     @values << nil
74     @values << Object.new
75     @values.each { |val|
76       (@nan >= val).should == nil
77     }
79     lambda { 10 >= @nan }.should raise_error(ArgumentError)
80     (10.5 >= @nan).should == false
82     (@infinity >= @nan).should == nil
83     (@infinity_neg >= @nan).should == nil
84     (@zero >= @nan).should == nil
85   end
87   it "returns nil if the argument is nil" do
88     (@zero >= nil).should == nil
89     (@infinity >= nil).should == nil
90     (@infinity_neg >= nil).should == nil
91     (@mixed >= nil).should == nil
92     (@pos_int >= nil).should == nil
93     (@neg_frac >= nil).should == nil
94   end
95 end