Coin: Switching to text template
parent
8e74d245c7
commit
e73e4cd868
|
@ -32,13 +32,15 @@ handle query_lc => sub {
|
||||||
return unless @output;
|
return unless @output;
|
||||||
|
|
||||||
my $result = join(', ', @output);
|
my $result = join(', ', @output);
|
||||||
return (
|
return $result . ' (random)', structured_answer => {
|
||||||
$result . ' (random)',
|
data => {
|
||||||
structured_answer => {
|
title => $result,
|
||||||
input => [$flips],
|
subtitle => "Flip coin: $flips"
|
||||||
operation => 'Flip coin',
|
},
|
||||||
result => $result
|
templates => {
|
||||||
});
|
group => 'text'
|
||||||
|
}
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -9,104 +9,36 @@ use DDG::Test::Goodie;
|
||||||
zci answer_type => 'coin';
|
zci answer_type => 'coin';
|
||||||
zci is_cached => 0;
|
zci is_cached => 0;
|
||||||
|
|
||||||
|
sub build_test {
|
||||||
|
my ($input, $text, $title) = @_;
|
||||||
|
return test_zci($text, structured_answer => {
|
||||||
|
data => {
|
||||||
|
title => $title,
|
||||||
|
subtitle => "Flip coin: $input"
|
||||||
|
},
|
||||||
|
templates => {
|
||||||
|
group => 'text'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
my $single_text_re = re(qr/(heads|tails) \(random\)/);
|
||||||
|
my $single_title_re = re(qr/^(heads|tails)$/);
|
||||||
|
|
||||||
ddg_goodie_test(
|
ddg_goodie_test(
|
||||||
[qw( DDG::Goodie::Coin )],
|
[qw( DDG::Goodie::Coin )],
|
||||||
'flip a coin' => test_zci(
|
'flip a coin' => build_test(1, $single_text_re, $single_title_re),
|
||||||
re(qr/(heads|tails) \(random\)/),
|
'flip coin' => build_test(1, $single_text_re, $single_title_re),
|
||||||
structured_answer => {
|
'coin flip' => build_test(1, $single_text_re, $single_title_re),
|
||||||
input => [1],
|
'coin toss' => build_test(1, $single_text_re, $single_title_re),
|
||||||
operation => 'Flip coin',
|
'flip 1 coin' => build_test(1, $single_text_re, $single_title_re),
|
||||||
result => re(qr/^(heads|tails)$/)
|
'heads or tails' => build_test(1, $single_text_re, $single_title_re),
|
||||||
}
|
'heads or tails?' => build_test(1, $single_text_re, $single_title_re),
|
||||||
),
|
'toss a coin' => build_test(1, $single_text_re, $single_title_re),
|
||||||
'flip coin' => test_zci(
|
'toss 1 coin' => build_test(1, $single_text_re, $single_title_re),
|
||||||
re(qr/(heads|tails) \(random\)/),
|
'flip 2 coins' => build_test(2, re(qr/(heads|tails), (heads|tails) \(random\)/), re(qr/(heads|tails), /)),
|
||||||
structured_answer => {
|
'toss 2 coins' => build_test(2, re(qr/(heads|tails), (heads|tails) \(random\)/), re(qr/(heads|tails), /)),
|
||||||
input => [1],
|
'flip 4 coins' => build_test(4, re(qr/((heads|tails),? ){4}\(random\)/), re(qr/(heads|tails),? /))
|
||||||
operation => 'Flip coin',
|
|
||||||
result => re(qr/^(heads|tails)$/)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'coin flip' => test_zci(
|
|
||||||
re(qr/(heads|tails) \(random\)/),
|
|
||||||
structured_answer => {
|
|
||||||
input => [1],
|
|
||||||
operation => 'Flip coin',
|
|
||||||
result => re(qr/^(heads|tails)$/)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'coin toss' => test_zci(
|
|
||||||
re(qr/(heads|tails) \(random\)/),
|
|
||||||
structured_answer => {
|
|
||||||
input => [1],
|
|
||||||
operation => 'Flip coin',
|
|
||||||
result => re(qr/^(heads|tails)$/)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'flip 1 coin' => test_zci(
|
|
||||||
re(qr/(heads|tails) \(random\)/),
|
|
||||||
structured_answer => {
|
|
||||||
input => [1],
|
|
||||||
operation => 'Flip coin',
|
|
||||||
result => re(qr/^(heads|tails)$/)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'flip 2 coins' => test_zci(
|
|
||||||
re(qr/(heads|tails), (heads|tails) \(random\)/),
|
|
||||||
structured_answer => {
|
|
||||||
input => [2],
|
|
||||||
operation => 'Flip coin',
|
|
||||||
result => re(qr/(heads|tails), /)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'toss a coin' => test_zci(
|
|
||||||
re(qr/(heads|tails) \(random\)/),
|
|
||||||
structured_answer => {
|
|
||||||
input => [1],
|
|
||||||
operation => 'Flip coin',
|
|
||||||
result => re(qr/^(heads|tails)$/)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'toss 1 coin' => test_zci(
|
|
||||||
re(qr/(heads|tails) \(random\)/),
|
|
||||||
structured_answer => {
|
|
||||||
input => [1],
|
|
||||||
operation => 'Flip coin',
|
|
||||||
result => re(qr/^(heads|tails)$/)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'toss 2 coins' => test_zci(
|
|
||||||
re(qr/(heads|tails), (heads|tails) \(random\)/),
|
|
||||||
structured_answer => {
|
|
||||||
input => [2],
|
|
||||||
operation => 'Flip coin',
|
|
||||||
result => re(qr/(heads|tails), /)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'heads or tails' => test_zci(
|
|
||||||
re(qr/(heads|tails) \(random\)/),
|
|
||||||
structured_answer => {
|
|
||||||
input => [1],
|
|
||||||
operation => 'Flip coin',
|
|
||||||
result => re(qr/^(heads|tails)$/)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'heads or tails?' => test_zci(
|
|
||||||
re(qr/(heads|tails) \(random\)/),
|
|
||||||
structured_answer => {
|
|
||||||
input => [1],
|
|
||||||
operation => 'Flip coin',
|
|
||||||
result => re(qr/^(heads|tails)$/)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
'flip 4 coins' => test_zci(
|
|
||||||
re(qr/((heads|tails),? ){4}\(random\)/),
|
|
||||||
structured_answer => {
|
|
||||||
input => [4],
|
|
||||||
operation => 'Flip coin',
|
|
||||||
result => re(qr/(heads|tails),? /)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Loading…
Reference in New Issue