mirror of
https://bitbucket.org/Mattrixwv/typescriptclasses.git
synced 2025-12-07 02:43:58 -05:00
Added isPandigital function
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user