Sha256: 0811218973a29d8c74c752a4f37a96f681c5a5c97592c4c701a4f9281d98c4bf

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

require_relative "../lib/duration-human.rb"
require "test/unit"
 
class TestNumeric < Test::Unit::TestCase
 
  def test_long_seconds
    assert_equal("70 seconds", 70.duration)
  end
 
  def test_long_minutes
    assert_equal("72 minutes and 12 seconds", 4332.duration)
  end
 
  def test_long_hours
    assert_equal("26 hours and 30 minutes", 95400.duration)
  end
 
  def test_long_days
    assert_equal("2 days and 2 hours", 180000.duration)
  end
 
  def test_concise_seconds
    assert_equal("70s", 70.duration(concise: true))
  end
 
  def test_concise_minutes
    assert_equal("72m 12s", 4332.duration(concise: true))
  end
 
  def test_concise_hours
    assert_equal("26h 30m", 95400.duration(concise: true))
  end
 
  def test_concise_days
    assert_equal("2d 2h", 180000.duration(concise: true))
  end

  def test_float
    assert_equal("3 seconds", 3.456.duration)
  end

  def test_rational
    assert_equal("4 seconds", (9 / 2).duration)
  end

  def test_zero
    assert_equal("0 seconds", 0.duration)
  end

  def test_nan
    assert_equal("", (0 / 0.0).duration)
  end

  def test_long_infinity
    assert_equal("an infinitely long time", (1 / 0.0).duration)
  end

  def test_concise_infinity
    assert_equal(8734.chr(Encoding::UTF_8), (1 / 0.0).duration(concise: true)) # "∞"
  end

  def test_long_negative
    assert_equal("minus 4 seconds", -4.duration)
  end
 
  def test_concise_negative
    assert_equal("-6s", -6.duration(concise: true))
  end
 
end
 

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
duration-human-0.0.2 test/test-duration-human.rb