2015-10-17 11:07:39 -07:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Test::More;
|
2016-05-16 06:07:57 -07:00
|
|
|
use Test::Deep;
|
2015-10-17 11:07:39 -07:00
|
|
|
use DDG::Test::Goodie;
|
|
|
|
|
2015-10-17 11:53:32 -07:00
|
|
|
zci answer_type => "prime";
|
2015-10-17 11:07:39 -07:00
|
|
|
zci is_cached => 1;
|
|
|
|
|
|
|
|
ddg_goodie_test(
|
|
|
|
[qw( DDG::Goodie::PrimeNumber )],
|
2015-11-04 12:22:58 -08:00
|
|
|
'prime numbers between 4 and 100' => test_zci(
|
|
|
|
"5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97",
|
|
|
|
make_structured_answer(4, 100, "5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97")
|
2015-10-17 11:53:32 -07:00
|
|
|
),
|
2015-11-04 12:22:58 -08:00
|
|
|
'prime numbers between 12.6 and 99.7' => test_zci(
|
|
|
|
"13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97",
|
|
|
|
make_structured_answer(12.6, 99.7, "13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97")
|
2015-10-18 06:39:07 -07:00
|
|
|
),
|
2015-11-04 12:22:58 -08:00
|
|
|
'prime numbers between 23 and 5' => test_zci(
|
|
|
|
"5, 7, 11, 13, 17, 19, 23",
|
|
|
|
make_structured_answer(5, 23, "5, 7, 11, 13, 17, 19, 23")
|
2015-10-18 06:39:07 -07:00
|
|
|
),
|
2015-11-04 12:22:58 -08:00
|
|
|
'prime numbers between 5 and 5' => test_zci(
|
|
|
|
"5",
|
|
|
|
make_structured_answer(5, 5, "5")
|
2015-10-18 06:39:07 -07:00
|
|
|
),
|
2015-11-04 12:22:58 -08:00
|
|
|
'prime numbers between 7.4' => test_zci(
|
|
|
|
"2, 3, 5, 7",
|
|
|
|
make_structured_answer(1, 7.4, "2, 3, 5, 7")
|
2015-10-18 06:39:07 -07:00
|
|
|
),
|
2015-11-04 12:22:58 -08:00
|
|
|
'prime num between 11 and 34' => test_zci(
|
|
|
|
"11, 13, 17, 19, 23, 29, 31",
|
|
|
|
make_structured_answer(11, 34, "11, 13, 17, 19, 23, 29, 31")
|
2015-10-18 06:39:07 -07:00
|
|
|
),
|
2015-11-04 12:22:58 -08:00
|
|
|
'prime number between 1010 and 1048' => test_zci(
|
|
|
|
"1013, 1019, 1021, 1031, 1033, 1039",
|
|
|
|
make_structured_answer(1010, 1048, "1013, 1019, 1021, 1031, 1033, 1039")
|
2015-10-18 06:39:07 -07:00
|
|
|
),
|
2015-11-04 12:22:58 -08:00
|
|
|
'prime numbers between 10010 and 10036' => test_zci(
|
|
|
|
"None",
|
|
|
|
make_structured_answer(10010, 10036, "None")
|
2015-10-18 06:39:07 -07:00
|
|
|
),
|
2015-11-04 12:22:58 -08:00
|
|
|
'prime numbers between' => test_zci(
|
|
|
|
"None",
|
|
|
|
make_structured_answer(1, 1, "None")
|
2015-10-18 06:39:07 -07:00
|
|
|
),
|
2015-11-04 12:22:58 -08:00
|
|
|
'prime numbers between -3.4 and 5.7' => test_zci(
|
|
|
|
"2, 3, 5",
|
|
|
|
make_structured_answer(-3.4, 5.7, "2, 3, 5")
|
2015-10-18 06:39:07 -07:00
|
|
|
),
|
2015-11-04 12:22:58 -08:00
|
|
|
'prime numbers between -3.4 and -5.7' => test_zci(
|
|
|
|
"None",
|
|
|
|
make_structured_answer(-5.7, -3.4, "None")
|
2015-10-18 06:39:07 -07:00
|
|
|
),
|
|
|
|
'prime numbers between hello and zebra' => undef,
|
|
|
|
'prime numbe between 3 and 45' => undef,
|
|
|
|
'prime numbers between 3 and four' => undef,
|
2015-10-17 11:07:39 -07:00
|
|
|
);
|
|
|
|
|
2015-11-04 12:22:58 -08:00
|
|
|
sub make_structured_answer {
|
|
|
|
my ($start, $end, $description ) = @_;
|
|
|
|
return structured_answer => {
|
|
|
|
data => {
|
|
|
|
title => "Prime numbers between $start and $end",
|
|
|
|
description => $description,
|
|
|
|
},
|
|
|
|
templates => {
|
|
|
|
group => 'text',
|
|
|
|
options => {
|
|
|
|
chompContent => 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-05-16 06:07:57 -07:00
|
|
|
done_testing;
|