Sha256: d40a90c617164f2a9e2b680e78e33ffedb8f599058024ede8dfcb15e54e1cb12

Contents?: true

Size: 1.26 KB

Versions: 16

Compression:

Stored size: 1.26 KB

Contents

require 'facets/numeric/round.rb'
require 'test/unit'

class TestRound < Test::Unit::TestCase

  def setup
    @f0 = [ 0, 10, 15, 105 ]
    @f1 = [ 10.1, 10.01, 10.9, 10.09, 10.5, 10.05, 10.49 ]
  end

  def test_round_at_arg1
    fr = @f0.collect{ |f| f.round_at(1) }
    assert_equal( [0,10,15,105], fr )
    fr = @f1.collect { |f| f.round_at(1) }
    assert_equal( [10.1,10.0,10.9,10.1,10.5,10.1,10.5], fr )
  end

  def test_round_at_arg2
    fr = @f0.collect { |f| f.round_at(2) }
    assert_equal( [0,10,15,105], fr )
    fr = @f1.collect { |f| f.round_at(2) }
    assert_equal( [10.1,10.01,10.9,10.09,10.5,10.05,10.49], fr )
  end

  #def test_round_off
  #  assert_equal( 1.0, 1.2.round_off )
  #  assert_equal( 2.0, 1.8.round_off )
  #end

  def test_round_to_arg1
    fr = @f0.collect { |f| f.round_to(0.1) }
    assert_equal( [0,10,15,105], fr )
    fr = @f1.collect { |f| f.round_to(0.1) }
    assert_equal( [10.1,10.0,10.9,10.1,10.5,10.1,10.5], fr )
  end

  def test_round_to_arg10
    fr = @f0.collect { |f| f.round_to(10) }
    assert_equal( [0,10,20,110], fr )
    fr = @f1.collect { |f| f.round_to(10) }
    assert_equal( [10,10,10,10,10,10,10], fr )
  end

  #def test_round_off
  #  assert_equal( 1.0, 1.2.round_off )
  #  assert_equal( 2.0, 1.8.round_off )
  #end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
facets-2.8.4 test/core/numeric/test_round.rb
facets-2.8.3 test/core/numeric/test_round.rb
facets-2.8.2 test/core/numeric/test_round.rb
facets-2.8.1 test/core/numeric/test_round.rb
facets-2.8.0 test/core/numeric/test_round.rb
facets-2.7.0 test/core/numeric/test_round.rb
facets-2.6.0 test/core/numeric/test_round.rb
facets-2.4.0 test/numeric/test_round.rb
facets-2.4.1 test/numeric/test_round.rb
facets-2.4.3 test/core/numeric/test_round.rb
facets-2.4.2 test/core/numeric/test_round.rb
facets-2.4.4 test/core/numeric/test_round.rb
facets-2.5.1 test/core/numeric/test_round.rb
facets-2.5.0 test/core/numeric/test_round.rb
facets-2.4.5 test/core/numeric/test_round.rb
facets-2.5.2 test/core/numeric/test_round.rb