web3.js/test/utils.fromDecimal.js

44 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-03-07 23:48:45 -08:00
var chai = require('chai');
2015-03-08 10:18:52 -07:00
var utils = require('../lib/utils/utils.js');
2015-03-07 23:48:45 -08:00
var assert = chai.assert;
var tests = [
{ value: 1, expected: '0x1' },
{ value: '1', expected: '0x1' },
{ value: '0x1', expected: '0x1'},
{ value: '0x01', expected: '0x1'},
{ value: 15, expected: '0xf'},
{ value: '15', expected: '0xf'},
{ value: '0xf', expected: '0xf'},
{ value: '0x0f', expected: '0xf'},
{ value: -1, expected: '-0x1'},
{ value: '-1', expected: '-0x1'},
{ value: '-0x1', expected: '-0x1'},
{ value: '-0x01', expected: '-0x1'},
{ value: -15, expected: '-0xf'},
{ value: '-15', expected: '-0xf'},
{ value: '-0xf', expected: '-0xf'},
{ value: '-0x0f', expected: '-0xf'},
{ value: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'},
{ value: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'},
{ value: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', expected: '-0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'},
{ value: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd', expected: '-0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd'},
{ value: 0, expected: '0x0'},
{ value: '0', expected: '0x0'},
{ value: '0x0', expected: '0x0'},
{ value: -0, expected: '0x0'},
{ value: '-0', expected: '0x0'},
{ value: '-0x0', expected: '0x0'}
];
2015-02-26 06:54:49 -08:00
2015-03-25 14:17:35 -07:00
describe('lib/utils/utils', function () {
2015-02-26 06:54:49 -08:00
describe('fromDecimal', function () {
2015-03-07 23:48:45 -08:00
tests.forEach(function (test) {
it('should turn ' + test.value + ' to ' + test.expected, function () {
assert.equal(utils.fromDecimal(test.value), test.expected);
});
2015-02-26 06:54:49 -08:00
});
});
2015-03-07 23:48:45 -08:00
});