Goodies Templates: update some goodies for auto-template usage.

Testing these in duckpan will depend upon the changes in that repository
being integrated.
master
Matt Miller 2014-09-26 15:21:38 -04:00
parent afe13a63ea
commit 5457d4ec62
10 changed files with 421 additions and 302 deletions

View File

@ -37,12 +37,6 @@ attribution github => ["https://github.com/loganom", 'loganom'],
github => ['https://github.com/gdrooid', 'gdrooid'],
email => ['gdrooid@openmailbox.org', 'gdrooid'];
# Wrap the response in html
sub html_output {
my ($str, $list) = @_;
return "<div class='zci--anagrams'>" . "<span class='text--secondary'>$str</span><br/>" . "<span class='text--primary'>$list</span>" . "</div>";
}
# Calculate the frequency of the characters in a string
sub calc_freq {
my ($str) = @_;
@ -57,6 +51,8 @@ sub calc_freq {
my %words = map { chomp; ($_ => undef); } share('words')->slurp; # This will cache letter frequencies as they get used.
my %easter_eggs = (voldemort => 'Tom Riddle');
handle remainder => sub {
my $word = $_;
@ -71,12 +67,13 @@ handle remainder => sub {
my $len = length $match_word;
if ($match_word eq 'voldemort') {
return 'Tom Riddle', html => html_output("Anagrams of \"$word\"", 'Tom Riddle');
my @output;
if (my $egg = $easter_eggs{lc $word}) {
push @output, $egg;
}
unless (@output) {
my $query_freq = calc_freq($match_word); # Calculate the letter-freq of the query
my @output;
foreach (keys %words) {
if (/^[$match_word]{$len}$/i) {
@ -97,22 +94,25 @@ handle remainder => sub {
push(@output, $_) if $is_anagram;
}
}
# Scramble when no anagram can be found.
if (!@output) {
my $w;
}
my ($response, $operation);
if (@output) {
$response = join ', ', sort { $a cmp $b } @output;
$operation = 'anagrams of';
} else {
do {
$w = join '', shuffle split(//, $word);
} while ($w eq $match_word);
# Do not cache the scrambled versions since the shuffle is random.
return $word,
html => html_output('Sorry, we found no anagrams for "' . html_enc($word) . '". We scrambled it for you:', html_enc($w)),
is_cached => 0;
$response = join '', shuffle split(//, $word);
} while (length($word) > 1 && $response eq $word);
$operation = 'scrambled letters of';
}
my $response = join ', ', sort { $a cmp $b } @output;
my $output_str = 'Anagrams of "' . html_enc($word) . '"';
return $response, html => html_output($output_str, $response);
return $response,
structured_answer => {
input => [html_enc($word)],
operation => $operation,
result => html_enc($response)
};
};
1;

View File

@ -4,46 +4,40 @@ package DDG::Goodie::MoonPhases;
use DDG::Goodie;
use Astro::MoonPhase;
zci answer_type => 'moon_phase';
zci is_cached => 0;
primary_example_queries "lunar phase";
secondary_example_queries
"moon phase",
"phase of the moon",
"what is the current lunar phase";
description "Lunar phase";
secondary_example_queries "moon phase", "phase of the moon", "what is the current lunar phase";
description "Lunar phase";
name "MoonPhases";
topics "special_interest", "everyday";
category "random";
attribution
github => ['https://github.com/rpicard', 'rpicard'],
twitter => ['https://twitter.com/__rlp', '__rlp'],
web => ['http://robert.io', 'Robert Picard'];
attribution github => ['https://github.com/rpicard', 'rpicard'],
twitter => ['https://twitter.com/__rlp', '__rlp'],
web => ['http://robert.io', 'Robert Picard'];
triggers any => 'moon', 'lunar';
my %triggerQueries = (
'moon phase' => 1,
'lunar phase' => 1,
'phase of the moon' => 1,
'current moon phase' => 1,
'current phase of the moon' => 1,
'what is the phase of the moon' => 1,
'whats the phase of the moon' => 1,
'what is the current phase of the moon' => 1,
'whats the current phase of them moon' => 1,
'current lunar phase' => 1,
'whats the lunar phase' => 1,
'what is the lunar phase' => 1,
'whats the current lunar phase' => 1,
'what is the current lunar phase' => 1,
'what phase is the moon in' => 1,
'what lunar phase is the moon in' => 1,
my %triggerQueries = map { $_ => 1 } (
'moon phase',
'lunar phase',
'phase of the moon',
'current moon phase',
'current phase of the moon',
'what is the phase of the moon',
'whats the phase of the moon',
'what is the current phase of the moon',
'whats the current phase of them moon',
'current lunar phase',
'whats the lunar phase',
'what is the lunar phase',
'whats the current lunar phase',
'what is the current lunar phase',
'what phase is the moon in',
'what lunar phase is the moon in',
);
handle query_lc => sub {
@ -72,9 +66,13 @@ handle query_lc => sub {
my $phaseUrl = $phase;
$phaseUrl =~ s/\s+/+/g;
return "The current lunar phase is: $phase", html => qq(The current lunar phase is: <a href="?q=$phaseUrl">$phase</a>);
return "The current lunar phase is: $phase",
structured_answer => {
input => [],
result => $phase,
operation => 'current lunar phase'
};
};
zci is_cached => 0;
1;

View File

@ -20,16 +20,6 @@ code_url 'https://github.com/duckduckgo/zeroclickinfo-goodies
attribution github => ['http://github.com/syst3mw0rm', 'syst3mw0rm'],
email => ['syst3m.w0rm@gmail.com', 'syst3m.w0rm@gmail.com'];
# Wrap the response in html
sub html_output {
my ($weekday_count, $start_end_dates) = @_;
return "<div class='zci--weekdaysbetween'>"
."<span class='text--primary'>$weekday_count</span><br/>"
."<span class='text--secondary'>$start_end_dates</span>"
."</div>";
}
my $datestring_regex = datestring_regex();
handle remainder => sub {
@ -50,7 +40,12 @@ handle remainder => sub {
my $response = "There $verb $weekday_count $weekday_plurality between $start_str and $end_str.";
return $response, html => html_output("$weekday_count $weekday_plurality", "between $start_str and $end_str.");
return $response,
structured_answer => {
input => [$start_str, $end_str],
operation => "$weekday_plurality between",
result => $weekday_count
};
};
# It calculates the number of weekdays between two given dates, both inclusive.

View File

@ -44,7 +44,12 @@ handle remainder => sub {
my $verb = $workdays == 1 ? 'is' : 'are';
my $number = $workdays == 1 ? 'workday' : 'workdays';
return "There $verb $workdays $number between $start_str and $end_str.";
return "There $verb $workdays $number between $start_str and $end_str.",
structured_answer => {
input => [$start_str, $end_str],
operation => "$number between",
result => $workdays
};
};
1;

View File

@ -1,13 +0,0 @@
.zci--answer .zci--anagrams {
font-weight: 300;
padding: .25em 0;
}
.zci--anagrams .text--primary {
font-size: 1.5em;
}
.zci--anagrams .text--secondary {
font-weight: 400;
font-size: 1.1em;
}

View File

@ -1,13 +0,0 @@
.zci--answer .zci--weekdaysbetween {
font-weight: 300;
padding: .25em 0;
}
.zci--weekdaysbetween .text--primary {
font-size: 1.7em;
}
.zci--weekdaysbetween .text--secondary {
font-weight: 400;
font-size: 1.0em;
}

View File

@ -10,39 +10,77 @@ zci is_cached => 1;
ddg_goodie_test(
[qw(DDG::Goodie::Anagram)],
# Sucessful anagram tests.
'Anagrams for filter' => test_zci('trifle', html => qr/Anagrams of "filter"/),
'anagram filter' => test_zci('trifle', html => qr/Anagrams of "filter"/),
'anagrams of events' => test_zci('Steven', html => qr/Anagrams of "events"/),
'anagram of algorithm' => test_zci('logarithm', html => qr/Anagrams of "algorithm"/),
'show anagram of algorithm' => test_zci('logarithm', html => qr/Anagrams of "algorithm"/),
'anagrams for times' => test_zci('emits, items, mites, smite', html => qr/Anagrams of "times"/),
'show anagrams of stop' => test_zci('Post, opts, post, pots, spot, tops', html => qr/Anagrams of "stop"/),
'find anagram for stop' => test_zci('Post, opts, post, pots, spot, tops', html => qr/Anagrams of "stop"/),
'anagrams lost' => test_zci('lots, slot', html => qr/Anagrams of "lost"/),
'anagrams of lost' => test_zci('lots, slot', html => qr/Anagrams of "lost"/),
'anagram for lost' => test_zci('lots, slot', html => qr/Anagrams of "lost"/),
'anagram of lost' => test_zci('lots, slot', html => qr/Anagrams of "lost"/),
'anagram of filter' => test_zci('trifle', html => qr/Anagrams of "filter"/),
'anagram of Filter' => test_zci('trifle', html => qr/Anagrams of "Filter"/),
'anagram of "partial men"' => test_zci('Parliament, parliament', html => qr/Anagrams of "partial men"/),
'find anagram for partial men' => test_zci('Parliament, parliament', html => qr/Anagrams of "partial men"/),
# Uncached scrambles tests.
'Anagram filter' => test_zci(
'trifle',
structured_answer => {
input => ['filter'],
operation => 'anagrams of',
result => 'trifle',
}
),
'anagrams events' => test_zci(
'Steven',
structured_answer => {
input => ['events'],
operation => 'anagrams of',
result => 'Steven',
}
),
'anagram of algorithm' => test_zci(
'logarithm',
structured_answer => {
input => ['algorithm'],
operation => 'anagrams of',
result => 'logarithm',
}
),
'anagrams of favorite' => test_zci(
'favorite',
html => qr/we found no anagrams for "favorite".*scrambled it for you:/,
is_cached => 0
'-ANY-',
structured_answer => {
input => ['favorite'],
operation => 'scrambled letters of',
result => '-ANY-',
}
),
'anagram for "Mixing it up"' => test_zci(
'Mixing it up',
html => qr/we found no anagrams for "Mixing it up".*scrambled it for you:/,
is_cached => 0
'anagrams of "Mixing it up"' => test_zci(
'-ANY-',
structured_answer => {
input => ['Mixing it up'],
operation => 'scrambled letters of',
result => '-ANY-',
}
),
# Full HTML test.
'anagrams of slot' => test_zci(
'lost, lots',
html =>
"<div class='zci--anagrams'><span class='text--secondary'>Anagrams of \"slot\"</span><br/><span class='text--primary'>lost, lots</span></div>",
'anagram times' => test_zci(
'emits, items, mites, smite',
structured_answer => {
input => ['times'],
operation => 'anagrams of',
result => 'emits, items, mites, smite',
}
),
'anagrams stop' => test_zci(
'Post, opts, post, pots, spot, tops',
structured_answer => {
input => ['stop'],
operation => 'anagrams of',
result => 'Post, opts, post, pots, spot, tops',
}
),
'anagram of lost' => test_zci(
'lots, slot',
structured_answer => {
input => ['lost'],
operation => 'anagrams of',
result => 'lots, slot',
}
),
'anagram of voldemort' => test_zci(
'Tom Riddle',
structured_answer => {
input => ['voldemort'],
operation => 'anagrams of',
result => 'Tom Riddle',
}
),
# No result tests.
'anagram of' => undef,

View File

@ -5,8 +5,8 @@ use warnings;
use Test::More;
use DDG::Test::Goodie;
zci answer_type => 'moon_phase';
zci is_cached => 0;
zci answer_type => 'moonphases';
my $space_plus = qr/(?:\s|\+)/;
my $wax_wane = qr/(?:Waxing|Waning)$space_plus(?:Gibbous|Crescent)/;
@ -19,10 +19,38 @@ my $html_answer = qr%^The current lunar phase is: <a href="\?q=$phases">$phases
ddg_goodie_test(
[qw( DDG::Goodie::MoonPhases)],
'moon phase' => test_zci($ascii_answer, html => $html_answer,),
'lunar phase' => test_zci($ascii_answer, html => $html_answer,),
'phase of the moon' => test_zci($ascii_answer, html => $html_answer,),
'what is the current lunar phase' => test_zci($ascii_answer, html => $html_answer,),
'moon phase' => test_zci(
$ascii_answer,
structured_answer => {
input => [],
operation => 'current lunar phase',
result => $phases,
}
),
'lunar phase' => test_zci(
$ascii_answer,
structured_answer => {
input => [],
operation => 'current lunar phase',
result => $phases,
}
),
'phase of the moon' => test_zci(
$ascii_answer,
structured_answer => {
input => [],
operation => 'current lunar phase',
result => $phases,
}
),
'what is the current lunar phase' => test_zci(
$ascii_answer,
structured_answer => {
input => [],
operation => 'current lunar phase',
result => $phases,
}
),
);
done_testing;

View File

@ -6,82 +6,127 @@ use Test::More;
use DDG::Test::Goodie;
zci answer_type => 'weekdays_between';
zci is_cached => 0;
zci is_cached => 0;
my @six_to_ten = (
"There are 5 weekdays between 06 Jan 2014 and 10 Jan 2014.",
structured_answer => {
input => ['06 Jan 2014', '10 Jan 2014'],
operation => 'weekdays between',
result => 5,
});
ddg_goodie_test(
[
'DDG::Goodie::WeekdaysBetween'
],
['DDG::Goodie::WeekdaysBetween'],
# Primary query example
'weekdays between 01/31/2000 01/31/2001' =>
test_zci("There are 263 weekdays between 31 Jan 2000 and 31 Jan 2001.", html => qr/.*/),
'weekdays between 01/31/2000 01/31/2001' => test_zci(
"There are 263 weekdays between 31 Jan 2000 and 31 Jan 2001.",
structured_answer => {
input => ['31 Jan 2000', '31 Jan 2001'],
operation => 'weekdays between',
result => 263,
}
),
# Test different trigger words
'week days between 01/06/2014 01/10/2014' =>
test_zci("There are 5 weekdays between 06 Jan 2014 and 10 Jan 2014.", html => qr/.*/),
'week days from 01/06/2014 01/10/2014' =>
test_zci("There are 5 weekdays between 06 Jan 2014 and 10 Jan 2014.", html => qr/.*/),
'weekdays from 01/06/2014 01/10/2014' =>
test_zci("There are 5 weekdays between 06 Jan 2014 and 10 Jan 2014.", html => qr/.*/),
'week days between 01/06/2014 01/10/2014' => test_zci(@six_to_ten),
'week days from 01/06/2014 01/10/2014' => test_zci(@six_to_ten),
'weekdays from 01/06/2014 01/10/2014' => test_zci(@six_to_ten),
# Standard work week
'weekdays between 01/06/2014 01/10/2014' =>
test_zci("There are 5 weekdays between 06 Jan 2014 and 10 Jan 2014.", html => qr/.*/),
'weekdays between 01/06/2014 01/10/2014' => test_zci(@six_to_ten),
# Ending date first
'weekdays between 01/10/2014 01/06/2014' =>
test_zci("There are 5 weekdays between 06 Jan 2014 and 10 Jan 2014.", html => qr/.*/),
# Ending date first
'weekdays between 01/10/2014 01/06/2014' => test_zci(@six_to_ten),
# Including the weekend -- Backwards
'weekdays between 01/13/2014 01/06/2014' =>
test_zci("There are 6 weekdays between 06 Jan 2014 and 13 Jan 2014.", html => qr/.*/),
'weekdays between 01/13/2014 01/06/2014' => test_zci(
"There are 6 weekdays between 06 Jan 2014 and 13 Jan 2014.",
structured_answer => {
input => ['06 Jan 2014', '13 Jan 2014'],
operation => 'weekdays between',
result => 6,
}
),
# Weekdays in a year - Dash format
'weekdays between 01-01-2014 01-01-2015' =>
test_zci("There are 262 weekdays between 01 Jan 2014 and 01 Jan 2015.", html => qr/.*/),
'weekdays between 01-01-2014 01-01-2015' => test_zci(
"There are 262 weekdays between 01 Jan 2014 and 01 Jan 2015.",
structured_answer => {
input => ['01 Jan 2014', '01 Jan 2015'],
operation => 'weekdays between',
result => 262,
}
),
# Single digit days and months - Dash format
'weekdays between 1-6-2014 1-10-2014' =>
test_zci("There are 5 weekdays between 06 Jan 2014 and 10 Jan 2014.", html => qr/.*/),
# Single digit days and months - Dash format
'weekdays between 1-6-2014 1-10-2014' => test_zci(@six_to_ten),
# Unambiguous date format
'weekdays between jan 6 2014 jan 10 2014' =>
test_zci("There are 5 weekdays between 06 Jan 2014 and 10 Jan 2014.", html => qr/.*/),
'weekdays between jan 6 2014 jan 10 2014' => test_zci(@six_to_ten),
# Unambiguous date format with comma separator
'weekdays between jan 6, 2014 jan 10, 2014' =>
test_zci("There are 5 weekdays between 06 Jan 2014 and 10 Jan 2014.", html => qr/.*/),
'weekdays between jan 6, 2014 jan 10, 2014' => test_zci(@six_to_ten),
# Weekend in the middle
'weekdays between jan 3, 2014 jan 6, 2014' =>
test_zci("There are 2 weekdays between 03 Jan 2014 and 06 Jan 2014.", html => qr/.*/),
'weekdays between jan 3, 2014 jan 6, 2014' => test_zci(
"There are 2 weekdays between 03 Jan 2014 and 06 Jan 2014.",
structured_answer => {
input => ['03 Jan 2014', '06 Jan 2014'],
operation => 'weekdays between',
result => 2,
}
),
# Same day
'weekdays between jan 3, 2014 jan 3, 2014' =>
test_zci("There is 1 weekday between 03 Jan 2014 and 03 Jan 2014.", html => qr/.*/),
'weekdays between jan 3, 2014 jan 3, 2014' => test_zci(
"There is 1 weekday between 03 Jan 2014 and 03 Jan 2014.",
structured_answer => {
input => ['03 Jan 2014', '03 Jan 2014'],
operation => 'weekday between',
result => 1,
}
),
# Same day on a weekend
'weekdays between jan 4, 2014 jan 4, 2014' =>
test_zci("There are 0 weekdays between 04 Jan 2014 and 04 Jan 2014.", html => qr/.*/),
'weekdays between jan 4, 2014 jan 4, 2014' => test_zci(
"There are 0 weekdays between 04 Jan 2014 and 04 Jan 2014.",
structured_answer => {
input => ['04 Jan 2014', '04 Jan 2014'],
operation => 'weekdays between',
result => 0,
}
),
# Starting on a Saturday
'weekdays between 01/11/2014 01/14/2014' =>
test_zci("There are 2 weekdays between 11 Jan 2014 and 14 Jan 2014.", html => qr/.*/),
'weekdays between 01/11/2014 01/14/2014' => test_zci(
"There are 2 weekdays between 11 Jan 2014 and 14 Jan 2014.",
structured_answer => {
input => ['11 Jan 2014', '14 Jan 2014'],
operation => 'weekdays between',
result => 2,
}
),
# Starting on a Sunday
'weekdays between 01/12/2014 01/17/2014' =>
test_zci("There are 5 weekdays between 12 Jan 2014 and 17 Jan 2014.", html => qr/.*/),
'weekdays between 01/12/2014 01/17/2014' => test_zci(
"There are 5 weekdays between 12 Jan 2014 and 17 Jan 2014.",
structured_answer => {
input => ['12 Jan 2014', '17 Jan 2014'],
operation => 'weekdays between',
result => 5,
}
),
# Invalid input
'weekdays between 01/2013 and 01/2014' => undef,
'weekdays between feb 30, 2014 to mar 3, 2014' => undef,
'weekdays between 01/01/2012' => undef,
'weekdays between 18/17/2013 21/23/2015' => undef,
'weekdays between 01/2013 and 01/2014 inclusive' => undef,
'weekdays between feb 30, 2014 mar 3, 2014 inclusive' => undef,
'weekdays between 01/01/2012 to' => undef,
'weekdays between 01/2013 and 01/2014' => undef,
'weekdays between feb 30, 2014 to mar 3, 2014' => undef,
'weekdays between 01/01/2012' => undef,
'weekdays between 18/17/2013 21/23/2015' => undef,
'weekdays between 01/2013 and 01/2014 inclusive' => undef,
'weekdays between feb 30, 2014 mar 3, 2014 inclusive' => undef,
'weekdays between 01/01/2012 to' => undef,
'weekdays between 18/17/2013 and 21/23/2015 inclusive' => undef,
);

View File

@ -8,183 +8,219 @@ use DDG::Test::Goodie;
zci answer_type => 'workdays_between';
zci is_cached => 0;
my @six_to_ten = (
'There are 5 workdays between 06 Jan 2014 and 10 Jan 2014.',
structured_answer => {
input => ['06 Jan 2014', '10 Jan 2014'],
operation => 'workdays between',
result => 5,
});
my @twentyfourteen = (
'There are 251 workdays between 01 Jan 2014 and 01 Jan 2015.',
structured_answer => {
input => ['01 Jan 2014', '01 Jan 2015'],
operation => 'workdays between',
result => 251,
});
my @twoohoh = (
'There are 253 workdays between 31 Jan 2000 and 31 Jan 2001.',
structured_answer => {
input => ['31 Jan 2000', '31 Jan 2001'],
operation => 'workdays between',
result => 253,
});
my @midjune = (
'There are 12 workdays between 05 Jun 2014 and 20 Jun 2014.',
structured_answer => {
input => ['05 Jun 2014', '20 Jun 2014'],
operation => 'workdays between',
result => 12,
});
my @midjan = (
'There are 6 workdays between 06 Jan 2014 and 13 Jan 2014.',
structured_answer => {
input => ['06 Jan 2014', '13 Jan 2014'],
operation => 'workdays between',
result => 6,
});
my @somejan = (
'There are 5 workdays between 06 Jan 2014 and 12 Jan 2014.',
structured_answer => {
input => ['06 Jan 2014', '12 Jan 2014'],
operation => 'workdays between',
result => 5,
});
my @somesat = (
'There are 2 workdays between 11 Jan 2014 and 14 Jan 2014.',
structured_answer => {
input => ['11 Jan 2014', '14 Jan 2014'],
operation => 'workdays between',
result => 2,
});
my @somesun = (
'There are 2 workdays between 12 Jan 2014 and 14 Jan 2014.',
structured_answer => {
input => ['12 Jan 2014', '14 Jan 2014'],
operation => 'workdays between',
result => 2,
});
my @latejun = (
'There are 5 workdays between 16 Jun 2014 and 20 Jun 2014.',
structured_answer => {
input => ['16 Jun 2014', '20 Jun 2014'],
operation => 'workdays between',
result => 5,
});
my @sameday = (
'There is 1 workday between 03 Jan 2014 and 03 Jan 2014.',
structured_answer => {
input => ['03 Jan 2014', '03 Jan 2014'],
operation => 'workday between',
result => 1,
});
my @samedaywknd = (
'There are 0 workdays between 04 Jan 2014 and 04 Jan 2014.',
structured_answer => {
input => ['04 Jan 2014', '04 Jan 2014'],
operation => 'workdays between',
result => 0,
});
my @weekend_middle = (
'There are 2 workdays between 03 Jan 2014 and 06 Jan 2014.',
structured_answer => {
input => ['03 Jan 2014', '06 Jan 2014'],
operation => 'workdays between',
result => 2,
});
ddg_goodie_test(
[
'DDG::Goodie::WorkdaysBetween'
],
['DDG::Goodie::WorkdaysBetween'],
# Standard work week
'workdays between 01/06/2014 01/10/2014' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between 01/06/2014 01/10/2014 inclusive' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between 01/06/2014 01/10/2014' => test_zci(@six_to_ten),
'workdays between 01/06/2014 01/10/2014 inclusive' => test_zci(@six_to_ten),
# Ending date first
'workdays between 01/10/2014 01/06/2014' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between 01/10/2014 01/06/2014 inclusive' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between 01/10/2014 01/06/2014' => test_zci(@six_to_ten),
'workdays between 01/10/2014 01/06/2014 inclusive' => test_zci(@six_to_ten),
# Ending date on a weekend
'workdays between 01/06/2014 01/12/2014' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 12 Jan 2014."),
'workdays between 01/06/2014 01/12/2014 inclusive' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 12 Jan 2014."),
'workdays between 01/06/2014 01/12/2014' => test_zci(@somejan),
'workdays between 01/06/2014 01/12/2014 inclusive' => test_zci(@somejan),
# Including the weekend
'workdays between 01/06/2014 01/13/2014' =>
test_zci("There are 6 workdays between 06 Jan 2014 and 13 Jan 2014."),
'workdays between 01/06/2014 01/13/2014 inclusive' =>
test_zci("There are 6 workdays between 06 Jan 2014 and 13 Jan 2014."),
'workdays between 01/06/2014 01/13/2014' => test_zci(@midjan),
'workdays between 01/06/2014 01/13/2014 inclusive' => test_zci(@midjan),
# Including the weekend -- Backwards
'workdays between 01/13/2014 01/06/2014' =>
test_zci("There are 6 workdays between 06 Jan 2014 and 13 Jan 2014."),
'workdays between 01/13/2014 01/06/2014 inclusive' =>
test_zci("There are 6 workdays between 06 Jan 2014 and 13 Jan 2014."),
'workdays between 01/13/2014 01/06/2014' => test_zci(@midjan),
'workdays between 01/13/2014 01/06/2014 inclusive' => test_zci(@midjan),
# Starting on a Saturday
'workdays between 01/11/2014 01/14/2014' =>
test_zci("There are 2 workdays between 11 Jan 2014 and 14 Jan 2014."),
'workdays between 01/11/2014 01/14/2014 inclusive' =>
test_zci("There are 2 workdays between 11 Jan 2014 and 14 Jan 2014."),
'workdays between 01/11/2014 01/14/2014' => test_zci(@somesat),
'workdays between 01/11/2014 01/14/2014 inclusive' => test_zci(@somesat),
# Starting on a Sunday
'workdays between 01/12/2014 01/14/2014' =>
test_zci("There are 2 workdays between 12 Jan 2014 and 14 Jan 2014."),
'workdays between 01/12/2014 01/14/2014 inclusive' =>
test_zci("There are 2 workdays between 12 Jan 2014 and 14 Jan 2014."),
'workdays between 01/12/2014 01/14/2014' => test_zci(@somesun),
'workdays between 01/12/2014 01/14/2014 inclusive' => test_zci(@somesun),
# Workdays in a year
'workdays between 01/01/2014 01/01/2015' =>
test_zci("There are 251 workdays between 01 Jan 2014 and 01 Jan 2015."),
'workdays between 01/01/2014 01/01/2015 inclusive' =>
test_zci("There are 251 workdays between 01 Jan 2014 and 01 Jan 2015."),
'workdays between 01/01/2014 01/01/2015' => test_zci(@twentyfourteen),
'workdays between 01/01/2014 01/01/2015 inclusive' => test_zci(@twentyfourteen),
# Business Days
'business days between 01/06/2014 01/10/2014' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'business days between 01/06/2014 01/10/2014 inclusive' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'business days between 01/06/2014 01/10/2014' => test_zci(@six_to_ten),
'business days between 01/06/2014 01/10/2014 inclusive' => test_zci(@six_to_ten),
# Month and Date are backwards
'workdays between 16/06/2014 20/06/2014' =>
test_zci("There are 5 workdays between 16 Jun 2014 and 20 Jun 2014."),
'workdays between 5/06/2014 20/06/2014' =>
test_zci("There are 12 workdays between 05 Jun 2014 and 20 Jun 2014."),
'workdays between 20/06/2014 5/06/2014' =>
test_zci("There are 12 workdays between 05 Jun 2014 and 20 Jun 2014."),
'workdays between 16/06/2014 20/06/2014' => test_zci(@latejun),
'workdays between 5/06/2014 20/06/2014' => test_zci(@midjune),
'workdays between 20/06/2014 5/06/2014' => test_zci(@midjune),
# Single digit days and months
'workdays between 1/6/2014 1/10/2014' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between 1/6/2014 1/10/2014 inclusive' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between 1/6/2014 1/10/2014' => test_zci(@six_to_ten),
'workdays between 1/6/2014 1/10/2014 inclusive' => test_zci(@six_to_ten),
# Workdays in a year - Dash format
'workdays between 01-01-2014 01-01-2015' =>
test_zci("There are 251 workdays between 01 Jan 2014 and 01 Jan 2015."),
'workdays between 01-01-2014 01-01-2015 inclusive' =>
test_zci("There are 251 workdays between 01 Jan 2014 and 01 Jan 2015."),
'workdays between 01-01-2014 01-01-2015' => test_zci(@twentyfourteen),
'workdays between 01-01-2014 01-01-2015 inclusive' => test_zci(@twentyfourteen),
# Business Days - Dash format
'business days between 01-06-2014 01-10-2014' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'business days between 01-06-2014 01-10-2014 inclusive' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'business days between 01-06-2014 01-10-2014' => test_zci(@six_to_ten),
'business days between 01-06-2014 01-10-2014 inclusive' => test_zci(@six_to_ten),
# Month and Date are backwards - Dash format
'workdays between 16-06-2014 20-06-2014' =>
test_zci("There are 5 workdays between 16 Jun 2014 and 20 Jun 2014."),
'workdays between 5-06-2014 20-06-2014' =>
test_zci("There are 12 workdays between 05 Jun 2014 and 20 Jun 2014."),
'workdays between 20-06-2014 5-06-2014' =>
test_zci("There are 12 workdays between 05 Jun 2014 and 20 Jun 2014."),
'workdays between 16-06-2014 20-06-2014' => test_zci(@latejun),
'workdays between 5-06-2014 20-06-2014' => test_zci(@midjune),
'workdays between 20-06-2014 5-06-2014' => test_zci(@midjune),
# Single digit days and months - Dash format
'workdays between 1-6-2014 1-10-2014' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between 1-6-2014 1-10-2014 inclusive' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between 1-6-2014 1-10-2014' => test_zci(@six_to_ten),
'workdays between 1-6-2014 1-10-2014 inclusive' => test_zci(@six_to_ten),
# Unambiguous date format
'workdays between jan 6 2014 jan 10 2014' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between jan 6 2014 jan 10 2014 inclusive' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between jan 6 2014 jan 10 2014' => test_zci(@six_to_ten),
'workdays between jan 6 2014 jan 10 2014 inclusive' => test_zci(@six_to_ten),
# Unambiguous date format with comma separator
'workdays between jan 6, 2014 jan 10, 2014' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between jan 6, 2014 jan 10, 2014 inclusive' =>
test_zci("There are 5 workdays between 06 Jan 2014 and 10 Jan 2014."),
'workdays between jan 6, 2014 jan 10, 2014' => test_zci(@six_to_ten),
'workdays between jan 6, 2014 jan 10, 2014 inclusive' => test_zci(@six_to_ten),
# Same day
'workdays between jan 3, 2014 jan 3, 2014' =>
test_zci("There is 1 workday between 03 Jan 2014 and 03 Jan 2014."),
'workdays between jan 3, 2014 jan 3, 2014 inclusive' =>
test_zci("There is 1 workday between 03 Jan 2014 and 03 Jan 2014."),
'workdays between jan 3, 2014 jan 3, 2014' => test_zci(@sameday),
'workdays between jan 3, 2014 jan 3, 2014 inclusive' => test_zci(@sameday),
# Same day on a weekend
'workdays between jan 4, 2014 jan 4, 2014' =>
test_zci("There are 0 workdays between 04 Jan 2014 and 04 Jan 2014."),
'workdays between jan 4, 2014 jan 5, 2014 inclusive' =>
test_zci("There are 0 workdays between 04 Jan 2014 and 05 Jan 2014."),
'workdays between jan 4, 2014 jan 4, 2014' => test_zci(@samedaywknd),
'workdays between jan 4, 2014 jan 4, 2014 inclusive' => test_zci(@samedaywknd),
# Weekend in the middle
'workdays between jan 3, 2014 jan 6, 2014' =>
test_zci("There are 2 workdays between 03 Jan 2014 and 06 Jan 2014."),
'workdays between jan 3, 2014 jan 6, 2014 inclusive' =>
test_zci("There are 2 workdays between 03 Jan 2014 and 06 Jan 2014."),
'workdays between jan 3, 2014 jan 6, 2014' => test_zci(@weekend_middle),
'workdays between jan 3, 2014 jan 6, 2014 inclusive' => test_zci(@weekend_middle),
# "to"
'workdays between jan 3, 2014 to jan 6, 2014' =>
test_zci("There are 2 workdays between 03 Jan 2014 and 06 Jan 2014."),
'workdays between jan 3, 2014 to jan 6, 2014 inclusive' =>
test_zci("There are 2 workdays between 03 Jan 2014 and 06 Jan 2014."),
'workdays between jan 3, 2014 to jan 6, 2014' => test_zci(@weekend_middle),
'workdays between jan 3, 2014 to jan 6, 2014 inclusive' => test_zci(@weekend_middle),
# # Same day on a weekend - shortened year
# 'workdays between jan 4, 14 jan 4, 2014' =>
# test_zci("There are 0 workdays between 04 Jan 2014 and 04 Jan 2014."),
# 'workdays between jan 4, 2014 jan 5, 14 inclusive' =>
# test_zci("There are 0 workdays between 04 Jan 2014 and 05 Jan 2014."),
'business days between jan 10 and jan 20' => test_zci(
qr"There are [1-9] workdays between 10 Jan [0-9]{4} and 20 Jan [0-9]{4}\.",
structured_answer => {
input => '-ANY-',
operation => 'workdays between',
result => qr/[1-9]/,
}
),
# # Weekend in the middle - shortened year
# 'workdays between jan 3, 14 jan 6, 14' =>
# test_zci("There are 2 workdays between 03 Jan 2014 and 06 Jan 2014."),
# 'workdays between jan 3, 14 jan 6, 14 inclusive' =>
# test_zci("There are 2 workdays between 03 Jan 2014 and 06 Jan 2014."),
'business days between january and february' => test_zci(
qr"There are [1-9][0-9] workdays between 01 Jan [0-9]{4} and 01 Feb [0-9]{4}\.",
structured_answer => {
input => '-ANY-',
operation => 'workdays between',
result => qr/[1-9][0-9]/,
}
),
# # "to" - shortened year
# 'workdays between jan 3, 14 to jan 6, 2014' =>
# test_zci("There are 2 workdays between 03 Jan 2014 and 06 Jan 2014."),
# 'workdays between jan 3, 14 to jan 6, 2014 inclusive' =>
# test_zci("There are 2 workdays between 03 Jan 2014 and 06 Jan 2014."),
'business days between jan 10 and jan 20' =>
test_zci(qr"There are [1-9] workdays between 10 Jan [0-9]{4} and 20 Jan [0-9]{4}\."),
'business days between january and february' =>
test_zci(qr"There are [1-9][0-9] workdays between 01 Jan [0-9]{4} and 01 Feb [0-9]{4}\."),
'workdays between 01/31/2000 01/31/2001' => test_zci(@twoohoh),
'workdays between 01/31/2000 01/31/2001 inclusive' => test_zci(@twoohoh),
'workdays between 01/31/2000 and 01/31/2001 inclusive' => test_zci(@twoohoh),
'workdays between jan 3 2013 and jan 4 2013' => test_zci(
"There are 2 workdays between 03 Jan 2013 and 04 Jan 2013.",
structured_answer => {
input => ['03 Jan 2013', '04 Jan 2013'],
operation => 'workdays between',
result => 2,
}
),
# Invalid input
'workdays between 01/2014 01/2015' => undef,
'workdays between 01/2014/01' => undef,
'workdays between 01/01/2014 inclusive' => undef,
'workdays between 01/01/2014' => undef,
'workdays between 20/01/2014 inclusive' => undef,
'workdays between 19/19/2014 20/24/2015' => undef,
'workdays between 01/2014 01/2015' => undef,
'workdays between 01/2014/01' => undef,
'workdays between 01/01/2014 inclusive' => undef,
'workdays between 01/01/2014' => undef,
'workdays between 20/01/2014 inclusive' => undef,
'workdays between 19/19/2014 20/24/2015' => undef,
'workdays between 19/19/2014 20/24/2015 inclusive' => undef,
'workdays from FEB 30 2014 to March 24 2014' => undef,
'workdays between 01/31/2000 01/31/2001' =>
test_zci("There are 253 workdays between 31 Jan 2000 and 31 Jan 2001."),
'workdays between 01/31/2000 01/31/2001 inclusive' =>
test_zci("There are 253 workdays between 31 Jan 2000 and 31 Jan 2001."),
'workdays between 01/31/2000 and 01/31/2001 inclusive' =>
test_zci("There are 253 workdays between 31 Jan 2000 and 31 Jan 2001."),
'workdays between jan 3 2013 and jan 4 2013' =>
test_zci("There are 2 workdays between 03 Jan 2013 and 04 Jan 2013."),
'workdays from FEB 30 2014 to March 24 2014' => undef,
);
done_testing;