2014-04-23 23:22:10 +02:00
|
|
|
var assert = require('assert')
|
|
|
|
var BigInteger = require('../').BigInteger
|
|
|
|
|
|
|
|
var fixtures = require('./fixtures/bigi')
|
|
|
|
|
|
|
|
describe('BigInteger', function() {
|
|
|
|
describe('fromBuffer/fromHex', function() {
|
|
|
|
it('should match the test vectors', function() {
|
|
|
|
fixtures.valid.forEach(function(f) {
|
2014-04-24 16:18:13 +02:00
|
|
|
assert.equal(BigInteger.fromHex(f.hex).toString(), f.dec)
|
|
|
|
assert.equal(BigInteger.fromHex(f.hexPadded).toString(), f.dec)
|
2014-04-23 23:22:10 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
fixtures.invalid.forEach(function(f) {
|
|
|
|
it('throws on ' + f.description, function() {
|
|
|
|
assert.throws(function() {
|
|
|
|
BigInteger.fromHex(f.string)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('toBuffer/toHex', function() {
|
|
|
|
it('should match the test vectors', function() {
|
|
|
|
fixtures.valid.forEach(function(f) {
|
2014-04-24 16:18:13 +02:00
|
|
|
var bi = new BigInteger(f.dec)
|
2014-04-23 23:22:10 +02:00
|
|
|
|
2014-04-24 16:18:13 +02:00
|
|
|
assert.equal(bi.toHex(), f.hex)
|
|
|
|
assert.equal(bi.toHex(32), f.hexPadded)
|
2014-04-23 23:22:10 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2014-04-24 16:18:13 +02:00
|
|
|
it('throws on non-finite padding value', function() {
|
|
|
|
var bi = new BigInteger('1')
|
2014-04-23 23:22:10 +02:00
|
|
|
|
2014-04-24 16:18:13 +02:00
|
|
|
assert.throws(function() { bi.toHex({}) })
|
|
|
|
assert.throws(function() { bi.toHex([]) })
|
|
|
|
assert.throws(function() { bi.toHex('') })
|
|
|
|
assert.throws(function() { bi.toHex(0 / 0) })
|
|
|
|
assert.throws(function() { bi.toHex(1 / 0) })
|
2014-04-23 23:22:10 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = BigInteger
|