2014-01-14 05:52:21 -08:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Test::More;
|
|
|
|
use DDG::Test::Goodie;
|
|
|
|
|
2015-02-01 03:18:43 -08:00
|
|
|
use Test::MockTime qw( :all );
|
|
|
|
|
2014-01-14 05:52:21 -08:00
|
|
|
zci answer_type => 'workdays_between';
|
2014-09-27 06:42:57 -07:00
|
|
|
zci is_cached => 0;
|
2014-01-14 05:52:21 -08:00
|
|
|
|
2014-09-26 12:21:38 -07:00
|
|
|
my @six_to_ten = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There are 5 Workdays between 06 Jan 2014 and 10 Jan 2014.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['06 Jan 2014', '10 Jan 2014'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 5,
|
|
|
|
});
|
|
|
|
my @twentyfourteen = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There are 251 Workdays between 01 Jan 2014 and 01 Jan 2015.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['01 Jan 2014', '01 Jan 2015'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 251,
|
|
|
|
});
|
|
|
|
my @twoohoh = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There are 253 Workdays between 31 Jan 2000 and 31 Jan 2001.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['31 Jan 2000', '31 Jan 2001'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 253,
|
|
|
|
});
|
|
|
|
my @midjune = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There are 12 Workdays between 05 Jun 2014 and 20 Jun 2014.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['05 Jun 2014', '20 Jun 2014'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 12,
|
|
|
|
});
|
|
|
|
my @midjan = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There are 6 Workdays between 06 Jan 2014 and 13 Jan 2014.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['06 Jan 2014', '13 Jan 2014'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 6,
|
|
|
|
});
|
|
|
|
my @somejan = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There are 5 Workdays between 06 Jan 2014 and 12 Jan 2014.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['06 Jan 2014', '12 Jan 2014'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 5,
|
|
|
|
});
|
|
|
|
my @somesat = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There are 2 Workdays between 11 Jan 2014 and 14 Jan 2014.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['11 Jan 2014', '14 Jan 2014'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 2,
|
|
|
|
});
|
|
|
|
my @somesun = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There are 2 Workdays between 12 Jan 2014 and 14 Jan 2014.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['12 Jan 2014', '14 Jan 2014'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 2,
|
|
|
|
});
|
|
|
|
my @latejun = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There are 5 Workdays between 16 Jun 2014 and 20 Jun 2014.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['16 Jun 2014', '20 Jun 2014'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 5,
|
|
|
|
});
|
|
|
|
my @sameday = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There is 1 Workday between 03 Jan 2014 and 03 Jan 2014.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['03 Jan 2014', '03 Jan 2014'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workday between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 1,
|
|
|
|
});
|
|
|
|
my @samedaywknd = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There are 0 Workdays between 04 Jan 2014 and 04 Jan 2014.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['04 Jan 2014', '04 Jan 2014'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 0,
|
|
|
|
});
|
|
|
|
my @weekend_middle = (
|
2015-01-09 06:18:15 -08:00
|
|
|
'There are 2 Workdays between 03 Jan 2014 and 06 Jan 2014.',
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['03 Jan 2014', '06 Jan 2014'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 2,
|
|
|
|
});
|
|
|
|
|
2014-01-14 05:52:21 -08:00
|
|
|
ddg_goodie_test(
|
2014-09-26 12:21:38 -07:00
|
|
|
['DDG::Goodie::WorkdaysBetween'],
|
2014-01-14 05:52:21 -08:00
|
|
|
|
|
|
|
# Standard work week
|
2015-01-09 06:18:15 -08:00
|
|
|
'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),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
2014-01-14 14:59:16 -08:00
|
|
|
# Ending date first
|
2015-01-09 06:18:15 -08:00
|
|
|
'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),
|
2014-01-14 14:59:16 -08:00
|
|
|
|
2014-01-14 05:52:21 -08:00
|
|
|
# Ending date on a weekend
|
2015-01-09 06:18:15 -08:00
|
|
|
'Workdays between 01/06/2014 01/12/2014' => test_zci(@somejan),
|
|
|
|
'Workdays between 01/06/2014 01/12/2014 inclusive' => test_zci(@somejan),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
|
|
|
# Including the weekend
|
2015-01-09 06:18:15 -08:00
|
|
|
'Workdays between 01/06/2014 01/13/2014' => test_zci(@midjan),
|
|
|
|
'Workdays between 01/06/2014 01/13/2014 inclusive' => test_zci(@midjan),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
2014-01-14 14:59:16 -08:00
|
|
|
# Including the weekend -- Backwards
|
2015-01-09 06:18:15 -08:00
|
|
|
'Workdays between 01/13/2014 01/06/2014' => test_zci(@midjan),
|
|
|
|
'Workdays between 01/13/2014 01/06/2014 inclusive' => test_zci(@midjan),
|
2014-01-14 14:59:16 -08:00
|
|
|
|
2014-01-14 05:52:21 -08:00
|
|
|
# Starting on a Saturday
|
2015-01-09 06:18:15 -08:00
|
|
|
'Workdays between 01/11/2014 01/14/2014' => test_zci(@somesat),
|
|
|
|
'Workdays between 01/11/2014 01/14/2014 inclusive' => test_zci(@somesat),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
|
|
|
# Starting on a Sunday
|
2015-01-09 06:18:15 -08:00
|
|
|
'Workdays between 01/12/2014 01/14/2014' => test_zci(@somesun),
|
|
|
|
'Workdays between 01/12/2014 01/14/2014 inclusive' => test_zci(@somesun),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
|
|
|
# Workdays in a year
|
2015-01-09 06:18:15 -08:00
|
|
|
'Workdays between 01/01/2014 01/01/2015' => test_zci(@twentyfourteen),
|
|
|
|
'Workdays between 01/01/2014 01/01/2015 inclusive' => test_zci(@twentyfourteen),
|
2014-01-14 05:52:21 -08:00
|
|
|
|
2014-01-15 12:58:05 -08:00
|
|
|
# Business Days
|
2014-09-26 12:21:38 -07:00
|
|
|
'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),
|
2014-01-15 12:58:05 -08:00
|
|
|
|
2014-01-15 14:15:44 -08:00
|
|
|
# Month and Date are backwards
|
2015-01-09 06:18:15 -08:00
|
|
|
'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),
|
2014-01-15 14:15:44 -08:00
|
|
|
|
2014-01-15 14:40:42 -08:00
|
|
|
# Single digit days and months
|
2015-01-09 06:18:15 -08:00
|
|
|
'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),
|
2014-01-15 14:40:42 -08:00
|
|
|
|
2014-01-28 06:14:32 -08:00
|
|
|
# Workdays in a year - Dash format
|
2015-01-09 06:18:15 -08:00
|
|
|
'Workdays between 01-01-2014 01-01-2015' => test_zci(@twentyfourteen),
|
|
|
|
'Workdays between 01-01-2014 01-01-2015 inclusive' => test_zci(@twentyfourteen),
|
2014-01-28 06:14:32 -08:00
|
|
|
|
|
|
|
# Business Days - Dash format
|
2014-09-26 12:21:38 -07:00
|
|
|
'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),
|
2014-01-28 06:14:32 -08:00
|
|
|
|
|
|
|
# Month and Date are backwards - Dash format
|
2015-01-09 06:18:15 -08:00
|
|
|
'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),
|
2014-01-28 06:14:32 -08:00
|
|
|
|
|
|
|
# Single digit days and months - Dash format
|
2015-01-09 06:18:15 -08:00
|
|
|
'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),
|
2014-01-28 06:14:32 -08:00
|
|
|
|
2014-01-15 14:36:01 -08:00
|
|
|
# Unambiguous date format
|
2015-01-09 06:18:15 -08:00
|
|
|
'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),
|
2014-01-15 14:36:01 -08:00
|
|
|
|
2014-01-15 14:38:36 -08:00
|
|
|
# Unambiguous date format with comma separator
|
2015-01-09 06:18:15 -08:00
|
|
|
'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),
|
2014-01-15 14:38:36 -08:00
|
|
|
|
2014-01-25 09:42:03 -08:00
|
|
|
# Same day
|
2015-01-09 06:18:15 -08:00
|
|
|
'Workdays between jan 3, 2014 jan 3, 2014' => test_zci(@sameday),
|
|
|
|
'Workdays between jan 3, 2014 jan 3, 2014 inclusive' => test_zci(@sameday),
|
2014-01-25 09:42:03 -08:00
|
|
|
|
|
|
|
# Same day on a weekend
|
2015-01-09 06:18:15 -08:00
|
|
|
'Workdays between jan 4, 2014 jan 4, 2014' => test_zci(@samedaywknd),
|
|
|
|
'Workdays between jan 4, 2014 jan 4, 2014 inclusive' => test_zci(@samedaywknd),
|
2014-01-25 09:42:03 -08:00
|
|
|
|
|
|
|
# Weekend in the middle
|
2015-01-09 06:18:15 -08:00
|
|
|
'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),
|
2014-01-25 09:42:03 -08:00
|
|
|
|
|
|
|
# "to"
|
2015-01-09 06:18:15 -08:00
|
|
|
'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),
|
2014-09-26 12:21:38 -07:00
|
|
|
|
2015-01-09 06:18:15 -08:00
|
|
|
'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.",
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['03 Jan 2013', '04 Jan 2013'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Workdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 2,
|
|
|
|
}
|
|
|
|
),
|
2014-01-28 21:01:22 -08:00
|
|
|
|
2014-01-14 05:52:21 -08:00
|
|
|
# Invalid input
|
2015-01-09 06:18:15 -08:00
|
|
|
'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,
|
2014-01-14 05:52:21 -08:00
|
|
|
);
|
|
|
|
|
2015-02-01 03:18:43 -08:00
|
|
|
set_fixed_time("2015-01-11T09:45:56");
|
|
|
|
ddg_goodie_test(
|
|
|
|
[qw(
|
|
|
|
DDG::Goodie::WorkdaysBetween
|
|
|
|
)],
|
|
|
|
'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]/,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
|
|
|
|
'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]/,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2014-01-14 05:52:21 -08:00
|
|
|
done_testing;
|