//C#/CSClasses/TestStringAlgorithms.cs
//Matthew Ellison
// Created: 07-04-21
//Modified: 10-11-21
//This class contains tests for my string algorithms library
/*
Copyright (C) 2021 Matthew Ellison
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
namespace TestStringAlgorithms{
[TestClass]
public class TestStringAlgorithms{
[TestMethod]
public void TestGetPermutations(){
//Test 1
string permString = "012";
List correctAnswer = new List(){"012", "021", "102", "120", "201", "210"};
List answer = mee.StringAlgorithms.GetPermutations(permString);
CollectionAssert.AreEqual(correctAnswer, answer, "GetPermutations failed");
}
[TestMethod]
public void TestFindNumOccurrence(){
//Test 1
string testString = "abcdefgdd";
char testChar = 'a';
long correctAnswer = 1;
long answer = mee.StringAlgorithms.FindNumOccurrence(testString, testChar);
Assert.AreEqual(correctAnswer, answer, "FindNumOccurrence 1 failed");
//Test 2
testChar = 'd';
correctAnswer = 3;
answer = mee.StringAlgorithms.FindNumOccurrence(testString, testChar);
Assert.AreEqual(correctAnswer, answer, "FindNumOccurrence 2 failed");
//Test 3
testChar = 'h';
correctAnswer = 0;
answer = mee.StringAlgorithms.FindNumOccurrence(testString, testChar);
Assert.AreEqual(correctAnswer, answer, "FindNumOccurrence 3 failed");
}
[TestMethod]
public void TestIsPalindrome(){
//Test 1
string str = "101";
bool correctAnswer = true;
bool answer = mee.StringAlgorithms.IsPalindrome(str);
Assert.AreEqual(correctAnswer, answer, "IsPalindrome 1 failed");
//Test 2
str = "100";
correctAnswer = false;
answer = mee.StringAlgorithms.IsPalindrome(str);
Assert.AreEqual(correctAnswer, answer, "IsPalindrome 2 failed");
//Test 3
str = "";
correctAnswer = true;
answer = mee.StringAlgorithms.IsPalindrome(str);
Assert.AreEqual(correctAnswer, answer, "IsPalindrome 3 failed");
}
[TestMethod]
public void TestIsPandigital(){
//Test 1
string num = "123456789";
bool correctAnswer = true;
bool answer = mee.StringAlgorithms.IsPandigital(num);
Assert.AreEqual(correctAnswer, answer, "IsPandigital 1 failed");
//Test 2
num = "123";
correctAnswer = true;
answer = mee.StringAlgorithms.IsPandigital(num, '1', '3');
Assert.AreEqual(correctAnswer, answer, "IsPandigital 2 failed");
//Test 3
num = "123";
correctAnswer = false;
answer = mee.StringAlgorithms.IsPandigital(num);
Assert.AreEqual(correctAnswer, answer, "IsPandigital 3 failed");
//Test 4
num = "123";
correctAnswer = false;
answer = mee.StringAlgorithms.IsPandigital(num, '3', '1');
Assert.AreEqual(correctAnswer, answer, "IsPandigital 4 failed");
//Test 5
num = "1";
correctAnswer = true;
answer = mee.StringAlgorithms.IsPandigital(num, '1', '1');
Assert.AreEqual(correctAnswer, answer, "IsPandigitial 5 failed");
//Test 6
num = "112";
correctAnswer = false;
answer = mee.StringAlgorithms.IsPandigital(num, '1', '3');
Assert.AreEqual(correctAnswer, answer, "IsPandigitial 6 failed");
}
}
}