better testing

This commit is contained in:
juanelas 2020-09-22 23:34:28 +02:00
parent 902e9fc4dd
commit 0603d4cfd7
1 changed files with 37 additions and 13 deletions

View File

@ -487,21 +487,20 @@ const inputs$6 = [
a: BigInt(-2), a: BigInt(-2),
n: BigInt(5), n: BigInt(5),
modInv: BigInt(2) modInv: BigInt(2)
}, }];
const invalidInputs = [
{ {
a: BigInt(2), a: BigInt(2),
n: BigInt(4), n: BigInt(4)
modInv: NaN
}, },
{ {
a: BigInt(0), a: BigInt(0),
n: BigInt(0), n: BigInt(0)
modInv: NaN
}, },
{ {
a: BigInt(0), a: BigInt(0),
n: BigInt(37), n: BigInt(37)
modInv: NaN
} }
]; ];
@ -515,6 +514,18 @@ describe('modInv', function () {
}); });
}); });
} }
for (const input of invalidInputs) {
describe(`modInv(${input.a}, ${input.n})`, function () {
it('should throw RangeError', function () {
try {
_pkg.modInv(input.a, input.n);
throw new Error('should have failed')
} catch (err) {
chai.expect(err).to.be.instanceOf(RangeError);
}
});
});
}
}); });
// Every test file (you can create as many as you want) should start like this // Every test file (you can create as many as you want) should start like this
@ -524,12 +535,6 @@ describe('modInv', function () {
// <-- // <--
const inputs$7 = [ const inputs$7 = [
{
a: BigInt(4),
b: BigInt(-1),
n: BigInt(0),
modPow: NaN
},
{ {
a: BigInt(4), a: BigInt(4),
b: BigInt(-1), b: BigInt(-1),
@ -559,6 +564,13 @@ const inputs$7 = [
b: BigInt(3), b: BigInt(3),
n: BigInt(25), n: BigInt(25),
modPow: BigInt(2) modPow: BigInt(2)
}];
const invalidInputs$1 = [
{
a: BigInt(4),
b: BigInt(-1),
n: BigInt(0)
} }
]; ];
@ -572,6 +584,18 @@ describe('modPow', function () {
}); });
}); });
} }
for (const input of invalidInputs$1) {
describe(`modPow(${input.a}, ${input.b}, ${input.n})`, function () {
it('should throw RangeError', function () {
try {
_pkg.modPow(input.a, input.b, input.n);
throw new Error('should have failed')
} catch (err) {
chai.expect(err).to.be.instanceOf(RangeError);
}
});
});
}
describe('Time profiling', function () { describe('Time profiling', function () {
let iterations = 500; let iterations = 500;
it(`just testing ${iterations} iterations of a big modular exponentiation (1024 bits)`, function () { it(`just testing ${iterations} iterations of a big modular exponentiation (1024 bits)`, function () {