From 0603d4cfd714212aed00c85eaf3b25b7b1ab11bb Mon Sep 17 00:00:00 2001 From: juanelas Date: Tue, 22 Sep 2020 23:34:28 +0200 Subject: [PATCH] better testing --- test/browser/tests.js | 50 ++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/test/browser/tests.js b/test/browser/tests.js index f8bae10..1090478 100644 --- a/test/browser/tests.js +++ b/test/browser/tests.js @@ -487,21 +487,20 @@ const inputs$6 = [ a: BigInt(-2), n: BigInt(5), modInv: BigInt(2) - }, + }]; + +const invalidInputs = [ { a: BigInt(2), - n: BigInt(4), - modInv: NaN + n: BigInt(4) }, { a: BigInt(0), - n: BigInt(0), - modInv: NaN + n: BigInt(0) }, { a: BigInt(0), - n: BigInt(37), - modInv: NaN + n: BigInt(37) } ]; @@ -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 @@ -524,12 +535,6 @@ describe('modInv', function () { // <-- const inputs$7 = [ - { - a: BigInt(4), - b: BigInt(-1), - n: BigInt(0), - modPow: NaN - }, { a: BigInt(4), b: BigInt(-1), @@ -559,6 +564,13 @@ const inputs$7 = [ b: BigInt(3), n: BigInt(25), 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 () { let iterations = 500; it(`just testing ${iterations} iterations of a big modular exponentiation (1024 bits)`, function () {