mirror of
https://bitbucket.org/Mattrixwv/typescriptclasses.git
synced 2025-12-06 18:33:59 -05:00
Added tests for sqrtBig and arrayEquals
This commit is contained in:
@@ -22,9 +22,78 @@ Copyright (C) 2021 Matthew Ellison
|
||||
|
||||
|
||||
import assert = require("assert");
|
||||
import { arrayEquals, getAllFib, getAllFibBig, getFactors, getFactorsBig, getPrimes, getPrimesBig, getNumPrimes, getNumPrimesBig } from "./Algorithms";
|
||||
import { arrayEquals, getAllFib, getAllFibBig, getFactors, getFactorsBig, getPrimes, getPrimesBig, getNumPrimes, getNumPrimesBig, sqrtBig } from "./Algorithms";
|
||||
|
||||
|
||||
function testArrayEquals(){
|
||||
//Test 1
|
||||
let ary1: number[] = [];
|
||||
let ary2: number[] = [];
|
||||
let correctAnswer = true;
|
||||
let answer = arrayEquals(ary1, ary2);
|
||||
assert.ok((answer == correctAnswer), "arrayEquals test 1 failed");
|
||||
|
||||
//Test 2
|
||||
ary1 = [1, 2, 3, 4, 5];
|
||||
ary2 = [1, 2, 3, 4, 5];
|
||||
correctAnswer = true;
|
||||
answer = arrayEquals(ary1, ary2);
|
||||
assert.ok((answer == correctAnswer), "arrayEquals test 2 failed");
|
||||
|
||||
//Test 3
|
||||
ary1 = [1, 2, 3, 4, 5];
|
||||
ary2 = [1];
|
||||
correctAnswer = false;
|
||||
answer = arrayEquals(ary1, ary2);
|
||||
assert.ok((answer == correctAnswer), "arrayEquals test 3 failed");
|
||||
|
||||
//Test 4
|
||||
ary1 = [1, 2, 3, 4, 5];
|
||||
ary2 = [6, 2, 3, 4, 5];
|
||||
correctAnswer = false;
|
||||
answer = arrayEquals(ary1, ary2);
|
||||
assert.ok((answer == correctAnswer), "arrayEquals test 4 failed");
|
||||
|
||||
//Test 5
|
||||
ary1 = [1, 2, 3, 4, 5];
|
||||
ary2 = [1, 2, 3, 4, 6];
|
||||
correctAnswer = false;
|
||||
answer = arrayEquals(ary1, ary2);
|
||||
assert.ok((answer == correctAnswer), "arrayEquals test 5 failed");
|
||||
|
||||
//Test 6
|
||||
let ary3: string[] = ["test1", "test2"];
|
||||
let ary4: string[] = ["test1", "test2"];
|
||||
correctAnswer = true;
|
||||
answer = arrayEquals(ary3, ary4);
|
||||
assert.ok((answer == correctAnswer), "arrayEquals test 6 failed");
|
||||
|
||||
//Test 7
|
||||
ary3 = ["test1", "Test2"];
|
||||
ary4 = ["test1", "test2"];
|
||||
correctAnswer = false;
|
||||
answer = arrayEquals(ary3, ary4);
|
||||
assert.ok((answer == correctAnswer), "arrayEquals test 7 failed");
|
||||
|
||||
console.log("testArrayEquals passed");
|
||||
}
|
||||
|
||||
function testSqrtBig(){
|
||||
//Test 1
|
||||
let square: bigint = 25n;
|
||||
let correctAnswer: bigint = 5n;
|
||||
let answer = sqrtBig(square);
|
||||
assert.ok((answer == correctAnswer), "sqrtBig test 1 failed");
|
||||
|
||||
//Test 2
|
||||
square = 0n;
|
||||
correctAnswer = 0n;
|
||||
answer = sqrtBig(square);
|
||||
assert.ok((answer == correctAnswer), "sqrtBig test 2 failed");
|
||||
|
||||
console.log("testSqrtBig passed");
|
||||
}
|
||||
|
||||
function testGetAllFib(){
|
||||
//Test 1
|
||||
let correctAnswer = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89];
|
||||
@@ -101,6 +170,8 @@ function testGetFactors(){
|
||||
|
||||
|
||||
//Run all of the tests
|
||||
testArrayEquals();
|
||||
testSqrtBig();
|
||||
testGetAllFib();
|
||||
testGetPrimes();
|
||||
testGetNumPrimes();
|
||||
|
||||
Reference in New Issue
Block a user