2012-03-20 19:23:09 -07:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
2017-09-14 07:37:11 -07:00
|
|
|
use utf8;
|
2012-03-20 19:23:09 -07:00
|
|
|
use Test::More;
|
2016-05-16 06:07:57 -07:00
|
|
|
use Test::Deep;
|
2012-03-20 19:23:09 -07:00
|
|
|
use DDG::Test::Goodie;
|
|
|
|
|
2012-03-20 21:08:12 -07:00
|
|
|
zci answer_type => 'binary_conversion';
|
2014-02-12 07:16:17 -08:00
|
|
|
zci is_cached => 1;
|
2012-03-20 19:23:09 -07:00
|
|
|
|
2016-04-28 11:17:57 -07:00
|
|
|
sub build_structured_answer {
|
|
|
|
my ($input, $from, $to, $result) = @_;
|
|
|
|
return qq/Binary conversion: $input ($from) = $result ($to)/,
|
|
|
|
structured_answer => {
|
|
|
|
data => {
|
|
|
|
title => $result,
|
|
|
|
subtitle =>$from . ' to ' . $to . ': ' . $input
|
|
|
|
},
|
|
|
|
templates => {
|
|
|
|
group => 'text'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub build_test { test_zci(build_structured_answer(@_)) }
|
|
|
|
|
2012-03-20 19:23:09 -07:00
|
|
|
ddg_goodie_test(
|
2014-02-12 07:16:17 -08:00
|
|
|
[qw( DDG::Goodie::Binary)],
|
2017-09-14 07:37:11 -07:00
|
|
|
'foo in binary' => build_test('foo', 'String (UTF-8)', 'Binary', '011001100110111101101111'),
|
2016-04-28 11:17:57 -07:00
|
|
|
'12 as binary' => build_test('12', 'Decimal', 'Binary', '00001100'),
|
2017-09-14 07:37:11 -07:00
|
|
|
'that to binary' => build_test('that', 'String (UTF-8)', 'Binary', '01110100011010000110000101110100'),
|
2016-04-28 11:17:57 -07:00
|
|
|
'127 to binary' => build_test('127', 'Decimal', 'Binary', '01111111'),
|
|
|
|
'256 to binary' => build_test('256', 'Decimal', 'Binary', '0000000100000000'),
|
|
|
|
'0x00 to binary' => build_test('0x00', 'Hex', 'Binary', '00000000'),
|
|
|
|
'0x1e to binary' => build_test('0x1e', 'Hex', 'Binary', '00011110'),
|
|
|
|
'xa1 to binary' => build_test('0xa1', 'Hex', 'Binary', '10100001'),
|
|
|
|
'ffff to binary' => build_test('0xffff', 'Hex', 'Binary', '1111111111111111'),
|
|
|
|
'hex 0xffff to binary' => build_test('0xffff', 'Hex', 'Binary', '1111111111111111'),
|
|
|
|
'FEFE to binary' => build_test('0xfefe', 'Hex', 'Binary', '1111111011111110'),
|
|
|
|
'10 binary' => build_test('10', 'Binary', 'Decimal', '2'),
|
|
|
|
'10 from binary' => build_test('10', 'Binary', 'Decimal', '2'),
|
|
|
|
'10 to binary' => build_test('10', 'Decimal', 'Binary', '00001010'),
|
|
|
|
'decimal 10 as binary' => build_test('10', 'Decimal', 'Binary', '00001010'),
|
|
|
|
'hex 10 into binary' => build_test('0x10', 'Hex', 'Binary', '00010000'),
|
2017-09-14 07:37:11 -07:00
|
|
|
'0xg into binary' => build_test('0xg', 'String (UTF-8)', 'Binary', '001100000111100001100111'),
|
|
|
|
'hex 0xg as binary' => build_test('hex 0xg', 'String (UTF-8)', 'Binary', '01101000011001010111100000100000001100000111100001100111'),
|
2016-04-28 11:17:57 -07:00
|
|
|
'2336462209024 in binary' => build_test('2336462209024', 'Decimal', 'Binary', '000000100010000000000000000000000000000000000000'),
|
|
|
|
'300000000000000 as binary' => build_test(300000000000000, 'Decimal', 'Binary', '00000001000100001101100100110001011011101100000000000000'),
|
2017-09-14 07:37:11 -07:00
|
|
|
'Cygnus X-1 as binary' => build_test('Cygnus X-1', 'String (UTF-8)', 'Binary', '01000011011110010110011101101110011101010111001100100000010110000010110100110001'),
|
|
|
|
'è in binary' => build_test('è', 'String (UTF-8)', 'Binary', '1100001110101000'),
|
|
|
|
'ج in binary' => build_test('ج', 'String (UTF-8)', 'Binary', '1101100010101100'), # Arabic Letter JEEM
|
|
|
|
'П in binary' => build_test('П', 'String (UTF-8)', 'Binary', '1101000010011111'), # Cyrillic Capital Letter PE
|
|
|
|
'한글 in binary' => build_test('한글', 'String (UTF-8)', 'Binary', '111011011001010110011100111010101011100010000000'), # Korean Hangul
|
|
|
|
'漢字 in binary' => build_test('漢字', 'String (UTF-8)', 'Binary', '111001101011110010100010111001011010110110010111'), # Japanese Kanji
|
|
|
|
'造字 in binary' => build_test('造字', 'String (UTF-8)', 'Binary', '111010011000000010100000111001011010110110010111'), # Simplified Chinese
|
|
|
|
'扩展 in binary' => build_test('扩展', 'String (UTF-8)', 'Binary', '111001101000100110101001111001011011000110010101'), # Traditional Chinese
|
|
|
|
'🦆 in binary' => build_test('🦆', 'String (UTF-8)', 'Binary', '11110000100111111010011010000110'), # Emoji
|
2014-10-15 06:16:52 -07:00
|
|
|
'binary 10' => undef,
|
|
|
|
'12 binary' => undef,
|
|
|
|
'12 from binary' => undef,
|
|
|
|
'decimal 12 binary' => undef,
|
|
|
|
'hex 12 binary' => undef,
|
|
|
|
'Cyngus X-1 binary' => undef,
|
|
|
|
'to binary' => undef,
|
2012-03-20 19:23:09 -07:00
|
|
|
);
|
|
|
|
|
2016-05-16 06:18:04 -07:00
|
|
|
done_testing;
|