From 0ea27f041a1dcfca0d24ffb12c4c0e253e38741c Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Mon, 11 Oct 2021 10:16:12 -0400 Subject: [PATCH] Added test for isPandigital --- test/mee/testStringAlgorithms.cpp | 34 +++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/test/mee/testStringAlgorithms.cpp b/test/mee/testStringAlgorithms.cpp index e5258f9..08ed8c1 100644 --- a/test/mee/testStringAlgorithms.cpp +++ b/test/mee/testStringAlgorithms.cpp @@ -39,14 +39,15 @@ bool testGetPermutations(); bool testFindNumOccurrence(); bool testSplit(); bool testIsPalindrome(); +bool testIsPandigital(); int main(){ mee::Stopwatch timer; bool passedTest = false; bool allPassed = true; - std::vector functions { testGetPermutations, testFindNumOccurrence, testSplit, testIsPalindrome}; - std::vector names { "getPermutations", "findNumOccurrence", "split", "isPalindrome"}; + std::vector functions { testGetPermutations, testFindNumOccurrence, testSplit, testIsPalindrome, testIsPandigital}; + std::vector names { "getPermutations", "findNumOccurrence", "split", "isPalindrome", "isPandigital"}; //Start doing tests and print out the results of each for(size_t cnt = 0;cnt < functions.size();++cnt){ @@ -161,3 +162,32 @@ bool testIsPalindrome(){ //If it hasn't failed a test then return true for passing all the tests return true; } + +bool testIsPandigital(){ + //Test 1 + std::string num = "123456789"; + bool correctAnswer = true; + bool answer = mee::isPandigital(num); + if(correctAnswer != answer){ + return false; + } + + //Test 2 + num = "123"; + correctAnswer = true; + answer = mee::isPandigital(num, '1', '3'); + if(correctAnswer != answer){ + return false; + } + + //Test 3 + num = "123"; + correctAnswer = false; + answer = mee::isPandigital(num); + if(correctAnswer != answer){ + return false; + } + + //If it hasn't failed a test then return true for passing all the tests + return true; +}