zeroclickinfo-goodies/t/Luhn.t

39 lines
881 B
Perl
Raw Permalink Normal View History

2016-04-30 09:31:43 -07:00
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use Test::Deep;
use DDG::Test::Goodie;
zci answer_type => "luhn";
zci is_cached => 1;
2016-05-10 12:39:39 -07:00
sub build_structured_answer {
my ($result, $input) = @_;
2016-05-10 12:39:39 -07:00
return $result,
structured_answer => {
2016-05-10 12:39:39 -07:00
data => {
title => $result,
2016-07-20 10:53:27 -07:00
subtitle => "Luhn check digit for $input"
2016-05-10 12:39:39 -07:00
},
templates => {
group => 'text',
}
};
}
sub build_test { test_zci(build_structured_answer(@_)) }
2016-04-30 09:31:43 -07:00
ddg_goodie_test(
[qw( DDG::Goodie::Luhn )],
'luhn 1' => build_test('8', '1'),,
'luhn 4242 4242 424' => build_test('2', '4242 4242 424'),
'luhn 42424242424' => build_test('2', '42424242424'),
'750318923 luhn' => build_test('0', '750318923'),
2016-04-30 09:31:43 -07:00
'luhn j' => undef,
'123O9 93 luhn' => undef,
);
done_testing;