zeroclickinfo-goodies/t/Dice.t

362 lines
9.7 KiB
Perl
Raw Normal View History

#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => 'dice_roll';
zci is_cached => 0;
my $heading = 'Random Dice Roll';
ddg_goodie_test(
2015-12-28 11:32:41 -08:00
[qw(
DDG::Goodie::Dice
)],
# Check trigger kicks in.
'throw dice' => test_zci(
re(qr/^., .$/),
structured_answer => {
data => ignore(),
templates => {
group => 'text',
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
}
}
),
'throw dices' => test_zci(
re(qr/^., .$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
'roll dice' => test_zci(
re(qr/^., .$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
'throw die' => test_zci(
re(qr/^.$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
# Simple "dice" query
"roll 5 dice" => test_zci(
re(qr/., ., ., ., .$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
# Simple shorthand query
"roll 2d6" => test_zci(
re(qr/^\d (\+|-) \d$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
2016-02-29 20:39:29 -08:00
# Query with numbers as words
"roll five dice" => test_zci(
re(qr/., ., ., ., .$/),
2016-02-29 20:39:29 -08:00
structured_answer => {
data => ignore(),
templates => {
group => 'text',
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
}
}
),
2016-02-29 20:39:29 -08:00
"roll seven dices" => test_zci(
re(qr/., ., ., ., .$/),
2016-02-29 20:39:29 -08:00
structured_answer => {
data => ignore(),
2016-02-29 20:39:29 -08:00
templates => {
group => 'text',
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
}
}
),
# Invalid numeric words
"roll foo dice" => undef,
# Out of range number of dice or number of face values
"roll 11d3" => undef,
"roll 2d32" => undef,
"roll twenty five dice" => undef,
"roll fifty-four dice" => undef,
2015-12-28 11:32:41 -08:00
"throw 1d20" => test_zci(
re(qr/^\d{1,2}$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
"roll d20" => test_zci(
re(qr/^\d{1,2}$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
# Simple shorthand queries with +-
"roll 3d12 + 4" => test_zci(
re(qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2}$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
"roll 3d8 - 8" => test_zci(
re(qr/^\d (\+|-) \d (\+|-) \d (\+|-) \d$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
"roll 4d6-l" => test_zci(
re(qr/^([1-6] \+ ){3}[1-6] - [1-6]$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
# Simple conjunctive "dice" query
"throw 2 dice and 3 dice" => test_zci(
re(qr/., .., ., .Total: \d+$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
2016-02-24 08:57:15 -08:00
group => 'list',
options => {
list_content => 'DDH.dice.content'
}
2015-12-28 11:32:41 -08:00
}
}
),
# Shorthand conjunctive query
"roll 2w6 and d20" => test_zci(
re(qr/^\d (\+|-) \d = \d+\d+Total: \d+$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
2016-02-24 08:57:15 -08:00
group => 'list',
options => {
list_content => 'DDH.dice.content'
}
2015-12-28 11:32:41 -08:00
}
}
),
# Shorthand conjunctive queries with +-
"roll 2d6 and 3d12 + 4" => test_zci(
re(qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
2016-02-24 08:57:15 -08:00
group => 'list',
options => {
list_content => 'DDH.dice.content'
}
2015-12-28 11:32:41 -08:00
}
}
),
"roll 2d6 and 3d12 - 4" => test_zci(
re(qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = -?\d+Total: \d+$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
2016-02-24 08:57:15 -08:00
group => 'list',
options => {
list_content => 'DDH.dice.content'
}
2015-12-28 11:32:41 -08:00
}
}
),
"throw 3d12 - 4 and 2d6" => test_zci(
re(qr/^\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = -?\d{1,2}\d (\+|-) \d = \d+Total: \d+$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
2016-02-24 08:57:15 -08:00
group => 'list',
options => {
list_content => 'DDH.dice.content'
}
2015-12-28 11:32:41 -08:00
}
}
),
"throw 2d6 and 3d12 + 4" => test_zci(
re(qr/^\d (\+|-) \d = \d+\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
2016-02-24 08:57:15 -08:00
group => 'list',
options => {
list_content => 'DDH.dice.content'
}
2015-12-28 11:32:41 -08:00
}
}
),
"roll 2d6 and 4w6-l" => test_zci(
re(qr/^\d (\+|-) \d = \d+([1-6] \+ ){3}[1-6] - [1-6] = \d{1,2}Total: \d+$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
2016-02-24 08:57:15 -08:00
group => 'list',
options => {
list_content => 'DDH.dice.content'
}
2015-12-28 11:32:41 -08:00
}
}
),
"roll 2 dice and 3d5 + 4" => test_zci(
re(qr/^., .\d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} (\+|-) \d{1,2} = \d+Total: \d+$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
2016-02-24 08:57:15 -08:00
group => 'list',
options => {
list_content => 'DDH.dice.content'
}
2015-12-28 11:32:41 -08:00
}
}
),
# Don't trigger
"roll 2d3 2d6 and 3d3" => undef,
"roll 2d4 and 2d30 d30" => undef,
"roll 222d3 and 3d2" => undef,
"roll the ball" => undef,
"throw the ball" => undef,
"roll " => undef,
"roll the" => undef,
"roll over" => undef,
"roll 0 dice" => undef,
"roll 0d6" => undef,
"roll 2d3 and 2d4-a" => undef,
"throw die" => test_zci(
re(qr/^.$/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
'roll 3d12' => test_zci(
re(qr/\d{1,2} \+ \d{1,2} \+ \d{1,2}/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
group => 'text',
2016-02-24 08:57:15 -08:00
options => {
subtitle_content => 'DDH.dice.subtitle_content'
}
2015-12-28 11:32:41 -08:00
}
}
),
'roll 3d12 and 2d4' => test_zci(
re(qr/\d{1,2} \+ \d{1,2} \+ \d{1,2} = \d+[1-4]+ \+ [1-4]+ = \dTotal: \d+/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
2016-02-24 08:57:15 -08:00
group => 'list',
options => {
list_content => 'DDH.dice.content'
}
2015-12-28 11:32:41 -08:00
}
}
),
'roll 2 dice and 3d5' => test_zci(
re(qr/[1-5]+ \+ [1-5]+ \+ [1-5]+ = \d+Total: \d+/),
2015-12-28 11:32:41 -08:00
structured_answer => {
data => ignore(),
2015-12-28 11:32:41 -08:00
templates => {
2016-02-24 08:57:15 -08:00
group => 'list',
options => {
list_content => 'DDH.dice.content'
}
2015-12-28 11:32:41 -08:00
}
}
),
);
2016-05-16 06:18:04 -07:00
done_testing;