Testing Lots Of Values Perl Programming

Started by thiruvasagamani, Nov 13, 2008, 09:56 PM

Previous topic - Next topic

thiruvasagamani

Perl Programming

Testing Lots Of Values

    * Date handling code is notorious for magic dates that cause problems

          o 1970, 2038, 1904, 10,000. Leap years. Daylight savings.

    * So we want to repeat sets of tests with different values.

It's Just Programming

use Test::More tests => 32;
use Date::ICal;
my %ICal_Dates = (
'19971024T120000' => # from the docs.
[ 1997, 10, 24, 12, 0, 0 ],
'20390123T232832' => # after the Unix epoch
[ 2039, 1, 23, 23, 28, 32 ],
'19671225T000000' => # before the Unix epoch
[ 1967, 12, 25, 0, 0, 0 ],
'18990505T232323' => # before the MacOS epoch
[ 1899, 5, 5, 23, 23, 23 ],
);
while( my($ical_str, $expect) = each %ICal_Dates ) {
my $ical = Date::ICal->new( ical => $ical_str, offset => 0 );
ok( defined $ical, "new(ical => '$ical_str')" );
ok( $ical->isa('Date::ICal'), " and it's the right class" );
is( $ical->year, $expect->
  • , ' year()' );
    is( $ical->month, $expect->[1], ' month()' );
    is( $ical->day, $expect->[2], ' day()' );
    is( $ical->hour, $expect->[3], ' hour()' );
    is( $ical->min, $expect->[4], ' min()' );
    is( $ical->sec, $expect->[5], ' sec()' );
    }
Thiruvasakamani Karnan