zeroclickinfo-goodies/t/DateMath.t

145 lines
4.1 KiB
Perl
Raw Normal View History

#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
2014-12-27 00:42:14 -08:00
use Test::MockTime qw( :all );
use DDG::Test::Goodie;
zci answer_type => 'date_math';
2014-10-06 03:26:19 -07:00
zci is_cached => 1;
2014-10-06 03:26:19 -07:00
my @overjan = (
'01 Jan 2012 + 32 days is 02 Feb 2012',
structured_answer => {
input => ['01 Jan 2012 + 32 days'],
operation => 'Date math',
2014-10-06 03:26:19 -07:00
result => '02 Feb 2012',
},
);
my @first_sec = (
'01 Jan 2012 + 1 day is 02 Jan 2012',
structured_answer => {
input => ['01 Jan 2012 + 1 day'],
operation => 'Date math',
2014-10-06 03:26:19 -07:00
result => '02 Jan 2012',
},
);
2014-12-27 00:42:14 -08:00
set_fixed_time("2014-03-12T10:00:00");
2014-12-25 08:23:31 -08:00
2014-10-06 03:26:19 -07:00
ddg_goodie_test([qw(
DDG::Goodie::DateMath
)
],
'Jan 1 2012 plus 32 days' => test_zci(@overjan),
'January 1 2012 plus 32 days' => test_zci(@overjan),
'January 1, 2012 plus 32 days' => test_zci(@overjan),
'January 1st 2012 plus 32 days' => test_zci(@overjan),
2014-12-24 23:05:12 -08:00
'32 days from January 1st 2012' => test_zci(@overjan),
2014-10-06 03:26:19 -07:00
'January 1st plus 32 days' => test_zci(
2014-12-27 01:47:30 -08:00
'01 Jan 2014 + 32 days is 02 Feb 2014',
2014-10-06 03:26:19 -07:00
structured_answer => {
input => '-ANY-',
operation => 'Date math',
2014-12-27 01:47:30 -08:00
result => '02 Feb 2014',
2014-10-06 03:26:19 -07:00
},
),
2014-12-24 23:05:12 -08:00
'date January 1st' => test_zci(
2014-12-27 01:47:30 -08:00
'01 Jan 2014',
2014-12-24 23:05:12 -08:00
structured_answer => {
input => ['january 1st'],
operation => 'Date math',
2014-12-27 01:47:30 -08:00
result => '01 Jan 2014',
2014-12-24 23:05:12 -08:00
}
),
2014-12-25 08:23:31 -08:00
'6 weeks ago' => test_zci(
2014-12-27 00:42:14 -08:00
'29 Jan 2014',
2014-12-25 08:23:31 -08:00
structured_answer => {
input => ['6 weeks ago'],
operation => 'Date math',
2014-12-27 00:42:14 -08:00
result => '29 Jan 2014',
2014-12-25 08:23:31 -08:00
}
),
'2 weeks from today' => test_zci(
2014-12-27 00:42:14 -08:00
'12 Mar 2014 + 2 weeks is 26 Mar 2014',
2014-12-25 08:23:31 -08:00
structured_answer => {
2014-12-27 00:42:14 -08:00
input => ['12 Mar 2014 + 2 weeks'],
operation => 'Date math',
2014-12-27 00:42:14 -08:00
result => '26 Mar 2014',
2014-12-25 08:23:31 -08:00
}
),
'in 3 weeks' => test_zci(
'02 Apr 2014',
structured_answer => {
input => ['in 3 weeks'],
operation => 'Date math',
result => '02 Apr 2014',
}
),
2014-12-25 08:23:31 -08:00
'date today' => test_zci(
2014-12-27 00:42:14 -08:00
'12 Mar 2014',
2014-12-25 08:23:31 -08:00
structured_answer => {
input => ['today'],
operation => 'Date math',
2014-12-27 00:42:14 -08:00
result => '12 Mar 2014',
2014-12-25 08:23:31 -08:00
}
),
2014-10-06 03:26:19 -07:00
'1/1/2012 plus 32 days' => test_zci(@overjan),
'1/1/2012 plus 5 weeks' => test_zci(
'01 Jan 2012 + 5 weeks is 05 Feb 2012',
structured_answer => {
input => ['01 Jan 2012 + 5 weeks'],
operation => 'Date math',
2014-10-06 03:26:19 -07:00
result => '05 Feb 2012',
},
),
'1/1/2012 PlUs 5 months' => test_zci(
'01 Jan 2012 + 5 months is 01 Jun 2012',
structured_answer => {
input => ['01 Jan 2012 + 5 months'],
operation => 'Date math',
2014-10-06 03:26:19 -07:00
result => '01 Jun 2012',
},
),
'1/1/2012 PLUS 5 years' => test_zci(
'01 Jan 2012 + 5 years is 01 Jan 2017',
structured_answer => {
input => ['01 Jan 2012 + 5 years'],
operation => 'Date math',
2014-10-06 03:26:19 -07:00
result => '01 Jan 2017',
},
),
2014-12-24 23:05:12 -08:00
'1 day from 1/1/2012' => test_zci(@first_sec),
2014-10-06 03:26:19 -07:00
'1/1/2012 plus 1 day' => test_zci(@first_sec),
'1/1/2012 plus 1 days' => test_zci(@first_sec),
'01/01/2012 + 1 day' => test_zci(@first_sec),
'1/1/2012 minus ten days' => test_zci(
'01 Jan 2012 - 10 days is 22 Dec 2011',
structured_answer => {
input => ['01 Jan 2012 - 10 days'],
operation => 'Date math',
2014-10-06 03:26:19 -07:00
result => '22 Dec 2011',
},
),
'1 jan 2014 plus 2 weeks' => test_zci(
'01 Jan 2014 + 2 weeks is 15 Jan 2014',
structured_answer => {
input => ['01 Jan 2014 + 2 weeks'],
operation => 'Date math',
2014-10-06 03:26:19 -07:00
result => '15 Jan 2014',
},
),
2014-12-25 08:23:31 -08:00
'yesterday' => undef,
'today' => undef,
'five years' => undef,
'two months' => undef,
'2 months' => undef,
'5 years' => undef,
);
done_testing;