2020-04-06 11:17:22 +00:00
|
|
|
'use strict'
|
2019-04-19 07:42:28 +00:00
|
|
|
|
2020-04-06 11:17:22 +00:00
|
|
|
// Every test file (you can create as many as you want) should start like this
|
|
|
|
// Please, do NOT touch. They will be automatically removed for browser tests -->
|
|
|
|
const _pkg = require('../lib/index.node')
|
|
|
|
const chai = require('chai')
|
|
|
|
// <--
|
2019-04-19 07:42:28 +00:00
|
|
|
|
|
|
|
const bitLengths = [
|
2020-04-20 22:50:53 +00:00
|
|
|
0,
|
2020-04-07 17:49:57 +00:00
|
|
|
8,
|
|
|
|
255,
|
2020-04-06 11:17:22 +00:00
|
|
|
256,
|
2020-04-07 17:49:57 +00:00
|
|
|
258,
|
2020-04-06 11:17:22 +00:00
|
|
|
512,
|
|
|
|
1024,
|
|
|
|
2048,
|
2020-04-20 22:50:53 +00:00
|
|
|
3072
|
2020-04-06 11:17:22 +00:00
|
|
|
]
|
2019-04-19 07:42:28 +00:00
|
|
|
|
2020-04-21 00:41:32 +00:00
|
|
|
describe('Testing prime generation', function () {
|
2020-04-06 11:17:22 +00:00
|
|
|
this.timeout(120000)
|
|
|
|
for (const bitLength of bitLengths) {
|
|
|
|
describe(`prime(${bitLength})`, function () {
|
2020-04-21 00:41:32 +00:00
|
|
|
if (bitLength > 0) {
|
|
|
|
it(`should return a random ${bitLength}-bits probable prime`, async function () {
|
2020-04-20 22:50:53 +00:00
|
|
|
const prime = await _pkg.prime(bitLength)
|
2020-04-21 00:41:32 +00:00
|
|
|
chai.expect(_pkg.bitLength(prime)).to.equal(bitLength)
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
it('should throw error', async function () {
|
|
|
|
chai.expect(() => _pkg.prime(bitLength)).to.throw(RangeError)
|
|
|
|
})
|
|
|
|
}
|
2020-04-06 11:17:22 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
describe('Testing sync (NOT-RECOMMENDED) version: primeSync()', function () {
|
|
|
|
it('should return a random 1024-bits probable prime', function () {
|
|
|
|
const prime = _pkg.primeSync(1024, 16)
|
2020-04-21 00:41:32 +00:00
|
|
|
chai.expect(_pkg.bitLength(prime)).to.equal(1024)
|
|
|
|
chai.expect(() => _pkg.primeSync(0)).to.throw(RangeError)
|
2020-04-06 11:17:22 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|