Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Updates Base Goodie Re: #2767 (#2853)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Thiessard authored and GuiltyDolphin committed Apr 28, 2016
1 parent bb46c37 commit 2b0d873
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 87 deletions.
10 changes: 7 additions & 3 deletions lib/DDG/Goodie/Base.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ handle query_clean => sub {
my $based = int2base($number, $base);
return "$number in base $base is $based",
structured_answer => {
input => ["$number"],
operation => 'Decimal to base ' . $base,
result => $based
data => {
title => $based,
subtitle => "Decimal to base $base: $number"
},
templates => {
group => 'text'
}
};
};

Expand Down
111 changes: 27 additions & 84 deletions t/Base.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,91 +8,34 @@ use DDG::Test::Goodie;
zci answer_type => 'conversion';
zci is_cached => 1;

ddg_goodie_test([qw(
DDG::Goodie::Base
)
],
sub build_structured_answer {
my ($number, $base, $based) = @_;
return "$number in base $base is $based",
structured_answer => {
data => {
title => $based,
subtitle => "Decimal to base $base: $number"
},
templates => {
group => 'text'
}
};
}

'255 in hex' => test_zci(
'255 in base 16 is FF',
structured_answer => {
input => [255],
operation => 'Decimal to base 16',
result => 'FF'
}
),
'255 in base 16' => test_zci(
'255 in base 16 is FF',
structured_answer => {
input => [255],
operation => 'Decimal to base 16',
result => 'FF'
}
),
'255 in base 16' => test_zci(
'255 in base 16 is FF',
structured_answer => {
input => [255],
operation => 'Decimal to base 16',
result => 'FF'
}
),
'42 in binary' => test_zci(
'42 in base 2 is 101010',
structured_answer => {
input => [42],
operation => 'Decimal to base 2',
result => '101010'
}
),
'42 in base 2' => test_zci(
'42 in base 2 is 101010',
structured_answer => {
input => [42],
operation => 'Decimal to base 2',
result => "101010",
}
),
'42 to hex' => test_zci(
'42 in base 16 is 2A',
structured_answer => {
input => [42],
operation => 'Decimal to base 16',
result => '2A'
}
),
'42 to octal' => test_zci(
'42 in base 8 is 52',
structured_answer => {
input => [42],
operation => 'Decimal to base 8',
result => '52'
}
),
'10 in base 3' => test_zci(
'10 in base 3 is 101',
structured_answer => {
input => [10],
operation => 'Decimal to base 3',
result => '101'
}
),
'18442240474082181119 to hex' => test_zci(
'18442240474082181119 in base 16 is FFEFFFFFFFFFFFFF',
structured_answer => {
input => [18442240474082181119],
operation => 'Decimal to base 16',
result => 'FFEFFFFFFFFFFFFF'
}
),
'999999999999999999999999 to hex' => test_zci(
'999999999999999999999999 in base 16 is D3C21BCECCEDA0FFFFFF',
structured_answer => {
input => ["999999999999999999999999"],
operation => 'Decimal to base 16',
result => 'D3C21BCECCEDA0FFFFFF'
}
),
sub build_test { test_zci(build_structured_answer(@_)) }

ddg_goodie_test(
[qw(DDG::Goodie::Base)],

'255 in hex' => build_test(255, 16, 'FF'),
'255 in base 16' => build_test(255, 16, 'FF'),
'42 in binary' => build_test(42, 2, '101010'),
'42 in base 2' => build_test(42, 2, '101010'),
'42 to hex' => build_test(42, 16, '2A'),
'42 to octal' => build_test(42, 8, '52'),
'10 in base 3' => build_test(10, 3, '101'),
'18442240474082181119 to hex' => build_test(18442240474082181119, 16, 'FFEFFFFFFFFFFFFF'),
'999999999999999999999999 to hex' => build_test("999999999999999999999999", 16, 'D3C21BCECCEDA0FFFFFF'),
);

done_testing;
Expand Down

0 comments on commit 2b0d873

Please sign in to comment.