diff options
author | Sebastian <sebasjm@gmail.com> | 2021-08-23 16:46:06 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-08-23 16:48:30 -0300 |
commit | 38acabfa6089ab8ac469c12b5f55022fb96935e5 (patch) | |
tree | 453dbf70000cc5e338b06201af1eaca8343f8f73 /big-integer/spec | |
parent | f26125e039143b92dc0d84e7775f508ab0cdcaa8 (diff) | |
download | node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.gz node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.bz2 node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.zip |
Diffstat (limited to 'big-integer/spec')
-rw-r--r-- | big-integer/spec/spec.js | 31 | ||||
-rw-r--r-- | big-integer/spec/tsDefinitions.ts | 53 |
2 files changed, 64 insertions, 20 deletions
diff --git a/big-integer/spec/spec.js b/big-integer/spec/spec.js index 4d01dd8..be999e9 100644 --- a/big-integer/spec/spec.js +++ b/big-integer/spec/spec.js @@ -630,6 +630,9 @@ describe("BigInteger", function () { } catch (e) {
expect(true).toBe(true);
}
+
+ expect(bigInt(2).modPow(-3, 11)).toEqualBigInt(7);
+ expect(bigInt(76455).modPow(-3758223534, 346346)).toEqualBigInt(339949);
});
});
@@ -818,7 +821,7 @@ describe("BigInteger", function () { }
});
it("correctly identifies pseudo primes", function () {
- var largePrimes = ["3825123056546413051", "3825123056546413051", "3825123056546413051", "318665857834031151167461"];
+ var largePrimes = ["4033", "4681", "3825123056546413051", "3825123056546413051", "3825123056546413051", "318665857834031151167461"];
for (var i = 0; i < largePrimes.length; i++) {
expect(bigInt(largePrimes[i]).isPrime()).toBe(false);
}
@@ -854,6 +857,24 @@ describe("BigInteger", function () { }
}
expect(falsePrimes / totalPrimes < 0.001).toBe(true);
+ }); + it("is predictable given predictable rng", function () { + function getProbablePrimes(fakeRNG) { + var result = []; + for (var i = 1; i < 100; i++) { + var x = bigInt(i); + if (x.isProbablePrime(1, fakeRNG)) { + result.push(i); + } + } + return result; + } + for (var i = 0; i < 100; i++) { + function fakeRNG() { + return (i * 0.3571) % 1; + } + expect(getProbablePrimes(fakeRNG)).toEqual(getProbablePrimes(fakeRNG)); + } });
});
@@ -1153,6 +1174,14 @@ describe("BigInteger", function () { expect(Math.abs(buckets[i] - ideal) / ideal < 0.1).toBe(true);
}
});
+ it("is predictable given predictable rng", function () {
+ for (var i = 0; i < 1e3; i++) {
+ function fakeRNG() {
+ return (i * 0.3571) % 1;
+ }
+ expect(bigInt.randBetween(0, 1024, fakeRNG)).toEqualBigInt(bigInt.randBetween(0, 1024, fakeRNG));
+ }
+ });
});
describe("isInstance", function () {
diff --git a/big-integer/spec/tsDefinitions.ts b/big-integer/spec/tsDefinitions.ts index 5e4b6d4..b88bb98 100644 --- a/big-integer/spec/tsDefinitions.ts +++ b/big-integer/spec/tsDefinitions.ts @@ -106,6 +106,7 @@ if (removedInstanceFns.length) { // constructor tests const noArgument = bigInt(); const numberArgument = bigInt(93); +const nativeBigintArgument = bigInt(93n); const stringArgument = bigInt("75643564363473453456342378564387956906736546456235345"); const baseArgumentInt = bigInt("101010", 2); const baseArgumentStr = bigInt("101010", "2"); @@ -131,6 +132,7 @@ isBigInteger = bigInt[0]; isBigInteger = bigInt[999]; isBigInteger = bigInt.fromArray([1, 2, 3]); +isBigInteger = bigInt.fromArray([1n, 2n, 3n]); isBigInteger = bigInt.fromArray(['1', '2', '3']); isBigInteger = bigInt.fromArray([bigInt.one, bigInt.zero, bigInt(9)], 10, true); @@ -138,55 +140,66 @@ isBigInteger = bigInt.gcd(0, 1); isBoolean = bigInt.isInstance(x); isBigInteger = bigInt.lcm(0, 1); isBigInteger = bigInt.max(0, 1); -isBigInteger = bigInt.gcd(0, 1); +isBigInteger = bigInt.min(0, 1); isBigInteger = bigInt.randBetween(0, 1); +isBigInteger = bigInt.randBetween(0, 1, () => 0.5); // Instance methods isBigInteger = x.abs(); -isBigInteger = x.add(0).add(x).add("100"); -isBigInteger = x.and(0).and(x).and("100"); +isBigInteger = x.add(0).add(x).add("100").add(100n); +isBigInteger = x.and(0).and(x).and("100").and(100n); isNumber = x.compare(0); isNumber = x.compare(x); isNumber = x.compare("100"); +isNumber = x.compare(100n); isNumber = x.compareAbs(0); isNumber = x.compareAbs(x); isNumber = x.compareAbs("100"); +isNumber = x.compareAbs(100n); isNumber = x.compareTo(0); isNumber = x.compareTo(x); isNumber = x.compareTo("100"); +isNumber = x.compareTo(100n); -isBigInteger = x.divide(10).divide(x).divide('10'); +isBigInteger = x.divide(10).divide(x).divide('10').divide(10n); isDivmod = x.divmod(10); isDivmod = x.divmod(x); isDivmod = x.divmod("100"); +isDivmod = x.divmod(100n); isBoolean = x.eq(0); isBoolean = x.eq(x); isBoolean = x.eq("100"); +isBoolean = x.eq(100n); isBoolean = x.equals(0); isBoolean = x.equals(x); isBoolean = x.equals("100"); +isBoolean = x.equals(100n); isBoolean = x.geq(0); isBoolean = x.geq(x); isBoolean = x.geq("100"); +isBoolean = x.geq(100n); isBoolean = x.greater(0); isBoolean = x.greater(x); isBoolean = x.greater("100"); +isBoolean = x.greater(100n); isBoolean = x.greaterOrEquals(0); isBoolean = x.greaterOrEquals(x); isBoolean = x.greaterOrEquals("100"); +isBoolean = x.greaterOrEquals(100n); isBoolean = x.gt(0); isBoolean = x.gt(x); isBoolean = x.gt("100"); +isBoolean = x.gt(100n); isBoolean = x.isDivisibleBy(x); isBoolean = x.isEven(); @@ -197,6 +210,7 @@ isBoolean = x.isPrime(); isBoolean = x.isProbablePrime(); isBoolean = x.isProbablePrime(5); +isBoolean = x.isProbablePrime(11, () => 0.5); isBoolean = x.isUnit(); isBoolean = x.isZero(); @@ -204,11 +218,11 @@ isBoolean = x.leq(x); isBoolean = x.lesser(0); isBoolean = x.lesserOrEquals(0); isBoolean = x.lt(0); -isBigInteger = x.minus(0).minus(x).minus('0'); -isBigInteger = x.mod(10).mod(x).mod('10'); -isBigInteger = bigInt(3).modInv(11); -isBigInteger = x.modPow(10, 2).modPow(x, x).modPow('10', '2'); -isBigInteger = x.multiply(0).multiply(x).multiply('0'); +isBigInteger = x.minus(0).minus(x).minus('0').minus(0n); +isBigInteger = x.mod(10).mod(x).mod('10').mod(10n); +isBigInteger = bigInt(3).modInv(11).modInv(11n); +isBigInteger = x.modPow(10, 2).modPow(x, x).modPow('10', '2').modPow(10n, 2n); +isBigInteger = x.multiply(0).multiply(x).multiply('0').multiply(0n); isBigInteger = x.negate(); isBoolean = x.neq(x); isBigInteger = x.next(); @@ -217,18 +231,19 @@ isBigInteger = x.not(); isBoolean = x.notEquals(0); isBoolean = x.notEquals(x); isBoolean = x.notEquals("100"); +isBoolean = x.notEquals(100n); -isBigInteger = x.or(10).or(x).or('10'); -isBigInteger = x.over(10).over(x).over('10'); -isBigInteger = x.plus(0).plus(x).plus('0'); -isBigInteger = x.pow(0).pow(x).pow('0'); +isBigInteger = x.or(10).or(x).or('10').or(10n); +isBigInteger = x.over(10).over(x).over('10').over(10n); +isBigInteger = x.plus(0).plus(x).plus('0').plus(0n); +isBigInteger = x.pow(0).pow(x).pow('0').pow(0n); isBigInteger = x.prev(); -isBigInteger = x.remainder(10).remainder(x).remainder('10'); -isBigInteger = x.shiftLeft(0).shiftLeft('0'); -isBigInteger = x.shiftRight(0).shiftRight('0'); +isBigInteger = x.remainder(10).remainder(x).remainder('10').remainder(10n); +isBigInteger = x.shiftLeft(0).shiftLeft('0').shiftLeft(0n); +isBigInteger = x.shiftRight(0).shiftRight('0').shiftRight(0n); isBigInteger = x.square(); -isBigInteger = x.subtract(0).subtract(x).subtract('0'); -isBigInteger = x.times(0).times(x).times('0'); +isBigInteger = x.subtract(0).subtract(x).subtract('0').subtract(0n); +isBigInteger = x.times(0).times(x).times('0').times(0n); isNumber = x.toJSNumber(); isBaseArray = x.toArray(10); @@ -239,4 +254,4 @@ isString = x.toString(36); isString = x.toJSON(); isNumber = x.valueOf(); -isBigInteger = x.xor(0).xor(x).xor('0'); +isBigInteger = x.xor(0).xor(x).xor('0').xor(0n); |