2019-05-04 16:08:30 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-02-27 20:51:48 +00:00
|
|
|
// For the browser test builder to work you MUST import the module in a variable that
|
2019-05-04 16:08:30 +00:00
|
|
|
// is the camelised version of the package name.
|
|
|
|
const bigintCryptoUtils = require('../dist/bigint-crypto-utils-latest.node');
|
|
|
|
const chai = require('chai');
|
|
|
|
|
|
|
|
const inputs = [
|
|
|
|
{
|
|
|
|
a: BigInt(1),
|
|
|
|
n: BigInt(19),
|
|
|
|
modInv: BigInt(1)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: BigInt(2),
|
|
|
|
n: BigInt(5),
|
|
|
|
modInv: BigInt(3)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
a: BigInt(-2),
|
|
|
|
n: BigInt(5),
|
|
|
|
modInv: BigInt(2)
|
2019-05-09 07:39:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
a: BigInt(2),
|
|
|
|
n: BigInt(4),
|
|
|
|
modInv: NaN
|
2019-05-04 16:08:30 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
describe('modInv', function () {
|
|
|
|
for (const input of inputs) {
|
|
|
|
describe(`modInv(${input.a}, ${input.n})`, function () {
|
|
|
|
it(`should return ${input.modInv}`, function () {
|
2019-05-29 15:44:18 +00:00
|
|
|
const ret = bigintCryptoUtils.modInv(input.a, input.n);
|
2019-05-09 07:39:12 +00:00
|
|
|
// chai.assert( String(ret) === String(input.modInv) );
|
|
|
|
chai.expect(String(ret)).to.be.equal(String(input.modInv));
|
2019-05-04 16:08:30 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|