2 * Copyright 2015-present Greg Hurrell. All rights reserved.
3 * Licensed under the terms of the MIT license.
8 import convert from '../convert';
10 describe('convert()', () => {
11 describe('converting from binary', () => {
12 it('treats binary-to-binary as a no-op', () => {
13 expect(convert('1011001', 2, 2)).toBe('1011001');
16 it('converts binary to decimal', () => {
19 it('converts binary to octal', () => {
22 it('converts binary to hexadecimal', () => {
25 it('converts with arbitrary precision', () => {
29 describe('converting from decimal', () => {
30 it('treats decimal-to-decimal as a no-op', () => {
31 expect(convert('324234124', 10, 10)).toBe('324234124');
34 it('converts decimal to binary', () => {
37 it('converts decimal to octal', () => {
40 it('converts decimal to hexadecimal', () => {
41 expect(convert('255', 10, 16)).toBe('ff');
42 expect(convert('4277009102', 10, 16)).toBe('feedface');
45 it('converts with arbitrary precision', () => {
49 describe('converting from octal', () => {
50 it('treats octal-to-octal as a no-op', () => {
51 expect(convert('723147234234', 8, 8)).toBe('723147234234');
54 it('converts octal to binary', () => {
57 it('converts octal to decimal', () => {
60 it('converts octal to hexadecimal', () => {
63 it('converts with arbitrary precision', () => {
67 describe('converting form hexadecimal', () => {
68 it('treats hexadecimal-to-hexadecimal as a no-op', () => {
69 expect(convert('deadbeef', 16, 16)).toBe('deadbeef');
72 it('converts hexadecimal to binary', () => {
75 it('converts hexadecimal to decimal', () => {
76 expect(convert('ff', 16, 10)).toBe('255');
77 expect(convert('feedface', 16, 10)).toBe('4277009102');
80 it('converts hexadecimal to octal', () => {
83 it('converts with arbitrary precision', () => {
84 expect(convert('ab92b650b5f18fb53ee9f6229fd82638d069d9af', 16, 10))
85 .toBe('979509212510335489186816896981475731336057182639');
86 expect(convert('ab92b650b5f18fb53ee9f6229fd82638d069d9af', 16, 8))
87 .toBe('125622554502657430766517564766105177301143432032354657');
88 expect(convert('ab92b650b5f18fb53ee9f6229fd82638d069d9af', 16, 2))
89 .toBe('1010101110010010101101100101000010110101111100011000111110110101001111101110100111110110001000101001111111011000001001100011100');