-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbigint-base-converter.js
71 lines (53 loc) · 2.51 KB
/
bigint-base-converter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*jshint node:true, mocha:true */
'use strict';
require('should');
var Big = require('arbitrary-precision')(require('bigjs-adapter'));
var toBigFactory = require('to-decimal-arbitrary-precision');
var d = toBigFactory(Big);
Big.Impl.E_POS = 40;
var symbols85 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~';
var other = require('bigint-base-converter');
var fn = require('../src/');
describe('bigint-base-converter', function() {
it('supports custom symbols', function() {
'10'
.should.be.exactly(other('a', '0123456789a', '0123456789'))
.and.exactly(fn.symbols('0123456789a', 11, 10, 'a'))
.and.exactly(fn.toDecimal.symbols('0123456789a', 11, 'a'));
});
it('yields the same results from base 16', function() {
var b16To10 = fn.toDecimal.big(d, 16);
'21932261930451111902915077091070067066'
.should.be.exactly(other('108000000000000000080800200C417A', '0123456789ABCDEF', '0123456789'))
.and.exactly(b16To10('108000000000000000080800200C417A'));
});
it('yields the same results for base 16', function() {
var b10To16 = fn.fromDecimal.big(d, 16);
'108000000000000000080800200C417A'
.should.be.exactly(other('21932261930451111902915077091070067066', '0123456789', '0123456789ABCDEF'))
.and.exactly(b10To16('21932261930451111902915077091070067066'));
});
it('yields the same results from 16 to 85', function() {
var b16To85 = fn.raw(d, symbols85, 16, 85);
'4)+k&C#VzJ4br>0wv%Yp'
.should.be.exactly(other('108000000000000000080800200C417A', '0123456789ABCDEF', symbols85))
.and.exactly(b16To85('108000000000000000080800200C417A'));
});
it('yields the same results from 10 to 85', function() {
var b10To85 = fn.fromDecimal.raw(d, symbols85, 85);
'4)+k&C#VzJ4br>0wv%Yp'
.should.be.exactly(other('21932261930451111902915077091070067066', '0123456789', symbols85))
.and.exactly(b10To85('21932261930451111902915077091070067066'));
});
it('yields the same results from 85 to 16', function() {
var b85To16 = fn.raw(d, symbols85, 85, 16);
'108000000000000000080800200C417A'
.should.be.exactly(other('4)+k&C#VzJ4br>0wv%Yp', symbols85, '0123456789ABCDEF'))
.and.exactly(b85To16('4)+k&C#VzJ4br>0wv%Yp'));
});
it('yields the same results from 85 to 10', function() {
'21932261930451111902915077091070067066'
.should.be.exactly(other('4)+k&C#VzJ4br>0wv%Yp', symbols85, '0123456789'))
.and.exactly(fn.toDecimal.raw(d, symbols85, 85, '4)+k&C#VzJ4br>0wv%Yp'));
});
});