Added getDivisors function

This commit is contained in:
2021-03-26 13:27:47 -04:00
parent 879fdfd126
commit 6443a56de8
2 changed files with 97 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ Copyright (C) 2021 Matthew Ellison
import assert = require("assert");
import { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } from "constants";
import { arrayEquals, getAllFib, getAllFibBig, getFactors, getFactorsBig, getPrimes, getPrimesBig, getNumPrimes, getNumPrimesBig,
sqrtBig, getSum, getSumBig, getProd, getProdBig } from "./Algorithms";
sqrtBig, getSum, getSumBig, getProd, getProdBig, getDivisors, getDivisorsBig } from "./Algorithms";
function testArrayEquals(){
@@ -170,6 +170,22 @@ function testGetFactors(){
console.log("getFactors passed");
}
function testGetDivisors(){
//Test 1
let correctAnswer: number[] = [1, 2, 4, 5, 10, 20, 25, 50, 100];
let topNum: number = 100;
let answer: number[] = getDivisors(topNum);
assert.ok(arrayEquals(answer, correctAnswer), "getDivisors number failed");
//Test 2
let bigCorrectAnswer: bigint[] = [1n, 2n, 4n, 5n, 10n, 20n, 25n, 50n, 100n];
let bigTopNum: bigint = 100n;
let bigAnswer: bigint[] = getDivisorsBig(bigTopNum);
assert.ok(arrayEquals(bigAnswer, bigCorrectAnswer), "getDivisors BigInt failed");
console.log("getDivisors passed");
}
function testGetSum(){
//Test 1
let correctAnswer: number = 0;
@@ -219,5 +235,6 @@ testGetAllFib();
testGetPrimes();
testGetNumPrimes();
testGetFactors();
testGetDivisors();
testGetSum();
testGetProd();