Sha256: 45a685192d25fffe6d5643182d2218adb661e67cae9be294a1b633413012239f

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__),'helper.rb'))

class TestComparisons < Minitest::Test


  def setup
    initialize_context
  end

  def test_hash
    assert_equal DecNum('1.1').hash, DecNum('1.1').hash
    assert_equal DecNum('1.1').hash, (DecNum('1.0')+DecNum('0.1')).hash
    assert_equal DecNum('1.1',:precision=>10).hash, DecNum('1.1',:precision=>3).hash
    refute_equal DecNum('1.0').hash, DecNum('1.1').hash
    refute_equal DecNum('1.0').hash, 1.0.hash
    refute_equal DecNum('1.0').hash, 1.hash

    assert DecNum('1.1').eql?(DecNum('1.1'))
    assert DecNum('1.1').eql?(DecNum('1.0')+DecNum('0.1'))
    assert DecNum('1.1',:precision=>10).eql?(DecNum('1.1',:precision=>3))
    assert !DecNum('1.1').eql?(DecNum('1.0'))
    assert !DecNum('1.0').eql?(1.0)
    assert !DecNum('1.0').eql?(1)
  end

  def test_equality
    assert DecNum('1.1') == DecNum('1.1')
    assert DecNum('1.1') == (DecNum('1.0')+DecNum('0.1'))
    assert DecNum('1.1',:precision=>10) == DecNum('1.1',:precision=>3)
    assert !(DecNum('1.1') == DecNum('1.0'))
    #assert DecNum('1.1') == 1.1
    #assert DecNum('1.0') == 1.0
    #assert DecNum('1.0') == BigDecimal('1.000')
    assert DecNum('1.0') == 1
    assert DecNum('0.1') == Rational(1)/Rational(10)

    assert !(DecNum.nan == DecNum.nan)
    assert !(DecNum.nan == DecNum('1'))
    assert !(DecNum.nan == DecNum('0'))
    assert !(DecNum.nan == DecNum.infinity)
    #assert !(DecNum.nan == (0.0/0.0))

    assert !(DecNum.infinity(+1) == DecNum.infinity(-1))
    assert !(DecNum.infinity(+1) == DecNum('0'))
    assert DecNum.infinity(+1) == DecNum.infinity
    assert DecNum.infinity(+1) == DecNum('1')/DecNum('0')
    assert DecNum.infinity(-1) == DecNum('-1')/DecNum('0')

    # TODO: test <=> <= etc.
  end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flt-1.5.4 test/test_comparisons.rb
flt-1.5.3 test/test_comparisons.rb