61 lines
2.5 KiB
JavaScript
61 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
// For the browser test builder to work you MUST import them module in a variable that
|
|
// 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),
|
|
b: BigInt(1),
|
|
gcd: BigInt(1)
|
|
},
|
|
{
|
|
a: BigInt(0),
|
|
b: BigInt(189),
|
|
gcd: BigInt(189)
|
|
},
|
|
{
|
|
a: BigInt(189),
|
|
b: BigInt(0),
|
|
gcd: BigInt(189)
|
|
},
|
|
{
|
|
a: BigInt(0),
|
|
b: BigInt(0),
|
|
gcd: BigInt(0)
|
|
},
|
|
{
|
|
a: BigInt(1),
|
|
b: BigInt('14546149867129487614601346814'),
|
|
gcd: BigInt(1)
|
|
},
|
|
{
|
|
a: BigInt(27),
|
|
b: BigInt(18),
|
|
gcd: BigInt(9)
|
|
},
|
|
{
|
|
a: BigInt(-27),
|
|
b: BigInt(18),
|
|
gcd: BigInt(9)
|
|
},
|
|
{
|
|
a: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109'),
|
|
b: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109') * BigInt('144678545212641449725111562354371812236197961234111744040227045242578772124779004756249085154188369039159690638725821245974978963371615699005072473649705367893567309027634121825164880046600125480885803891136149601797439273507802533807541605261215613891134865916295914192271736572001975016089773532547481638243'),
|
|
gcd: BigInt('168694196579467171180863939518634764192343817610869919231900537093664715354591592262546800497540343203057121816378265655992490621138321114570420047522219942818258345349322155251835677199539229050711145144861404607171419723967136221126986330819362088262358855325306938646602003059377699727688477555163239222109')
|
|
}
|
|
];
|
|
|
|
describe('gcd', function () {
|
|
for (const input of inputs) {
|
|
let ret;
|
|
describe(`gcd(${input.a}, ${input.b})`, function () {
|
|
it(`should return ${input.gcd}`, function () {
|
|
ret = bigintCryptoUtils.gcd(input.a, input.b);
|
|
chai.expect(ret).to.equal(input.gcd);
|
|
});
|
|
});
|
|
}
|
|
}); |