File: eql.rb

package info (click to toggle)
ruby2.7 2.7.4-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,576 kB
  • sloc: ruby: 849,454; ansic: 697,834; yacc: 45,100; xml: 25,367; pascal: 10,051; javascript: 6,575; sh: 3,848; makefile: 759; cpp: 713; asm: 333; python: 295; lisp: 97; sed: 94; perl: 62; awk: 36
file content (61 lines) | stat: -rw-r--r-- 2,322 bytes parent folder | download | duplicates (7)
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
require 'bigdecimal'

describe :bigdecimal_eql, shared: true do
  before :each do
    @bg6543_21 = BigDecimal("6543.21")
    @bg5667_19 = BigDecimal("5667.19")
    @a = BigDecimal("1.0000000000000000000000000000000000000000005")
    @b = BigDecimal("1.00000000000000000000000000000000000000000005")
    @bigint = BigDecimal("1000.0")
    @nan = BigDecimal("NaN")
    @infinity = BigDecimal("Infinity")
    @infinity_minus = BigDecimal("-Infinity")
  end

  it "tests for equality" do
    @bg6543_21.send(@method, @bg6543_21).should == true
    @a.send(@method, @a).should == true
    @a.send(@method, @b).should == false
    @bg6543_21.send(@method, @a).should == false
    @bigint.send(@method, 1000).should == true
  end

  it "returns false for NaN as it is never equal to any number" do
    @nan.send(@method, @nan).should == false
    @a.send(@method, @nan).should == false
    @nan.send(@method, @a).should == false
    @nan.send(@method, @infinity).should == false
    @nan.send(@method, @infinity_minus).should == false
    @infinity.send(@method, @nan).should == false
    @infinity_minus.send(@method, @nan).should == false
  end

  it "returns true for infinity values with the same sign" do
    @infinity.send(@method, @infinity).should == true
    @infinity.send(@method, BigDecimal("Infinity")).should == true
    BigDecimal("Infinity").send(@method, @infinity).should == true

    @infinity_minus.send(@method, @infinity_minus).should == true
    @infinity_minus.send(@method, BigDecimal("-Infinity")).should == true
    BigDecimal("-Infinity").send(@method, @infinity_minus).should == true
  end

  it "returns false for infinity values with different signs" do
    @infinity.send(@method, @infinity_minus).should == false
    @infinity_minus.send(@method, @infinity).should == false
  end

  it "returns false when infinite value compared to finite one" do
    @infinity.send(@method, @a).should == false
    @infinity_minus.send(@method, @a).should == false

    @a.send(@method, @infinity).should == false
    @a.send(@method, @infinity_minus).should == false
  end

  it "returns false when compared objects that can not be coerced into BigDecimal" do
    @infinity.send(@method, nil).should == false
    @bigint.send(@method, nil).should == false
    @nan.send(@method, nil).should == false
  end
end