2015-03-08 07:33:22 +00:00
|
|
|
var chai = require('chai');
|
2015-03-08 17:18:52 +00:00
|
|
|
var utils = require('../lib/utils/utils.js');
|
2015-02-26 14:54:49 +00:00
|
|
|
var BigNumber = require('bignumber.js');
|
2015-03-08 07:33:22 +00:00
|
|
|
var assert = chai.assert;
|
|
|
|
|
|
|
|
var tests = [
|
|
|
|
{ value: 1, expected: '1' },
|
|
|
|
{ value: '1', expected: '1' },
|
|
|
|
{ value: '0x1', expected: '1'},
|
|
|
|
{ value: '0x01', expected: '1'},
|
|
|
|
{ value: 15, expected: '15'},
|
|
|
|
{ value: '15', expected: '15'},
|
|
|
|
{ value: '0xf', expected: '15'},
|
|
|
|
{ value: '0x0f', expected: '15'},
|
2015-03-08 09:07:32 +00:00
|
|
|
{ value: new BigNumber('f', 16), expected: '15'},
|
2015-03-08 07:33:22 +00:00
|
|
|
{ value: -1, expected: '-1'},
|
|
|
|
{ value: '-1', expected: '-1'},
|
|
|
|
{ value: '-0x1', expected: '-1'},
|
|
|
|
{ value: '-0x01', expected: '-1'},
|
|
|
|
{ value: -15, expected: '-15'},
|
|
|
|
{ value: '-15', expected: '-15'},
|
|
|
|
{ value: '-0xf', expected: '-15'},
|
|
|
|
{ value: '-0x0f', expected: '-15'},
|
|
|
|
{ value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639935'},
|
|
|
|
{ value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '115792089237316195423570985008687907853269984665640564039457584007913129639933'},
|
|
|
|
{ value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639935'},
|
|
|
|
{ value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-115792089237316195423570985008687907853269984665640564039457584007913129639933'},
|
|
|
|
{ value: 0, expected: '0'},
|
|
|
|
{ value: '0', expected: '0'},
|
|
|
|
{ value: '0x0', expected: '0'},
|
|
|
|
{ value: -0, expected: '0'},
|
|
|
|
{ value: '-0', expected: '0'},
|
2015-03-08 09:07:32 +00:00
|
|
|
{ value: '-0x0', expected: '0'},
|
|
|
|
{ value: new BigNumber(0), expected: '0'}
|
2015-03-08 07:33:22 +00:00
|
|
|
];
|
2015-02-26 14:54:49 +00:00
|
|
|
|
2015-03-25 21:17:35 +00:00
|
|
|
describe('lib/utils/utils', function () {
|
2015-02-26 14:54:49 +00:00
|
|
|
describe('toBigNumber', function () {
|
2015-03-08 07:33:22 +00:00
|
|
|
tests.forEach(function (test) {
|
|
|
|
it('should turn ' + test.value + ' to ' + test.expected, function () {
|
|
|
|
assert.equal(utils.toBigNumber(test.value).toString(10), test.expected);
|
|
|
|
});
|
2015-02-26 14:54:49 +00:00
|
|
|
});
|
|
|
|
});
|
2015-03-07 16:53:06 +00:00
|
|
|
});
|