2012-04-15 13:04:53 -07:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Test::More;
|
2016-05-16 06:07:57 -07:00
|
|
|
use Test::Deep;
|
2012-04-15 13:04:53 -07:00
|
|
|
use DDG::Test::Goodie;
|
|
|
|
|
|
|
|
zci answer_type => 'average';
|
|
|
|
zci is_cached => 1;
|
|
|
|
|
2016-04-28 11:00:13 -07:00
|
|
|
sub build_structured_answer {
|
|
|
|
my ($input, $type, $result) = @_;
|
|
|
|
return "$type: $result",
|
|
|
|
structured_answer => {
|
|
|
|
data => {
|
|
|
|
title => $result,
|
|
|
|
subtitle => $type . ' of: ' . $input
|
|
|
|
},
|
|
|
|
templates => {
|
|
|
|
group => 'text'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub build_test { test_zci(build_structured_answer(@_)) }
|
|
|
|
|
2012-04-15 13:04:53 -07:00
|
|
|
ddg_goodie_test(
|
2016-04-28 11:00:13 -07:00
|
|
|
[qw(DDG::Goodie::Average)],
|
|
|
|
|
|
|
|
'1 2 3 avg' => build_test('1 2 3', 'Mean', '2'),
|
|
|
|
'mean 1, 2, 3' => build_test('1 2 3', 'Mean', '2'),
|
|
|
|
'root mean square 1,2,3' => build_test('1 2 3', 'Root Mean Square', '2.16024689946929'),
|
|
|
|
'rms 1,2,3' => build_test('1 2 3', 'Root Mean Square', '2.16024689946929'),
|
|
|
|
"average 12 45 78 1234.12" => build_test('12 45 78 1234.12', 'Mean', '342.28'),
|
|
|
|
"average 12, 45, 78, 1234.12" => build_test('12 45 78 1234.12', 'Mean', '342.28'),
|
|
|
|
"average 12;45;78;1234.12" => build_test('12 45 78 1234.12', 'Mean', '342.28'),
|
|
|
|
'average 12, 45, 78, 1234' => build_test('12 45 78 1234', 'Mean', '342.25'),
|
|
|
|
'median 1,2,3' => build_test('1 2 3', 'Median', '2'),
|
2014-07-23 22:34:12 -07:00
|
|
|
|
|
|
|
#Should not trigger
|
|
|
|
'average temperature philadelphia 2012 january' => undef,
|
2012-04-15 13:04:53 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
done_testing;
|