PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/more/test_times.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 89 lines | 50 code | 24 blank | 15 comment | 0 complexity | d02f5ea1f6211f06bcfb064eb760da94 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. # Test facets/times.rb
  2. require 'facets/times.rb'
  3. require 'test/unit'
  4. class TC_Times < Test::Unit::TestCase
  5. #def test_micro_seconds
  6. # assert_equal( 0.000001, 1.microsecond )
  7. #end
  8. #def test_milli_seconds
  9. # assert_equal( 0.001, 1.millisecond )
  10. #end
  11. def test_seconds
  12. assert_equal( 60**0, 1.seconds )
  13. end
  14. def test_minutes
  15. assert_equal( 60**1, 1.minutes )
  16. end
  17. def test_hours
  18. assert_equal( 60**2, 1.hours )
  19. end
  20. def test_days
  21. assert_equal( 24*(60**2), 1.days )
  22. end
  23. def test_weeks
  24. assert_equal( 7*24*(60**2), 1.weeks )
  25. end
  26. def test_fortnights
  27. assert_equal( 14*24*(60**2), 1.fortnights )
  28. end
  29. def test_months
  30. assert_equal( 30*24*(60**2), 1.months )
  31. end
  32. def test_years
  33. assert_equal( 365*24*(60**2), 1.years )
  34. end
  35. def test_before
  36. t = Time.now
  37. assert_equal( t - 1.day, 1.day.before(t) )
  38. end
  39. def test_after
  40. t = Time.now
  41. assert_equal( t + 1.day, 1.day.after(t) )
  42. end
  43. end
  44. class WeekdaysTest < Test::Unit::TestCase
  45. MONDAY = Time.at(1165250000)
  46. THURSDAY = Time.at(1165500000)
  47. FRIDAY = Time.at(1165606025)
  48. def test_weekday_after_monday
  49. assert_equal 2, 1.weekday.since(MONDAY).wday
  50. end
  51. def test_weekday_after_friday
  52. assert_equal 1, 1.weekday.after(FRIDAY).wday
  53. end
  54. def test_weekdays_before_friday
  55. assert_equal 2, 3.weekdays.before(FRIDAY).wday
  56. end
  57. #def test_weekday_before_today
  58. # Time.expects(:now).returns(THURSDAY)
  59. # assert_equal 3, 1.weekday.ago.wday
  60. #end
  61. #def test_weekdays_after_today
  62. # Time.expects(:now).returns(MONDAY)
  63. # assert_equal 3, 2.weekday.from_now.wday
  64. #end
  65. end