Sha256: 45eb6b9bb5c1d154f998122b3b5c346a98b489cdddc53bf9053e446f957b6919

Contents?: true

Size: 1.83 KB

Versions: 21

Compression:

Stored size: 1.83 KB

Contents

require 'test_helper'
require 'tins'

module Tins
  class DurationTest < Test::Unit::TestCase
    def test_short_to_s
      assert_equal '00:11:06', Tins::Duration.new(666).to_s
    end

    def test_to_s_with_days
      assert_equal '7+17:11:06', Tins::Duration.new(666666).to_s
    end

    def test_to_s_with_fractional_seconds
      assert_equal '00:11:06.123', Tins::Duration.new(666.123456).to_s
    end

    def test_to_s_with_days_and_fractional_seconds
      assert_equal '7+17:11:06.123', Tins::Duration.new(666666.123456).to_s
    end

    def test_format_without_precision
      assert_equal '0+00:11:06.123456', Tins::Duration.new(666.123456).format
    end

    def test_smart_format
      assert_equal '00:11:06.123', Tins::Duration.new(666.123456).format('%D')
      assert_equal '7+17:11:06.123', Tins::Duration.new(666666.123456).format('%D')
    end

    def test_predicate_days
      s = 0
      assert_false Tins::Duration.new(s).days?
      s += 86_400
      assert_true Tins::Duration.new(s).days?
    end

    def test_predicate_hours
      s = 0
      assert_false Tins::Duration.new(s).hours?
      s += 3600
      assert_true Tins::Duration.new(s).hours?
    end

    def test_predicate_minutes
      s = 0
      assert_false Tins::Duration.new(s).minutes?
      s += 60
      assert_true Tins::Duration.new(s).minutes?
    end

    def test_predicate_seconds
      s = 0
      assert_false Tins::Duration.new(s).seconds?
      s += 1
      assert_true Tins::Duration.new(s).seconds?
    end

    def test_predicate_fractional_seconds
      s = 0
      assert_false Tins::Duration.new(s).fractional_seconds?
      s += 0.1
      assert_true Tins::Duration.new(s).fractional_seconds?
    end

    def test_comparison
      t1 = Tins::Duration.new(666.23456)
      t2 = Tins::Duration.new(666.12345)
      assert_operator t1, :>, t2
    end
  end
end

Version data entries

21 entries across 20 versions & 2 rubygems

Version Path
tins-1.20.3 tests/duration_test.rb
tdiary-5.0.13 vendor/bundle/gems/tins-1.20.2/tests/duration_test.rb
tdiary-5.0.12.1 vendor/bundle/gems/tins-1.20.2/tests/duration_test.rb
tdiary-5.0.11 vendor/bundle/gems/tins-1.20.2/tests/duration_test.rb
tdiary-5.0.11 vendor/bundle/gems/tins-1.16.3/tests/duration_test.rb
tins-1.20.2 tests/duration_test.rb
tins-1.20.1 tests/duration_test.rb
tins-1.20.0 tests/duration_test.rb
tins-1.19.0 tests/duration_test.rb
tins-1.18.0 tests/duration_test.rb
tins-1.17.0 tests/duration_test.rb
tdiary-5.0.9 vendor/bundle/gems/tins-1.16.3/tests/duration_test.rb
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/vendor/bundle/gems/tins-1.16.3/tests/duration_test.rb
tdiary-5.0.7 vendor/bundle/gems/tins-1.16.3/tests/duration_test.rb
tins-1.16.3 tests/duration_test.rb
tins-1.16.2 tests/duration_test.rb
tins-1.16.1 tests/duration_test.rb
tins-1.16.0 tests/duration_test.rb
tins-1.15.1 tests/duration_test.rb
tdiary-5.0.6 vendor/bundle/gems/tins-1.15.0/tests/duration_test.rb