Sha256: 2a2f39b781927d1ece19d068134372ed8aecdc3c3133e8c96a717ce2e94da026

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

#
# Testing Rufus
#
# John Mettraux at openwfe.org
#
# Fri Feb 29 11:18:48 JST 2008
#

$:.unshift(File.dirname(__FILE__) + '/../lib')

require 'test/unit'
require 'rufus/otime'


#
# testing otime
#
class Time1Test < Test::Unit::TestCase

  def test_0

    tts 0, "0s"
    tts 0, "0m", { :drop_seconds => true }
    tts 60, "1m"
    tts 61, "1m1s"
    tts 3661, "1h1m1s"
    tts 24 * 3600, "1d"
    tts 7 * 24 * 3600 + 1, "1w1s"
    tts 30 * 24 * 3600 + 1, "4w2d1s"
  end

  def test_1

    tts 30 * 24 * 3600 + 1, "1M1s", { :months => true }
  end

  def test_2

    tts 0.120 + 30 * 24 * 3600 + 1, "4w2d1s120"
    tts 0.130, "130"
    tts 61.127, "1m", { :drop_seconds => true }
  end

  def test_3

    tdh 0, {}
    tdh 0.128, { :ms => 128 }
    tdh 60.127, { :m => 1, :ms => 127 }
    tdh 61.127, { :m => 1, :s => 1, :ms => 127 }
    tdh 61.127, { :m => 1 }, { :drop_seconds => true }
  end

  protected

    def tts (seconds, time_string, options={})

      assert_equal(
        time_string,
        Rufus::to_time_string(seconds, options),
        "#{seconds} seconds did not map to '#{time_string}'")
    end

    def tdh (seconds, time_hash, options={})

      assert_equal(
        time_hash,
        Rufus::to_duration_hash(seconds, options))
    end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rufus-scheduler-1.0.12 test/time_1_test.rb