2012-05-07 18:33:55 -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-05-07 18:33:55 -07:00
|
|
|
use DDG::Test::Goodie;
|
|
|
|
|
|
|
|
zci is_cached => 1;
|
|
|
|
zci answer_type => 'frequency';
|
|
|
|
|
2016-06-28 21:47:37 -07:00
|
|
|
my $all_chars_subtitle = "Frequency of all characters";
|
2016-06-22 08:47:07 -07:00
|
|
|
|
2016-07-09 03:49:57 -07:00
|
|
|
my @test_response = ('e:1/4 s:1/4 t:2/4', "test", "$all_chars_subtitle", {
|
|
|
|
'e' => 1,
|
|
|
|
's' => 1,
|
|
|
|
't' => 2
|
|
|
|
}, ['e', 's', 't']);
|
|
|
|
|
2016-06-14 05:23:29 -07:00
|
|
|
sub build_structured_test {
|
2016-06-28 21:47:37 -07:00
|
|
|
my ($plaintext, $title, $subtitle, $record_data, $record_keys) = @_;
|
2016-06-14 05:23:29 -07:00
|
|
|
|
|
|
|
return $plaintext,
|
|
|
|
structured_answer => {
|
|
|
|
data => {
|
2016-06-20 13:24:30 -07:00
|
|
|
title => $title,
|
2016-06-28 21:47:37 -07:00
|
|
|
subtitle => $subtitle,
|
2016-06-14 05:23:29 -07:00
|
|
|
record_data => $record_data,
|
|
|
|
record_keys => $record_keys
|
|
|
|
},
|
|
|
|
templates => {
|
|
|
|
group => "list",
|
|
|
|
options => {
|
|
|
|
content => "record"
|
|
|
|
}
|
2016-06-13 17:17:50 -07:00
|
|
|
}
|
2016-06-14 05:23:29 -07:00
|
|
|
};
|
|
|
|
}
|
2016-06-13 17:17:50 -07:00
|
|
|
|
2016-06-14 05:23:29 -07:00
|
|
|
sub build_test {
|
|
|
|
test_zci(build_structured_test(@_));
|
|
|
|
}
|
2016-06-14 04:22:18 -07:00
|
|
|
|
2012-05-07 18:33:55 -07:00
|
|
|
ddg_goodie_test(
|
|
|
|
[qw(
|
|
|
|
DDG::Goodie::Frequency
|
|
|
|
)],
|
2016-06-13 17:17:50 -07:00
|
|
|
|
2016-07-09 03:49:57 -07:00
|
|
|
"frequency of all in test" => build_test(@test_response),
|
2016-06-14 05:23:29 -07:00
|
|
|
|
2016-07-09 03:49:57 -07:00
|
|
|
'frequency of all letters in test' => build_test(@test_response),
|
2016-06-14 05:23:29 -07:00
|
|
|
|
2016-07-09 03:49:57 -07:00
|
|
|
'frequency of letters in test' => build_test(@test_response),
|
2016-06-14 05:23:29 -07:00
|
|
|
|
2016-07-09 03:49:57 -07:00
|
|
|
'frequency of all characters in test' => build_test(@test_response),
|
2016-06-14 05:23:29 -07:00
|
|
|
|
2016-07-09 03:49:57 -07:00
|
|
|
'frequency of all alphabets in test' => build_test(@test_response),
|
2016-06-28 21:58:51 -07:00
|
|
|
|
2016-07-09 03:49:57 -07:00
|
|
|
'frequency of all chars in test' => build_test(@test_response),
|
2016-06-14 05:23:29 -07:00
|
|
|
|
2016-07-06 13:04:48 -07:00
|
|
|
'frequency of all in testing 1234 ABC!' => build_test('a:1/10 b:1/10 c:1/10 e:1/10 g:1/10 i:1/10 n:1/10 s:1/10 t:2/10', "testing 1234 ABC!", "$all_chars_subtitle", {
|
2016-06-14 05:23:29 -07:00
|
|
|
'a' => 1,
|
|
|
|
'b' => 1,
|
|
|
|
'c' => 1,
|
|
|
|
'e' => 1,
|
|
|
|
'g' => 1,
|
|
|
|
'i' => 1,
|
|
|
|
'n' => 1,
|
|
|
|
's' => 1,
|
|
|
|
't' => 2
|
|
|
|
}, ['a', 'b', 'c', 'e', 'g', 'i', 'n', 's', 't']),
|
|
|
|
|
2016-06-28 21:47:37 -07:00
|
|
|
'frequency of a in Atlantic Ocean' => build_test('a:3/13', "Atlantic Ocean", "Frequency of 'a'", {
|
2016-06-14 05:23:29 -07:00
|
|
|
"a" => 3
|
|
|
|
}, ["a"]),
|
|
|
|
|
2016-06-28 21:47:37 -07:00
|
|
|
'freq of B in battle' => build_test('b:1/6', "battle", "Frequency of 'B'", {
|
2016-06-14 05:23:29 -07:00
|
|
|
'b' => 1
|
|
|
|
}, ['b']),
|
|
|
|
|
2016-06-28 21:47:37 -07:00
|
|
|
'freq of s in Spoons' => build_test('s:2/6', "Spoons", "Frequency of 's'", {
|
2016-06-14 05:23:29 -07:00
|
|
|
's' => 2
|
|
|
|
}, ['s']),
|
2016-06-13 17:17:50 -07:00
|
|
|
|
2016-06-14 04:22:18 -07:00
|
|
|
'frequency s in spoons' => undef,
|
|
|
|
'freq s in spoons' => undef,
|
|
|
|
'frequency s spoons' => undef,
|
|
|
|
'freq s spoons' => undef,
|
|
|
|
'frequency of s spoons' => undef,
|
|
|
|
'freq of s spoons' => undef
|
2016-06-13 17:17:50 -07:00
|
|
|
|
2012-05-07 18:33:55 -07:00
|
|
|
);
|
|
|
|
|
2016-05-16 06:18:04 -07:00
|
|
|
done_testing;
|