| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094 | /* * Copyright 2018 Scytl Secure Electronic Voting SA * * All rights reserved * * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package *//* jshint node:true */'use strict';var mathematical = require('../lib/index');var CommonTestData = require('./data/common-data');var ValidationTestData = require('./data/validation-data');describe('The mathematical module should be able to ...', function() {  var mathService_;  var mathArrayCompressor_;  var mathRandomGenerator_;  var mathGroupHandler_;  var g_;  var p_;  var q_;  var group_;  var qrGroup_;  var elementValue_;  var element_;  var exponentValue_;  var exponent_;  var elements_;  var exponents_;  var elementFromAnotherGroup_;  var exponentFromAnotherGroup_;  var multiGroupElementValues_;  var minCertaintyLevel_;  var nonObject_;  var emptyObject_;  var nonSecureRandomService_;  var nonBoolean_;  var nonNumber_;  var nonPositiveNumber_;  var nonString_;  var nonJsonString_;  var nonArray_;  var nonMathObject_;  var nonMathObjectArray_;  var tooSmallModulus_;  var tooSmallOrder_;  var tooLargeOrder_;  var tooSmallGenerator_;  var tooLargeGenerator_;  var tooSmallElementValue_;  var tooLargeElementValue_;  var tooSmallModulusBitLength_;  var tooLowCertaintyLevel_;  var tooLargeNumMembersRequired_;  beforeAll(function() {    mathService_ = mathematical.newService();    mathArrayCompressor_ = mathService_.newArrayCompressor();    mathRandomGenerator_ = mathService_.newRandomGenerator();    mathGroupHandler_ = mathService_.newGroupHandler();    var commonTestData = new CommonTestData();    p_ = commonTestData.getP();    q_ = commonTestData.getQ();    g_ = commonTestData.getG();    group_ = commonTestData.getGroup();    qrGroup_ = commonTestData.getQuadraticResidueGroup();    elementValue_ = commonTestData.getElementValue();    element_ = commonTestData.getElement();    exponentValue_ = commonTestData.getExponentValue();    exponent_ = commonTestData.getExponent();    elements_ = commonTestData.getElements();    exponents_ = commonTestData.getExponents();    elementFromAnotherGroup_ = commonTestData.getElementFromAnotherGroup();    exponentFromAnotherGroup_ = commonTestData.getExponentFromAnotherGroup();    multiGroupElementValues_ = commonTestData.multiGroupElementValues();    minCertaintyLevel_ = commonTestData.getMinimumCertaintyLevel();    var validationTestData = new ValidationTestData();    nonObject_ = validationTestData.getNonObject();    emptyObject_ = validationTestData.getEmptyObject();    nonSecureRandomService_ = validationTestData.getNonSecureRandomService();    nonBoolean_ = validationTestData.getNonBoolean();    nonNumber_ = validationTestData.getNonNumber();    nonPositiveNumber_ = validationTestData.getNonPositiveNumber();    nonString_ = validationTestData.getNonString();    nonJsonString_ = validationTestData.getNonJsonString();    nonArray_ = validationTestData.getNonArray();    nonMathObject_ = validationTestData.getNonMathObject();    nonMathObjectArray_ = validationTestData.getNonMathObjectArray();    tooSmallModulus_ = validationTestData.getTooSmallModulus();    tooSmallOrder_ = validationTestData.getTooSmallOrder();    tooLargeOrder_ = validationTestData.getTooLargeOrder();    tooSmallGenerator_ = validationTestData.getTooSmallGenerator();    tooLargeGenerator_ = validationTestData.getTooLargeGenerator();    tooSmallElementValue_ = validationTestData.getTooSmallElementValue();    tooLargeElementValue_ = validationTestData.getTooLargeElementValue();    tooSmallModulusBitLength_ =        validationTestData.getTooSmallModulusBitLength();    tooLowCertaintyLevel_ = validationTestData.getTooLowCertaintyLevel();    tooLargeNumMembersRequired_ =        validationTestData.getTooLargeNumMembersRequired();  });  describe('create a mathematical service that should be able to ..', function() {    it('throw an error when being created, using an invalid secure random service object',       function() {         expect(function() {           Object.create(mathematical.newService({secureRandomService: null}));         }).toThrow();         expect(function() {           Object.create(               mathematical.newService({secureRandomService: nonObject_}));         }).toThrow();         expect(function() {           Object.create(               mathematical.newService({secureRandomService: emptyObject_}));         }).toThrow();       });    it('throw an error when creating a new ZpSubgroup object, using an invalid modulus p or JSON representation',       function() {         expect(function() {           mathService_.newZpSubgroup(undefined, q_, g_);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(null, q_, g_);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(nonMathObject_, q_, g_);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(tooSmallModulus_, q_, g_);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(nonJsonString_);         }).toThrow();       });    it('throw an error when creating a new ZpSubgroup object, using an invalid order q',       function() {         expect(function() {           mathService_.newZpSubgroup(p_, undefined, g_);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(p_, null, g_);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(p_, nonMathObject_, g_);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(p_, tooSmallOrder_, g_);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(p_, tooLargeOrder_, g_);         }).toThrow();       });    it('throw an error when creating a new ZpSubgroup object, using an invalid generator',       function() {         expect(function() {           mathService_.newZpSubgroup(p_, q_);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(p_, q_, undefined);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(p_, q_, null);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(p_, q_, nonMathObject_);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(p_, q_, tooSmallGenerator_);         }).toThrow();         expect(function() {           mathService_.newZpSubgroup(p_, q_, tooLargeGenerator_);         }).toThrow();       });    it('throw an error when creating a new ZpGroupElement object, using an invalid modulus p or JSON representation',       function() {         expect(function() {           mathService_.newZpGroupElement(undefined, q_, elementValue_);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(null, q_, elementValue_);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(nonMathObject_, q_, elementValue_);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(tooSmallModulus_, q_, elementValue_);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(nonJsonString_);         }).toThrow();       });    it('throw an error when creating a new ZpGroupElement object, using an invalid order q',       function() {         expect(function() {           mathService_.newZpGroupElement(p_, undefined, elementValue_);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(p_, null, elementValue_);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(p_, nonMathObject_, elementValue_);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(p_, tooSmallOrder_, elementValue_);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(p_, tooLargeOrder_, elementValue_);         }).toThrow();       });    it('throw an error when creating a new ZpGroupElement object, using an invalid element value',       function() {         expect(function() {           mathService_.newZpGroupElement(p_, q_);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(p_, q_, undefined);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(p_, q_, null);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(p_, q_, nonMathObject_);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(p_, q_, tooSmallElementValue_);         }).toThrow();         expect(function() {           mathService_.newZpGroupElement(p_, q_, tooLargeElementValue_);         }).toThrow();       });    it('throw an error when creating a new Exponent object, using an invalid order q or JSON representation',       function() {         expect(function() {           mathService_.newExponent(undefined, exponentValue_);         }).toThrow();         expect(function() {           mathService_.newExponent(null, exponentValue_);         }).toThrow();         expect(function() {           mathService_.newExponent(nonMathObject_, exponentValue_);         }).toThrow();         expect(function() {           mathService_.newExponent(tooSmallOrder_, exponentValue_);         }).toThrow();         expect(function() {           mathService_.newExponent(nonJsonString_);         }).toThrow();       });    it('throw an error when creating a new Exponent object, using an invalid exponent value',       function() {         expect(function() {           mathService_.newExponent(q_);         }).toThrow();         expect(function() {           mathService_.newExponent(q_, undefined);         }).toThrow();         expect(function() {           mathService_.newExponent(q_, null);         }).toThrow();         expect(function() {           mathService_.newExponent(q_, nonMathObject_);         }).toThrow();       });    it('throw an error when creating a new quadratic residue Zp subgroup, using invalid input data',       function() {         expect(function() {           mathService_.newQuadraticResidueGroup(p_);         }).toThrow();         expect(function() {           mathService_.newQuadraticResidueGroup(undefined, q_);         }).toThrow();         expect(function() {           mathService_.newQuadraticResidueGroup(null, q_);         }).toThrow();         expect(function() {           mathService_.newQuadraticResidueGroup(nonMathObject_, q_);         }).toThrow();         expect(function() {           mathService_.newQuadraticResidueGroup(tooSmallModulus_, q_);         }).toThrow();         expect(function() {           mathService_.newQuadraticResidueGroup(p_, undefined);         }).toThrow();         expect(function() {           mathService_.newQuadraticResidueGroup(p_, null);         }).toThrow();         expect(function() {           mathService_.newQuadraticResidueGroup(p_, nonMathObject_);         }).toThrow();         expect(function() {           mathService_.newQuadraticResidueGroup(p_, tooSmallOrder_);         }).toThrow();         expect(function() {           mathService_.newQuadraticResidueGroup(p_, tooLargeOrder_);         }).toThrow();       });    describe('create a new ZpSubgroup object that should ..', function() {      it('throw an error when checking for group membership, using invalid input data',         function() {           expect(function() {             group_.isGroupMember();           }).toThrow();           expect(function() {             group_.isGroupMember(undefined);           }).toThrow();           expect(function() {             group_.isGroupMember(null);           }).toThrow();           expect(function() {             group_.isGroupMember(nonMathObject_);           }).toThrow();         });      it('throw an error when checking for equality with another ZpSubgroup object, using invalid input data',         function() {           expect(function() {             group_.equals();           }).toThrow();           expect(function() {             group_.equals(undefined);           }).toThrow();           expect(function() {             group_.equals(null);           }).toThrow();           expect(function() {             group_.equals(nonMathObject_);           }).toThrow();         });    });    describe('create a new ZpGroupElement object that should ..', function() {      it('throw an error when multiplying itself with another ZpGroupElement object, using invalid input data',         function() {           expect(function() {             element_.multiply();           }).toThrow();           expect(function() {             element_.multiply(undefined);           }).toThrow();           expect(function() {             element_.multiply(null);           }).toThrow();           expect(function() {             element_.multiply(nonMathObject_);           }).toThrow();           expect(function() {             element_.multiply(elementFromAnotherGroup_);           }).toThrow();         });      it('throw an error when exponentiating itself with an Exponent object, using invalid input data',         function() {           expect(function() {             element_.exponentiate();           }).toThrow();           expect(function() {             element_.exponentiate(undefined);           }).toThrow();           expect(function() {             element_.exponentiate(null);           }).toThrow();           expect(function() {             element_.exponentiate(nonMathObject_);           }).toThrow();           expect(function() {             element_.exponentiate(exponentFromAnotherGroup_);           }).toThrow();         });      it('throw an error when comparing itself to another ZpGroupElement object, using invalid input data',         function() {           expect(function() {             element_.equals();           }).toThrow();           expect(function() {             element_.equals(undefined);           }).toThrow();           expect(function() {             element_.equals(null);           }).toThrow();           expect(function() {             element_.equals(nonMathObject_);           }).toThrow();         });    });    describe('create a new Exponent object that should ..', function() {      it('throw an error when adding itself to another Exponent object, using invalid input data',         function() {           expect(function() {             exponent_.add();           }).toThrow();           expect(function() {             exponent_.add(undefined);           }).toThrow();           expect(function() {             exponent_.add(null);           }).toThrow();           expect(function() {             exponent_.add(nonMathObject_);           }).toThrow();           expect(function() {             exponent_.add(exponentFromAnotherGroup_);           }).toThrow();         });      it('throw an error when subtracting another Exponent object from itself, using invalid input data',         function() {           expect(function() {             exponent_.subtract();           }).toThrow();           expect(function() {             exponent_.subtract(undefined);           }).toThrow();           expect(function() {             exponent_.subtract(null);           }).toThrow();           expect(function() {             exponent_.subtract(nonMathObject_);           }).toThrow();           expect(function() {             exponent_.add(exponentFromAnotherGroup_);           }).toThrow();         });      it('throw an error when multiplying itself with another Exponent object, using invalid input data',         function() {           expect(function() {             exponent_.multiply();           }).toThrow();           expect(function() {             exponent_.multiply(undefined);           }).toThrow();           expect(function() {             exponent_.multiply(null);           }).toThrow();           expect(function() {             exponent_.multiply(nonMathObject_);           }).toThrow();           expect(function() {             exponent_.add(exponentFromAnotherGroup_);           }).toThrow();         });      it('throw an error when comparing itself to another Exponent object, using invalid input data',         function() {           expect(function() {             exponent_.equals();           }).toThrow();           expect(function() {             exponent_.equals(undefined);           }).toThrow();           expect(function() {             exponent_.equals(null);           }).toThrow();           expect(function() {             exponent_.equals(nonMathObject_);           }).toThrow();         });    });    describe(        'create a new MathematicalArrayCompressor object that should ..',        function() {          it('throw an error when compressing an array of Zp group elements, using invalid input data',             function() {               expect(function() {                 mathArrayCompressor_.compressZpGroupElements();               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressZpGroupElements(undefined);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressZpGroupElements(null);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressZpGroupElements(nonArray_);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressZpGroupElements(                     nonMathObjectArray_);               }).toThrow();             });          it('throw an error when compressing an array of exponents, using invalid input data',             function() {               expect(function() {                 mathArrayCompressor_.compressExponents();               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressExponents(undefined);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressExponents(null);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressExponents(nonArray_);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressExponents(nonMathObjectArray_);               }).toThrow();             });          it('throw an error when compressing the trailing elements of an array of Zp group elements, using invalid input data',             function() {               expect(function() {                 mathArrayCompressor_.compressTrailingZpGroupElements(                     elements_);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingZpGroupElements(                     undefined, 2);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingZpGroupElements(null, 2);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingZpGroupElements(                     nonArray_, 2);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingZpGroupElements(                     nonMathObjectArray_, 2);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingZpGroupElements(                     elements_, undefined);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingZpGroupElements(                     elements_, null);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingZpGroupElements(                     elements_, nonNumber_);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingZpGroupElements(                     elements_, nonPositiveNumber_);               }).toThrow();             });          it('throw an error when compressing the trailing exponents of an array of exponents, using invalid input data',             function() {               expect(function() {                 mathArrayCompressor_.compressTrailingExponents(exponents_);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingExponents(undefined, 2);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingExponents(null, 2);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingExponents(nonArray_, 2);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingExponents(                     nonMathObjectArray_, 2);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingExponents(                     exponents_, undefined);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingExponents(                     exponents_, null);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingExponents(                     exponents_, nonNumber_);               }).toThrow();               expect(function() {                 mathArrayCompressor_.compressTrailingExponents(                     exponents_, nonPositiveNumber_);               }).toThrow();             });        });    describe(        'create a new MathematicalRandomGenerator object that should ..',        function() {          it('throw an error when generating a random exponent, using invalid input data',             function() {               expect(function() {                 mathRandomGenerator_.nextExponent();               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextExponent(undefined);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextExponent(null);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextExponent(nonMathObject_);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextExponent(                     group_, {secureRandomGenerator: nonObject_});               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextExponent(                     group_, {secureRandomGenerator: emptyObject_});               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextExponent(                     group_, {secureRandomGenerator: nonMathObject_});               }).toThrow();             });          it('throw an error when generating a random Zp group element, using invalid input data',             function() {               expect(function() {                 mathRandomGenerator_.nextZpGroupElement();               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextZpGroupElement(undefined);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextZpGroupElement(null);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextZpGroupElement(nonMathObject_);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextZpGroupElement(                     group_, {secureRandomGenerator: nonObject_});               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextZpGroupElement(                     group_, {secureRandomGenerator: emptyObject_});               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextZpGroupElement(                     group_, {secureRandomGenerator: nonMathObject_});               }).toThrow();             });          it('throw an error when generating a random quadratic residue group, using invalid input data',             function() {               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(16);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(                     undefined, minCertaintyLevel_);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(                     null, minCertaintyLevel_);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(                     nonNumber_, minCertaintyLevel_);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(                     nonPositiveNumber_, minCertaintyLevel_);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(                     tooSmallModulusBitLength_, minCertaintyLevel_);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(16, undefined);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(16, null);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(16, nonNumber_);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(                     16, nonPositiveNumber_);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(                     16, tooLowCertaintyLevel_);               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(                     16, minCertaintyLevel_,                     {secureRandomGenerator: nonObject_});               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(                     16, minCertaintyLevel_,                     {secureRandomGenerator: emptyObject_});               }).toThrow();               expect(function() {                 mathRandomGenerator_.nextQuadraticResidueGroup(                     16, minCertaintyLevel_,                     {secureRandomGenerator: nonMathObject_});               }).toThrow();             });        });    describe('create a new MathematicalGroupHandler object that should ..', function() {      it('throw an error when exponentiating an array of ZpGroupElement objects, using invalid input data',         function() {           expect(function() {             mathGroupHandler_.exponentiateElements(group_);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(group_, elements_);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(                 undefined, elements_, exponent_);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(null, elements_, exponent_);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(                 nonMathObject_, elements_, exponent_);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(                 group_, undefined, exponent_);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(group_, null, exponent_);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(                 group_, nonArray_, exponent_);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(                 group_, nonMathObjectArray_, exponent_);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(                 group_, elements_, undefined);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(                 group_, elements_, nonMathObject_);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(                 group_, elements_, exponentFromAnotherGroup_);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(                 group_, elements_, exponent_, null);           }).toThrow();           expect(function() {             mathGroupHandler_.exponentiateElements(                 group_, elements_, exponent_, nonBoolean_);           }).toThrow();         });      it('throw an error when dividing one array of ZpGroupElement objects with another, using invalid input data',         function() {           expect(function() {             mathGroupHandler_.divideElements(elements_);           }).toThrow();           expect(function() {             mathGroupHandler_.divideElements(undefined, elements_);           }).toThrow();           expect(function() {             mathGroupHandler_.divideElements(null, elements_);           }).toThrow();           expect(function() {             mathGroupHandler_.divideElements(nonArray_, elements_);           }).toThrow();           expect(function() {             mathGroupHandler_.divideElements(nonMathObjectArray_, elements_);           }).toThrow();           expect(function() {             mathGroupHandler_.divideElements(elements_, undefined);           }).toThrow();           expect(function() {             mathGroupHandler_.divideElements(elements_, null);           }).toThrow();           expect(function() {             mathGroupHandler_.divideElements(elements_, nonArray_);           }).toThrow();           expect(function() {             mathGroupHandler_.divideElements(elements_, nonMathObjectArray_);           }).toThrow();           expect(function() {             mathGroupHandler_.divideElements(elements_, [element_]);           }).toThrow();         });      it('throw an error when checking for group membership, using invalid input data',         function() {           expect(function() {             mathGroupHandler_.checkGroupMembership(undefined, elements_);           }).toThrow();           expect(function() {             mathGroupHandler_.checkGroupMembership(null, elements_);           }).toThrow();           expect(function() {             mathGroupHandler_.checkGroupMembership(nonMathObject_, elements_);           }).toThrow();           expect(function() {             mathGroupHandler_.checkGroupMembership(group_, undefined);           }).toThrow();           expect(function() {             mathGroupHandler_.checkGroupMembership(group_, null);           }).toThrow();           expect(function() {             mathGroupHandler_.checkGroupMembership(group_, nonArray_);           }).toThrow();           expect(function() {             mathGroupHandler_.checkGroupMembership(                 group_, nonMathObjectArray_);           }).toThrow();         });      it('throw an error when extracting Zp group elements from an array of BigIntegers, using invalid input data',         function() {           expect(function() {             mathGroupHandler_.extractGroupMembers(                 group_, multiGroupElementValues_);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(                 undefined, multiGroupElementValues_, 2);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(                 null, multiGroupElementValues_, 2);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(                 nonMathObject_, multiGroupElementValues_, 2);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(group_, undefined, 2);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(group_, null, 2);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(group_, nonArray_, 2);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(                 group_, nonMathObjectArray_, 2);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(                 group_, multiGroupElementValues_, undefined);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(                 group_, multiGroupElementValues_, null);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(                 group_, multiGroupElementValues_, nonNumber_);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(                 group_, multiGroupElementValues_, nonPositiveNumber_);           }).toThrow();           expect(function() {             mathGroupHandler_.extractGroupMembers(                 group_, multiGroupElementValues_, tooLargeNumMembersRequired_);           }).toThrow();         });      it('throw an error when finding the smallest generator for a given Zp subgroup, using invalid input data',         function() {           expect(function() {             mathGroupHandler_.findMinGenerator(p_);           }).toThrow();           expect(function() {             mathGroupHandler_.findMinGenerator(undefined, q_);           }).toThrow();           expect(function() {             mathGroupHandler_.findMinGenerator(null, q_);           }).toThrow();           expect(function() {             mathGroupHandler_.findMinGenerator(nonMathObject_, q_);           }).toThrow();           expect(function() {             mathGroupHandler_.findMinGenerator(tooSmallModulus_, q_);           }).toThrow();           expect(function() {             mathGroupHandler_.findMinGenerator(p_, undefined);           }).toThrow();           expect(function() {             mathGroupHandler_.findMinGenerator(p_, null);           }).toThrow();           expect(function() {             mathGroupHandler_.findMinGenerator(p_, nonMathObject_);           }).toThrow();           expect(function() {             mathGroupHandler_.findMinGenerator(p_, tooSmallOrder_);           }).toThrow();           expect(function() {             mathGroupHandler_.findMinGenerator(p_, tooLargeOrder_);           }).toThrow();         });    });  });});
 |