Merge remote-tracking branch 'upstream/master' into issue-2002

master
rgaul 2016-05-16 16:56:15 +00:00
commit 7e056981e9
223 changed files with 2232 additions and 1777 deletions

View File

@ -30,13 +30,17 @@ handle remainder => sub {
return unless $month;
my $stone = $birthstones{$month};
return unless $stone;
return $month . " birthstone: $stone",
structured_answer => {
input => [$month],
operation => 'Birthstone',
result => $stone
};
structured_answer => {
data => {
title => $stone,
subtitle => 'Birthstone for '.$month
},
templates => {
group => "text",
}
}
};
1;

View File

@ -7,7 +7,7 @@ use DDG::Goodie;
use Convert::Braille;
use utf8;
triggers query_raw => qr/\p{Braille}|braille/i;
triggers query_raw => qr/\p{Braille}|( in| to){1} braille$|^braille:/i;
zci is_cached => 1;
@ -16,22 +16,29 @@ my $braille_space = ''; # the braille unicode space (U+2800)
handle query_raw => sub {
my $query = $_;
$query =~ s/translate to braille |( in)? braille$|^braille //;
$query =~ s/( in| to){1} braille$|^braille:\s?//;
return unless $query;
my $result;
my $response;
my $type;
if ($query =~ /\p{Braille}/) {
$result = join(" ", map { lc(brailleDotsToAscii($_)) } split(/$braille_space/, $query));
$response = join(" ", map { lc(brailleDotsToAscii($_)) } split(/$braille_space/, $query));
$type = "Ascii/Unicode";
} else {
$result = join($braille_space, map { brailleAsciiToUnicode(uc $_) } split(/\s/, $query));
$response = join($braille_space, map { brailleAsciiToUnicode(uc $_) } split(/\s/, $query));
$type = "Braille";
}
return $result . ' (Braille)',
return $response,
structured_answer => {
input => [html_enc($query)],
operation => 'Braille translation',
result => html_enc($result),
data => {
title => $response,
subtitle => 'Braille translation: ' . html_enc($query),
},
templates => {
group => 'text',
},
};
};

View File

@ -45,12 +45,23 @@ sub generate_triggers {
my %triggers;
# This will contain a lookup from triggers to categories and/or files.
my %trigger_lookup;
# This will contain all the ignored phrases and their associated categories.
my %ignore_phrases;
while (my ($name, $trigger_setsh) = each %spec_triggers) {
my $ignore_phrases = delete $trigger_setsh->{ignore};
while (my ($trigger_type, $triggersh) = each %$trigger_setsh) {
foreach my $trigger (@{$triggersh}) {
# Add trigger to global triggers.
$triggers{$trigger_type}{$trigger} = 1;
# Handle ignored components - these will be stripped
# from query and not be included in final trigger.
if (defined $ignore_phrases) {
my %new_ignore_phrases = map { $_ => 1 }
(keys %{$ignore_phrases{$trigger} || {}},
@$ignore_phrases);
$ignore_phrases{$trigger} = \%new_ignore_phrases;
}
my %new_triggers = map { $_ => 1}
(keys %{$trigger_lookup{$trigger}});
if ($name !~ /cheat_sheet$/) {
@ -65,7 +76,7 @@ sub generate_triggers {
while (my ($trigger_type, $triggers) = each %triggers) {
triggers $trigger_type => (keys %{$triggers});
}
return %trigger_lookup;
return (\%ignore_phrases, %trigger_lookup);
}
# Initialize aliases.
@ -100,15 +111,17 @@ sub get_aliases {
my $aliases = get_aliases();
my %trigger_lookup = generate_triggers($aliases);
my ($trigger_ignore, %trigger_lookup) = generate_triggers($aliases);
handle remainder => sub {
my $remainder = shift;
handle remainder_lc => sub {
my @query_parts = split /\s+/o, shift;
my $trigger = join(' ', split /\s+/o, lc($req->matched_trigger));
my $lookup = $trigger_lookup{$trigger};
my $file = $aliases->{join(' ', split /\s+/o, lc($remainder))} or return;
my $alias = join ' ', exists $trigger_ignore->{$trigger}
? grep { not exists $trigger_ignore->{$trigger}{$_} } @query_parts
: @query_parts;
my $file = $aliases->{$alias} or return;
open my $fh, $file or return;
my $json = do { local $/; <$fh> };
my $data = decode_json($json) or return;

13
lib/DDG/Goodie/Combination.pm Normal file → Executable file
View File

@ -51,11 +51,14 @@ handle query => sub {
my $formatted_result = $style->for_display($result);
return $formatted_result,
structured_answer => {
input => [$style->for_display($n) . " $operation " . $style->for_display($k)],
operation => 'Calculate',
result => $formatted_result,
return $formatted_result, structured_answer => {
data => {
title => $formatted_result,
subtitle => $style->for_display($n) . " $operation " . $style->for_display($k)
},
templates => {
group => 'text'
}
};
};

View File

@ -8,6 +8,7 @@ with 'DDG::GoodieRole::NumberStyler';
use Math::Round qw/nearest/;
use utf8;
use YAML::XS 'LoadFile';
use List::Util qw(any);
zci answer_type => 'conversions';
zci is_cached => 1;
@ -16,10 +17,15 @@ use bignum;
my @types = LoadFile(share('ratios.yml'));
my %unit_to_plural = ();
my @units = ();
my %plural_to_unit = ();
foreach my $type (@types) {
push(@units, $type->{'unit'});
push(@units, $type->{'plural'}) unless lc $type->{'unit'} eq lc $type->{'plural'};
push(@units, @{$type->{'aliases'}});
$unit_to_plural{lc $type->{'unit'}} = $type->{'plural'};
$plural_to_unit{lc $type->{'plural'}} = $type->{'unit'};
}
# build triggers based on available conversion units:
@ -35,32 +41,6 @@ my $question_prefix = qr/(?<prefix>convert|what (?:is|are|does)|how (?:much|many
my $factor_re = join('|', ('a', 'an', number_style_regex()));
my $guard = qr/^(?<question>$question_prefix)\s?(?<left_num>$factor_re*)\s?(?<left_unit>$keys)\s(?<connecting_word>in|to|into|(?:in to)|from)?\s?(?<right_num>$factor_re*)\s?(?:of\s)?(?<right_unit>$keys)[\?]?$/i;
# exceptions for pluralized forms:
my %plural_exceptions = (
'stone' => 'stone',
'foot' => 'feet',
'inch' => 'inches',
'pounds per square inch' => 'pounds per square inch',
'ton of TNT' => 'tons of TNT',
'metric horsepower' => 'metric horsepower',
'horsepower' => 'horsepower',
'electrical horsepower' => 'electrical horsepower',
'pounds force' => 'pounds force',
'坪' => '坪',
'km/h' => 'km/h',
'mph' => 'mph',
'm/s' => 'm/s',
'ft/s' => 'ft/s',
'dram avoirdupois' => 'drams avoirdupois',
'thousandth of an inch' => 'thousandths of an inch',
'century' => 'centuries',
'millennium' => 'millennia',
'mmHg' => 'mmHg',
'torr' => 'torr',
'cubic inch' => 'cubic inches'
);
my %singular_exceptions = reverse %plural_exceptions;
# fix precision and rounding:
my $precision = 3;
my $nearest = '.' . ('0' x ($precision-1)) . '1';
@ -132,8 +112,7 @@ handle query_lc => sub {
&& "" eq $+{'right_num'}
&& $+{'question'} !~ qr/convert/i
&& !looks_plural($+{'right_unit'})
&& $+{'connecting_word'} !~ qr/to/i
&& $factor1[0] > $factor2[0]))
&& $+{'connecting_word'} !~ qr/to/i ))
{
$factor = $+{'right_num'};
@matches = ($matches[1], $matches[0]);
@ -193,31 +172,31 @@ handle query_lc => sub {
};
$factor = $styler->for_display($factor);
return $factor . " $result->{'from_unit'} = $result->{'result'} $result->{'to_unit'}",
structured_answer => {
data => {
raw_input => $styler->for_computation($factor),
raw_answer => $styler->for_computation($result->{'result'}),
left_unit => $result->{'from_unit'},
right_unit => $result->{'to_unit'},
markup_input => $styler->with_html($factor),
styled_output => $styler->with_html($result->{'result'}),
physical_quantity => $result->{'type'}
},
templates => {
group => 'text',
options => {
content => 'DDH.conversions.content'
}
}
return "$factor $result->{'from_unit'} = $result->{'result'} $result->{'to_unit'}",
structured_answer => {
data => {
raw_input => $styler->for_computation($factor),
raw_answer => $styler->for_computation($result->{'result'}),
left_unit => $result->{'from_unit'},
right_unit => $result->{'to_unit'},
markup_input => $styler->with_html($factor),
styled_output => $styler->with_html($result->{'result'}),
physical_quantity => $result->{'type'}
},
templates => {
group => 'text',
options => {
content => 'DDH.conversions.content'
}
}
};
};
sub looks_plural {
my ($unit) = @_;
my @unit_letters = split //, $unit;
return exists $singular_exceptions{$unit} || $unit_letters[-1] eq 's';
my ($input) = @_;
return defined $plural_to_unit{lc $input};
}
sub convert_temperatures {
my ($from, $to, $in_temperature) = @_;
@ -243,11 +222,10 @@ sub convert_temperatures {
}
sub get_matches {
my @input_matches = @_;
my @output_matches = ();
foreach my $match (@input_matches) {
foreach my $type (@types) {
if (lc $match eq $type->{'unit'} || grep { $_ eq lc $match } @{$type->{'aliases'}}) {
if (lc $match eq $type->{'unit'} || lc $match eq lc $type->{'plural'} || grep { $_ eq lc $match } @{$type->{'aliases'}}) {
push(@output_matches,{
type => $type->{'type'},
factor => $type->{'factor'},
@ -266,6 +244,7 @@ sub convert {
my @matches = get_matches($conversion->{'from_unit'}, $conversion->{'to_unit'});
return if $conversion->{'factor'} < 0 && !($matches[0]->{'can_be_negative'});
# matches must be of the same type (e.g., can't convert mass to length):
return if ($matches[0]->{'type'} ne $matches[1]->{'type'});
@ -285,19 +264,11 @@ sub convert {
"type" => $matches[0]->{'type'}
};
}
sub set_unit_pluralisation {
my ($unit, $count) = @_;
my $proper_unit = $unit;
my $already_plural = looks_plural($unit);
if ($already_plural && $count == 1) {
$proper_unit = $singular_exceptions{$unit} || substr($unit, 0, -1);
} elsif (!$already_plural && $count != 1) {
$proper_unit = $plural_exceptions{$unit} || $unit . 's';
}
return $proper_unit;
$unit = $unit_to_plural{lc $unit} if ($count != 1 && !looks_plural($unit));
return $unit;
}
1;

View File

@ -36,9 +36,13 @@ handle remainder => sub {
return 'ISO 3166: '. ucfirst $input .' - '. $answer[0],
structured_answer => {
input => [ucfirst $input],
operation => 'ISO 3166 Country code',
result => ($answer[0]),
data => {
title => $answer[0],
subtitle => "ISO 3166 Country code: " . ucfirst ($input)
},
templates => {
group => "text"
}
};
};

15
lib/DDG/Goodie/Factors.pm Normal file → Executable file
View File

@ -17,12 +17,15 @@ handle remainder => sub {
my $factors = join ', ', divisors($query);
return "Factors of $query: $factors",
structured_answer => {
input => [$query],
operation => 'Factors',
result => $factors
};
return "Factors of $query: $factors", structured_answer => {
data => {
title => $factors,
subtitle => "Factors of: $query"
},
templates => {
group => 'text'
}
};
};
1;

View File

@ -20,9 +20,13 @@ handle remainder => sub {
return $result,
structured_answer => {
input => [html_enc($input)],
operation => 'Flip text',
result => html_enc($result),
data => {
title => $result,
subtitle => "Flip text $input"
},
templates => {
group => 'text',
}
};
};

15
lib/DDG/Goodie/Fortune.pm Normal file → Executable file
View File

@ -18,12 +18,15 @@ handle remainder => sub {
my $output = $fortune_file->get_random_fortune();
$output =~ s/\n/ /g;
return $output,
structured_answer => {
input => [],
operation => 'Random fortune',
result => $output
};
return $output, structured_answer => {
data => {
title => $output,
subtitle => "Random Fortune"
},
templates => {
group => 'text'
}
};
};
1;

15
lib/DDG/Goodie/GenerateMAC.pm Normal file → Executable file
View File

@ -20,12 +20,15 @@ handle remainder => sub {
my $address = join(':', map { sprintf '%0.2X', rand(255) } (1 .. 6));
return "Here's a random MAC address: $address",
structured_answer => {
input => [],
operation => 'Random MAC address',
result => $address
};
return "Here's a random MAC address: $address", structured_answer => {
data => {
title => $address,
subtitle => 'Random MAC Address'
},
templates => {
group => 'text'
}
};
};
1;

View File

@ -3,6 +3,7 @@ package DDG::Goodie::GreatestCommonFactor;
use strict;
use DDG::Goodie;
use Math::BigInt try => 'GMP';
zci answer_type => "greatest_common_factor";
zci is_cached => 1;
@ -22,23 +23,18 @@ handle remainder => sub {
my $formatted_numbers = join(', ', @numbers);
$formatted_numbers =~ s/, ([^,]*)$/ and $1/;
my $result = shift @numbers;
foreach (@numbers) {
$result = gcf($result, $_)
}
my $result = Math::BigInt::bgcd(@numbers);
return "Greatest common factor of $formatted_numbers is $result.",
structured_answer => {
input => [$formatted_numbers],
operation => 'Greatest common factor',
result => $result
data => {
title => "$result",
subtitle => "Greatest common factor: $formatted_numbers"
},
templates => {
group => "text",
}
};
};
sub gcf {
my ($x, $y) = @_;
($x, $y) = ($y, $x % $y) while $y;
return $x;
}
1;

12
lib/DDG/Goodie/HexToDec.pm Normal file → Executable file
View File

@ -17,10 +17,14 @@ handle query_raw => sub {
my $decimal = Math::BigInt->from_hex($hex);
return "$hex base 16 = $decimal base 10", structured_answer => {
input => ['0x' . $hex],
operation => 'Hex to decimal',
result => "$decimal", # Quoted for display precision as string.
data => {
title => "$decimal", # Quoted for display precision as string.
subtitle => "Hex to decimal: 0x" . $hex
},
templates => {
group => 'text',
}
};
};
0x41414141;
0x01;

15
lib/DDG/Goodie/Lowercase.pm Normal file → Executable file
View File

@ -18,12 +18,15 @@ handle remainder => sub {
return if ($lower eq $input);
return $lower,
structured_answer => {
input => [html_enc($input)],
operation => 'Lowercase',
result => html_enc($lower)
};
return $lower, structured_answer => {
data => {
title => html_enc($lower),
subtitle => "Lowercase: " . html_enc($input)
},
templates => {
group => 'text',
}
};
};
1;

15
lib/DDG/Goodie/POTUS.pm Normal file → Executable file
View File

@ -37,12 +37,15 @@ handle remainder => sub {
my $the_guy = $presidents[$index];
my $which = ordinate($num);
return "$the_guy $fact $which $POTUS.",
structured_answer => {
input => [$which],
operation => $POTUS,
result => $the_guy,
};
return "$the_guy $fact $which $POTUS.", structured_answer => {
data => {
title => $the_guy,
subtitle => "$which $POTUS",
},
templates => {
group => 'text'
}
};
};
1;

View File

@ -38,11 +38,15 @@ handle query_lc => sub {
$rand = int($rand) + $start;
}
return $rand . " (random number)",
return "$rand (random number)",
structured_answer => {
input => [$start, $end],
operation => 'Random number between',
result => $rand
data => {
title => $rand,
subtitle => "Random number between $start - $end"
},
templates => {
group => "text",
}
};
};

15
lib/DDG/Goodie/TitleCase.pm Normal file → Executable file
View File

@ -29,12 +29,15 @@ handle remainder => sub {
} @words
);
return $title_case,
structured_answer => {
input => [html_enc($input)],
operation => 'Title case',
result => html_enc($title_case),
};
return $title_case, structured_answer => {
data => {
title => html_enc($title_case),
subtitle => 'Title case: '.html_enc($input)
},
templates => {
group => 'text'
}
};
};
1;

View File

@ -8,7 +8,7 @@ use DateTime;
use List::MoreUtils qw( uniq );
use Try::Tiny;
my @trigger_words = ("unixtime", "datetime", "unix timestamp", "unix time stamp", "unix epoch", "epoch", "timestamp", "unix time", "utc time", "utc now", "current utc", "time since epoch");
my @trigger_words = ("unixtime", "datetime", "unix timestamp", "unix time stamp", "unix epoch", "epoch", "timestamp", "unix time", "utc time", "utc now", "current utc", "time since epoch", "epoch converter", "epoch time converter");
triggers startend => @trigger_words;
zci answer_type => "time_conversion";

15
lib/DDG/Goodie/Uppercase.pm Normal file → Executable file
View File

@ -20,12 +20,15 @@ handle remainder => sub {
my $upper = uc $input;
return $upper,
structured_answer => {
input => [html_enc($input)],
operation => 'Uppercase',
result => html_enc($upper),
};
return $upper, structured_answer => {
data => {
title => html_enc($upper),
subtitle => "Uppercase: ".html_enc($input)
},
templates => {
group => 'text'
}
};
};
1;

View File

@ -17,9 +17,13 @@ handle remainder => sub {
return $answer,
structured_answer => {
input => ['Valar morghulis'],
operation => 'Code phrase',
result => $answer
data => {
title => $answer,
subtitle => 'Code phrase: Valar morghulis'
},
templates => {
group => 'text'
}
};
};

View File

@ -22,9 +22,17 @@ handle query => sub {
return join("\n", @quote),
structured_answer => {
input => [],
operation => 'Zapp Brannigan quote',
result => join('<br>', @quote)};
data => {
content => join("<br>", @quote),
subtitle => 'Zapp Brannigan quote'
},
templates => {
group => "text",
options => {
content => 'DDH.zapp_brannigan.content'
}
}
};
};
1;
1;

View File

@ -1,5 +1,5 @@
{
"id": "backbonejs_cheat_sheet",
"id": "backbone_js_cheat_sheet",
"name": "Backbone.js",
"description": "A quick reference for Backbone.js, a JavaScript framework with a RESTful JSON interface and is based on the modelviewpresenter (MVP) application design paradigm",
"metadata": {
@ -8,7 +8,7 @@
},
"aliases": [
"backbone.js",
"backbone js",
"backbonejs",
"backbone"
],
"template_type": "terminal",
@ -162,4 +162,4 @@
"key": "Backbone.setDomLibrary(jQueryNew);"
}]
}
}
}

View File

@ -23,18 +23,6 @@
],
"sections": {
"Arithmetic Operators": [
{
"val": "Basic assignment",
"key": "a = b"
},
{
"val": "Addition",
"key": "a + b"
},
{
"val": "Subtraction",
"key": "a - b"
},
{
"val": "Unary plus (integer promotion)",
"key": "+a"
@ -43,18 +31,6 @@
"val": "Unary minus (additive inverse)",
"key": "-a"
},
{
"val": "Multiplication",
"key": "a * b"
},
{
"val": "Division",
"key": "a / b"
},
{
"val": "Modulo (integer remainder)",
"key": "a % b"
},
{
"val": "Increment Prefix",
"key": "++a"
@ -70,6 +46,30 @@
{
"val": "Decrement Postfix",
"key": "a--"
},
{
"val": "Multiplication",
"key": "a * b"
},
{
"val": "Division",
"key": "a / b"
},
{
"val": "Modulo (integer remainder)",
"key": "a % b"
},
{
"val": "Addition",
"key": "a + b"
},
{
"val": "Subtraction",
"key": "a - b"
},
{
"val": "Basic assignment",
"key": "a = b"
}
],
"Comparison Operators": [
@ -78,21 +78,21 @@
"key": "a < b"
},
{
"val": "a equal to b",
"key": "a == b"
"val": "a less than equal to b",
"key": "a <= b"
},
{
"val": "a greater than b",
"key": "a > b"
},
{
"val": "a less than equal to b",
"key": "a <= b"
},
{
"val": "a greater than equal to b",
"key": "a >= b"
},
{
"val": "a equal to b",
"key": "a == b"
},
{
"val": "a not equal to b",
"key": "a != b"
@ -117,18 +117,6 @@
"val": "Bitwise NOT / One's Complement",
"key": "~a"
},
{
"val": "Bitwise AND",
"key": "a & b"
},
{
"val": "Bitwise OR",
"key": "a | b"
},
{
"val": "Bitwise XOR",
"key": "a ^ b"
},
{
"val": "Bitwise left shift",
"key": "a << b"
@ -136,6 +124,18 @@
{
"val": "Bitwise right shift",
"key": "a >> b"
},
{
"val": "Bitwise AND",
"key": "a & b"
},
{
"val": "Bitwise XOR",
"key": "a ^ b"
},
{
"val": "Bitwise OR",
"key": "a | b"
}
],
"Other Operators": [
@ -275,4 +275,4 @@
}
]
}
}
}

View File

@ -138,7 +138,7 @@
"val": "Specifies the type of positioning method used for an element",
"key": "position:"
}, {
"val": "Specifies the stack order of an elemen",
"val": "Specifies the stack order of an element",
"key": "z-index:"
}],
"Background Properties": [{

View File

@ -0,0 +1,192 @@
{
"id": "emacs_evil_mode_cheat_sheet",
"name": "Evil-Mode for Emacs",
"description": "Shortcuts for the Evil-mode of the Emacs editor",
"metadata": {
"sourceName": "GitHub",
"sourceUrl": "https://github.com/amirrajan/devbox/wiki/EMACS-Evil-Cheat-Sheet"
},
"template_type": "keyboard",
"aliases": [
"evil emacs",
"emacs evil-mode",
"evil-mode emacs",
"evil-mode for emacs",
"evil mode for emacs",
"evil emacs mode"
],
"section_order": [
"Editing Text",
"Window Navigation",
"Discovery"
],
"sections": {
"Editing Text": [
{
"key": "ESC",
"val": "Command Mode"
},
{
"key": ":w",
"val": "save"
},
{
"key": ":q",
"val": "quit"
},
{
"key": ":wq",
"val": "save and quit"
},
{
"key": ":wqa",
"val": "save quit all"
},
{
"key": "hjkl",
"val": "to navigate"
},
{
"key": "w",
"val": "to move forward by one word"
},
{
"key": "b",
"val": "to move back by one word"
},
{
"key": "shift+[",
"val": "move up by new lines"
},
{
"key": "shift+]",
"val": "to move down by new lines"
},
{
"key": "yy",
"val": "copy line"
},
{
"key": "dd",
"val": "delete line"
},
{
"key": "cc",
"val": "change line"
},
{
"key": "Y",
"val": "copy till the end of line"
},
{
"key": "D",
"val": "delete till the end of line"
},
{
"key": "C",
"val": "change till the end of line"
},
{
"key": "yw",
"val": "yank word"
},
{
"key": "dw",
"val": "delete word"
},
{
"key": "cw",
"val": "change word"
},
{
"key": "gg",
"val": "go to top of file"
},
{
"key": "G",
"val": "goto bottom of file"
}
],
"Window Navigation": [
{
"key": ",g",
"val": "go to file"
},
{
"key": ",b",
"val": "view recently visited files"
},
{
"key": ",m",
"val": "new vertical split"
},
{
"key": ":split",
"val": "new horizontal split"
},
{
"key": ",.",
"val": "open current directory"
},
{
"key": "C-h , C-j ,C-k ,C-l",
"val": "navigate between windows"
},
{
"key": ",)",
"val": "previous buffer"
},
{
"key": ",(",
"val": "next buffer"
},
{
"key": ":ack ENT",
"val": "search across files"
},
{
"key": ",f",
"val": "next search result"
},
{
"key": ",d",
"val": "previous search result"
},
{
"key": "CTRL+v",
"val": "visula block mode"
},
{
"key": "While in visual Block Mode shift + i",
"val": "Insert Mode to append text to selection from Visual Block Mode"
}
],
"Discovery": [
{
"key": ":describe-char",
"val": "describes the char underneath the cursor, allows you to change color theme from there"
},
{
"key": ":customize-face",
"val": "editor for changing all color themes use tab and shift+tab to navigate"
},
{
"key": "F1 k KEYSTROKE",
"val": "press F1 followed by k, then enter a key stroke to find information about what editor method was invoked"
},
{
"key": "F1 f METHODNAME",
"val": "gives information about an editor method"
},
{
"key": "F1 a SEARCH",
"val": "search for an editor method containing the search term"
},
{
"key": ":METHODNAME",
"val": "invoke editor method"
}
]
}
}

View File

@ -120,6 +120,9 @@
}, {
"val": "repeat the expression in query <N>",
"key": "e(N)."
}, {
"val": "forget variable binding <N>",
"key": "f(N)."
}, {
"val": "forget all variable bindings",
"key": "f()."

View File

@ -2,7 +2,6 @@
"id": "finnish_cheat_sheet",
"name": "Finnish Cheat Sheet",
"description": "Basic Finnish words and phrases",
"aliases": ["english to finnish", "basic finnish"],
"template_type": "language",
"section_order": ["Basics", "Getting Help", "Travelling", "Etiquette", "Going out for dinner", "Numbers"],
"sections": {

View File

@ -9,7 +9,7 @@
},
"aliases": [
"valyrian", "game of thrones language", "valyrian language"
"valyrian"
],
"template_type": "language",

View File

@ -8,10 +8,6 @@
"sourceUrl" : "http://www.omniglot.com/language/phrases/kannada.php"
},
"aliases": [
"basic kannada"
],
"template_type": "language",
"section_order": [

View File

@ -9,7 +9,7 @@
},
"aliases": [
"spanish words", "spanish to english", "spanish greetings", "basic spanish", "spanish questions"
"spanish words", "spanish greetings", "spanish questions"
],
"template_type": "language",
@ -330,4 +330,4 @@
}
]
}
}
}

View File

@ -6,10 +6,6 @@
"sourceName":"Wikitravel",
"sourceUrl":"http://wikitravel.org/en/Telugu_phrasebook"
},
"aliases":[
"english to telugu",
"basic telugu"
],
"template_type":"language",
"section_order":[
"Basics",
@ -269,4 +265,4 @@
}
]
}
}
}

View File

@ -1,7 +1,7 @@
{
"id": "logarithms_cheat_sheet",
"name": "Logarithms",
"description": "displayed as subtitle of the AnswerBar; optional",
"description": "List of logarithmic rules and formulae.",
"metadata": {
"sourceName": "SCRIBD",
@ -9,7 +9,10 @@
},
"aliases": [
"logarithmic identities", "logarithms rules"
"logarithmic identities", "logarithms rules",
"logarithm identities", "logarithm rules",
"log identities", "log rules",
"logarithm"
],
"template_type": "reference",

View File

@ -132,7 +132,7 @@
}],
"Basic Syntax": [{
"val": "Read command line params",
"key": "($a, $b) = shift(@ARGV);"
"key": "($a, $b) = @ARGV;"
}, {
"val": "Define subroutine",
"key": "sub p\\{my $var = shift; ...\\}"

View File

@ -236,9 +236,6 @@
}, {
"key": "FOREIGN KEY",
"val": "Ensure the referential integrity of the data in one table to match values in another table"
}, {
"key": "FOREIGN KEY",
"val": "Ensure the referential integrity of the data in one table to match values in another table"
}, {
"key": "DEFAULT",
"val": "Specifies a default value for a column"

View File

@ -8,13 +8,13 @@
},
"template_type": "keyboard",
"section_order": [
"Exiting",
"Cursor movement",
"Insert mode - inserting/appending text",
"Editing",
"Marking text (visual mode)",
"Visual commands",
"Cut and paste",
"Exiting",
"Search and replace",
"Working with multiple files",
"Tabs",

View File

@ -5,6 +5,7 @@
"sourceName": "Microsoft",
"sourceUrl": "https://msdn.microsoft.com/en-us/library/da5kh0wa.aspx"
},
"template_type": "keyboard",
"section_order": ["Edit","Debug","Build","Project"],
"sections": {
"Edit": [{

View File

@ -0,0 +1,61 @@
{
"id": "wget_cheat_sheet",
"name": "Wget",
"description": "A computer program that retrieves content from web servers via HTTP, HTTPS, and FTP protocols",
"metadata": {
"sourceName": "GNU",
"sourceUrl" : "https://www.gnu.org/manual/manual.html"
},
"aliases": [
"gnu wget"
],
"template_type": "terminal",
"section_order": [
"Useful Commands"
],
"sections": {
"Useful Commands": [
{
"key": "wget <url>",
"val": "Download single file and stores in a current directory"
},
{
"key": "-O (uppercase)",
"val": "Download file with different name"
},
{
"key": "http:// , ftp://",
"val": "Download multiple file with http and ftp protocol"
},
{
"key": "wget -i /wget/tmp.txt",
"val": "Read URLs from a file"
},
{
"key": "wget -c",
"val": "Resume uncompleted download"
},
{
"key": "wget -b",
"val": "Download files in background"
},
{
"key": "wget -c --limit-rate=100k",
"val": "Restrict download speed limits"
},
{
"key": "wget --http-user=narad --http-password=password",
"val": "Restricted FTP and HTTP downloads with username and password"
},
{
"key": "wget --version",
"val": "Find wget version"
}
]
}
}

View File

@ -0,0 +1,110 @@
{
"id": "youtubedl_cheat_sheet",
"name": "Youtube-dl",
"description": "Small command-line program to download videos from YouTube.com and other video sites",
"metadata": {
"sourceName": "Github",
"sourceUrl": "https://github.com/rg3/youtube-dl/blob/master/README.md#readme"
},
"aliases": [
"youtube-dl", "youtube dl"
],
"template_type": "terminal",
"section_order": [
"Network Options",
"Video Selection",
"Download Options",
"Filesystem Options",
"Video Format Options"
],
"sections": {
"Network Options": [{
"key": "--proxy URL",
"val": "Use the specified HTTP/HTTPS proxy. Pass in an empty string (--proxy ) for direct connection"
}, {
"key": "-4, --force-ipv4",
"val": " Make all connections via IPv4"
}, {
"key": "-6, --force-ipv6",
"val": " Make all connections via IPv6"
}, {
"key": "--source-address IP ",
"val": "Client-side IP address to bind to"
}],
"Video Selection": [{
"key": "--playlist-start NUMBER",
"val": "Playlist video to start at (default is 1)"
}, {
"key": "--playlist-end NUMBER",
"val": "Playlist video to end at (default is last)"
}, {
"key": "--max-downloads NUMBER",
"val": "Abort after downloading NUMBER files"
}, {
"key": "--include-ads",
"val": "Download advertisements as well"
}, {
"key": "--yes-playlist",
"val": "Download the playlist, if the URL refers to a video and a playlist"
}],
"Download Options": [{
"key": "-r, --rate-limit LIMIT",
"val": "Maximum download rate in bytes per second"
}, {
"key": "-R, --retries RETRIES",
"val": "Number of retries (default is 10), or infinite"
}, {
"key": "--buffer-size SIZE",
"val": "Size of download buffer (e.g. 1024 or 16K)"
}, {
"key": "--external-downloader COMMAND",
"val": "Use the specified external downloader Currently supports"
}, {
"key": "--external-downloader-args ARGS",
"val": "Give these arguments to the external downloader"
}],
"Filesystem Options": [{
"key": "-a, --batch-file FILE",
"val": "File containing URLs to download"
}, {
"key": "--id",
"val": "Use only video ID in file name"
}, {
"key": "--autonumber-size NUMBER",
"val": "Specify the number of digits in %(autonumber)s when it is present in output filename template or --auto-number option is given"
}, {
"key": "-c, --continue",
"val": "Force resume of partially downloaded files. By default, youtube-dl will resume downloads if possible."
}, {
"key": "--no-continue",
"val": "Do not resume partially downloaded files"
}, {
"key": "--cookies FILE",
"val": "File to read cookies from and dump cookie jar in"
}],
"Video Format Options": [{
"key": "-f, --format FORMAT",
"val": "Video format code, see the FORMAT SELECTION for all the info"
}, {
"key": "--all-formats",
"val": "Download all available video formats"
}, {
"key": "--prefer-free-formats",
"val": "Prefer free video formats unless a specific one is requested"
}, {
"key": "-F, --list-formats",
"val": "List all available formats of requested videos"
}, {
"key": "--youtube-skip-dash-manifest",
"val": "Do not download the DASH manifests and related data on YouTube videos"
}, {
"key": "--merge-output-format FORMAT",
"val": "If a merge is required (e.g. bestvideo+bestaudio), output to given container format. One of mkv, mp4, ogg, webm, flv. Ignored if no merge is required"
}]
}
}

View File

@ -0,0 +1,112 @@
{
"id": "zfs_cheat_sheet",
"name": "ZFS",
"description": "The combined file system and logical volume manager. Data are important - be careful with it.",
"metadata": {
"sourceName": "FreeBSD handbook - The Z File System (ZFS)",
"sourceUrl": "https://www.freebsd.org/doc/handbook/zfs.html"
},
"aliases": [
"z file system",
"zpool"
],
"template_type": "terminal",
"section_order": [
"Pools",
"Datasets"
],
"sections": {
"Pools": [
{
"key": "zpool list",
"val": "Lists the given pools."
},
{
"key": "zpool status \\[$POOLNAME\\]",
"val": "Displays the detailed health status."
},
{
"key": "zpool get all $POOLNAME",
"val": "Retrieves the all properties for the pool."
},
{
"key": "zpool set $PROPERTY=$VALUE $POOLNAME",
"val": "Sets the given property on the pool."
},
{
"key": "zpool create \\[$POOLTYPE\\] $POOLNAME $DEVICE1",
"val": "Create a pool (Pool types: _ | spare | mirror | raidz)."
},
{
"key": "zpool replace $POOLNAME $DEV_OLD \\[$DEV_NEW\\]",
"val": "Replaces the old device with new one."
},
{
"key": "zpool destroy $POOLNAME",
"val": "Destroys the given pool."
},
{
"key": "zpool remove $POOLNAME $DEVICE",
"val": "Remove a physical device from the pool."
},
{
"key": "zpool online $POOLNAME $DEVICE",
"val": "Device is online and functioning."
},
{
"key": "zpool offline $POOLNAME $DEVICE",
"val": "Take device explicitly offline."
},
{
"key": "zpool scrub $POOLNAME",
"val": "Begin to examines all data in the pool to verify that checksums are correctly."
},
{
"key": "zpool \\[attach|detach\\] $POOLNAME $DEVICE",
"val": "Attach or Detaches device from a pool."
},
{
"key": "zpool iostat \\[$POOLNAME\\]",
"val": "Displays I/O statistics for the given pool."
}
],
"Datasets": [
{
"key": "zfs list",
"val": "Lists the properties for the given datasets."
},
{
"key": "zfs list -t snapshot /\\[$DATASET\\]",
"val": "Display a list of snapshots from /[] directory."
},
{
"key": "zfs snaphot \\[-r\\] $POOLNAME/$DATASET@$SNAPSHOTNAME",
"val": "Takes a [recursiv] snaphot of dataset."
},
{
"key": "zfs set $OPTION=$VALUE $POOLNAME/$DATASET",
"val": "Set the property to the given value for a dataset."
},
{
"key": "zfs clone $POOLNAME/$DATASET@$SNAPSHOTNAME $POOLNAME/$CLONE",
"val": "Creates a clone of the given snapshot."
},
{
"key": "zfs rollback \\[-rR\\] $POOLNAME/$DATASET@$SNAPSHOTNAME",
"val": "Roll back the given dataset to a previous snapshot."
},
{
"key": "zfs destroy $POOLNAME/$DATASET@$SNAPSHOTNAME",
"val": "Destroys the given dataset."
},
{
"key": "zfs mount $POOLNAME",
"val": "Mounts of the ZFS file systems."
},
{
"key": "zfs umount $POOLNAME\\[/$MOUNTPOINT\\]",
"val": "Unmounts currently mounted ZFS file systems."
}
]
}
}

View File

@ -36,6 +36,8 @@ categories:
- "cheat codes"
- "cheats"
- "secrets"
ignore:
- "game"
# Describes or introduces syntax of a programming language.
code:
startend:
@ -61,17 +63,26 @@ categories:
- "keyboard shortcuts"
- "keys"
- "shortcuts"
ignore:
- "default"
# Introduces basic translations for a human language.
language:
startend:
- "phrases"
- "translations"
ignore:
- "basic"
- "english to"
- "language"
# Shows links to other sites.
links:
startend:
- "links"
- "sites"
- "websites"
ignore:
- "list"
- "list of"
# Shows mathematical equations.
math:
startend:
@ -82,8 +93,9 @@ categories:
reference:
startend:
- "help"
- "quick reference"
- "reference"
ignore:
- "quick"
# Describes commands that can be entered at a terminal.
terminal:
startend:

View File

@ -80,16 +80,26 @@ bohr magneton:
html: '9.27400968 × 10<sup>24</sup> J T<sup>1</sup>'
boltzmann constant:
name: The Stefan Boltzmann Constant
name: The Boltzmann Constant
aliases:
- stefan boltzmann constant
- the stefan boltzmann constant
symbol:
- the boltzmann constant
symbol: k
wiki:
value:
plain: '1.3806503 × 10^-23 m^2 kg s^-2 K^-1'
html: '1.3806503 × 10<sup>-23</sup> m<sup>2</sup> kg s<sup>-2</sup> K<sup>-1</sup>'
stefan-boltzmann constant:
name: The Stefan-Boltzmann Constant
aliases:
- the stefan boltzmann constant
- stefan boltzmann constant
symbol: σ
wiki:
value:
plain: '5.670367 × 10^8 W m^2 K^4'
html: '5.670367 × 10<sup>8</sup> W m<sup>2</sup> K<sup>4</sup>'
elementary electric charge:
name: Elementary Electric Charge
aliases:

415
share/goodie/conversions/ratios.yml Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
<h3 class="c-base__title">{{{content}}}</h3>

28
t/ABC.t
View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'choice';
@ -12,7 +13,7 @@ sub create_structured_answer
{
my $data = shift;
return {
data => $data, #'-ANY-',
data => $data, #ignore(),
templates => {
group => 'text',
moreAt => 0
@ -30,28 +31,28 @@ ddg_goodie_test(
'choose his or or her house' => undef,
'choose from products like turkey or venison' => undef,
'choose pick or axe' => test_zci(
qr/(pick|axe) \(Random\)/,
structured_answer => create_structured_answer('-ANY-')
re(qr/(pick|axe) \(Random\)/),
structured_answer => create_structured_answer(ignore())
),
'choose yes or no' => test_zci(
qr/(yes|no) \(Random\)/,
structured_answer => create_structured_answer('-ANY-')
re(qr/(yes|no) \(Random\)/),
structured_answer => create_structured_answer(ignore())
),
'choose this or that or none' => test_zci(
qr/(this|that|none) \(Random\)/,
structured_answer => create_structured_answer('-ANY-')
re(qr/(this|that|none) \(Random\)/),
structured_answer => create_structured_answer(ignore())
),
'pick this or that or none' => test_zci(
qr/(this|that|none) \(Random\)/,
structured_answer => create_structured_answer('-ANY-')
re(qr/(this|that|none) \(Random\)/),
structured_answer => create_structured_answer(ignore())
),
'select heads or tails' => test_zci(
qr/(heads|tails) \(Random\)/,
structured_answer => create_structured_answer('-ANY-')
re(qr/(heads|tails) \(Random\)/),
structured_answer => create_structured_answer(ignore())
),
'choose heads or tails' => test_zci(
qr/(heads|tails) \(Random\)/,
structured_answer => create_structured_answer('-ANY-')
re(qr/(heads|tails) \(Random\)/),
structured_answer => create_structured_answer(ignore())
),
'choose duckduckgo or google or bing or something' => test_zci(
'duckduckgo (Non-random)',
@ -70,4 +71,3 @@ ddg_goodie_test(
);
done_testing;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'date_conversion';

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'anagram';

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'aspect_ratio';

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'atbash';

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'average';
@ -42,4 +43,3 @@ ddg_goodie_test(
);
done_testing;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "bpmto_ms";
@ -30,49 +31,49 @@ ddg_goodie_test(
"120 beats per minute to ms" => test_zci(
$plaintext_120,
structured_answer => {
data => '-ANY-',
data => ignore(),
# [
# {
# note_type => "Whole Note",
# triplet => 1333,
# dotted => 3000,
# milliseconds => 2000,
# image => qr/.*/
# image => re(qr/.*/)
# },
# {
# note_type => "Half Note",
# triplet => 667,
# dotted => 1500,
# milliseconds => 1000,
# image => qr/.*/
# image => re(qr/.*/)
# },
# {
# note_type => "Quarter Note",
# triplet => 333,
# dotted => 750,
# milliseconds => 500,
# image => qr/.*/
# image => re(qr/.*/)
# },
# {
# note_type => "1/8 Note",
# triplet => 167,
# dotted => 375,
# milliseconds => 250,
# image => qr/.*/
# image => re(qr/.*/)
# },
# {
# note_type => "1/16 Note",
# triplet => 83,
# dotted => 188,
# milliseconds => 125,
# image => qr/.*/
# image => re(qr/.*/)
# },
# {
# note_type => "1/32 Note",
# triplet => 42,
# dotted => 94,
# milliseconds => 63,
# image => qr/.*/
# image => re(qr/.*/)
# }
# ],
meta => {
@ -92,49 +93,49 @@ ddg_goodie_test(
"61 beats per minute to ms" => test_zci(
$plaintext_61,
structured_answer => {
data => '-ANY-',
data => ignore(),
# [
# {
# note_type => "Whole Note",
# triplet => 2623,
# dotted => 5902,
# milliseconds => 3934,
# image => qr/.*/
# image => re(qr/.*/)
# },
# {
# note_type => "Half Note",
# triplet => 1311,
# dotted => 2951,
# milliseconds => 1967,
# image => qr/.*/
# image => re(qr/.*/)
# },
# {
# note_type => "Quarter Note",
# triplet => 656,
# dotted => 1475,
# milliseconds => 984,
# image => qr/.*/
# image => re(qr/.*/)
# },
# {
# note_type => "1/8 Note",
# triplet => 328,
# dotted => 738,
# milliseconds => 492,
# image => qr/.*/
# image => re(qr/.*/)
# },
# {
# note_type => "1/16 Note",
# triplet => 164,
# dotted => 369,
# milliseconds => 246,
# image => qr/.*/
# image => re(qr/.*/)
# },
# {
# note_type => "1/32 Note",
# triplet => 82,
# dotted => 184,
# milliseconds => 123,
# image => qr/.*/
# image => re(qr/.*/)
# }
# ],
meta => {

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "brt";

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'conversion';
@ -39,4 +40,3 @@ ddg_goodie_test(
);
done_testing;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'base64_conversion';

View File

@ -2,6 +2,7 @@ use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'expression_description';
@ -12,7 +13,7 @@ ddg_goodie_test(
'DDG::Goodie::BashPrimaryExpressions'
],
"bash [ -a b ]" => test_zci(
qr/.+ true if b exists./,
re(qr/.+ true if b exists./),
structured_answer => {
data => {
intro => "[ -a b ]",
@ -39,9 +40,9 @@ ddg_goodie_test(
}
),
'bash [[ "abc" < "cba" ]]' => test_zci(
qr/.+ true if "abc" string-sorts before "cba" in the current locale./,
re(qr/.+ true if "abc" string-sorts before "cba" in the current locale./),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -52,9 +53,9 @@ ddg_goodie_test(
}
),
'bash [ 2 -gt 1 ]' => test_zci(
qr/.+ true if 2 is numerically greater than 1./,
re(qr/.+ true if 2 is numerically greater than 1./),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -65,9 +66,9 @@ ddg_goodie_test(
}
),
'bash [ ! hello == world ]' => test_zci(
qr/.+ false if the strings hello and world are equal./,
re(qr/.+ false if the strings hello and world are equal./),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -78,9 +79,9 @@ ddg_goodie_test(
}
),
'bash [[ /tmp/hello -nt /etc/test ]]' => test_zci (
qr#.+ true if /tmp/hello has been changed more recently than /etc/test or if /tmp/hello exists and /etc/test does not.#,
re(qr#.+ true if /tmp/hello has been changed more recently than /etc/test or if /tmp/hello exists and /etc/test does not.#),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -91,9 +92,9 @@ ddg_goodie_test(
}
),
'bash [ -z hello ]' => test_zci(
qr/.+ true if the length of 'hello' is zero./,
re(qr/.+ true if the length of 'hello' is zero./),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -104,9 +105,9 @@ ddg_goodie_test(
}
),
'bash if [[ "abc" -lt "cba" ]]' => test_zci(
qr/.+ true if "abc" is numerically less than "cba"./,
re(qr/.+ true if "abc" is numerically less than "cba"./),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "beam_me_up_scotty";

View File

@ -1,6 +1,7 @@
#!/usr/bin/env perl
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
use utf8;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'binary_conversion';

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
use utf8;

View File

@ -3,53 +3,37 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "birth_stone";
zci is_cached => 1;
sub get_structured_answer {
my($month, $birthstone) = @_;
return $month . " birthstone: $birthstone",
structured_answer => {
data => {
title => $birthstone,
subtitle => 'Birthstone for '.$month
},
templates => {
group => "text",
}
}
}
sub build_test {
test_zci(get_structured_answer(@_));
}
ddg_goodie_test(
[qw( DDG::Goodie::BirthStone )],
'april birth stone' => test_zci(
'April birthstone: Diamond',
structured_answer => {
input => ['April'],
operation => 'Birthstone',
result => 'Diamond'
}
),
'birthstone JUNE' => test_zci(
'June birthstone: Pearl',
structured_answer => {
input => ['June'],
operation => 'Birthstone',
result => 'Pearl'
}
),
'DecEmber birthstone' => test_zci(
'December birthstone: Turquoise',
structured_answer => {
input => ['December'],
operation => 'Birthstone',
result => 'Turquoise'
}
),
'birthstone april' => test_zci(
'April birthstone: Diamond',
structured_answer => {
input => ['April'],
operation => 'Birthstone',
result => 'Diamond'
}
),
'may birth stone' => test_zci(
'May birthstone: Emerald',
structured_answer => {
input => ['May'],
operation => 'Birthstone',
result => 'Emerald'
}
),
'april birth stone' => build_test('April', 'Diamond'),
'birthstone JUNE' => build_test('June', 'Pearl'),
'DecEmber birthstone' => build_test('December', 'Turquoise'),
'birthstone april' => build_test('April', 'Diamond'),
'may birth stone' => build_test('May', 'Emerald')
);
done_testing;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "bitsum";

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "blood_donor";

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
use Convert::Braille;
use utf8;
@ -10,62 +11,37 @@ use utf8;
zci answer_type => 'braille';
zci is_cached => 1;
sub build_structured_answer {
my ($query, $response) = @_;
return $response,
structured_answer => {
data => {
title => $response,
subtitle => 'Braille translation: ' . $query,
},
templates => {
group => 'text',
}
},
}
sub build_test { test_zci(build_structured_answer(@_)) }
ddg_goodie_test(
[qw( DDG::Goodie::Braille)],
'hello in braille' => test_zci(
"⠓⠑⠇⠇⠕ (Braille)",
structured_answer => {
input => ['hello'],
operation => 'Braille translation',
result => '&#x2813;&#x2811;&#x2807;&#x2807;&#x2815;'
}
),
'⠓⠑⠇⠇⠕' => test_zci(
"hello (Braille)",
structured_answer => {
input => ['&#x2813;&#x2811;&#x2807;&#x2807;&#x2815;'],
operation => 'Braille translation',
result => 'hello'
}
),
'translate to braille translate to braille' => test_zci(
"⠞⠗⠁⠝⠎⠇⠁⠞⠑⠀⠞⠕⠀⠃⠗⠁⠊⠇⠇⠑ (Braille)",
structured_answer => {
input => ['translate to braille'],
operation => 'Braille translation',
result =>
'&#x281E;&#x2817;&#x2801;&#x281D;&#x280E;&#x2807;&#x2801;&#x281E;&#x2811;&#x2800;&#x281E;&#x2815;&#x2800;&#x2803;&#x2817;&#x2801;&#x280A;&#x2807;&#x2807;&#x2811;'
}
),
'⠞⠗⠁⠝⠎⠇⠁⠞⠑⠀⠞⠕⠀⠃⠗⠁⠊⠇⠇⠑' => test_zci(
"translate to braille (Braille)",
structured_answer => {
input => [
'&#x281E;&#x2817;&#x2801;&#x281D;&#x280E;&#x2807;&#x2801;&#x281E;&#x2811;&#x2800;&#x281E;&#x2815;&#x2800;&#x2803;&#x2817;&#x2801;&#x280A;&#x2807;&#x2807;&#x2811;'
],
operation => 'Braille translation',
result => 'translate to braille'
}
),
'braille asdf k' => test_zci(
"⠁⠎⠙⠋⠀⠅ (Braille)",
structured_answer => {
input => ['asdf k'],
operation => 'Braille translation',
result => '&#x2801;&#x280E;&#x2819;&#x280B;&#x2800;&#x2805;'
}
),
'⠁⠎⠙⠋⠀⠅' => test_zci(
"asdf k (Braille)",
structured_answer => {
input => ['&#x2801;&#x280E;&#x2819;&#x280B;&#x2800;&#x2805;'],
operation => 'Braille translation',
result => 'asdf k'
}
),
# Ascii/Unicode -> Braille
'hello in braille' => build_test('hello', '⠓⠑⠇⠇⠕'),
'hello to braille' => build_test('hello', '⠓⠑⠇⠇⠕'),
'translate to braille to braille' => build_test('translate to braille', '⠞⠗⠁⠝⠎⠇⠁⠞⠑⠀⠞⠕⠀⠃⠗⠁⠊⠇⠇⠑'),
'braille: asdf k' => build_test('asdf k', '⠁⠎⠙⠋⠀⠅'),
# Braille -> Ascii/Unicode
'⠓⠑⠀⠇⠇⠕' => build_test('&#x2813;&#x2811;&#x2800;&#x2807;&#x2807;&#x2815;', 'he llo'),
'⠞⠗⠁⠝⠎⠇⠁⠞⠑⠀⠞⠕⠀⠃⠗⠁⠊⠇⠇⠑' => build_test('&#x281E;&#x2817;&#x2801;&#x281D;&#x280E;&#x2807;&#x2801;&#x281E;&#x2811;&#x2800;&#x281E;&#x2815;&#x2800;&#x2803;&#x2817;&#x2801;&#x280A;&#x2807;&#x2807;&#x2811;', 'translate to braille'),
'⠁⠎⠙⠋⠀⠅' => build_test('&#x2801;&#x280E;&#x2819;&#x280B;&#x2800;&#x2805;', 'asdf k'),
# Invalid Queries
'braille asdf k' => undef,
'how long to learn braille' => undef,
'braille to braille is good' => undef,
);
done_testing;

View File

@ -3,13 +3,14 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'caesar_cipher';
zci is_cached => 1;
my $decode_response = {
data => '-ANY-', # We only need to check it is the right template.
data => ignore(), # We only need to check it is the right template.
meta => {
sourceUrl => 'https://en.wikipedia.org/wiki/Caesar_cipher',
sourceName => 'Wikipedia',

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'root';

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
use DDG::Goodie::Calculator; # For function subtests.
use utf8;
@ -18,7 +19,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 - 2'],
operation => 'Calculate',
result => qr/>0</
result => re(qr/>0</)
}
),
'solve 2+2' => test_zci(
@ -27,7 +28,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 + 2'],
operation => 'Calculate',
result => qr/>4</
result => re(qr/>4</)
}
),
'2^8' => test_zci(
@ -36,7 +37,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 ^ 8'],
operation => 'Calculate',
result => qr/>256</
result => re(qr/>256</)
}
),
'2 *7' => test_zci(
@ -45,7 +46,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 * 7'],
operation => 'Calculate',
result => qr/>14</
result => re(qr/>14</)
}
),
'4 ∙ 5' => test_zci(
@ -54,7 +55,7 @@ ddg_goodie_test(
structured_answer => {
input => ['4 * 5'],
operation => 'Calculate',
result => qr/>20</
result => re(qr/>20</)
}
),
'6 ⋅ 7' => test_zci(
@ -63,7 +64,7 @@ ddg_goodie_test(
structured_answer => {
input => ['6 * 7'],
operation => 'Calculate',
result => qr/>42</
result => re(qr/>42</)
}
),
'3 × dozen' => test_zci(
@ -72,7 +73,7 @@ ddg_goodie_test(
structured_answer => {
input => ['3 * dozen'],
operation => 'Calculate',
result => qr/>36</
result => re(qr/>36</)
}
),
'dozen ÷ 4' => test_zci(
@ -81,7 +82,7 @@ ddg_goodie_test(
structured_answer => {
input => ['dozen / 4'],
operation => 'Calculate',
result => qr/>3</
result => re(qr/>3</)
}
),
'1 dozen * 2' => test_zci(
@ -90,7 +91,7 @@ ddg_goodie_test(
structured_answer => {
input => ['1 dozen * 2'],
operation => 'Calculate',
result => qr/>24</
result => re(qr/>24</)
}
),
'dozen + dozen' => test_zci(
@ -99,7 +100,7 @@ ddg_goodie_test(
structured_answer => {
input => ['dozen + dozen'],
operation => 'Calculate',
result => qr/>24</
result => re(qr/>24</)
}
),
'2divided by 4' => test_zci(
@ -108,7 +109,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 divided by 4'],
operation => 'Calculate',
result => qr/>0.5</
result => re(qr/>0.5</)
}
),
'2^2' => test_zci(
@ -117,7 +118,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 ^ 2'],
operation => 'Calculate',
result => qr/>4</
result => re(qr/>4</)
}
),
'2^0.2' => test_zci(
@ -126,7 +127,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 ^ 0.2'],
operation => 'Calculate',
result => qr/>1\.14869835499704</
result => re(qr/>1\.14869835499704</)
}
),
'cos(0)' => test_zci(
@ -135,7 +136,7 @@ ddg_goodie_test(
structured_answer => {
input => ['cos(0)'],
operation => 'Calculate',
result => qr/>1</
result => re(qr/>1</)
}
),
'tan(1)' => test_zci(
@ -144,7 +145,7 @@ ddg_goodie_test(
structured_answer => {
input => ['tan(1)'],
operation => 'Calculate',
result => qr/>1\.5574077246549</
result => re(qr/>1\.5574077246549</)
}
),
'tanh(1)' => test_zci(
@ -153,7 +154,7 @@ ddg_goodie_test(
structured_answer => {
input => ['tanh(1)'],
operation => 'Calculate',
result => qr/>0\.761594155955765</
result => re(qr/>0\.761594155955765</)
}
),
'cotan(1)' => test_zci(
@ -162,7 +163,7 @@ ddg_goodie_test(
structured_answer => {
input => ['cotan(1)'],
operation => 'Calculate',
result => qr/>0\.642092615934331</
result => re(qr/>0\.642092615934331</)
}
),
'sin(1)' => test_zci(
@ -171,7 +172,7 @@ ddg_goodie_test(
structured_answer => {
input => ['sin(1)'],
operation => 'Calculate',
result => qr/>0\.841470984807897</
result => re(qr/>0\.841470984807897</)
}
),
'csc(1)' => test_zci(
@ -180,7 +181,7 @@ ddg_goodie_test(
structured_answer => {
input => ['csc(1)'],
operation => 'Calculate',
result => qr/>1\.18839510577812</
result => re(qr/>1\.18839510577812</)
}
),
'sec(1)' => test_zci(
@ -189,7 +190,7 @@ ddg_goodie_test(
structured_answer => {
input => ['sec(1)'],
operation => 'Calculate',
result => qr/>1\.85081571768093</
result => re(qr/>1\.85081571768093</)
}
),
'log(3)' => test_zci(
@ -198,7 +199,7 @@ ddg_goodie_test(
structured_answer => {
input => ['log(3)'],
operation => 'Calculate',
result => qr/>1\.09861228866811</
result => re(qr/>1\.09861228866811</)
}
),
'ln(3)' => test_zci(
@ -207,7 +208,7 @@ ddg_goodie_test(
structured_answer => {
input => ['log(3)'],
operation => 'Calculate',
result => qr/>1\.09861228866811</
result => re(qr/>1\.09861228866811</)
}
),
'log10(100.00)' => test_zci(
@ -216,7 +217,7 @@ ddg_goodie_test(
structured_answer => {
input => ['log10(100.00)'],
operation => 'Calculate',
result => qr/>2</
result => re(qr/>2</)
}
),
'log_10(100.00)' => test_zci(
@ -225,7 +226,7 @@ ddg_goodie_test(
structured_answer => {
input => ['log_10(100.00)'],
operation => 'Calculate',
result => qr/>2</
result => re(qr/>2</)
}
),
'log_2(16)' => test_zci(
@ -234,7 +235,7 @@ ddg_goodie_test(
structured_answer => {
input => ['log_2(16)'],
operation => 'Calculate',
result => qr/>4</
result => re(qr/>4</)
}
),
'log_23(25)' => test_zci(
@ -243,7 +244,7 @@ ddg_goodie_test(
structured_answer => {
input => ['log_23(25)'],
operation => 'Calculate',
result => qr/>1\.0265928122321</
result => re(qr/>1\.0265928122321</)
}
),
'log23(25)' => test_zci(
@ -252,7 +253,7 @@ ddg_goodie_test(
structured_answer => {
input => ['log23(25)'],
operation => 'Calculate',
result => qr/>1\.0265928122321</
result => re(qr/>1\.0265928122321</)
}
),
'$3.43+$34.45' => test_zci(
@ -261,7 +262,7 @@ ddg_goodie_test(
structured_answer => {
input => ['$3.43 + $34.45'],
operation => 'Calculate',
result => qr/>\$37\.88</
result => re(qr/>\$37\.88</)
}
),
'$3.45+$34.45' => test_zci(
@ -270,7 +271,7 @@ ddg_goodie_test(
structured_answer => {
input => ['$3.45 + $34.45'],
operation => 'Calculate',
result => qr/>\$37\.90</
result => re(qr/>\$37\.90</)
}
),
'$3+$34' => test_zci(
@ -279,7 +280,7 @@ ddg_goodie_test(
structured_answer => {
input => ['$3 + $34'],
operation => 'Calculate',
result => qr/>\$37\.00</
result => re(qr/>\$37\.00</)
}
),
'$3,4+$34,4' => test_zci(
@ -288,7 +289,7 @@ ddg_goodie_test(
structured_answer => {
input => ['$3,4 + $34,4'],
operation => 'Calculate',
result => qr/>\$37,80</
result => re(qr/>\$37,80</)
}
),
'64*343' => test_zci(
@ -297,7 +298,7 @@ ddg_goodie_test(
structured_answer => {
input => ['64 * 343'],
operation => 'Calculate',
result => qr/>21,952</
result => re(qr/>21,952</)
}
),
'1E2 + 1' => test_zci(
@ -306,7 +307,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(1 * 10 ^ 2) + 1'],
operation => 'Calculate',
result => qr/>101</
result => re(qr/>101</)
}
),
'1 + 1E2' => test_zci(
@ -315,7 +316,7 @@ ddg_goodie_test(
structured_answer => {
input => ['1 + (1 * 10 ^ 2)'],
operation => 'Calculate',
result => qr/>101</
result => re(qr/>101</)
}
),
'2 * 3 + 1E2' => test_zci(
@ -324,7 +325,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 * 3 + (1 * 10 ^ 2)'],
operation => 'Calculate',
result => qr/>106</
result => re(qr/>106</)
}
),
'1E2 + 2 * 3' => test_zci(
@ -333,7 +334,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(1 * 10 ^ 2) + 2 * 3'],
operation => 'Calculate',
result => qr/>106</
result => re(qr/>106</)
}
),
'1E2 / 2' => test_zci(
@ -342,7 +343,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(1 * 10 ^ 2) / 2'],
operation => 'Calculate',
result => qr/>50</
result => re(qr/>50</)
}
),
'2 / 1E2' => test_zci(
@ -351,7 +352,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 / (1 * 10 ^ 2)'],
operation => 'Calculate',
result => qr/>0\.02</
result => re(qr/>0\.02</)
}
),
'424334+2253828' => test_zci(
@ -360,7 +361,7 @@ ddg_goodie_test(
structured_answer => {
input => ['424334 + 2253828'],
operation => 'Calculate',
result => qr/>2,678,162</
result => re(qr/>2,678,162</)
}
),
'4.243,34+22.538,28' => test_zci(
@ -369,7 +370,7 @@ ddg_goodie_test(
structured_answer => {
input => ['4.243,34 + 22.538,28'],
operation => 'Calculate',
result => qr/>26\.781,62</
result => re(qr/>26\.781,62</)
}
),
'sin(1,0) + 1,05' => test_zci(
@ -378,7 +379,7 @@ ddg_goodie_test(
structured_answer => {
input => ['sin(1,0) + 1,05'],
operation => 'Calculate',
result => qr/>1,8914709848079</
result => re(qr/>1,8914709848079</)
}
),
'21 + 15 x 0 + 5' => test_zci(
@ -387,7 +388,7 @@ ddg_goodie_test(
structured_answer => {
input => ['21 + 15 * 0 + 5'],
operation => 'Calculate',
result => qr/>26</
result => re(qr/>26</)
}
),
'0.8158 - 0.8157' => test_zci(
@ -396,7 +397,7 @@ ddg_goodie_test(
structured_answer => {
input => ['0.8158 - 0.8157'],
operation => 'Calculate',
result => qr/>0\.0001</
result => re(qr/>0\.0001</)
}
),
'2,90 + 4,6' => test_zci(
@ -405,7 +406,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2,90 + 4,6'],
operation => 'Calculate',
result => qr/>7,50</
result => re(qr/>7,50</)
}
),
'2,90 + sec(4,6)' => test_zci(
@ -414,7 +415,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2,90 + sec(4,6)'],
operation => 'Calculate',
result => qr/>-6,01642861135959</
result => re(qr/>-6,01642861135959</)
}
),
'100 - 96.54' => test_zci(
@ -423,7 +424,7 @@ ddg_goodie_test(
structured_answer => {
input => ['100 - 96.54'],
operation => 'Calculate',
result => qr/>3\.46</
result => re(qr/>3\.46</)
}
),
'1. + 1.' => test_zci(
@ -432,7 +433,7 @@ ddg_goodie_test(
structured_answer => {
input => ['1. + 1.'],
operation => 'Calculate',
result => qr/>2</
result => re(qr/>2</)
}
),
'1 + sin(pi)' => test_zci(
@ -441,7 +442,7 @@ ddg_goodie_test(
structured_answer => {
input => ['1 + sin(pi)'],
operation => 'Calculate',
result => qr/>1</
result => re(qr/>1</)
}
),
'1 - 1' => test_zci(
@ -450,7 +451,7 @@ ddg_goodie_test(
structured_answer => {
input => ['1 - 1'],
operation => 'Calculate',
result => qr/>0</
result => re(qr/>0</)
}
),
'sin(pi/2)' => test_zci(
@ -459,7 +460,7 @@ ddg_goodie_test(
structured_answer => {
input => ['sin(pi / 2)'],
operation => 'Calculate',
result => qr/>1</
result => re(qr/>1</)
}
),
'sin(pi)' => test_zci(
@ -468,7 +469,7 @@ ddg_goodie_test(
structured_answer => {
input => ['sin(pi)'],
operation => 'Calculate',
result => qr/>0</
result => re(qr/>0</)
}
),
'cos(2pi)' => test_zci(
@ -477,7 +478,7 @@ ddg_goodie_test(
structured_answer => {
input => ['cos(2 pi)'],
operation => 'Calculate',
result => qr/>1</
result => re(qr/>1</)
}
),
'5 squared' => test_zci(
@ -486,7 +487,7 @@ ddg_goodie_test(
structured_answer => {
input => ['5 ^ 2'],
operation => 'Calculate',
result => qr/>25</
result => re(qr/>25</)
}
),
'sqrt(4)' => test_zci(
@ -495,7 +496,7 @@ ddg_goodie_test(
structured_answer => {
input => ['sqrt(4)'],
operation => 'Calculate',
result => qr/>2</
result => re(qr/>2</)
}
),
'1.0 + 5 squared' => test_zci(
@ -504,7 +505,7 @@ ddg_goodie_test(
structured_answer => {
input => ['1.0 + 5 ^ 2'],
operation => 'Calculate',
result => qr/>26</
result => re(qr/>26</)
}
),
'3 squared + 4 squared' => test_zci(
@ -513,7 +514,7 @@ ddg_goodie_test(
structured_answer => {
input => ['3 ^ 2 + 4 ^ 2'],
operation => 'Calculate',
result => qr/>25</
result => re(qr/>25</)
}
),
'2,2 squared' => test_zci(
@ -522,7 +523,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2,2 ^ 2'],
operation => 'Calculate',
result => qr/>4,84</
result => re(qr/>4,84</)
}
),
'0.8^2 + 0.6^2' => test_zci(
@ -531,7 +532,7 @@ ddg_goodie_test(
structured_answer => {
input => ['0.8 ^ 2 + 0.6 ^ 2'],
operation => 'Calculate',
result => qr/>1</,
result => re(qr/>1</),
}
),
'2 squared ^ 3' => test_zci(
@ -540,7 +541,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 ^ 2 ^ 3'],
operation => 'Calculate',
result => qr/>256</
result => re(qr/>256</)
}
),
'2 squared ^ 3.06' => test_zci(
@ -549,7 +550,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 ^ 2 ^ 3.06'],
operation => 'Calculate',
result => qr/>323\.972172143725</
result => re(qr/>323\.972172143725</)
}
),
'2^3 squared' => test_zci(
@ -558,7 +559,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 ^ 3 ^ 2'],
operation => 'Calculate',
result => qr/>512</
result => re(qr/>512</)
}
),
'sqrt(2)' => test_zci(
@ -567,7 +568,7 @@ ddg_goodie_test(
structured_answer => {
input => ['sqrt(2)'],
operation => 'Calculate',
result => qr/>1\.4142135623731</
result => re(qr/>1\.4142135623731</)
}
),
'sqrt(3 pi / 4 + 1) + 1' => test_zci(
@ -576,7 +577,7 @@ ddg_goodie_test(
structured_answer => {
input => ['sqrt(3 pi / 4 + 1) + 1'],
operation => 'Calculate',
result => qr/>2\.83199194599549</
result => re(qr/>2\.83199194599549</)
}
),
'4 score + 7' => test_zci(
@ -585,7 +586,7 @@ ddg_goodie_test(
structured_answer => {
input => ['4 score + 7'],
operation => 'Calculate',
result => qr/>87</
result => re(qr/>87</)
}
),
'418.1 / 2' => test_zci(
@ -594,7 +595,7 @@ ddg_goodie_test(
structured_answer => {
input => ['418.1 / 2'],
operation => 'Calculate',
result => qr/>209\.05</
result => re(qr/>209\.05</)
}
),
'418.005 / 8' => test_zci(
@ -603,7 +604,7 @@ ddg_goodie_test(
structured_answer => {
input => ['418.005 / 8'],
operation => 'Calculate',
result => qr/>52\.250625</
result => re(qr/>52\.250625</)
}
),
'(pi^4+pi^5)^(1/6)' => test_zci(
@ -612,7 +613,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(pi ^ 4 + pi ^ 5) ^ (1 / 6)'],
operation => 'Calculate',
result => qr/>2\.71828180861191</
result => re(qr/>2\.71828180861191</)
}
),
'(pi^4+pi^5)^(1/6)+1' => test_zci(
@ -621,7 +622,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(pi ^ 4 + pi ^ 5) ^ (1 / 6) + 1'],
operation => 'Calculate',
result => qr/>3\.71828180861191</
result => re(qr/>3\.71828180861191</)
}
),
'5^4^(3-2)^1' => test_zci(
@ -630,7 +631,7 @@ ddg_goodie_test(
structured_answer => {
input => ['5 ^ 4 ^ (3 - 2) ^ 1'],
operation => 'Calculate',
result => qr/>625</
result => re(qr/>625</)
}
),
'(5-4)^(3-2)^1' => test_zci(
@ -639,7 +640,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(5 - 4) ^ (3 - 2) ^ 1'],
operation => 'Calculate',
result => qr/>1</
result => re(qr/>1</)
}
),
'(5+4-3)^(2-1)' => test_zci(
@ -648,7 +649,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(5 + 4 - 3) ^ (2 - 1)'],
operation => 'Calculate',
result => qr/>6</
result => re(qr/>6</)
}
),
'5^((4-3)*(2+1))+6' => test_zci(
@ -657,7 +658,7 @@ ddg_goodie_test(
structured_answer => {
input => ['5 ^ ((4 - 3) * (2 + 1)) + 6'],
operation => 'Calculate',
result => qr/>131</
result => re(qr/>131</)
}
),
'20x07' => test_zci(
@ -666,7 +667,7 @@ ddg_goodie_test(
structured_answer => {
input => ['20 * 07'],
operation => 'Calculate',
result => qr/>140</
result => re(qr/>140</)
}
),
'83.166.167.160/33' => test_zci(
@ -675,7 +676,7 @@ ddg_goodie_test(
structured_answer => {
input => ['83.166.167.160 / 33'],
operation => 'Calculate',
result => qr/>2\.520\.186\.883,63636</
result => re(qr/>2\.520\.186\.883,63636</)
}
),
'123.123.123.123/255.255.255.256' => test_zci(
@ -684,7 +685,7 @@ ddg_goodie_test(
structured_answer => {
input => ['123.123.123.123 / 255.255.255.256'],
operation => 'Calculate',
result => qr/>0,482352941174581</
result => re(qr/>0,482352941174581</)
}
),
'4E5 +1 ' => test_zci(
@ -693,7 +694,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(4 * 10 ^ 5) + 1'],
operation => 'Calculate',
result => qr/>400,001</
result => re(qr/>400,001</)
}
),
'4e5 +1 ' => test_zci(
@ -702,7 +703,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(4 * 10 ^ 5) + 1'],
operation => 'Calculate',
result => qr/>400,001</
result => re(qr/>400,001</)
}
),
'3e-2* 9 ' => test_zci(
@ -711,7 +712,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(3 * 10 ^- 2) * 9'],
operation => 'Calculate',
result => qr/>0.27</
result => re(qr/>0.27</)
}
),
'7e-4 *8' => test_zci(
@ -720,7 +721,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(7 * 10 ^- 4) * 8'],
operation => 'Calculate',
result => qr/>0.0056</
result => re(qr/>0.0056</)
}
),
'6 * 2e-11' => test_zci(
@ -729,7 +730,7 @@ ddg_goodie_test(
structured_answer => {
input => ['6 * (2 * 10 ^- 11)'],
operation => 'Calculate',
result => qr/>1\.2 \* 10<sup>-10<\/sup></
result => re(qr/>1\.2 \* 10<sup>-10<\/sup></)
}
),
'7 + 7e-7' => test_zci(
@ -738,7 +739,7 @@ ddg_goodie_test(
structured_answer => {
input => ['7 + (7 * 10 ^- 7)'],
operation => 'Calculate',
result => qr/>7.0000007</
result => re(qr/>7.0000007</)
}
),
'1 * 7 + e-7' => test_zci(
@ -747,7 +748,7 @@ ddg_goodie_test(
structured_answer => {
input => ['1 * 7 + e - 7'],
operation => 'Calculate',
result => qr/>2.71828182845905</
result => re(qr/>2.71828182845905</)
}
),
'7 * e- 5' => test_zci(
@ -756,7 +757,7 @@ ddg_goodie_test(
structured_answer => {
input => ['7 * e - 5'],
operation => 'Calculate',
result => qr/>14.0279727992134</
result => re(qr/>14.0279727992134</)
}
),
'pi/1e9' => test_zci(
@ -765,7 +766,7 @@ ddg_goodie_test(
structured_answer => {
input => ['pi / (1 * 10 ^ 9)'],
operation => 'Calculate',
result => qr/>3\.14159265358979 \* 10<sup>-9<\/sup></
result => re(qr/>3\.14159265358979 \* 10<sup>-9<\/sup></)
}
),
'pi*1e9' => test_zci(
@ -774,7 +775,7 @@ ddg_goodie_test(
structured_answer => {
input => ['pi * (1 * 10 ^ 9)'],
operation => 'Calculate',
result => qr/>3,141,592,653\.58979</
result => re(qr/>3,141,592,653\.58979</)
}
),
'1 234 + 5 432' => test_zci(
@ -783,7 +784,7 @@ ddg_goodie_test(
structured_answer => {
input => ['1234 + 5432'],
operation => 'Calculate',
result => qr/6,666/
result => re(qr/6,666/)
}
),
'1_234 + 5_432' => test_zci(
@ -792,7 +793,7 @@ ddg_goodie_test(
structured_answer => {
input => ['1234 + 5432'],
operation => 'Calculate',
result => qr/6,666/
result => re(qr/6,666/)
}
),
'(0.4e^(0))*cos(0)' => test_zci(
@ -801,7 +802,7 @@ ddg_goodie_test(
structured_answer => {
input => ['(0.4e ^ (0)) * cos(0)'],
operation => 'Calculate',
result => qr'0.4'
result => re(qr'0.4')
}
),
'2pi' => test_zci(
@ -810,7 +811,7 @@ ddg_goodie_test(
structured_answer => {
input => ['2 pi'],
operation => 'Calculate',
result => qr"6.28318530717958"
result => re(qr"6.28318530717958")
}
),
'fact(3)' => test_zci(
@ -819,7 +820,7 @@ ddg_goodie_test(
structured_answer => {
input => ['fact(3)'],
operation => 'Calculate',
result => qr/>6</
result => re(qr/>6</)
}
),
'factorial(3)' => test_zci(
@ -828,7 +829,7 @@ ddg_goodie_test(
structured_answer => {
input => ['fact(3)'],
operation => 'Calculate',
result => qr/>6</
result => re(qr/>6</)
}
),
'123.123.123.123/255.255.255.255' => undef,

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'calendar_conversion';

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
use Test::MockTime qw( :all );
@ -14,9 +15,9 @@ ddg_goodie_test(
DDG::Goodie::CalendarToday
)],
'calendar' => test_zci(
qr/\nS M T W T F S[ ]+[A-Za-z]+ [0-9]{4}\n.+/,
re(qr/\nS M T W T F S[ ]+[A-Za-z]+ [0-9]{4}\n.+/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -27,9 +28,9 @@ ddg_goodie_test(
}
),
'calendar november' => test_zci(
qr/\nS M T W T F S November [0-9]{4}\n.+/,
re(qr/\nS M T W T F S November [0-9]{4}\n.+/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -40,9 +41,9 @@ ddg_goodie_test(
}
),
'calendar november 12th' => test_zci(
qr/\nS M T W T F S November [0-9]{4}\n.+/,
re(qr/\nS M T W T F S November [0-9]{4}\n.+/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -53,9 +54,9 @@ ddg_goodie_test(
}
),
'calendar last november' => test_zci(
qr/\nS M T W T F S November [0-9]{4}\n.+/,
re(qr/\nS M T W T F S November [0-9]{4}\n.+/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -66,9 +67,9 @@ ddg_goodie_test(
}
),
'calendar next november' => test_zci(
qr/\nS M T W T F S November [0-9]{4}\n.+/,
re(qr/\nS M T W T F S November [0-9]{4}\n.+/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -217,7 +218,7 @@ S M T W T F S November 2009
29 30
",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -236,7 +237,7 @@ S M T W T F S November 2015
|29| 30
",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -255,7 +256,7 @@ S M T W T F S November 2015
|29| 30
",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -275,7 +276,7 @@ S M T W T F S November 1980
30
",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -294,7 +295,7 @@ S M T W T F S November 2009
29 30
",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -305,9 +306,9 @@ S M T W T F S November 2009
}
),
'next november on a calendar' => test_zci(
qr/\nS M T W T F S November [0-9]{4}\n.+/,
re(qr/\nS M T W T F S November [0-9]{4}\n.+/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -318,9 +319,9 @@ S M T W T F S November 2009
}
),
'calendar for november' => test_zci(
qr/\nS M T W T F S November [0-9]{4}\n.+/,
re(qr/\nS M T W T F S November [0-9]{4}\n.+/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -339,7 +340,7 @@ S M T W T F S November 2009
29 30
",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -351,9 +352,9 @@ S M T W T F S November 2009
),
'22/8/2003 to the hijri calendar' => undef,
"today's calendar" => test_zci(
qr/\nS M T W T F S [A-Z][a-z]+ [0-9]{4}\n.+/,
re(qr/\nS M T W T F S [A-Z][a-z]+ [0-9]{4}\n.+/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -364,9 +365,9 @@ S M T W T F S November 2009
}
),
"november's calendar" => test_zci(
qr/\nS M T W T F S November [0-9]{4}\n.+/,
re(qr/\nS M T W T F S November [0-9]{4}\n.+/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -379,14 +380,14 @@ S M T W T F S November 2009
);
# Special focus on relative dates, examining the "today" circle
my $test_location_tz = qr/\(EDT, UTC-4\)/;
my $test_location_tz = re(qr/\(EDT, UTC-4\)/);
set_fixed_time("2014-06-11T09:45:56");
ddg_goodie_test(
[qw(
DDG::Goodie::CalendarToday
)],
"calendar yesterday" => test_zci(
qr/June 2014.*\|10\|/s,
re(qr/June 2014.*\|10\|/s),
structured_answer => {
data => {
month_year => "June 2014",
@ -445,7 +446,7 @@ ddg_goodie_test(
}
),
"calendar today" => test_zci(
qr/June 2014.*\|11\|/s,
re(qr/June 2014.*\|11\|/s),
structured_answer => {
data => {
month_year => "June 2014",
@ -504,7 +505,7 @@ ddg_goodie_test(
}
),
"calendar tomorrow" => test_zci(
qr/June 2014.*\|12\|/s,
re(qr/June 2014.*\|12\|/s),
structured_answer => {
data => {
month_year => "June 2014",
@ -563,7 +564,7 @@ ddg_goodie_test(
}
),
"calendar 20 days ago" => test_zci(
qr/May 2014.*\|22\|/s,
re(qr/May 2014.*\|22\|/s),
structured_answer => {
data => {
month_year => "May 2014",
@ -627,7 +628,7 @@ ddg_goodie_test(
}
),
"calendar in 20 days" => test_zci(
qr/July 2014.*\| 1\|/s,
re(qr/July 2014.*\| 1\|/s),
structured_answer => {
data => {
month_year => "July 2014",
@ -689,7 +690,7 @@ ddg_goodie_test(
}
),
"calendar last week" => test_zci(
qr/June 2014.*\| 4\|/s,
re(qr/June 2014.*\| 4\|/s),
structured_answer => {
data => {
month_year => "June 2014",
@ -748,7 +749,7 @@ ddg_goodie_test(
}
),
"calendar next week" =>
test_zci(qr/June 2014.*\|18\|/s,
test_zci(re(qr/June 2014.*\|18\|/s),
structured_answer => {
data => {
month_year => "June 2014",
@ -807,7 +808,7 @@ ddg_goodie_test(
}
),
"calendar last year" =>
test_zci(qr/June 2013.*\|11\|/s,
test_zci(re(qr/June 2013.*\|11\|/s),
structured_answer => {
data => {
month_year => "June 2013",
@ -874,7 +875,7 @@ ddg_goodie_test(
}
),
"calendar next year" =>
test_zci(qr/June 2015.*\|11\|/s,
test_zci(re(qr/June 2015.*\|11\|/s),
structured_answer => {
data => {
month_year => "June 2015",
@ -937,4 +938,3 @@ ddg_goodie_test(
restore_time();
done_testing;

View File

@ -4,6 +4,7 @@ use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "calling_codes";

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "camel_case";

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'chars';
@ -103,4 +104,3 @@ ddg_goodie_test(
);
done_testing;

View File

@ -13,6 +13,7 @@ use IO::All;
use List::Util qw(first none all any max);
use YAML::XS qw(LoadFile);
use File::Find::Rule;
use DDG::Meta::Data;
my $json_dir = "share/goodie/cheat_sheets/json";
@ -40,6 +41,7 @@ sub id_to_file_name {
sub check_aliases_for_triggers {
my ($aliases, $trigger_types) = @_;
my @aliases = @$aliases;
my %bad_aliases;
while (my ($trigger_type, $triggers) = each %{$trigger_types}) {
my @triggers = @$triggers;
foreach my $alias (@aliases) {
@ -50,11 +52,32 @@ sub check_aliases_for_triggers {
|| ($trigger_type =~ /end$/
&& ($trigger = first { $alias =~ /$_$/ } @triggers))
) {
return ($alias, $trigger);
$bad_aliases{$alias} = $trigger;
}
}
}
return;
return %bad_aliases;
}
sub check_aliases_for_ignore {
my ($aliases, $ignore) = @_;
my @ignore = @$ignore;
my %bad_aliases;
foreach my $alias (@$aliases) {
if (my $contained_ignore = first { $alias =~ $_ } @ignore) {
$bad_aliases{$alias} = $ignore;
}
}
return %bad_aliases;
}
sub verify_meta {
my $json = shift;
my @tests;
my $id = $json->{id};
my $meta = DDG::Meta::Data->get_ia(id => $id);
push(@tests, {msg => "No Instant Answer page found with ID '$id'", critical => 1, pass => defined $meta});
return @tests;
}
my @fnames = @ARGV ? map { "$_.json" } @ARGV : ("*.json");
@ -62,8 +85,16 @@ my @test_paths = File::Find::Rule->file()->name(@fnames)->in($json_dir);
my $max_name_len = max map { $_ =~ /.+\/(.+)\.json$/; length $1 } @test_paths;
sub cmp_base {
$a =~ qr{/([^/]+)$};
my $base1 = $1;
$b =~ qr{/([^/]+)$};
my $base2 = $1;
return $base1 cmp $base2;
}
# Iterate over all Cheat Sheet JSON files...
foreach my $path (@test_paths) {
foreach my $path (sort { cmp_base } @test_paths) {
my ($file_name) = $path =~ /$json_dir\/(.+)/;
my ($name) = $path =~ /.+\/(.+)\.json$/;
@ -136,13 +167,22 @@ foreach my $path (@test_paths) {
# Make sure aliases don't contain any category triggers.
while (my ($category, $trigger_types) = each %{$triggers_yaml->{categories}}) {
my $critical = $categories{$category};
if (my ($alias, $trigger) = check_aliases_for_triggers(\@aliases, $trigger_types)) {
my %bad_aliases = check_aliases_for_triggers(\@aliases, $trigger_types);
while (my ($alias, $trigger) = each %bad_aliases) {
push(@tests, {msg => "Alias ($alias) contains a trigger ($trigger) defined in the '$category' category", critical => $critical});
}
# Critical if they have aliases that contain ignored phrases.
if ($critical and my $ignored = $trigger_types->{ignore}) {
my %bad_aliases = check_aliases_for_ignore(\@aliases, $ignored);
while (my ($alias, $ignore) = each %bad_aliases) {
push (@tests, {msg => "Alias ($alias) contains a phrase ($ignore) that is ignored and may be omitted", critical => 1});
}
}
}
# Make sure aliases don't contain any custom triggers for the cheat sheet.
if (my $custom = $triggers_yaml->{custom_triggers}{$cheat_id}) {
if (my ($alias, $trigger) = check_aliases_for_triggers(\@aliases, $custom)) {
my %bad_aliases = check_aliases_for_triggers(\@aliases, $custom);
while (my ($alias, $trigger) = each %bad_aliases) {
push(@tests, {msg => "Alias ($alias) contains a custom trigger ($trigger)", critical => 1});
}
}
@ -224,6 +264,8 @@ foreach my $path (@test_paths) {
}
}
push @tests, verify_meta($json);
PRINT_RESULTS:
my $result = print_results($name, \@tests);

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'chess960_position';
@ -15,7 +16,7 @@ ddg_goodie_test(
'chess960 random' => test_zci(
'Chess 960',
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => "text",
item => 0,
@ -28,4 +29,3 @@ ddg_goodie_test(
);
done_testing;

View File

@ -4,6 +4,7 @@ use strict;
use warnings;
use Test::MockTime qw( :all );
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
use utf8;
@ -132,4 +133,3 @@ ddg_goodie_test(
restore_time();
done_testing;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "coffee_to_water_ratio";

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'coin';
@ -11,83 +12,83 @@ zci is_cached => 0;
ddg_goodie_test(
[qw( DDG::Goodie::Coin )],
'flip a coin' => test_zci(
qr/(heads|tails) \(random\)/,
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => qr/^(heads|tails)$/
result => re(qr/^(heads|tails)$/)
}
),
'flip coin' => test_zci(
qr/(heads|tails) \(random\)/,
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => qr/^(heads|tails)$/
result => re(qr/^(heads|tails)$/)
}
),
'flip 1 coin' => test_zci(
qr/(heads|tails) \(random\)/,
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => qr/^(heads|tails)$/
result => re(qr/^(heads|tails)$/)
}
),
'flip 2 coins' => test_zci(
qr/(heads|tails), (heads|tails) \(random\)/,
re(qr/(heads|tails), (heads|tails) \(random\)/),
structured_answer => {
input => [2],
operation => 'Flip coin',
result => qr/(heads|tails), /
result => re(qr/(heads|tails), /)
}
),
'toss a coin' => test_zci(
qr/(heads|tails) \(random\)/,
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => qr/^(heads|tails)$/
result => re(qr/^(heads|tails)$/)
}
),
'toss 1 coin' => test_zci(
qr/(heads|tails) \(random\)/,
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => qr/^(heads|tails)$/
result => re(qr/^(heads|tails)$/)
}
),
'toss 2 coins' => test_zci(
qr/(heads|tails), (heads|tails) \(random\)/,
re(qr/(heads|tails), (heads|tails) \(random\)/),
structured_answer => {
input => [2],
operation => 'Flip coin',
result => qr/(heads|tails), /
result => re(qr/(heads|tails), /)
}
),
'heads or tails' => test_zci(
qr/(heads|tails) \(random\)/,
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => qr/^(heads|tails)$/
result => re(qr/^(heads|tails)$/)
}
),
'heads or tails?' => test_zci(
qr/(heads|tails) \(random\)/,
re(qr/(heads|tails) \(random\)/),
structured_answer => {
input => [1],
operation => 'Flip coin',
result => qr/^(heads|tails)$/
result => re(qr/^(heads|tails)$/)
}
),
'flip 4 coins' => test_zci(
qr/((heads|tails),? ){4}\(random\)/,
re(qr/((heads|tails),? ){4}\(random\)/),
structured_answer => {
input => [4],
operation => 'Flip coin',
result => qr/(heads|tails),? /
result => re(qr/(heads|tails),? /)
}
),
);

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'color_code';
@ -13,7 +14,7 @@ my $green_answer = 'Hex: #00FF00 ~ RGBA(0, 255, 0, 1) ~ RGB(0%, 100%, 0%) ~ HSL(
my %basic_answer = (
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
item => 0,
@ -110,4 +111,4 @@ ddg_goodie_test(
'wield color' => undef,
);
done_testing;
done_testing;

64
t/Combination.t Normal file → Executable file
View File

@ -3,55 +3,35 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "combination";
zci is_cached => 1;
sub build_test
{
my ($answer, $question) = @_;
return test_zci(
$answer, structured_answer => {
data => {
title => $answer,
subtitle => $question
},
templates => {
group => 'text'
}
}
);
}
ddg_goodie_test(
[qw( DDG::Goodie::Combination )],
'10 choose 3' => test_zci('120',
structured_answer => {
input => ['10 choose 3'],
operation => 'Calculate',
result => '120',
}
),
'10 nCr 3' => test_zci('120',
structured_answer => {
input => ['10 choose 3'],
operation => 'Calculate',
result => '120',
}
),
'25 permute 16' => test_zci('4.27447366714368 * 10^19',
structured_answer => {
input => ['25 permute 16'],
operation => 'Calculate',
result => '4.27447366714368 * 10^19'
}
),
'16 permutation 3' => test_zci('3,360',
structured_answer => {
input => ['16 permute 3'],
operation => 'Calculate',
result => '3,360'
}
),
'15 permutation 0' => test_zci('1',
structured_answer => {
input => ['15 permute 0'],
operation => 'Calculate',
result => '1'
}
),
'1,000 choose 2' => test_zci('499,500',
structured_answer => {
input => ['1,000 choose 2'],
operation => 'Calculate',
result => '499,500'
}
),
'10 choose 3' => build_test('120', '10 choose 3'),
'10 nCr 3' => build_test('120', '10 choose 3'),
'25 permute 16' => build_test('4.27447366714368 * 10^19', '25 permute 16'),
'16 permutation 3' => build_test('3,360', '16 permute 3'),
'15 permutation 0' => build_test('1', '15 permute 0'),
'1,000 choose 2' => build_test('499,500', '1,000 choose 2'),
'0 choose 100' => undef,
'10 choose 100' => undef,
'10.5 choose 1' => undef,

View File

@ -4,6 +4,7 @@ use strict;
use warnings;
use utf8;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "constants";

View File

@ -2,6 +2,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
use utf8;
zci answer_type => 'conversions';
@ -359,6 +360,18 @@ ddg_goodie_test(
physical_quantity => 'pressure'
})
),
'0.01933677566613741911668448550544 psi in mmHg' => test_zci(
'0.01933677566613741911668448550544 pounds per square inch = 1 mmHg',
structured_answer => make_answer({
markup_input => '0.01933677566613741911668448550544',
raw_input => '0.01933677566613741911668448550544',
from_unit => 'pounds per square inch',
styled_output => '1',
raw_answer => '1',
to_unit => 'mmHg',
physical_quantity => 'pressure'
})
),
'2 thou to mm' => test_zci(
'2 thousandths of an inch = 0.051 millimeters',
structured_answer => make_answer({
@ -599,6 +612,18 @@ ddg_goodie_test(
physical_quantity => 'energy'
})
),
'1000000 kcal in tons of tnt' => test_zci(
'1,000,000 large calories = 1 ton of TNT',
structured_answer => make_answer({
markup_input => '1,000,000',
raw_input => '1000000',
from_unit => 'large calories',
styled_output => '1',
raw_answer => '1',
to_unit => 'ton of TNT',
physical_quantity => 'energy'
})
),
'90 ps in watts' => test_zci(
'90 metric horsepower = 66,194.888 watts',
structured_answer => make_answer({
@ -984,14 +1009,14 @@ ddg_goodie_test(
})
),
'ml in gallons' => test_zci(
'1 millilitre = 0.000264 us gallons',
'1 us gallon = 3,785.412 millilitres',,
structured_answer => make_answer({
markup_input => '1',
raw_input => '1',
from_unit => 'millilitre',
styled_output => '0.000264',
raw_answer => '0.000264',
to_unit => 'us gallons',
from_unit => 'us gallon',
styled_output => '3,785.412',
raw_answer => '3785.412',
to_unit => 'millilitres',
physical_quantity => 'volume'
})
),
@ -1431,14 +1456,14 @@ ddg_goodie_test(
})
),
'how many cm in metres?' => test_zci(
'1 centimeter = 0.010 meters',
'1 meter = 100 centimeters',
structured_answer => make_answer({
markup_input => '1',
raw_input => '1',
from_unit => 'centimeter',
styled_output => '0.010',
raw_answer => '0.010',
to_unit => 'meters',
from_unit => 'meter',
styled_output => '100',
raw_answer => '100',
to_unit => 'centimeters',
physical_quantity => 'length'
})
),
@ -2755,7 +2780,18 @@ ddg_goodie_test(
physical_quantity => 'speed'
})
),
'acre square feet' => test_zci(
'1 acre = 43,560.173 square feet',
structured_answer => make_answer({
markup_input => '1',
raw_input => '1',
from_unit => 'acre',
styled_output => '43,560.173',
raw_answer => '43560.173',
to_unit => 'square feet',
physical_quantity => 'area'
})
),
# Intentionally untriggered

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
use utf8;
@ -102,14 +103,14 @@ ddg_goodie_test(
'convert 39.75 degrees to farenheit' => undef,
#Check for to-format name
'16.5° S, 68.15° W dms' => test_zci(qr/./,
'16.5° S, 68.15° W dms' => test_zci(re(qr/./),
structured_answer => {
input => ["16.5° S", "68.15° W"],
operation => "Convert to DMS",
result => "16&deg; 30&prime; S, 68&deg; 9&prime; W",
}
),
'16° 30 S, 68° 9 W decimal' => test_zci(qr/./,
'16° 30 S, 68° 9 W decimal' => test_zci(re(qr/./),
structured_answer => {
input => ["16° 30 S", "68° 9 W"],
operation => "Convert to decimal",
@ -119,4 +120,3 @@ ddg_goodie_test(
);
done_testing;

View File

@ -4,121 +4,45 @@ use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "country_codes";
zci is_cached => 1;
my $text = '</div><div class="zci__subheader">ISO 3166 Country code for';
sub build_structured_answer{
my ($country, $response) = @_;
return 'ISO 3166: '. ucfirst $country .' - '. $response,
structured_answer => {
data => {
title => $response,
subtitle => "ISO 3166 Country code: " . ucfirst ($country),
},
templates => {
group => "text",
},
},
}
sub build_test { test_zci(build_structured_answer(@_)) }
ddg_goodie_test(
[ 'DDG::Goodie::CountryCodes' ],
"country code Japan" => test_zci(
qq(ISO 3166: Japan - jp),
structured_answer => {
input => ['Japan'],
operation => 'ISO 3166 Country code',
result => 'jp'
}
),
"3 letter country code Japan" => test_zci(
qq(ISO 3166: Japan - jpn),
structured_answer => {
input => ['Japan'],
operation => 'ISO 3166 Country code',
result => 'jpn'
}
),
"3 letter country code of China" => test_zci(
qq(ISO 3166: China - chn),
structured_answer => {
input => ['China'],
operation => 'ISO 3166 Country code',
result => 'chn'
}
),
"Japan 3 letter country code" => test_zci(
qq(ISO 3166: Japan - jpn),
structured_answer => {
input => ['Japan'],
operation => 'ISO 3166 Country code',
result => 'jpn'
}
),
"Russia two letter country code" => test_zci(
qq(ISO 3166: Russia - ru),
structured_answer => {
input => ['Russia'],
operation => 'ISO 3166 Country code',
result => 'ru'
}
),
"two letter country code Japan" => test_zci(
qq(ISO 3166: Japan - jp),
structured_answer => {
input => ['Japan'],
operation => 'ISO 3166 Country code',
result => 'jp'
}
),
"three letter country code for Japan" => test_zci(
qq(ISO 3166: Japan - jpn),
structured_answer => {
input => ['Japan'],
operation => 'ISO 3166 Country code',
result => 'jpn'
}
),
"numerical iso code japan" => test_zci(
qq(ISO 3166: Japan - 392),
structured_answer => {
input => ['Japan'],
operation => 'ISO 3166 Country code',
result => '392'
}
),
"iso code for spain" => test_zci(
qq(ISO 3166: Spain - es),
structured_answer => {
input => ['Spain'],
operation => 'ISO 3166 Country code',
result => 'es'
}
),
"country code jp" => test_zci(
qq(ISO 3166: Japan - jp),
structured_answer => {
input => ['Japan'],
operation => 'ISO 3166 Country code',
result => 'jp'
}
),
"japan numerical iso 3166" => test_zci(
qq(ISO 3166: Japan - 392),
structured_answer => {
input => ['Japan'],
operation => 'ISO 3166 Country code',
result => '392'
}
),
"united states of america iso code" => test_zci(
qq(ISO 3166: United states of america - us),
structured_answer => {
input => ['United states of america'],
operation => 'ISO 3166 Country code',
result => 'us'
}
),
"3 letter iso code isle of man" => test_zci(
qq(ISO 3166: Isle of man - imn),
structured_answer => {
input => ['Isle of man'],
operation => 'ISO 3166 Country code',
result => 'imn'
}
),
'country code for gelgamek' => undef,
'iso code for english' => undef,
"country code Japan" => build_test("Japan","jp"),
"3 letter country code Japan" => build_test("Japan","jpn"),
"3 letter country code of China" => build_test("China","chn"),
"Japan 3 letter country code" => build_test("Japan","jpn"),
"Russia two letter country code" => build_test("Russia","ru"),
"two letter country code Japan" => build_test("Japan","jp"),
"three letter country code for Japan" => build_test("Japan","jpn"),
"numerical iso code japan" => build_test("Japan",392),
"iso code for spain" => build_test("Spain","es"),
"country code jp" => build_test("Japan","jp"),
"japan numerical iso 3166" => build_test("Japan",392),
"united states of america iso code" => build_test("United states of america","us"),
"3 letter iso code isle of man" => build_test("Isle of man","imn"),
'country code for gelgamek' => undef,
'iso code for english' => undef,
);
done_testing;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'crypthashcheck';
@ -171,4 +172,3 @@ ddg_goodie_test(
done_testing;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'currency_in';

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "cusip";
@ -56,7 +57,7 @@ ddg_goodie_test(
),
'cusip check 037833100' => test_zci("037833100 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -64,7 +65,7 @@ ddg_goodie_test(
),
'cusip 844741108' => test_zci("844741108 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -72,7 +73,7 @@ ddg_goodie_test(
),
'037833100 cusip' => test_zci("037833100 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -80,7 +81,7 @@ ddg_goodie_test(
),
'037833100 cusip check' => test_zci("037833100 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -90,7 +91,7 @@ ddg_goodie_test(
# starting white space should be stripped
'cusip 037833100' => test_zci("037833100 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -100,7 +101,7 @@ ddg_goodie_test(
# ending white space should be stripped
'cusip 037833100 ' => test_zci("037833100 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -110,7 +111,7 @@ ddg_goodie_test(
# starting and ending white space should be stripped
'cusip 037833100 ' => test_zci("037833100 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -120,7 +121,7 @@ ddg_goodie_test(
# same AAPL queries with an incorrect check digit
'cusip 03783310A' => test_zci("03783310A is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -128,7 +129,7 @@ ddg_goodie_test(
),
'cusip 03783310A' => test_zci("03783310A is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -136,7 +137,7 @@ ddg_goodie_test(
),
'cusip 03783310A ' => test_zci("03783310A is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -144,7 +145,7 @@ ddg_goodie_test(
),
'cusip 03783310A ' => test_zci("03783310A is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -154,7 +155,7 @@ ddg_goodie_test(
# check CUSIP IDs with capital letters (these are for GOOG and Blackberry)
'cusip 38259P706' => test_zci("38259P706 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -162,7 +163,7 @@ ddg_goodie_test(
),
'cusip 38259P508' => test_zci("38259P508 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -170,7 +171,7 @@ ddg_goodie_test(
),
'cusip 09228F103' => test_zci("09228F103 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -180,7 +181,7 @@ ddg_goodie_test(
# check the same CUSIP IDs with lower case letters
'cusip 38259p706' => test_zci("38259P706 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -188,7 +189,7 @@ ddg_goodie_test(
),
'cusip 38259p508' => test_zci("38259P508 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -196,7 +197,7 @@ ddg_goodie_test(
),
'cusip 09228f103' => test_zci("09228F103 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -208,7 +209,7 @@ ddg_goodie_test(
# if possible, these tests should be replaced with verified CUSIP IDs
'cusip 037833*00' => test_zci("037833*00 is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -216,7 +217,7 @@ ddg_goodie_test(
),
'cusip 037833*02' => test_zci("037833*02 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -224,7 +225,7 @@ ddg_goodie_test(
),
'cusip 0378331#0' => test_zci("0378331#0 is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -232,7 +233,7 @@ ddg_goodie_test(
),
'cusip 0378331#7' => test_zci("0378331#7 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -240,7 +241,7 @@ ddg_goodie_test(
),
'cusip 037833@00' => test_zci("037833\@00 is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -248,7 +249,7 @@ ddg_goodie_test(
),
'cusip 037833@01' => test_zci("037833\@01 is a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -259,7 +260,7 @@ ddg_goodie_test(
# even though they are always invalid IDs
'cusip 03783310*' => test_zci("03783310* is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -267,7 +268,7 @@ ddg_goodie_test(
),
'cusip 03783310#' => test_zci("03783310# is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -275,7 +276,7 @@ ddg_goodie_test(
),
'cusip 03783310@' => test_zci("03783310\@ is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -285,7 +286,7 @@ ddg_goodie_test(
# Odd CUSIP IDs should not break the IA
'cusip ********8' => test_zci("********8 is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -293,7 +294,7 @@ ddg_goodie_test(
),
'cusip ########9' => test_zci("########9 is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -301,7 +302,7 @@ ddg_goodie_test(
),
'cusip @#*@#*@#*' => test_zci("\@#*\@#*\@#* is not a properly formatted CUSIP number.",
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
}
@ -310,4 +311,3 @@ ddg_goodie_test(
);
done_testing;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'dhl';
@ -28,4 +29,3 @@ ddg_goodie_test(
);
done_testing;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use Test::MockTime qw( :all );
use DDG::Test::Goodie;
use DDG::Test::Location;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
use Test::MockTime qw( :all );

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
use Test::MockTime qw( :all );
@ -76,57 +77,57 @@ ddg_goodie_test(
},
),
'days between jan 1 and jan 15 inclusive' => test_zci(
qr/^There are 15 days between.+inclusive\.$/,
re(qr/^There are 15 days between.+inclusive\.$/),
structured_answer => {
input => '-ANY-',
input => ignore(),
operation => 'Days between, inclusive',
result => 15
},
),
'days between jan 1 and 15th feb' => test_zci(
qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/,
re(qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/),
structured_answer => {
input => '-ANY-',
input => ignore(),
operation => 'Days between',
result => 45
},
),
'number of days between jan 1 and 15th feb' => test_zci(
qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/,
re(qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/),
structured_answer => {
input => '-ANY-',
input => ignore(),
operation => 'Days between',
result => 45
},
),
'number of days from jan 1 and 15th feb' => test_zci(
qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/,
re(qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/),
structured_answer => {
input => '-ANY-',
input => ignore(),
operation => 'Days between',
result => 45
},
),
'days from jan 1 and 15th feb' => test_zci(
qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/,
re(qr/^There are 45 days between.+and 15 Feb [0-9]{4}\.$/),
structured_answer => {
input => '-ANY-',
input => ignore(),
operation => 'Days between',
result => 45
},
),
'days between today and tomorrow' => test_zci(
qr/^There are 1 days between.+ and.+\.$/,
re(qr/^There are 1 days between.+ and.+\.$/),
structured_answer => {
input => '-ANY-',
input => ignore(),
operation => 'Days between',
result => 1
},
),
'how many days between feb 2 and feb 17' => test_zci(
qr/^There are 15 days between.+ and.+\.$/,
re(qr/^There are 15 days between.+ and.+\.$/),
structured_answer => {
input => '-ANY-',
input => ignore(),
operation => 'Days between',
result => 15
},

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'dessert';
@ -13,81 +14,81 @@ ddg_goodie_test(
'DDG::Goodie::Dessert'
],
'desserts beginning with a' => test_zci(
qr/(.*?) is a dessert that begins with 'a'\.$/,
re(qr/(.*?) is a dessert that begins with 'a'\.$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'info',
}
}
),
'desserts beginning with A' => test_zci(
qr/(.*?) is a dessert that begins with 'A'\.$/,
re(qr/(.*?) is a dessert that begins with 'A'\.$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'info',
}
}
),
'dessert start with a' => test_zci(
qr/(.*?) is a dessert that begins with 'a'\.$/,
re(qr/(.*?) is a dessert that begins with 'a'\.$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'info',
}
}
),
'desserts starting with a' => test_zci(
qr/(.*?) is a dessert that begins with 'a'\.$/,
re(qr/(.*?) is a dessert that begins with 'a'\.$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'info',
}
}
),
'dessert starts with a' => test_zci(
qr/(.*?) is a dessert that begins with 'a'\.$/,
re(qr/(.*?) is a dessert that begins with 'a'\.$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'info',
}
}
),
'desserts beginning with z' => test_zci(
qr/(.*?) is a dessert that begins with 'z'\.$/,
re(qr/(.*?) is a dessert that begins with 'z'\.$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'info',
}
}
),
'a dessert that begins with a' => test_zci(
qr/(.*?) is a dessert that begins with 'a'\.$/,
re(qr/(.*?) is a dessert that begins with 'a'\.$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'info',
}
}
),
'a dessert that starts with the letter a' => test_zci(
qr/(.*?) is a dessert that begins with 'a'\.$/,
re(qr/(.*?) is a dessert that begins with 'a'\.$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'info',
}
}
),
'dessert that begins with the letter z' => test_zci(
qr/(.*?) is a dessert that begins with 'z'\.$/,
re(qr/(.*?) is a dessert that begins with 'z'\.$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'info',
}

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'dewey_decimal';
@ -17,7 +18,7 @@ ddg_goodie_test(
'dewey decimal system 640s' => test_zci("", html => '<table cellpadding=1><tr><td>641</td><td>&nbsp;<a href="/?q=Food">Food</a> & <a href="/?q=drink">drink</a></td></tr><tr><td>642</td><td>&nbsp;<a href="/?q=Meal">Meal</a>s & table service</td></tr><tr><td>643</td><td>&nbsp;<a href="/?q=House">Housing</a> & household equipment</td></tr><tr><td>644</td><td>&nbsp;<a href="/?q=Household">Household</a> utilities</td></tr><tr><td>645</td><td>&nbsp;<a href="/?q=Furniture">Household furnishings</a></td></tr><tr><td>646</td><td>&nbsp;<a href="/?q=Sewing">Sewing</a>, <a href="/?q=clothing">clothing</a>, personal living</td></tr><tr><td>647</td><td>&nbsp;<a href="/?q=Household management">Management of public household</a>s</td></tr><tr><td>648</td><td>&nbsp;<a href="/?q=Household chore">Housekeeping</a></td></tr><tr><td>649</td><td>&nbsp;<a href="/?q=Child rearing">Child rearing</a> & <a href="/?q=home care">home care</a> of sick</td></tr></table>'),
'#1 in the dewey decimal system' => test_zci("001 is knowledge in the Dewey Decimal System.", html => '001 is <a href="/?q=outline of knowledge">knowledge</a> in the Dewey Decimal System.'),
'dewey decimal system naturalism' => test_zci("146 is naturalism and related systems in the Dewey Decimal System.", html => '146 is <a href="/?q=naturalism (philosophy)">naturalism</a> and related systems in the Dewey Decimal System.'),
'etymology in the dewey decimal system' => test_zci("", html => qr{^<table cellpadding=1>.*</table>$}),
'etymology in the dewey decimal system' => test_zci("", html => re(qr{^<table cellpadding=1>.*</table>$})),
'dewey 644' => test_zci('644 is household utilities in the Dewey Decimal System.', html => '644 is <a href="/?q=household">household</a> utilities in the Dewey Decimal System.'),
);

109
t/Dice.t
View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'dice_roll';
@ -17,9 +18,9 @@ ddg_goodie_test(
# Check trigger kicks in.
'throw dice' => test_zci(
qr/^., .$/,
re(qr/^., .$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -29,9 +30,9 @@ ddg_goodie_test(
}
),
'throw dices' => test_zci(
qr/^., .$/,
re(qr/^., .$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -41,9 +42,9 @@ ddg_goodie_test(
}
),
'roll dice' => test_zci(
qr/^., .$/,
re(qr/^., .$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -53,9 +54,9 @@ ddg_goodie_test(
}
),
'throw die' => test_zci(
qr/^.$/,
re(qr/^.$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -68,9 +69,9 @@ ddg_goodie_test(
# Simple "dice" query
"roll 5 dice" => test_zci(
qr/., ., ., ., .$/,
re(qr/., ., ., ., .$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -82,9 +83,9 @@ ddg_goodie_test(
# Simple shorthand query
"roll 2d6" => test_zci(
qr/^\d (\+|-) \d$/,
re(qr/^\d (\+|-) \d$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -96,9 +97,9 @@ ddg_goodie_test(
# Query with numbers as words
"roll five dice" => test_zci(
qr/., ., ., ., .$/,
re(qr/., ., ., ., .$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -108,9 +109,9 @@ ddg_goodie_test(
}
),
"roll twenty five dice" => test_zci(
qr/., ., ., ., .$/,
re(qr/., ., ., ., .$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -120,9 +121,9 @@ ddg_goodie_test(
}
),
"roll fifty-four dice" => test_zci(
qr/., ., ., ., .$/,
re(qr/., ., ., ., .$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -132,9 +133,9 @@ ddg_goodie_test(
}
),
"roll seven dices" => test_zci(
qr/., ., ., ., .$/,
re(qr/., ., ., ., .$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -147,9 +148,9 @@ ddg_goodie_test(
"roll foo dice" => undef,
"throw 1d20" => test_zci(
qr/^\d{1,2}$/,
re(qr/^\d{1,2}$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -159,9 +160,9 @@ ddg_goodie_test(
}
),
"roll d20" => test_zci(
qr/^\d{1,2}$/,
re(qr/^\d{1,2}$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -173,9 +174,9 @@ ddg_goodie_test(
# Simple shorthand queries with +-
"roll 3d12 + 4" => test_zci(
qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2}$/,
re(qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2}$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -185,9 +186,9 @@ ddg_goodie_test(
}
),
"roll 3d8 - 8" => test_zci(
qr/^\d (\+|-) \d (\+|-) \d (\+|-) \d$/,
re(qr/^\d (\+|-) \d (\+|-) \d (\+|-) \d$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -197,9 +198,9 @@ ddg_goodie_test(
}
),
"roll 4d6-l" => test_zci(
qr/^([1-6] \+ ){3}[1-6] - [1-6]$/,
re(qr/^([1-6] \+ ){3}[1-6] - [1-6]$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -211,9 +212,9 @@ ddg_goodie_test(
# Simple conjunctive "dice" query
"throw 2 dice and 3 dice" => test_zci(
qr/., .., ., .Total: \d+$/,
re(qr/., .., ., .Total: \d+$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'list',
options => {
@ -225,9 +226,9 @@ ddg_goodie_test(
# Shorthand conjunctive query
"roll 2w6 and d20" => test_zci(
qr/^\d (\+|-) \d = \d+\d+Total: \d+$/,
re(qr/^\d (\+|-) \d = \d+\d+Total: \d+$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'list',
options => {
@ -239,9 +240,9 @@ ddg_goodie_test(
# Shorthand conjunctive queries with +-
"roll 2d6 and 3d12 + 4" => test_zci(
qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/,
re(qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'list',
options => {
@ -251,9 +252,9 @@ ddg_goodie_test(
}
),
"roll 2d6 and 3d12 - 4" => test_zci(
qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = -?\d+Total: \d+$/,
re(qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = -?\d+Total: \d+$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'list',
options => {
@ -263,9 +264,9 @@ ddg_goodie_test(
}
),
"throw 3d12 - 4 and 2d6" => test_zci(
qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = -?\d{1,2}\d (\+|-) \d = \d+Total: \d+$/,
re(qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = -?\d{1,2}\d (\+|-) \d = \d+Total: \d+$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'list',
options => {
@ -275,9 +276,9 @@ ddg_goodie_test(
}
),
"throw 2d6 and 3d12 + 4" => test_zci(
qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/,
re(qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'list',
options => {
@ -287,9 +288,9 @@ ddg_goodie_test(
}
),
"roll 2d6 and 4w6-l" => test_zci(
qr/^\d (\+|-) \d = \d+([1-6] \+ ){3}[1-6] - [1-6] = \d{1,2}Total: \d+$/,
re(qr/^\d (\+|-) \d = \d+([1-6] \+ ){3}[1-6] - [1-6] = \d{1,2}Total: \d+$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'list',
options => {
@ -299,9 +300,9 @@ ddg_goodie_test(
}
),
"roll 2 dice and 3d5 + 4" => test_zci(
qr/^., .\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/,
re(qr/^., .\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'list',
options => {
@ -325,9 +326,9 @@ ddg_goodie_test(
"roll 2d3 and 2d4-a" => undef,
"throw die" => test_zci(
qr/^.$/,
re(qr/^.$/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -338,9 +339,9 @@ ddg_goodie_test(
),
'roll 3d12' => test_zci(
qr/\d{1,2} \+ \d{1,2} \+ \d{1,2}/,
re(qr/\d{1,2} \+ \d{1,2} \+ \d{1,2}/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'text',
options => {
@ -350,9 +351,9 @@ ddg_goodie_test(
}
),
'roll 3d12 and 2d4' => test_zci(
qr/\d{1,2} \+ \d{1,2} \+ \d{1,2} = \d+[1-4]+ \+ [1-4]+ = \dTotal: \d+/,
re(qr/\d{1,2} \+ \d{1,2} \+ \d{1,2} = \d+[1-4]+ \+ [1-4]+ = \dTotal: \d+/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'list',
options => {
@ -362,9 +363,9 @@ ddg_goodie_test(
}
),
'roll 2 dice and 3d5' => test_zci(
qr/[1-5]+ \+ [1-5]+ \+ [1-5]+ = \d+Total: \d+/,
re(qr/[1-5]+ \+ [1-5]+ \+ [1-5]+ = \d+Total: \d+/),
structured_answer => {
data => '-ANY-',
data => ignore(),
templates => {
group => 'list',
options => {

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'duckduckgo';
@ -174,4 +175,3 @@ ddg_goodie_test(
);
done_testing;

View File

@ -1,6 +1,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'conversion';

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'email_validation';
@ -11,60 +12,60 @@ zci is_cached => 1;
ddg_goodie_test(
['DDG::Goodie::EmailValidator'],
'validate my email foo@example.com' => test_zci(
qr/appears to be valid/,
re(qr/appears to be valid/),
structured_answer => {
input => ['foo@example.com'],
operation => 'Email address validation',
result => qr/appears to be valid/
result => re(qr/appears to be valid/)
}
),
'validate my email foo+abc@example.com' => test_zci(
qr/appears to be valid/,
re(qr/appears to be valid/),
structured_answer => {
input => ['foo+abc@example.com'],
operation => 'Email address validation',
result => qr/appears to be valid/
result => re(qr/appears to be valid/)
}
),
'validate my email foo.bar@example.com' => test_zci(
qr/appears to be valid/,
re(qr/appears to be valid/),
structured_answer => {
input => ['foo.bar@example.com'],
operation => 'Email address validation',
result => qr/appears to be valid/
result => re(qr/appears to be valid/)
}
),
'validate user@exampleaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com'
=> test_zci(
qr/Please check the address/,
re(qr/Please check the address/),
structured_answer => {
input => '-ANY-',
input => ignore(),
operation => 'Email address validation',
result => qr/Please check the address/,
result => re(qr/Please check the address/),
}
),
'validate foo@example.com' => test_zci(
qr/appears to be valid/,
re(qr/appears to be valid/),
structured_answer => {
input => ['foo@example.com'],
operation => 'Email address validation',
result => qr/appears to be valid/
result => re(qr/appears to be valid/)
}
),
'validate foo@!!!.com' => test_zci(
qr/Please check the fully qualified domain name/,
re(qr/Please check the fully qualified domain name/),
structured_answer => {
input => ['foo@!!!.com'],
operation => 'Email address validation',
result => qr/Please check the fully qualified domain name/,
result => re(qr/Please check the fully qualified domain name/),
}
),
'validate foo@example.lmnop' => test_zci(
qr/Please check the top-level domain/,
re(qr/Please check the top-level domain/),
structured_answer => {
input => ['foo@example.lmnop'],
operation => 'Email address validation',
result => qr/Please check the top-level domain/,
result => re(qr/Please check the top-level domain/),
}
),
'validate foo' => undef,

View File

@ -4,6 +4,7 @@ use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'figlet';

51
t/Factors.t Normal file → Executable file
View File

@ -3,45 +3,32 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "factors";
zci is_cached => 1;
sub build_test
{
my ($text_answer, $input, $answer) = @_;
return test_zci($text_answer, structured_answer =>{
data => {
title => $answer,
subtitle => "Factors of: $input"
},
templates => {
group => 'text'
}
});
}
ddg_goodie_test(
[qw( DDG::Goodie::Factors)],
'30 factors' => test_zci(
'Factors of 30: 1, 2, 3, 5, 6, 10, 15, 30',
structured_answer => {
input => ['30'],
operation => 'Factors',
result => '1, 2, 3, 5, 6, 10, 15, 30'
}
),
'factors of 72' => test_zci(
'Factors of 72: 1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72',
structured_answer => {
input => ['72'],
operation => 'Factors',
result => '1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72'
}
),
'factors of 30' => test_zci(
'Factors of 30: 1, 2, 3, 5, 6, 10, 15, 30',
structured_answer => {
input => ['30'],
operation => 'Factors',
result => '1, 2, 3, 5, 6, 10, 15, 30'
}
),
'72 factors' => test_zci(
'Factors of 72: 1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72',
structured_answer => {
input => ['72'],
operation => 'Factors',
result => '1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72'
}
),
'30 factors' => build_test('Factors of 30: 1, 2, 3, 5, 6, 10, 15, 30', '30', '1, 2, 3, 5, 6, 10, 15, 30'),
'factors of 72' => build_test('Factors of 72: 1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72', '72', '1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72'),
'factors of 30' => build_test('Factors of 30: 1, 2, 3, 5, 6, 10, 15, 30', '30', '1, 2, 3, 5, 6, 10, 15, 30'),
'72 factors' => build_test('Factors of 72: 1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72', '72', '1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72'),
);
done_testing;

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'fedex';

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "fen_viewer";

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'fibonacci';

View File

@ -3,6 +3,7 @@
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "firefoxos";
@ -10,7 +11,7 @@ zci is_cached => 1;
#Structured answer template data
my $templateData = {
data => '-ANY-',
data => ignore(),
meta => {
sourceName => "Mozilla Developer Network",
sourceUrl => "https://developer.mozilla.org/en-US/Apps/Reference/Firefox_OS_device_APIs"

View File

@ -4,45 +4,39 @@ use strict;
use warnings;
use utf8;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'flip_text';
zci is_cached => 1;
sub build_structured_answer{
my ($input,$result) = @_;
return $result,
structured_answer => {
data => {
title => $result,
subtitle => "Flip text $input"
},
templates => {
group => 'text',
}
}
}
sub build_test{ test_zci(build_structured_answer(@_)) }
ddg_goodie_test(
[qw( DDG::Goodie::FlipText)],
'flip text test' => test_zci(
"\x{0287}\x{0073}\x{01DD}\x{0287}",
structured_answer => {
input => ['test'],
operation => 'Flip text',
result => '&#x287;s&#x1DD;&#x287;'
}
),
'mirror text test' => test_zci(
"\x{0287}\x{0073}\x{01DD}\x{0287}",
structured_answer => {
input => ['test'],
operation => 'Flip text',
result => '&#x287;s&#x1DD;&#x287;'
}
),
'flip text my sentence' => test_zci(
'ǝɔuǝʇuǝs ʎɯ',
structured_answer => {
input => ['my sentence'],
operation => 'Flip text',
result => '&#x1DD;&#x254;u&#x1DD;&#x287;u&#x1DD;s &#x28E;&#x26F;'
}
),
'mirror text text' => test_zci(
'ʇxǝʇ',
structured_answer => {
input => ['text'],
operation => 'Flip text',
result => '&#x287;x&#x1DD;&#x287;'
}
),
'flip text test' => build_test('test','ʇsǝʇ'),
'mirror text test' => build_test('test','ʇsǝʇ'),
'flip text my sentence' => build_test('my sentence','ǝɔuǝʇuǝs ʎɯ'),
'mirror text text' => build_test('text','ʇxǝʇ'),
'flip text <hello-world>' => build_test('<hello-world>','<pʃɹoʍ-oʃʃǝɥ>'),
'rotate text "hello world"' => build_test('"hello world"','„pʃɹoʍ oʃʃǝɥ„'),
'spin text ;hello world;' => build_test(';hello world;','؛pʃɹoʍ oʃʃǝɥ؛'),
'spin text [\'hello\']' => build_test('[\'hello\']','[,oʃʃǝɥ,]'),
'spin text <<"hello\' % & * () = + . #@!^(/world">>' => build_test('<<"hello\' % & * () = + . #@!^(/world">>','<<„pʃɹoʍ/)∨¡@# ˙ + = () ⅋ % ,oʃʃǝɥ„>>'),
);
done_testing;

Some files were not shown because too many files have changed in this diff Show More