File: minus_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 (58 lines) | stat: -rw-r--r-- 1,909 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
require File.expand_path('../../../spec_helper', __FILE__)
require 'bigdecimal'

describe "BigDecimal#-" do

  before(:each) do
    @one = BigDecimal("1")
    @zero = BigDecimal("0")
    @two = BigDecimal("2")
    @nan = BigDecimal("NaN")
    @infinity = BigDecimal("Infinity")
    @infinity_minus = BigDecimal("-Infinity")
    @one_minus = BigDecimal("-1")
    @frac_1 = BigDecimal("1E-99999")
    @frac_2 = BigDecimal("0.9E-99999")
  end

  it "returns a - b" do
    (@two - @one).should == @one
    (@one - @two).should == @one_minus
    (@one - @one_minus).should == @two
    (@frac_2 - @frac_1).should == BigDecimal("-0.1E-99999")
    (@two - @two).should == @zero
    (@frac_1 - @frac_1).should == @zero
    (BigDecimal('1.23456789') - BigDecimal('1.2')).should == BigDecimal("0.03456789")
  end

  it "returns NaN if NaN is involved" do
    (@one - @nan).nan?.should == true
    (@nan - @one).nan?.should == true
    (@nan - @nan).nan?.should == true
    (@nan - @infinity).nan?.should == true
    (@nan - @infinity_minus).nan?.should == true
    (@infinity - @nan).nan?.should == true
    (@infinity_minus - @nan).nan?.should == true
  end

  it "returns NaN both operands are infinite with the same sign" do
    (@infinity - @infinity).nan?.should == true
    (@infinity_minus - @infinity_minus).nan?.should == true
  end

  it "returns Infinity or -Infinity if these are involved" do
    (@infinity - @infinity_minus).should == @infinity
    (@infinity_minus - @infinity).should == @infinity_minus

    (@infinity - @zero).should == @infinity
    (@infinity - @frac_2).should == @infinity
    (@infinity - @two).should == @infinity
    (@infinity - @one_minus).should == @infinity

    (@zero - @infinity).should == @infinity_minus
    (@frac_2 - @infinity).should == @infinity_minus
    (@two - @infinity).should == @infinity_minus
    (@one_minus - @infinity).should == @infinity_minus
  end

end