From f724bd53534d6b4fe182f6606bfe43395ddcbbd7 Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Mon, 16 Apr 2018 22:09:41 +0300 Subject: [PATCH] Add primality tests. --- src/algorithms/math/primality-tests/__test__/primalityTest.js | 2 ++ src/algorithms/math/primality-tests/trialDivision.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/algorithms/math/primality-tests/__test__/primalityTest.js b/src/algorithms/math/primality-tests/__test__/primalityTest.js index 96edb3c6..72a456be 100644 --- a/src/algorithms/math/primality-tests/__test__/primalityTest.js +++ b/src/algorithms/math/primality-tests/__test__/primalityTest.js @@ -16,6 +16,8 @@ export default function primalityTest(testFunction) { expect(testFunction(4)).toBeFalsy(); expect(testFunction(6)).toBeFalsy(); expect(testFunction(12)).toBeFalsy(); + expect(testFunction(14)).toBeFalsy(); + expect(testFunction(25)).toBeFalsy(); expect(testFunction(192)).toBeFalsy(); expect(testFunction(200)).toBeFalsy(); expect(testFunction(400)).toBeFalsy(); diff --git a/src/algorithms/math/primality-tests/trialDivision.js b/src/algorithms/math/primality-tests/trialDivision.js index eb3272e2..79988e64 100644 --- a/src/algorithms/math/primality-tests/trialDivision.js +++ b/src/algorithms/math/primality-tests/trialDivision.js @@ -18,7 +18,7 @@ export default function trialDivision(number) { // If there is no dividers up to square root of n then there is no higher dividers as well. const dividerLimit = Math.sqrt(number); - for (let divider = 3; divider < dividerLimit; divider += 2) { + for (let divider = 3; divider <= dividerLimit; divider += 2) { if (number % divider === 0) { return false; }