Skip to content

Commit f724bd5

Browse files
committed
Add primality tests.
1 parent 81ca672 commit f724bd5

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/algorithms/math/primality-tests/__test__/primalityTest.js

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export default function primalityTest(testFunction) {
1616
expect(testFunction(4)).toBeFalsy();
1717
expect(testFunction(6)).toBeFalsy();
1818
expect(testFunction(12)).toBeFalsy();
19+
expect(testFunction(14)).toBeFalsy();
20+
expect(testFunction(25)).toBeFalsy();
1921
expect(testFunction(192)).toBeFalsy();
2022
expect(testFunction(200)).toBeFalsy();
2123
expect(testFunction(400)).toBeFalsy();

src/algorithms/math/primality-tests/trialDivision.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function trialDivision(number) {
1818

1919
// If there is no dividers up to square root of n then there is no higher dividers as well.
2020
const dividerLimit = Math.sqrt(number);
21-
for (let divider = 3; divider < dividerLimit; divider += 2) {
21+
for (let divider = 3; divider <= dividerLimit; divider += 2) {
2222
if (number % divider === 0) {
2323
return false;
2424
}

0 commit comments

Comments
 (0)