Date-Holidays-CA
view release on metacpan or search on metacpan
t/04correctness.t view on Meta::CPAN
use strict;
use warnings;
use Test::More qw(no_plan);
BEGIN { use_ok('Date::Holidays::CA', qw(:all)) };
# correctness tests.
# do the holidays actually fall on the days we say they do?
# do we get back the right holidays for the province we give?
# do we get back the holiday names in the right language?
# load up a table of representative years and see if the module's
# output matches.
my %CANONICAL_HOLIDAYS_FOR = canonical_holidays();
my %SUBSTITUTE_HOLIDAYS_FOR = substitute_holidays();
foreach my $year (keys %CANONICAL_HOLIDAYS_FOR) {
my $calendar = Date::Holidays::CA->new(
{language => 'EN', province => 'CA'}
);
my $holidays_ref = $calendar->holidays($year);
# first check that we've generated the correct number of holidays
is (
scalar keys %{$holidays_ref},
scalar keys %{$CANONICAL_HOLIDAYS_FOR{$year}},
"correct number of holidays for $year"
);
# now check the individual dates
foreach my $holiday_name (keys %{$CANONICAL_HOLIDAYS_FOR{$year}}) {
my ($canon_year, $canon_month, $canon_day) =
split '-', $CANONICAL_HOLIDAYS_FOR{$year}->{$holiday_name};
is(
$holidays_ref->{$canon_month . $canon_day},
$holiday_name,
"correct date for $year $holiday_name"
);
}
}
## pseudo-DATA section ############################################
sub canonical_holidays {
1583 => {
'New Year\'s Day' => '1583-01-01',
'Good Friday' => '1583-04-08',
'Easter Monday' => '1583-04-11',
'Victoria Day' => '1583-05-23',
'Canada Day' => '1583-07-01',
'Civic Holiday' => '1583-08-01',
'Labour Day' => '1583-09-05',
'National Day for Truth and Reconciliation' => '1583-09-30',
'Thanksgiving Day' => '1583-10-10',
'Remembrance Day' => '1583-11-11',
'Christmas Day' => '1583-12-26',
'Boxing Day' => '1583-12-27',
},
1584 => {
'New Year\'s Day' => '1584-01-01',
'Good Friday' => '1584-03-30',
'Easter Monday' => '1584-04-02',
'Victoria Day' => '1584-05-21',
'Civic Holiday' => '1584-08-06',
'Canada Day' => '1584-07-02',
'Labour Day' => '1584-09-03',
'National Day for Truth and Reconciliation' => '1584-09-30',
'Thanksgiving Day' => '1584-10-08',
'Remembrance Day' => '1584-11-11',
'Christmas Day' => '1584-12-25',
'Boxing Day' => '1584-12-26',
},
1969 => {
'New Year\'s Day' => '1969-01-01',
'Good Friday' => '1969-04-04',
'Easter Monday' => '1969-04-07',
'Victoria Day' => '1969-05-19',
( run in 1.900 second using v1.01-cache-2.11-cpan-364913b4093 )