mirror of
https://bitbucket.org/Mattrixwv/typescriptclasses.git
synced 2025-12-06 18:33:59 -05:00
Added functions to get a certain number of primes
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
//typescriptClasses/Algorithms.ts
|
||||
//Matthew Ellison
|
||||
// Created: 10-19-20
|
||||
//Modified: 10-19-20
|
||||
//Modified: 03-10-21
|
||||
//This class holds many algorithms that I have found it useful to keep around
|
||||
/*
|
||||
Copyright (C) 2020 Matthew Ellison
|
||||
Copyright (C) 2021 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -20,8 +20,9 @@ Copyright (C) 2020 Matthew Ellison
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
import assert = require("assert");
|
||||
import { arrayEquals, getAllFib, getAllFibBig, getFactors, getFactorsBig, getPrimes, getPrimesBig } from "./Algorithms";
|
||||
import { arrayEquals, getAllFib, getAllFibBig, getFactors, getFactorsBig, getPrimes, getPrimesBig, getNumPrimes, getNumPrimesBig } from "./Algorithms";
|
||||
|
||||
|
||||
function testGetAllFib(){
|
||||
@@ -61,6 +62,22 @@ function testGetPrimes(){
|
||||
console.log("getPrimes passed");
|
||||
}
|
||||
|
||||
function testGetNumPrimes(){
|
||||
//Test1
|
||||
let correctAnswer = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
|
||||
let numPrimes = 25;
|
||||
let answer = getNumPrimes(numPrimes);
|
||||
assert.ok(arrayEquals(answer, correctAnswer), "getNumPrimes number failed");
|
||||
|
||||
//Test2
|
||||
let bigCorrectAnswer = [2n, 3n, 5n, 7n, 11n, 13n, 17n, 19n, 23n, 29n, 31n, 37n, 41n, 43n, 47n, 53n, 59n, 61n, 67n, 71n, 73n, 79n, 83n, 89n, 97n];
|
||||
let bigNumPrimes = 25n;
|
||||
let bigAnswer = getNumPrimesBig(bigNumPrimes);
|
||||
assert.ok(arrayEquals(bigAnswer, bigCorrectAnswer), "getNumPrimesBig failed");
|
||||
|
||||
console.log("getNumPrimes passed");
|
||||
}
|
||||
|
||||
function testGetFactors(){
|
||||
//Test 1
|
||||
let correctAnswer = [2, 2, 5, 5];
|
||||
@@ -86,4 +103,5 @@ function testGetFactors(){
|
||||
//Run all of the tests
|
||||
testGetAllFib();
|
||||
testGetPrimes();
|
||||
testGetNumPrimes();
|
||||
testGetFactors();
|
||||
|
||||
Reference in New Issue
Block a user