zeroclickinfo-goodies/t/Frequency.t

104 lines
2.3 KiB
Perl
Raw Normal View History

2012-05-07 18:33:55 -07:00
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Deep;
2012-05-07 18:33:55 -07:00
use DDG::Test::Goodie;
zci is_cached => 1;
zci answer_type => 'frequency';
sub build_structured_test {
my ($plaintext, $record_data, $record_keys) = @_;
return $plaintext,
structured_answer => {
data => {
title => "Frequency",
record_data => $record_data,
record_keys => $record_keys
},
templates => {
group => "list",
options => {
content => "record"
}
2016-06-13 17:17:50 -07:00
}
};
}
2016-06-13 17:17:50 -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
"frequency of all in test" => build_test('e:1/4 s:1/4 t:2/4', {
'e' => 1,
's' => 1,
't' => 2
}, ['e', 's', 't']),
'frequency of all letters in test' => build_test('e:1/4 s:1/4 t:2/4', {
'e' => 1,
's' => 1,
't' => 2
}, ['e', 's', 't']),
'frequency of letters in test' => build_test('e:1/4 s:1/4 t:2/4', {
'e' => 1,
's' => 1,
't' => 2
}, ['e', 's', 't']),
'frequency of all characters in test' => build_test('e:1/4 s:1/4 t:2/4', {
'e' => 1,
's' => 1,
't' => 2
}, ['e', 's', 't']),
'frequency of all chars in test' => build_test('e:1/4 s:1/4 t:2/4', {
'e' => 1,
's' => 1,
't' => 2
}, ['e', 's', 't']),
'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', {
'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']),
'frequency of a in Atlantic Ocean' => build_test('a:3/13', {
"a" => 3
}, ["a"]),
'freq of B in battle' => build_test('b:1/6', {
'b' => 1
}, ['b']),
'freq of s in Spoons' => build_test('s:2/6', {
'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;