2012-04-15 12:05:05 -07:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Test::More;
|
2016-05-16 06:07:57 -07:00
|
|
|
use Test::Deep;
|
2012-04-15 12:05:05 -07:00
|
|
|
use DDG::Test::Goodie;
|
|
|
|
|
|
|
|
zci answer_type => 'conversion';
|
2014-10-15 00:17:44 -07:00
|
|
|
zci is_cached => 1;
|
2012-04-15 12:05:05 -07:00
|
|
|
|
2016-04-28 11:24:01 -07:00
|
|
|
sub build_structured_answer {
|
2016-05-20 16:59:21 -07:00
|
|
|
my ($input, $from_base, $to_base, $output) = @_;
|
|
|
|
return "$input in base $to_base is $output",
|
2016-04-28 11:24:01 -07:00
|
|
|
structured_answer => {
|
|
|
|
data => {
|
2016-05-20 16:59:21 -07:00
|
|
|
title => $output,
|
|
|
|
subtitle => "From base $from_base to base $to_base: $input"
|
2016-04-28 11:24:01 -07:00
|
|
|
},
|
|
|
|
templates => {
|
|
|
|
group => 'text'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2014-10-28 11:36:15 -07:00
|
|
|
|
2016-04-28 11:24:01 -07:00
|
|
|
sub build_test { test_zci(build_structured_answer(@_)) }
|
|
|
|
|
|
|
|
ddg_goodie_test(
|
|
|
|
[qw(DDG::Goodie::Base)],
|
|
|
|
|
2016-05-20 16:59:21 -07:00
|
|
|
'255 in hex' => build_test(255, 10, 16, 'FF'),
|
|
|
|
'255 in base 16' => build_test(255, 10, 16, 'FF'),
|
|
|
|
'42 in binary' => build_test(42, 10, 2, '101010'),
|
|
|
|
'42 in base 2' => build_test(42, 10, 2, '101010'),
|
|
|
|
'42 to hex' => build_test(42, 10, 16, '2A'),
|
|
|
|
'42 to octal' => build_test(42, 10, 8, '52'),
|
|
|
|
'10 in base 3' => build_test(10, 10, 3, '101'),
|
|
|
|
'18442240474082181119 to hex' => build_test(18442240474082181119, 10, 16, 'FFEFFFFFFFFFFFFF'),
|
|
|
|
'999999999999999999999999 to hex' => build_test("999999999999999999999999", 10, 16, 'D3C21BCECCEDA0FFFFFF'),
|
|
|
|
'DDG in base 36 to decimal' => build_test('DDG', 36, 10, '17332'),
|
|
|
|
'0b1111 in base 10' => build_test('1111', 2, 10, '15'),
|
|
|
|
'81 in base 9 to base 3' => build_test(81, 9, 3, '2201'),
|
|
|
|
'1111 in binary as octal' => build_test(1111, 2, 8, '17'),
|
|
|
|
'FF in hex to decimal' => build_test('FF', 16, 10, '255'),
|
2016-05-20 17:06:34 -07:00
|
|
|
'0xFF in base 10' => build_test('FF', 16, 10, '255'),
|
|
|
|
'BEEF as base 36 to hex' => build_test('BEEF', 36, 16, '81DA7'),
|
|
|
|
'HELLOWORLD as base 33 to decimal'=> build_test('HELLOWORLD', 33, 10, '809608041709942')
|
|
|
|
|
2012-04-15 12:05:05 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
done_testing;
|