|
| 1 | +var assert = require('assert') |
| 2 | +var BigInteger = require('../').BigInteger |
| 3 | + |
| 4 | +var fixtures = require('./fixtures/bigi') |
| 5 | + |
| 6 | +describe('BigInteger', function() { |
| 7 | + describe('fromBuffer/fromHex', function() { |
| 8 | + it('should match the test vectors', function() { |
| 9 | + fixtures.valid.forEach(function(f) { |
| 10 | + assert.deepEqual(BigInteger.fromHex(f.hex).toString(), f.dec) |
| 11 | + assert.deepEqual(BigInteger.fromHex(f.hexPadded).toString(), f.dec) |
| 12 | + }) |
| 13 | + }) |
| 14 | + |
| 15 | + fixtures.invalid.forEach(function(f) { |
| 16 | + it('throws on ' + f.description, function() { |
| 17 | + assert.throws(function() { |
| 18 | + BigInteger.fromHex(f.string) |
| 19 | + }) |
| 20 | + }) |
| 21 | + }) |
| 22 | + }) |
| 23 | + |
| 24 | + describe('toBuffer/toHex', function() { |
| 25 | + it('should match the test vectors', function() { |
| 26 | + fixtures.valid.forEach(function(f) { |
| 27 | + var actualHex = new BigInteger(f.dec).toHex() |
| 28 | + |
| 29 | + assert.equal(actualHex, f.hex) |
| 30 | + }) |
| 31 | + }) |
| 32 | + }) |
| 33 | + |
| 34 | + describe('toPaddedBuffer', function() { |
| 35 | + it('should match the test vectors', function() { |
| 36 | + fixtures.valid.forEach(function(f) { |
| 37 | + var actualBuf = new BigInteger(f.dec).toPaddedBuffer(32) |
| 38 | + |
| 39 | + assert.equal(actualBuf.length, 32) |
| 40 | + assert.equal(actualBuf.toString('hex'), f.hexPadded) |
| 41 | + }) |
| 42 | + }) |
| 43 | + }) |
| 44 | +}) |
| 45 | + |
| 46 | +module.exports = BigInteger |
0 commit comments