Sha256: 486e2a04bb0fca7c766e24ff1df11558a233067b1162f65a48f1df80bf8f77d7

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

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

class TestFloat < Minitest::Test
  def setup
    initialize_context
  end

  def test_sign
    assert_equal(-1, Float.context.sign(-1.0))
    assert_equal(-1, Float.context.sign(-100.0))
    assert_equal(-1, Float.context.sign(-0.0))
    assert_equal(-1, Float.context.sign(-Float::MIN))
    assert_equal(-1, Float.context.sign(-Float::MAX))
    assert_equal(-1, Float.context.sign(-Float::EPSILON))
    assert_equal(-1, Float.context.sign(-Float::INFINITY))

    assert_equal(+1, Float.context.sign(+1.0))
    assert_equal(+1, Float.context.sign(+100.0))
    assert_equal(+1, Float.context.sign(+0.0))
    assert_equal(+1, Float.context.sign(Float::MIN))
    assert_equal(+1, Float.context.sign(Float::MAX))
    assert_equal(+1, Float.context.sign(Float::EPSILON))
    assert_equal(+1, Float.context.sign(Float::INFINITY))

    assert_nil Float.context.sign(Float.context.nan)
  end

  def copy_sign
    assert_equal(-1.23, BigDecimal.context.copy_sign(1.23, -1))
    assert_equal(-1.23, BigDecimal.context.copy_sign(1.23, -10.0))
    assert_equal(-1.23, BigDecimal.context.copy_sign(-1.23, -1))
    assert_equal(-1.23, BigDecimal.context.copy_sign(-1.23, -10.0))
    assert_equal(1.23, BigDecimal.context.copy_sign(-1.23, +1))
    assert_equal(1.23, BigDecimal.context.copy_sign(-1.23, 10.0))
    assert_equal(1.23, BigDecimal.context.copy_sign(1.23, +1))
    assert_equal(1.23, BigDecimal.context.copy_sign(1.23, 10.0))
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
flt-1.5.4 test/test_float.rb
flt-1.5.3 test/test_float.rb
flt-1.5.2 test/test_float.rb
flt-1.5.1 test/test_float.rb