|
@@ -1,23 +1,26 @@
|
|
|
-import { assert, assertEquals } from "https://deno.land/std@0.161.0/testing/asserts.ts";
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ assert,
|
|
|
|
|
+ assertEquals,
|
|
|
|
|
+} from "https://deno.land/std@0.161.0/testing/asserts.ts";
|
|
|
import { Prime } from "./prime.class.ts";
|
|
import { Prime } from "./prime.class.ts";
|
|
|
|
|
|
|
|
-Deno.test('Prime class', async (t) => {
|
|
|
|
|
- await t.step('static method isPrime()', async (t) => {
|
|
|
|
|
- await t.step('validate prime numbers', () => {
|
|
|
|
|
|
|
+Deno.test("Prime class", async (t) => {
|
|
|
|
|
+ await t.step("static method isPrime()", async (t) => {
|
|
|
|
|
+ await t.step("validate prime numbers", () => {
|
|
|
[2, 3, 5, 7, 11, 13].forEach((number) => {
|
|
[2, 3, 5, 7, 11, 13].forEach((number) => {
|
|
|
assert(Prime.isPrime(number), `${number} is a prime`);
|
|
assert(Prime.isPrime(number), `${number} is a prime`);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- await t.step('validate non-prime numbers', () => {
|
|
|
|
|
|
|
+ await t.step("validate non-prime numbers", () => {
|
|
|
[1, 4, 6, 8, 9, 10, 15].forEach((number) => {
|
|
[1, 4, 6, 8, 9, 10, 15].forEach((number) => {
|
|
|
assert(!Prime.isPrime(number), `${number} is NOT a prime`);
|
|
assert(!Prime.isPrime(number), `${number} is NOT a prime`);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- await t.step('static method factors()', async (t) => {
|
|
|
|
|
- await t.step('returns the list of prime factors', () => {
|
|
|
|
|
|
|
+ await t.step("static method factors()", async (t) => {
|
|
|
|
|
+ await t.step("returns the list of prime factors", () => {
|
|
|
assertEquals(Prime.factors(13), [13]);
|
|
assertEquals(Prime.factors(13), [13]);
|
|
|
assertEquals(Prime.factors(625), [5, 5, 5, 5]);
|
|
assertEquals(Prime.factors(625), [5, 5, 5, 5]);
|
|
|
assertEquals(Prime.factors(901255), [5, 17, 23, 461]);
|
|
assertEquals(Prime.factors(901255), [5, 17, 23, 461]);
|
|
@@ -25,28 +28,162 @@ Deno.test('Prime class', async (t) => {
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- await t.step('static method isGood()', async (t) => {
|
|
|
|
|
- await t.step('validate good prime numbers (the deep version)', () => {
|
|
|
|
|
- [5, 11, 17, 29, 37, 41, 53, 59, 67, 71, 97, 101, 127, 149, 179, 191, 223, 227, 251, 257, 269, 307, 311, 331, 347, 419, 431, 541, 557, 563, 569, 587, 593, 599, 641, 727, 733, 739, 809, 821, 853, 929, 937, 967].forEach((number) => {
|
|
|
|
|
|
|
+ await t.step("static method isGood()", async (t) => {
|
|
|
|
|
+ await t.step("validate good prime numbers (the deep version)", () => {
|
|
|
|
|
+ [
|
|
|
|
|
+ 5,
|
|
|
|
|
+ 11,
|
|
|
|
|
+ 17,
|
|
|
|
|
+ 29,
|
|
|
|
|
+ 37,
|
|
|
|
|
+ 41,
|
|
|
|
|
+ 53,
|
|
|
|
|
+ 59,
|
|
|
|
|
+ 67,
|
|
|
|
|
+ 71,
|
|
|
|
|
+ 97,
|
|
|
|
|
+ 101,
|
|
|
|
|
+ 127,
|
|
|
|
|
+ 149,
|
|
|
|
|
+ 179,
|
|
|
|
|
+ 191,
|
|
|
|
|
+ 223,
|
|
|
|
|
+ 227,
|
|
|
|
|
+ 251,
|
|
|
|
|
+ 257,
|
|
|
|
|
+ 269,
|
|
|
|
|
+ 307,
|
|
|
|
|
+ 311,
|
|
|
|
|
+ 331,
|
|
|
|
|
+ 347,
|
|
|
|
|
+ 419,
|
|
|
|
|
+ 431,
|
|
|
|
|
+ 541,
|
|
|
|
|
+ 557,
|
|
|
|
|
+ 563,
|
|
|
|
|
+ 569,
|
|
|
|
|
+ 587,
|
|
|
|
|
+ 593,
|
|
|
|
|
+ 599,
|
|
|
|
|
+ 641,
|
|
|
|
|
+ 727,
|
|
|
|
|
+ 733,
|
|
|
|
|
+ 739,
|
|
|
|
|
+ 809,
|
|
|
|
|
+ 821,
|
|
|
|
|
+ 853,
|
|
|
|
|
+ 929,
|
|
|
|
|
+ 937,
|
|
|
|
|
+ 967,
|
|
|
|
|
+ ].forEach((number) => {
|
|
|
assert(Prime.isGood(number), `${number} is a good prime`);
|
|
assert(Prime.isGood(number), `${number} is a good prime`);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- await t.step('validate non-prime numbers', () => {
|
|
|
|
|
|
|
+ await t.step("validate non-prime numbers", () => {
|
|
|
[1, 4, 6, 8, 9, 10, 15, 79, 137].forEach((number) => {
|
|
[1, 4, 6, 8, 9, 10, 15, 79, 137].forEach((number) => {
|
|
|
assert(!Prime.isGood(number), `${number} is NOT a good prime`);
|
|
assert(!Prime.isGood(number), `${number} is NOT a good prime`);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- await t.step('static method isGoodWeak()', async (t) => {
|
|
|
|
|
- await t.step('validate good prime numbers (the weak version)', () => {
|
|
|
|
|
- [5, 11, 17, 29, 37, 41, 53, 59, 67, 71, 79, 97, 101, 107, 127, 137, 149, 157, 163, 173, 179, 191, 197, 211, 223, 227, 239, 251, 257, 263, 269, 277, 281, 307, 311, 331, 347, 367, 373, 379, 397, 419, 431, 439, 457, 461, 479, 487, 499, 521, 541, 557, 563, 569, 587, 593, 599, 607, 613, 617, 631, 641, 653, 659, 673, 701, 719, 727, 733, 739, 751, 757, 769, 787, 809, 821, 827, 853, 857, 877, 881, 907, 929, 937, 947, 967, 977, 991].forEach((number) => {
|
|
|
|
|
|
|
+ await t.step("static method isGoodWeak()", async (t) => {
|
|
|
|
|
+ await t.step("validate good prime numbers (the weak version)", () => {
|
|
|
|
|
+ [
|
|
|
|
|
+ 5,
|
|
|
|
|
+ 11,
|
|
|
|
|
+ 17,
|
|
|
|
|
+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 727,
|
|
|
|
|
+ 733,
|
|
|
|
|
+ 739,
|
|
|
|
|
+ 751,
|
|
|
|
|
+ 757,
|
|
|
|
|
+ 769,
|
|
|
|
|
+ 787,
|
|
|
|
|
+ 809,
|
|
|
|
|
+ 821,
|
|
|
|
|
+ 827,
|
|
|
|
|
+ 853,
|
|
|
|
|
+ 857,
|
|
|
|
|
+ 877,
|
|
|
|
|
+ 881,
|
|
|
|
|
+ 907,
|
|
|
|
|
+ 929,
|
|
|
|
|
+ 937,
|
|
|
|
|
+ 947,
|
|
|
|
|
+ 967,
|
|
|
|
|
+ 977,
|
|
|
|
|
+ 991,
|
|
|
|
|
+ ].forEach((number) => {
|
|
|
assert(Prime.isGoodWeak(number), `${number} is a weak good prime`);
|
|
assert(Prime.isGoodWeak(number), `${number} is a weak good prime`);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- await t.step('validate non-prime numbers', () => {
|
|
|
|
|
|
|
+ await t.step("validate non-prime numbers", () => {
|
|
|
[1, 4, 6, 8, 9, 10, 15, 978, 999, 1000].forEach((number) => {
|
|
[1, 4, 6, 8, 9, 10, 15, 978, 999, 1000].forEach((number) => {
|
|
|
assert(!Prime.isGood(number), `${number} is NOT a weak good prime`);
|
|
assert(!Prime.isGood(number), `${number} is NOT a weak good prime`);
|
|
|
});
|
|
});
|