diff options
author | Steve Kemp <steve@steve.org.uk> | 2013-06-24 14:44:27 +0100 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2013-06-24 14:44:27 +0100 |
commit | 9f9ecbc9b2906824e06b48d09b9758c8152b1588 (patch) | |
tree | 5b29e9f4ed17d112237fcaa486c5040336fe6da3 /t | |
parent | d5bdfdb5c40ef4d9df9ee8c01b4b621642611ec1 (diff) |
Updated the code to be more module.
Broke down the inside? function into a function for returning the hours
in a period, and for sanitizing hour strings "14" vs. "2pm", etc.
Updated test-cases to match.
Diffstat (limited to 't')
-rwxr-xr-x | t/test-custodian-util-timespan.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/t/test-custodian-util-timespan.rb b/t/test-custodian-util-timespan.rb index 048f582..fde3de8 100755 --- a/t/test-custodian-util-timespan.rb +++ b/t/test-custodian-util-timespan.rb @@ -24,6 +24,49 @@ class TestTimeSpanUtil < Test::Unit::TestCase end # + # Test the expansion of "obvious" hour-specifiers. + # + def test_to_hour + + for hour in 0..23 + assert_equal( hour, Custodian::Util::TimeSpan::to_hour(hour)) + end + + # + # Invalid hours will throw exceptions + # + assert_raise ArgumentError do + result = Custodian::Util::TimeSpan.to_hour( 0.5 ) + end + assert_raise ArgumentError do + result = Custodian::Util::TimeSpan.to_hour( -1 ) + end + assert_raise ArgumentError do + result = Custodian::Util::TimeSpan.to_hour( 100 ) + end + assert_raise ArgumentError do + result = Custodian::Util::TimeSpan.to_hour( 24 ) + end + assert_raise ArgumentError do + result = Custodian::Util::TimeSpan.to_hour( 25 ) + end + + # + # Ensure AM times work well + # + for hour in 0..11 + assert_equal( hour, Custodian::Util::TimeSpan::to_hour( "#{hour}am")) + end + + for hour in 0..11 + assert_equal( 12 +hour, Custodian::Util::TimeSpan::to_hour( "#{hour}pm")) + end + + end + + + # + # # Ensure we received errors if the start/end hours are under/over 24 # def test_excessive_hours @@ -161,6 +204,27 @@ class TestTimeSpanUtil < Test::Unit::TestCase for i in 0..23 assert( Custodian::Util::TimeSpan.inside?( 0, 23, i ) ) end + end + + # + # Test that we don't wrap-around unexpectedly. + # + # + # i.e. "between 00-00" is one hour, not 24. + # + def test_wrap_around + + for h in 00..23 + assert_equal( 1, Custodian::Util::TimeSpan::to_hours( h,h ).size() ) + end + + # + # But the time-period 00-23 is a full day + # + assert_equal( 24, + Custodian::Util::TimeSpan::to_hours( 0,23 ).size() ) end + + end |