Class DTimeTest
In: lib/d_time.rb
Parent: Test::Unit::TestCase

Methods

Included Modules

YamlExtension::Assertions

Public Instance methods

[Source]

# File lib/d_time.rb, line 330
  def test_add
    d = DTime.new(4.5)
    assert_equal(6.5, d + 2)
  end

[Source]

# File lib/d_time.rb, line 225
  def test_complex
    d = DTime.new(265678.42000)
    assert_equal(265678, d.delta.floor)
    assert_equal(58, d.sec.floor)
    assert_equal(47, d.min)
    assert_equal(1, d.hour)
    assert_equal(3, d.day)
    assert_equal([ 3, 1, 47, 58 ], d.to_a.map { |x| x.to_i })
    h = d.to_hash
    assert_equal(3, h[:day])
    assert_equal(1, h[:hour])
    assert_equal(47, h[:minute])
    assert_equal(58, h[:second].floor)
  end

[Source]

# File lib/d_time.rb, line 240
  def test_conversion
    d = DTime.new(260.75)
    assert_equal('260.75', d.to_f.to_s)
    assert_equal('4 minutes 20.75 seconds', d.to_s)
    assert_equal('4 minutes 20.75 seconds:DTime', d.inspect)
    assert_equal(260, d.to_f.floor)
    assert_equal(260, d.to_i)
    assert_equal(260, d.floor)
    assert_equal(261, d.round)
  end

[Source]

# File lib/d_time.rb, line 276
  def test_diff
    @foo = 1
    d = DTime.diff(42, 43) do |*args|
      assert_equal([42, 43], args)
      @foo = 2
      sleep 0.3
      @foo = 3
    end
    assert_kind_of(DTime, d)
    assert_equal(3, @foo)
    assert(d.to_f > 0.2)
    assert(d.sec > 0.2)
  end

[Source]

# File lib/d_time.rb, line 320
  def test_divide
    d = DTime.new(4.5)
    assert_equal(2.25, d / 2)
  end

[Source]

# File lib/d_time.rb, line 316
  def test_equal
    assert(DTime.new(4.5) == 4.5)
  end

[Source]

# File lib/d_time.rb, line 308
  def test_greater_or_equal
    assert(DTime.new(4.5) >= 4.5)
  end

[Source]

# File lib/d_time.rb, line 290
  def test_init_from_dtime
    c = DTime.new(260.33)
    d = DTime.new(c)
    assert_equal(260, d.delta.floor)
    assert_equal(20, d.sec.floor)
    assert_equal(4, d.min)
    assert_equal(0, d.hour)
    assert_equal(0, d.day)
  end

[Source]

# File lib/d_time.rb, line 312
  def test_lesser_or_equal
    assert(DTime.new(4.5) <= 4.5)
  end

[Source]

# File lib/d_time.rb, line 260
  def test_marshal
    d = DTime.new(-265678.42000)
    assert_equal(d.floor, Marshal.load(Marshal.dump(d)).floor)
  end

[Source]

# File lib/d_time.rb, line 325
  def test_multiple
    d = DTime.new(4.5)
    assert_equal(9, d * 2)
  end

[Source]

# File lib/d_time.rb, line 251
  def test_negative
    d = DTime.new(-265678.42000)
    assert_equal(-265679, d.delta.floor)
    assert_equal(58, d.sec.floor)
    assert_equal(47, d.min)
    assert_equal(1, d.hour)
    assert_equal(3, d.day)
  end

[Source]

# File lib/d_time.rb, line 207
  def test_simple
    d = DTime.new(260.33)
    assert_equal(260, d.delta.floor)
    assert_equal(20, d.seconds.floor)
    assert_equal(20, d.second.floor)
    assert_equal(20, d.sec.floor)
    assert_equal(4, d.minutes)
    assert_equal(4, d.minute)
    assert_equal(4, d.min)
    assert_equal(0, d.hours)
    assert_equal(0, d.hour)
    assert_equal(0, d.days)
    assert_equal(0, d.day)
    assert_equal(0, d.week)
    assert_equal(0, d.year)
    assert_equal(0, d.century)
  end

[Source]

# File lib/d_time.rb, line 300
  def test_stricly_greater
    assert(DTime.new(4.5) > 2)
  end

[Source]

# File lib/d_time.rb, line 304
  def test_stricly_lesser
    assert(DTime.new(4.5) < 4.6)
  end

[Source]

# File lib/d_time.rb, line 335
  def test_sub
    d = DTime.new(4.5)
    assert_kind_of(DTime, d - 2)
    assert_equal(2.5, d - 2)
  end

[Source]

# File lib/d_time.rb, line 265
  def test_to_yaml
    d = DTime.new(265678.42000)
    assert_yaml_dump(d, '!dtime 3 days 1 hour 47 minutes 58.4199999999837 seconds')
    d = DTime.new(5678.42000)
    assert_yaml_dump(d, '!dtime 1 hour 34 minutes 38.4200000000001 seconds')
    d = DTime.new(158.42000)
    assert_yaml_dump(d, '!dtime 2 minutes 38.42 seconds')
    d = DTime.new(58.42000)
    assert_yaml_dump(d, '!dtime 58.42 seconds')
  end

[Source]

# File lib/d_time.rb, line 341
  def test_uadd
    d = DTime.new(4.5)
    assert_equal(4.5, +d)
  end

[Source]

# File lib/d_time.rb, line 346
  def test_usub
    d = DTime.new(2.5)
    assert_equal(-2.5, -d)
  end

[Validate]