mirror of
https://bitbucket.org/Mattrixwv/typescriptclasses.git
synced 2025-12-06 18:33:59 -05:00
Added getDivisors function
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user