Sha256: 97008410d236a735bbfb738ec05436c67dd46cdcf70b5e292583a86af3788a98

Contents?: true

Size: 893 Bytes

Versions: 2

Compression:

Stored size: 893 Bytes

Contents

require File.dirname(__FILE__) + '/test_helper.rb'

class TestFloatExtensions < Test::Unit::TestCase

  context "fractional_part?" do
    should "return true for a number with a fractional part" do
      n = 1.249
      assert n.fractional_part?
    end
    
    should "return true for a number without a fractional part" do
       n = 1.0
       assert !n.fractional_part?
     end
  end
  
  context "fractional_part" do
    should "return the decimal parts for a number" do
      n = 12.2456
      assert_in_delta 0.2456, n.fractional_part, 0.00000001
    end
    
    should "retrun the decimal parts, even if they are 0" do
      n = 12.0
      assert_equal 0.0, n.fractional_part
    end
    
    should "retrun the decimal as a positive number, even if the original float is negative" do
      n = -12.2399
      assert_in_delta 0.2399, n.fractional_part, 0.00000001
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
bkoski-array_stats-0.5.0 test/test_float_extensions.rb
array_stats-0.6.0 test/test_float_extensions.rb