2014-04-29 08:09:33 -07:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Test::More;
|
|
|
|
use DDG::Test::Goodie;
|
|
|
|
|
|
|
|
zci answer_type => 'weekdays_between';
|
2014-09-26 12:21:38 -07:00
|
|
|
zci is_cached => 0;
|
|
|
|
|
|
|
|
my @six_to_ten = (
|
2015-01-09 06:18:15 -08:00
|
|
|
"There are 5 Weekdays 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 => 'Weekdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 5,
|
|
|
|
});
|
2014-04-29 08:09:33 -07:00
|
|
|
|
|
|
|
ddg_goodie_test(
|
2014-09-26 12:21:38 -07:00
|
|
|
['DDG::Goodie::WeekdaysBetween'],
|
2014-04-29 08:09:33 -07:00
|
|
|
|
2014-08-30 02:39:09 -07:00
|
|
|
# Primary query example
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between 01/31/2000 01/31/2001' => test_zci(
|
|
|
|
"There are 263 Weekdays 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 => 'Weekdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 263,
|
|
|
|
}
|
|
|
|
),
|
2014-08-30 02:39:09 -07:00
|
|
|
|
2014-07-07 15:03:45 -07:00
|
|
|
# Test different trigger words
|
2014-09-26 12:21:38 -07:00
|
|
|
'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),
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays from 01/06/2014 01/10/2014' => test_zci(@six_to_ten),
|
2014-07-07 15:03:45 -07:00
|
|
|
|
2014-04-29 08:09:33 -07:00
|
|
|
# Standard work week
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between 01/06/2014 01/10/2014' => test_zci(@six_to_ten),
|
2014-10-28 11:36:15 -07:00
|
|
|
|
2014-09-26 12:21:38 -07:00
|
|
|
# Ending date first
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between 01/10/2014 01/06/2014' => test_zci(@six_to_ten),
|
2014-07-07 14:53:10 -07:00
|
|
|
|
|
|
|
# Including the weekend -- Backwards
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between 01/13/2014 01/06/2014' => test_zci(
|
|
|
|
"There are 6 Weekdays 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 => 'Weekdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 6,
|
|
|
|
}
|
|
|
|
),
|
2014-07-07 14:53:10 -07:00
|
|
|
|
2014-07-07 15:03:45 -07:00
|
|
|
# Weekdays in a year - Dash format
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between 01-01-2014 01-01-2015' => test_zci(
|
|
|
|
"There are 262 Weekdays 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 => 'Weekdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 262,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
|
|
|
|
# Single digit days and months - Dash format
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between 1-6-2014 1-10-2014' => test_zci(@six_to_ten),
|
2014-07-07 15:03:45 -07:00
|
|
|
|
|
|
|
# Unambiguous date format
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between jan 6 2014 jan 10 2014' => test_zci(@six_to_ten),
|
2014-07-07 15:03:45 -07:00
|
|
|
|
|
|
|
# Unambiguous date format with comma separator
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between jan 6, 2014 jan 10, 2014' => test_zci(@six_to_ten),
|
2014-07-07 15:03:45 -07:00
|
|
|
|
2014-04-29 08:09:33 -07:00
|
|
|
# Weekend in the middle
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between jan 3, 2014 jan 6, 2014' => test_zci(
|
|
|
|
"There are 2 Weekdays 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 => 'Weekdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 2,
|
|
|
|
}
|
|
|
|
),
|
2014-04-29 08:09:33 -07:00
|
|
|
|
|
|
|
# Same day
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between jan 3, 2014 jan 3, 2014' => test_zci(
|
|
|
|
"There is 1 Weekday 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 => 'Weekday between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 1,
|
|
|
|
}
|
|
|
|
),
|
2014-10-28 11:36:15 -07:00
|
|
|
|
2014-04-29 08:09:33 -07:00
|
|
|
# Same day on a weekend
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between jan 4, 2014 jan 4, 2014' => test_zci(
|
|
|
|
"There are 0 Weekdays 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 => 'Weekdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 0,
|
|
|
|
}
|
|
|
|
),
|
2014-10-28 11:36:15 -07:00
|
|
|
|
2014-07-07 14:53:10 -07:00
|
|
|
# Starting on a Saturday
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between 01/11/2014 01/14/2014' => test_zci(
|
|
|
|
"There are 2 Weekdays 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 => 'Weekdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 2,
|
|
|
|
}
|
|
|
|
),
|
2014-07-07 14:53:10 -07:00
|
|
|
|
|
|
|
# Starting on a Sunday
|
2015-01-09 06:18:15 -08:00
|
|
|
'Weekdays between 01/12/2014 01/17/2014' => test_zci(
|
|
|
|
"There are 5 Weekdays between 12 Jan 2014 and 17 Jan 2014.",
|
2014-09-26 12:21:38 -07:00
|
|
|
structured_answer => {
|
|
|
|
input => ['12 Jan 2014', '17 Jan 2014'],
|
2015-01-09 00:46:54 -08:00
|
|
|
operation => 'Weekdays between',
|
2014-09-26 12:21:38 -07:00
|
|
|
result => 5,
|
|
|
|
}
|
|
|
|
),
|
2014-07-07 14:53:10 -07:00
|
|
|
|
2014-10-28 11:36:15 -07:00
|
|
|
# Invalid input
|
2015-01-09 06:18:15 -08:00
|
|
|
'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,
|
2014-04-29 08:09:33 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
done_testing;
|