Added isPandigital function

This commit is contained in:
2021-10-11 12:57:57 -04:00
parent 648c48a39d
commit c558d5b8d8
3 changed files with 74 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
//typescriptClasses/TestStringAlgorithms.ts
//Matthew Ellison
// Created: 07-13-21
//Modified: 07-13-21
//Modified: 10-11-21
//Tests for the string algorithms
/*
Copyright (C) 2021 Matthew Ellison
@@ -23,7 +23,7 @@ Copyright (C) 2021 Matthew Ellison
import assert = require("assert");
import { arrayEquals } from "./ArrayAlgorithms";
import { getPermutations, isPalindrome } from "./StringAlgorithms";
import { getPermutations, isPalindrome, isPandigital, isPandigitalFull } from "./StringAlgorithms";
export function testGetPermutations(){
@@ -75,3 +75,43 @@ export function testFindNumOccurrences(){
console.log("findNumOccurrences passed");
}
export function testIsPandigital(){
//Test 1
let str: string = "123456789";
let correctAnswer: boolean = true;
let answer = isPandigital(str);
assert.ok((answer == correctAnswer), "isPandigital 1 failed");
//Test 2
str = "123";
correctAnswer = true;
answer = isPandigitalFull(str, 1, 3);
assert.ok((answer == correctAnswer), "isPandigital 2 failed");
//Test 3
str = "123";
correctAnswer = false;
answer = isPandigital(str);
assert.ok((answer == correctAnswer), "isPandigital 3 failed");
//Test 4
str = "123";
correctAnswer = false;
answer = isPandigitalFull(str, 3, 1);
assert.ok((answer == correctAnswer), "isPandigital 4 failed");
//Test 5
str = "1";
correctAnswer = true;
answer = isPandigitalFull(str, 1, 1);
assert.ok((answer == correctAnswer), "isPandigital 5 failed");
//Test 6
str = "112";
correctAnswer = false;
answer = isPandigitalFull(str, 1, 3);
assert.ok((answer == correctAnswer), "isPandigital 6 failed");
console.log("isPandigital passed");
}