diff --git a/CSClasses/ArrayAlgorithms.cs b/CSClasses/ArrayAlgorithms.cs
new file mode 100644
index 0000000..9fac4bc
--- /dev/null
+++ b/CSClasses/ArrayAlgorithms.cs
@@ -0,0 +1,125 @@
+//C#/CSClasses/ArrayAlgorithms.cs
+//Matthew Ellison
+// Created: 07-04-21
+//Modified: 07-04-21
+//This class contains functions that perform algorithms on numbers
+/*
+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 System.Collections.Generic;
+using System.Linq;
+using System.Numerics;
+
+
+namespace mee{
+ public class ArrayAlgorithms{
+ //These functions get a value from combining elements in an array
+ public static int GetSum(List ary){
+ return ary.Sum();
+ }
+ public static long GetSum(List ary){
+ return ary.Sum();
+ }
+ public static BigInteger GetSum(List ary){
+ BigInteger sum = 0;
+ foreach(BigInteger num in ary){
+ sum += num;
+ }
+ return sum;
+ }
+ public static int GetProd(List ary){
+ //If a blank list was passed to the function return 0 as the product
+ if(ary.Capacity == 0){
+ return 0;
+ }
+
+ int prod = 1; //Start at 1 because x * 1 = x
+ foreach(int num in ary){
+ prod *= num;
+ }
+ return prod;
+ }
+ public static long GetProd(List ary){
+ //If a blank list was passed to the function return 0 as the product
+ if(ary.Capacity == 0){
+ return 0;
+ }
+
+ long prod = 1; //Start at 1 because x * 1 = x
+ foreach(long num in ary){
+ prod *= num;
+ }
+ return prod;
+ }
+ public static BigInteger GetProd(List ary){
+ //If a blank list was passed to the function return 0 as the product
+ if(ary.Capacity == 0){
+ return 0;
+ }
+
+ BigInteger prod = 1; //Start at 1 because x * 1 = x
+ foreach(BigInteger num in ary){
+ prod *= num;
+ }
+ return prod;
+ }
+ //This is a function the creates all permutations of a string and returns a list of those permutations
+ public static List GetPermutations(string master){
+ return GetPermutations(master, 0);
+ }
+ public static List GetPermutations(string master, int num){
+ List perms = new List();
+ //Check if the number is out of bounds
+ if((num >= master.Length) || (num < 0)){
+ //Do nothing and return an empty list
+ }
+ //If this is the last possible recurse just return the current string
+ else if(num == (master.Length - 1)){
+ perms.Add(master);
+ }
+ //If there are more possible recurses, the recurse with the current permutation
+ else{
+ List temp = GetPermutations(master, num + 1);
+ perms.AddRange(temp);
+ //You need to swap the current letter with every possible letter after it
+ //The ones needed to swap before will happen automatically when the function recurses
+ for(int cnt = 1;(num + cnt) < master.Length;++cnt){
+ master = SwapString(master, num, (num + cnt));
+ temp = GetPermutations(master, num + 1);
+ perms.AddRange(temp);
+ master = SwapString(master, num, (num + cnt));
+ }
+
+ //The array is not necessarily in alpha-numeric order. So if this is the full array sort it before returning
+ if(num == 0){
+ perms.Sort();
+ }
+ }
+
+ //Return the list that was build
+ return perms;
+ }
+ public static string SwapString(string str, int first, int second){
+ char[] tempStr = str.ToCharArray();
+ char temp = str[first];
+ tempStr[first] = tempStr[second];
+ tempStr[second] = temp;
+ return new string(tempStr);
+ }
+ }
+}
\ No newline at end of file
diff --git a/CSClasses/Algorithms.cs b/CSClasses/NumberAlgorithms.cs
similarity index 87%
rename from CSClasses/Algorithms.cs
rename to CSClasses/NumberAlgorithms.cs
index c005e2a..486ccac 100644
--- a/CSClasses/Algorithms.cs
+++ b/CSClasses/NumberAlgorithms.cs
@@ -1,8 +1,8 @@
-//C#/CSClasses/Algorithms.cs
+//C#/CSClasses/NumberAlgorithms.cs
//Matthew Ellison
-// Created: 08-23-20
-//Modified: 06-30-21
-//This file contains a class that is used to time the execution time of other programs
+// Created: 07-04-21
+//Modified: 07-04-21
+//This class contains functions that perform algorithms on numbers
/*
Copyright (C) 2021 Matthew Ellison
@@ -28,8 +28,7 @@ using System.Numerics;
namespace mee{
- public class Algorithms{
- //These are a few functions that help with some utility within the class
+ public class NumberAlgorithms{
//Returns the sqrt of the BigInt passed to it
public static BigInteger BigIntegerSqrt(BigInteger num){
BigInteger sqrt;
@@ -45,7 +44,6 @@ namespace mee{
}
return sqrt;
}
-
//These functions return a list of all Fibonacci numbers <= goalNumber
public static List GetAllFib(int goalNumber){
//Setup the variables
@@ -632,99 +630,6 @@ namespace mee{
//Return the list
return divisors;
}
- //These functions get a value from combining elements in an array
- public static int GetSum(List ary){
- return ary.Sum();
- }
- public static long GetSum(List ary){
- return ary.Sum();
- }
- public static BigInteger GetSum(List ary){
- BigInteger sum = 0;
- foreach(BigInteger num in ary){
- sum += num;
- }
- return sum;
- }
- public static int GetProd(List ary){
- //If a blank list was passed to the function return 0 as the product
- if(ary.Capacity == 0){
- return 0;
- }
-
- int prod = 1; //Start at 1 because x * 1 = x
- foreach(int num in ary){
- prod *= num;
- }
- return prod;
- }
- public static long GetProd(List ary){
- //If a blank list was passed to the function return 0 as the product
- if(ary.Capacity == 0){
- return 0;
- }
-
- long prod = 1; //Start at 1 because x * 1 = x
- foreach(long num in ary){
- prod *= num;
- }
- return prod;
- }
- public static BigInteger GetProd(List ary){
- //If a blank list was passed to the function return 0 as the product
- if(ary.Capacity == 0){
- return 0;
- }
-
- BigInteger prod = 1; //Start at 1 because x * 1 = x
- foreach(BigInteger num in ary){
- prod *= num;
- }
- return prod;
- }
- //This is a function the creates all permutations of a string and returns a list of those permutations
- public static List GetPermutations(string master){
- return GetPermutations(master, 0);
- }
- public static List GetPermutations(string master, int num){
- List perms = new List();
- //Check if the number is out of bounds
- if((num >= master.Length) || (num < 0)){
- //Do nothing and return an empty list
- }
- //If this is the last possible recurse just return the current string
- else if(num == (master.Length - 1)){
- perms.Add(master);
- }
- //If there are more possible recurses, the recurse with the current permutation
- else{
- List temp = GetPermutations(master, num + 1);
- perms.AddRange(temp);
- //You need to swap the current letter with every possible letter after it
- //The ones needed to swap before will happen automatically when the function recurses
- for(int cnt = 1;(num + cnt) < master.Length;++cnt){
- master = SwapString(master, num, (num + cnt));
- temp = GetPermutations(master, num + 1);
- perms.AddRange(temp);
- master = SwapString(master, num, (num + cnt));
- }
-
- //The array is not necessarily in alpha-numeric order. So if this is the full array sort it before returning
- if(num == 0){
- perms.Sort();
- }
- }
-
- //Return the list that was build
- return perms;
- }
- public static string SwapString(string str, int first, int second){
- char[] tempStr = str.ToCharArray();
- char temp = str[first];
- tempStr[first] = tempStr[second];
- tempStr[second] = temp;
- return new string(tempStr);
- }
//This function returns the goalSubscript'th Fibonacci number
public static int GetFib(int goalSubscript){
//Setup the variables
@@ -814,10 +719,6 @@ namespace mee{
}
return num1 | num2;
}
- //This function return sht enumber of times the character occurs in the string
- public static long FindNumOccurrence(string str, char c){
- return str.Count(ch => ch == c);
- }
//Return the factorial of the number passed in
public static int Factorial(int num){
int fact = 1;
@@ -840,16 +741,6 @@ namespace mee{
}
return fact;
}
- //Returns true if the string passed in is a palindrome
- public static bool IsPalindrome(string str){
- string rev = new string(str.ToCharArray().Reverse().ToArray());
- if(str == rev){
- return true;
- }
- else{
- return false;
- }
- }
//Converts a number to its binary equivalent
public static string ToBin(int num){
//Convert the number to a binary string
@@ -944,29 +835,5 @@ namespace mee{
}
}
}
- //Print a list
- public static string PrintList(List list){
- string listString = "[";
- for(int cnt = 0;cnt < list.Count;++cnt){
- listString += list[cnt];
- if(cnt < list.Count - 1){
- listString += ", ";
- }
- }
- listString += "]";
- return listString;
- }
- //Print an array
- public static string PrintArray(T[] array){
- string arrayString = "[";
- for(int cnt = 0;cnt < array.Length;++cnt){
- arrayString += array[cnt];
- if(cnt < array.Length - 1){
- arrayString += ", ";
- }
- }
- arrayString += "]";
- return arrayString;
- }
}
}
diff --git a/CSClasses/StringAlgorithms.cs b/CSClasses/StringAlgorithms.cs
new file mode 100644
index 0000000..c826326
--- /dev/null
+++ b/CSClasses/StringAlgorithms.cs
@@ -0,0 +1,70 @@
+//C#/CSClasses/StringAlgorithms.cs
+//Matthew Ellison
+// Created: 07-04-21
+//Modified: 07-04-21
+//This class contains functions that perform algorithms on numbers
+/*
+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 System.Collections.Generic;
+using System.Linq;
+
+
+
+namespace mee{
+ public class StringAlgorithms{
+ //This function return sht enumber of times the character occurs in the string
+ public static long FindNumOccurrence(string str, char c){
+ return str.Count(ch => ch == c);
+ }
+ //Returns true if the string passed in is a palindrome
+ public static bool IsPalindrome(string str){
+ string rev = new string(str.ToCharArray().Reverse().ToArray());
+ if(str == rev){
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+ //Print a list
+ public static string PrintList(List list){
+ string listString = "[";
+ for(int cnt = 0;cnt < list.Count;++cnt){
+ listString += list[cnt];
+ if(cnt < list.Count - 1){
+ listString += ", ";
+ }
+ }
+ listString += "]";
+ return listString;
+ }
+ //Print an array
+ public static string PrintArray(T[] array){
+ string arrayString = "[";
+ for(int cnt = 0;cnt < array.Length;++cnt){
+ arrayString += array[cnt];
+ if(cnt < array.Length - 1){
+ arrayString += ", ";
+ }
+ }
+ arrayString += "]";
+ return arrayString;
+ }
+ }
+}
\ No newline at end of file
diff --git a/TestCSClasses/TestArrayAlgorithms.cs b/TestCSClasses/TestArrayAlgorithms.cs
new file mode 100644
index 0000000..2cedc06
--- /dev/null
+++ b/TestCSClasses/TestArrayAlgorithms.cs
@@ -0,0 +1,91 @@
+//C#/CSClasses/TestArrayAlgorithms.cs
+//Matthew Ellison
+// Created: 07-04-21
+//Modified: 07-04-21
+//This class contains tests for my array 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;
+using System.Numerics;
+
+
+namespace TestCSClasses{
+ [TestClass]
+ public class TestArrayAlgorithms{
+ [TestMethod]
+ public void TestGetSum(){
+ //Test 1
+ int correctAnswer = 0;
+ List numbers = new List();
+ int answer = mee.ArrayAlgorithms.GetSum(numbers);
+ Assert.AreEqual(correctAnswer, answer, "GetSum Integer 1 failed");
+ //Test 2
+ correctAnswer = 118;
+ numbers = new List(){2, 2, 3, 3, 4, 4, 100};
+ answer = mee.ArrayAlgorithms.GetSum(numbers);
+ Assert.AreEqual(correctAnswer, answer, "GetSum Integer 2 failed");
+
+ //Test 3
+ long longCorrectAnswer = 118;
+ List longNumbers = new List(){2, 2, 3, 3, 4, 4, 100};
+ long longAnswer = mee.ArrayAlgorithms.GetSum(longNumbers);
+ Assert.AreEqual(longCorrectAnswer, longAnswer, "GetSum Long failed");
+
+ //Test 4
+ BigInteger bigCorrectAnswer = 118;
+ List bigNumbers = new List(){2, 2, 3, 3, 4, 4, 100};
+ BigInteger bigAnswer = mee.ArrayAlgorithms.GetSum(bigNumbers);
+ Assert.AreEqual(bigCorrectAnswer, bigAnswer, "GetSum BigInteger failed");
+ }
+ [TestMethod]
+ public void TestGetProd(){
+ //Test 1
+ int correctAnswer = 0;
+ List numbers = new List();
+ int answer = mee.ArrayAlgorithms.GetProd(numbers);
+ Assert.AreEqual(correctAnswer, answer, "GetProd Integer 1 failed");
+ //Test 2
+ correctAnswer = 57600;
+ numbers = new List(){2, 2, 3, 3, 4, 4, 100};
+ answer = mee.ArrayAlgorithms.GetProd(numbers);
+ Assert.AreEqual(correctAnswer, answer, "GetProd Integer 2 failed");
+
+ //Test 3
+ long longCorrectAnswer = 57600;
+ List longNumbers = new List(){2, 2, 3, 3, 4, 4, 100};
+ long longAnswer = mee.ArrayAlgorithms.GetProd(longNumbers);
+ Assert.AreEqual(longCorrectAnswer, longAnswer, "GetProd Long failed");
+
+ //Test 4
+ BigInteger bigCorrectAnswer = 57600;
+ List bigNumbers = new List(){2, 2, 3, 3, 4, 4, 100};
+ BigInteger bigAnswer = mee.ArrayAlgorithms.GetProd(bigNumbers);
+ Assert.AreEqual(bigCorrectAnswer, bigAnswer, "GetProd BigInteger failed");
+ }
+ [TestMethod]
+ public void TestGetPermutations(){
+ //Test 1
+ string permString = "012";
+ List correctAnswer = new List(){"012", "021", "102", "120", "201", "210"};
+ List answer = mee.ArrayAlgorithms.GetPermutations(permString);
+ CollectionAssert.AreEqual(correctAnswer, answer, "GetPermutations failed");
+ }
+ }
+}
\ No newline at end of file
diff --git a/TestCSClasses/TestAlgorithms.cs b/TestCSClasses/TestNumberAlgorithms.cs
similarity index 57%
rename from TestCSClasses/TestAlgorithms.cs
rename to TestCSClasses/TestNumberAlgorithms.cs
index 3870ad9..8ddbce7 100644
--- a/TestCSClasses/TestAlgorithms.cs
+++ b/TestCSClasses/TestNumberAlgorithms.cs
@@ -1,8 +1,8 @@
-//C#/CSClasses/TestCSClasses/TestAlgorithms.cs
+//C#/CSClasses/TestNumberAlgorithms.cs
//Matthew Ellison
-// Created: 03-11-21
-//Modified: 06-30-21
-//This file contains the tests for the Algorithms class
+// Created: 07-04-21
+//Modified: 07-04-21
+//This class contains tests for my number algorithms library
/*
Copyright (C) 2021 Matthew Ellison
@@ -26,32 +26,32 @@ using System.Collections.Generic;
using System.Numerics;
-namespace TestCSClasses{
+namespace TestNumberAlgorithms{
[TestClass]
- public class TestAlgorithms{
+ public class TestNumberAlgorithms{
[TestMethod]
public void TestGetAllFib(){
//Test 1
List correctAnswer = new List(){1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89};
int highestNumber = 100;
- List answer = mee.Algorithms.GetAllFib(highestNumber);
+ List answer = mee.NumberAlgorithms.GetAllFib(highestNumber);
CollectionAssert.AreEqual(correctAnswer, answer, "GetAllFib Integer 1 failed");
//Test 2
correctAnswer = new List(){1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987};
highestNumber = 1000;
- answer = mee.Algorithms.GetAllFib(highestNumber);
+ answer = mee.NumberAlgorithms.GetAllFib(highestNumber);
CollectionAssert.AreEqual(correctAnswer, answer, "GetAllFib Integer 2 failed");
//Test 3
List longCorrectAnswer = new List(){1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987};
long longHighestNumber = 1000;
- List longAnswer = mee.Algorithms.GetAllFib(longHighestNumber);
+ List longAnswer = mee.NumberAlgorithms.GetAllFib(longHighestNumber);
CollectionAssert.AreEqual(longCorrectAnswer, longAnswer, "GetAllFib Long failed");
//Test 4
List bigCorrectAnswer = new List(){1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987};
BigInteger bigHighestNumber = 1000;
- List bigAnswer = mee.Algorithms.GetAllFib(bigHighestNumber);
+ List bigAnswer = mee.NumberAlgorithms.GetAllFib(bigHighestNumber);
CollectionAssert.AreEqual(bigCorrectAnswer, bigAnswer, "GetAllFib BigInteger failed");
}
[TestMethod]
@@ -59,24 +59,24 @@ namespace TestCSClasses{
//Test 1
List correctAnswer = new List(){2, 2, 5, 5};
int number = 100;
- List answer = mee.Algorithms.GetFactors(number);
+ List answer = mee.NumberAlgorithms.GetFactors(number);
CollectionAssert.AreEqual(correctAnswer, answer, "GetFactors Integer 1 failed");
//Test 2
correctAnswer = new List(){2, 7, 7};
number = 98;
- answer = mee.Algorithms.GetFactors(number);
+ answer = mee.NumberAlgorithms.GetFactors(number);
CollectionAssert.AreEqual(correctAnswer, answer, "getFactors Integer 2 failed");
//Test 3
List longCorrectAnswer = new List(){2, 2, 5, 5};
long longNumber = 100;
- List longAnswer = mee.Algorithms.GetFactors(longNumber);
+ List longAnswer = mee.NumberAlgorithms.GetFactors(longNumber);
CollectionAssert.AreEqual(longCorrectAnswer, longAnswer, "GetFactors Long failed");
//Test 4
List bigCorrectAnswer = new List(){2, 2, 5, 5};
BigInteger bigNumber = 100;
- List bigAnswer = mee.Algorithms.GetFactors(bigNumber);
+ List bigAnswer = mee.NumberAlgorithms.GetFactors(bigNumber);
CollectionAssert.AreEqual(bigCorrectAnswer, bigAnswer, "GetFactors BigInteger failed");
}
[TestMethod]
@@ -84,19 +84,19 @@ namespace TestCSClasses{
//Test 1
List correctAnswer = new List(){2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int topNum = 100;
- List answer = mee.Algorithms.GetPrimes(topNum);
+ List answer = mee.NumberAlgorithms.GetPrimes(topNum);
CollectionAssert.AreEqual(correctAnswer, answer, "GetPrimes Integer failed");
//Test 2
List longCorrectAnswer = new List(){2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
long longTopNum = 100;
- List longAnswer = mee.Algorithms.GetPrimes(longTopNum);
+ List longAnswer = mee.NumberAlgorithms.GetPrimes(longTopNum);
CollectionAssert.AreEqual(longCorrectAnswer, longAnswer, "GetPrimes Long failed");
//Test 3
List bigCorrectAnswer = new List(){2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
BigInteger bigTopNum = 100;
- List bigAnswer = mee.Algorithms.GetPrimes(bigTopNum);
+ List bigAnswer = mee.NumberAlgorithms.GetPrimes(bigTopNum);
CollectionAssert.AreEqual(bigCorrectAnswer, bigAnswer, "GetPrimes BigInteger failed");
}
[TestMethod]
@@ -104,19 +104,19 @@ namespace TestCSClasses{
//Test 1
List correctAnswer = new List(){2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int numPrimes = 25;
- List answer = mee.Algorithms.GetNumPrimes(numPrimes);
+ List answer = mee.NumberAlgorithms.GetNumPrimes(numPrimes);
CollectionAssert.AreEqual(correctAnswer, answer, "GetNumPrimes Integer failed");
//Test 2
List longCorrectAnswer = new List(){2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
long longNumPrimes = 25;
- List longAnswer = mee.Algorithms.GetNumPrimes(longNumPrimes);
+ List longAnswer = mee.NumberAlgorithms.GetNumPrimes(longNumPrimes);
CollectionAssert.AreEqual(longCorrectAnswer, longAnswer, "GetNumPrimes Long failed");
//Test 3
List bigCorrectAnswer = new List(){2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
BigInteger bigNumPrimes = 25;
- List bigAnswer = mee.Algorithms.GetNumPrimes(bigNumPrimes);
+ List bigAnswer = mee.NumberAlgorithms.GetNumPrimes(bigNumPrimes);
CollectionAssert.AreEqual(bigCorrectAnswer, bigAnswer, "GetNumPrimes BigInteger failes");
}
[TestMethod]
@@ -124,64 +124,64 @@ namespace TestCSClasses{
//Test 1
int num = 2;
bool correctAnswer = true;
- bool answer = mee.Algorithms.IsPrime(num);
+ bool answer = mee.NumberAlgorithms.IsPrime(num);
Assert.AreEqual(correctAnswer, answer, "IsPrime 1 failed");
//Test 2
num = 97;
correctAnswer = true;
- answer = mee.Algorithms.IsPrime(num);
+ answer = mee.NumberAlgorithms.IsPrime(num);
Assert.AreEqual(correctAnswer, answer, "IsPrime 2 failed");
//Test 3
num = 1000;
correctAnswer = false;
- answer = mee.Algorithms.IsPrime(num);
+ answer = mee.NumberAlgorithms.IsPrime(num);
Assert.AreEqual(correctAnswer, answer, "IsPrime 3 failed");
//Test 4
num = 1;
correctAnswer = false;
- answer = mee.Algorithms.IsPrime(num);
+ answer = mee.NumberAlgorithms.IsPrime(num);
Assert.AreEqual(correctAnswer, answer, "IsPrime 4 failed");
//Test 5
long longNum = 2;
correctAnswer = true;
- answer = mee.Algorithms.IsPrime(longNum);
+ answer = mee.NumberAlgorithms.IsPrime(longNum);
Assert.AreEqual(correctAnswer, answer, "IsPrime long 1 failed");
//Test 6
longNum = 97;
correctAnswer = true;
- answer = mee.Algorithms.IsPrime(longNum);
+ answer = mee.NumberAlgorithms.IsPrime(longNum);
Assert.AreEqual(correctAnswer, answer, "IsPrime long 2 failed");
//Test 7
longNum = 1000;
correctAnswer = false;
- answer = mee.Algorithms.IsPrime(longNum);
+ answer = mee.NumberAlgorithms.IsPrime(longNum);
Assert.AreEqual(correctAnswer, answer, "IsPrime long 3 failed");
//Test 8
longNum = 1;
correctAnswer = false;
- answer = mee.Algorithms.IsPrime(longNum);
+ answer = mee.NumberAlgorithms.IsPrime(longNum);
Assert.AreEqual(correctAnswer, answer, "IsPrime long 4 failed");
//Test 9
BigInteger bigNum = 2;
correctAnswer = true;
- answer = mee.Algorithms.IsPrime(bigNum);
+ answer = mee.NumberAlgorithms.IsPrime(bigNum);
Assert.AreEqual(correctAnswer, answer, "IsPrime Big 1 failed");
//Test 10
bigNum = 97;
correctAnswer = true;
- answer = mee.Algorithms.IsPrime(bigNum);
+ answer = mee.NumberAlgorithms.IsPrime(bigNum);
Assert.AreEqual(correctAnswer, answer, "IsPrime Big 2 failed");
//Test 11
bigNum = 1000;
correctAnswer = false;
- answer = mee.Algorithms.IsPrime(bigNum);
+ answer = mee.NumberAlgorithms.IsPrime(bigNum);
Assert.AreEqual(correctAnswer, answer, "IsPrime Big 3 failed");
//Test 12
bigNum = 1;
correctAnswer = false;
- answer = mee.Algorithms.IsPrime(bigNum);
+ answer = mee.NumberAlgorithms.IsPrime(bigNum);
Assert.AreEqual(correctAnswer, answer, "IsPrime Big 4 failed");
}
[TestMethod]
@@ -189,102 +189,44 @@ namespace TestCSClasses{
//Test 1
List correctAnswer = new List(){1, 2, 4, 5, 10, 20, 25, 50, 100};
int topNum = 100;
- List answer = mee.Algorithms.GetDivisors(topNum);
+ List answer = mee.NumberAlgorithms.GetDivisors(topNum);
CollectionAssert.AreEqual(correctAnswer, answer, "GetDivisors Integer failed");
//Test 2
List longCorrectAnswer = new List(){1, 2, 4, 5, 10, 20, 25, 50, 100};
long longTopNum = 100;
- List longAnswer = mee.Algorithms.GetDivisors(longTopNum);
+ List longAnswer = mee.NumberAlgorithms.GetDivisors(longTopNum);
CollectionAssert.AreEqual(longCorrectAnswer, longAnswer, "GetDivisors Long failed");
//Test 3
List bigCorrectAnswer = new List(){1, 2, 4, 5, 10, 20, 25, 50, 100};
BigInteger bigTopNum = 100;
- List bigAnswer = mee.Algorithms.GetDivisors(bigTopNum);
+ List bigAnswer = mee.NumberAlgorithms.GetDivisors(bigTopNum);
CollectionAssert.AreEqual(bigCorrectAnswer, bigAnswer, "GetDivisors BigInteger failed");
}
[TestMethod]
- public void TestGetSum(){
- //Test 1
- int correctAnswer = 0;
- List numbers = new List();
- int answer = mee.Algorithms.GetSum(numbers);
- Assert.AreEqual(correctAnswer, answer, "GetSum Integer 1 failed");
- //Test 2
- correctAnswer = 118;
- numbers = new List(){2, 2, 3, 3, 4, 4, 100};
- answer = mee.Algorithms.GetSum(numbers);
- Assert.AreEqual(correctAnswer, answer, "GetSum Integer 2 failed");
-
- //Test 3
- long longCorrectAnswer = 118;
- List longNumbers = new List(){2, 2, 3, 3, 4, 4, 100};
- long longAnswer = mee.Algorithms.GetSum(longNumbers);
- Assert.AreEqual(longCorrectAnswer, longAnswer, "GetSum Long failed");
-
- //Test 4
- BigInteger bigCorrectAnswer = 118;
- List bigNumbers = new List(){2, 2, 3, 3, 4, 4, 100};
- BigInteger bigAnswer = mee.Algorithms.GetSum(bigNumbers);
- Assert.AreEqual(bigCorrectAnswer, bigAnswer, "GetSum BigInteger failed");
- }
- [TestMethod]
- public void TestGetProd(){
- //Test 1
- int correctAnswer = 0;
- List numbers = new List();
- int answer = mee.Algorithms.GetProd(numbers);
- Assert.AreEqual(correctAnswer, answer, "GetProd Integer 1 failed");
- //Test 2
- correctAnswer = 57600;
- numbers = new List(){2, 2, 3, 3, 4, 4, 100};
- answer = mee.Algorithms.GetProd(numbers);
- Assert.AreEqual(correctAnswer, answer, "GetProd Integer 2 failed");
-
- //Test 3
- long longCorrectAnswer = 57600;
- List longNumbers = new List(){2, 2, 3, 3, 4, 4, 100};
- long longAnswer = mee.Algorithms.GetProd(longNumbers);
- Assert.AreEqual(longCorrectAnswer, longAnswer, "GetProd Long failed");
-
- //Test 4
- BigInteger bigCorrectAnswer = 57600;
- List bigNumbers = new List(){2, 2, 3, 3, 4, 4, 100};
- BigInteger bigAnswer = mee.Algorithms.GetProd(bigNumbers);
- Assert.AreEqual(bigCorrectAnswer, bigAnswer, "GetProd BigInteger failed");
- }
- [TestMethod]
- public void TestGetPermutations(){
- //Test 1
- string permString = "012";
- List correctAnswer = new List(){"012", "021", "102", "120", "201", "210"};
- List answer = mee.Algorithms.GetPermutations(permString);
- CollectionAssert.AreEqual(correctAnswer, answer, "GetPermutations failed");
- }
- [TestMethod]
public void TestGetFib(){
//Test 1
int correctAnswer = 144;
int number = 12;
- int answer = mee.Algorithms.GetFib(number);
+ int answer = mee.NumberAlgorithms.GetFib(number);
Assert.AreEqual(correctAnswer, answer, "GetFib Integer 1 failed");
//Test 2
correctAnswer = 6765;
number = 20;
- answer = mee.Algorithms.GetFib(number);
+ answer = mee.NumberAlgorithms.GetFib(number);
Assert.AreEqual(correctAnswer, answer, "GetFib Integer 2 failed");
//Test 3
long longCorrectAnswer = 6765;
long longNumber = 20;
- long longAnswer = mee.Algorithms.GetFib(longNumber);
+ long longAnswer = mee.NumberAlgorithms.GetFib(longNumber);
Assert.AreEqual(longCorrectAnswer, longAnswer, "GetFib Long failed");
//Test 4
BigInteger bigCorrectAnswer = BigInteger.Parse("1070066266382758936764980584457396885083683896632151665013235203375314520604694040621889147582489792657804694888177591957484336466672569959512996030461262748092482186144069433051234774442750273781753087579391666192149259186759553966422837148943113074699503439547001985432609723067290192870526447243726117715821825548491120525013201478612965931381792235559657452039506137551467837543229119602129934048260706175397706847068202895486902666185435124521900369480641357447470911707619766945691070098024393439617474103736912503231365532164773697023167755051595173518460579954919410967778373229665796581646513903488154256310184224190259846088000110186255550245493937113651657039447629584714548523425950428582425306083544435428212611008992863795048006894330309773217834864543113205765659868456288616808718693835297350643986297640660000723562917905207051164077614812491885830945940566688339109350944456576357666151619317753792891661581327159616877487983821820492520348473874384736771934512787029218636250627816");
BigInteger bigNumber = 4782;
- BigInteger bigAnswer = mee.Algorithms.GetFib(bigNumber);
+ BigInteger bigAnswer = mee.NumberAlgorithms.GetFib(bigNumber);
Assert.AreEqual(bigCorrectAnswer, bigAnswer, "getFib BigInteger failed");
}
[TestMethod]
@@ -293,182 +235,143 @@ namespace TestCSClasses{
int num1 = 2;
int num2 = 3;
int correctAnswer = 1;
- int answer = mee.Algorithms.GCD(num1, num2);
+ int answer = mee.NumberAlgorithms.GCD(num1, num2);
Assert.AreEqual(correctAnswer, answer, "GCD Integer 1 failed");
//Test 2
num1 = 1000;
num2 = 575;
correctAnswer = 25;
- answer = mee.Algorithms.GCD(num1, num2);
+ answer = mee.NumberAlgorithms.GCD(num1, num2);
Assert.AreEqual(correctAnswer, answer, "GCD Integer 2 failed");
//Test 3
num1 = 1000;
num2 = 1000;
correctAnswer = 1000;
- answer = mee.Algorithms.GCD(num1, num2);
+ answer = mee.NumberAlgorithms.GCD(num1, num2);
Assert.AreEqual(correctAnswer, answer, "GCD Integer 3 failed");
//Test 4
long longNum1 = 2;
long longNum2 = 3;
long longCorrectAnswer = 1;
- long longAnswer = mee.Algorithms.GCD(longNum1, longNum2);
+ long longAnswer = mee.NumberAlgorithms.GCD(longNum1, longNum2);
Assert.AreEqual(longCorrectAnswer, longAnswer, "GCD Long 1 failed");
//Test 5
longNum1 = 1000;
longNum2 = 575;
longCorrectAnswer = 25;
- longAnswer = mee.Algorithms.GCD(longNum1, longNum2);
+ longAnswer = mee.NumberAlgorithms.GCD(longNum1, longNum2);
Assert.AreEqual(longCorrectAnswer, longAnswer, "GCD Long 2 failed");
//Test 6
longNum1 = 1000;
longNum2 = 1000;
longCorrectAnswer = 1000;
- longAnswer = mee.Algorithms.GCD(longNum1, longNum2);
+ longAnswer = mee.NumberAlgorithms.GCD(longNum1, longNum2);
Assert.AreEqual(longCorrectAnswer, longAnswer, "GCD Long 3 failed");
//Test 7
BigInteger bigNum1 = 2;
BigInteger bigNum2 = 3;
BigInteger bigCorrectAnswer = 1;
- BigInteger bigAnswer = mee.Algorithms.GCD(bigNum1, bigNum2);
+ BigInteger bigAnswer = mee.NumberAlgorithms.GCD(bigNum1, bigNum2);
Assert.AreEqual(bigCorrectAnswer, bigAnswer, "GCD BigInteger 1 failed");
//Test 8
bigNum1 = 1000;
bigNum2 = 575;
bigCorrectAnswer = 25;
- bigAnswer = mee.Algorithms.GCD(bigNum1, bigNum2);
+ bigAnswer = mee.NumberAlgorithms.GCD(bigNum1, bigNum2);
Assert.AreEqual(bigCorrectAnswer, bigAnswer, "GCD BigInteger 2 failed");
//Test 9
bigNum1 = 1000;
bigNum2 = 1000;
bigCorrectAnswer = 1000;
- bigAnswer = mee.Algorithms.GCD(bigNum1, bigNum2);
+ bigAnswer = mee.NumberAlgorithms.GCD(bigNum1, bigNum2);
Assert.AreEqual(bigCorrectAnswer, bigAnswer, "GCD BigInteger 3 failed");
}
[TestMethod]
- public void TestFindNumOccurrence(){
- //Test 1
- string testString = "abcdefgdd";
- char testChar = 'a';
- long correctAnswer = 1;
- long answer = mee.Algorithms.FindNumOccurrence(testString, testChar);
- Assert.AreEqual(correctAnswer, answer, "FindNumOccurrence 1 failed");
- //Test 2
- testChar = 'd';
- correctAnswer = 3;
- answer = mee.Algorithms.FindNumOccurrence(testString, testChar);
- Assert.AreEqual(correctAnswer, answer, "FindNumOccurrence 2 failed");
- //Test 3
- testChar = 'h';
- correctAnswer = 0;
- answer = mee.Algorithms.FindNumOccurrence(testString, testChar);
- Assert.AreEqual(correctAnswer, answer, "FindNumOccurrence 3 failed");
- }
- [TestMethod]
public void TestFactorial(){
//Test 1
int num = 1;
int correctAnswer = 1;
- int answer = mee.Algorithms.Factorial(num);
+ int answer = mee.NumberAlgorithms.Factorial(num);
Assert.AreEqual(correctAnswer, answer, "Factorial 1 failed");
//Test 2
num = 10;
correctAnswer = 3628800;
- answer = mee.Algorithms.Factorial(num);
+ answer = mee.NumberAlgorithms.Factorial(num);
Assert.AreEqual(correctAnswer, answer, "Factorial 2 failed");
//Test 3
num = -5;
correctAnswer = 1;
- answer = mee.Algorithms.Factorial(num);
+ answer = mee.NumberAlgorithms.Factorial(num);
Assert.AreEqual(correctAnswer, answer, "Factorial 3 failed");
//Test 4
long numLong = 10;
long correctAnswerLong = 3628800;
- long answerLong = mee.Algorithms.Factorial(numLong);
+ long answerLong = mee.NumberAlgorithms.Factorial(numLong);
Assert.AreEqual(correctAnswerLong, answerLong, "Factorial 4 failed");
//Test 5
BigInteger numBig = 10;
BigInteger correctAnswerBig = 3628800;
- BigInteger answerBig = mee.Algorithms.Factorial(numBig);
+ BigInteger answerBig = mee.NumberAlgorithms.Factorial(numBig);
Assert.AreEqual(correctAnswerBig, answerBig, "Factorial 5 failed");
}
[TestMethod]
- public void TestIsPalindrome(){
- //Test 1
- string str = "101";
- bool correctAnswer = true;
- bool answer = mee.Algorithms.IsPalindrome(str);
- Assert.AreEqual(correctAnswer, answer, "IsPalindrome 1 failed");
-
- //Test 2
- str = "100";
- correctAnswer = false;
- answer = mee.Algorithms.IsPalindrome(str);
- Assert.AreEqual(correctAnswer, answer, "IsPalindrome 2 failed");
-
- //Test 3
- str = "";
- correctAnswer = true;
- answer = mee.Algorithms.IsPalindrome(str);
- Assert.AreEqual(correctAnswer, answer, "IsPalindrome 3 failed");
- }
- [TestMethod]
public void TestToBin(){
//Test 1
int num = 7;
string correctAnswer = "111";
- string answer = mee.Algorithms.ToBin(num);
+ string answer = mee.NumberAlgorithms.ToBin(num);
Assert.AreEqual(correctAnswer, answer, "ToBin 1 failed");
//Test 2
num = 0;
correctAnswer = "0";
- answer = mee.Algorithms.ToBin(num);
+ answer = mee.NumberAlgorithms.ToBin(num);
Assert.AreEqual(correctAnswer, answer, "ToBin 2 failed");
//Test 3
num = 1000000;
correctAnswer = "11110100001001000000";
- answer = mee.Algorithms.ToBin(num);
+ answer = mee.NumberAlgorithms.ToBin(num);
Assert.AreEqual(correctAnswer, answer, "ToBin 3 failed");
//Test 4
long longNum = 7;
correctAnswer = "111";
- answer = mee.Algorithms.ToBin(longNum);
+ answer = mee.NumberAlgorithms.ToBin(longNum);
Assert.AreEqual(correctAnswer, answer, "ToBing long 1 failed");
//Test 5
longNum = 0;
correctAnswer = "0";
- answer = mee.Algorithms.ToBin(longNum);
+ answer = mee.NumberAlgorithms.ToBin(longNum);
Assert.AreEqual(correctAnswer, answer, "ToBin long 2 failed");
//Test 6
longNum = 1000000;
correctAnswer = "11110100001001000000";
- answer = mee.Algorithms.ToBin(longNum);
+ answer = mee.NumberAlgorithms.ToBin(longNum);
Assert.AreEqual(correctAnswer, answer, "ToBing long 3 failed");
//Test 7
BigInteger bigNum = 7;
correctAnswer = "111";
- answer = mee.Algorithms.ToBin(bigNum);
+ answer = mee.NumberAlgorithms.ToBin(bigNum);
Assert.AreEqual(correctAnswer, answer, "ToBin big 1 failed");
//Test 8
bigNum = 0;
correctAnswer = "0";
- answer = mee.Algorithms.ToBin(bigNum);
+ answer = mee.NumberAlgorithms.ToBin(bigNum);
Assert.AreEqual(correctAnswer, answer, "ToBin big 2 failed");
//Test 9
bigNum = 1000000;
correctAnswer = "11110100001001000000";
- answer = mee.Algorithms.ToBin(bigNum);
+ answer = mee.NumberAlgorithms.ToBin(bigNum);
Assert.AreEqual(correctAnswer, answer, "ToBin big 3 failed");
}
[TestMethod]
public void TestSieveOfEratosthenes(){
//Test 1
- IEnumerator sieve = mee.Algorithms.SieveOfEratosthenes().GetEnumerator();
+ IEnumerator sieve = mee.NumberAlgorithms.SieveOfEratosthenes().GetEnumerator();
List correctAnswer = new List(){2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
List answer = new List();
for(int cnt = 0;cnt < 25;++cnt){
@@ -478,7 +381,7 @@ namespace TestCSClasses{
CollectionAssert.AreEqual(correctAnswer, answer, "SieveOfEratosthenes failed");
//Test 2
- IEnumerator bigSieve = mee.Algorithms.SieveOfEratosthenesBig().GetEnumerator();
+ IEnumerator bigSieve = mee.NumberAlgorithms.SieveOfEratosthenesBig().GetEnumerator();
List bigCorrectAnswer = new List(){2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
List bigAnswer = new List();
for(int cnt = 0;cnt < 25;++cnt){
@@ -487,63 +390,5 @@ namespace TestCSClasses{
}
CollectionAssert.AreEqual(bigCorrectAnswer, bigAnswer, "SieveOfEratosthenesBig failed");
}
- [TestMethod]
- public void TestPrintList(){
- //Test 1
- List nums = new List();
- string correctAnswer = "[]";
- string answer = mee.Algorithms.PrintList(nums);
- Assert.AreEqual(correctAnswer, answer, "PrintList 1 failed");
- //Test 2
- nums = new List(){1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- correctAnswer = "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]";
- answer = mee.Algorithms.PrintList(nums);
- Assert.AreEqual(correctAnswer, answer, "PrintList 2 failed");
- //Test 3
- nums = new List(){-3, -2, -1, 0, 1, 2, 3};
- correctAnswer = "[-3, -2, -1, 0, 1, 2, 3]";
- answer = mee.Algorithms.PrintList(nums);
- Assert.AreEqual(correctAnswer, answer, "PrintList 3 failed");
-
- //Test 4
- List strings = new List(){"A", "B", "C"};
- correctAnswer = "[A, B, C]";
- answer = mee.Algorithms.PrintList(strings);
- Assert.AreEqual(correctAnswer, answer, "PrintList 1 failed");
- //Test 5
- strings = new List(){"abc", "def", "ghi"};
- correctAnswer = "[abc, def, ghi]";
- answer = mee.Algorithms.PrintList(strings);
- Assert.AreEqual(correctAnswer, answer, "PrintList 2 failed");
- }
- [TestMethod]
- public void TestPrintArray(){
- //Test 1
- int[] nums = new int[]{};
- string correctAnswer = "[]";
- string answer = mee.Algorithms.PrintArray(nums);
- Assert.AreEqual(correctAnswer, answer, "PrintArray 1 failed");
- //Test 2
- nums = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
- correctAnswer = "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]";
- answer = mee.Algorithms.PrintArray(nums);
- Assert.AreEqual(correctAnswer, answer, "PrintArray 2 failed");
- //Test 3
- nums = new int[]{-3, -2, -1, 0, 1, 2, 3};
- correctAnswer = "[-3, -2, -1, 0, 1, 2, 3]";
- answer = mee.Algorithms.PrintArray(nums);
- Assert.AreEqual(correctAnswer, answer, "PrintArray 3 failed");
-
- //Test 4
- string[] strings = new string[]{"A", "B", "C"};
- correctAnswer = "[A, B, C]";
- answer = mee.Algorithms.PrintArray(strings);
- Assert.AreEqual(correctAnswer, answer, "PrintArray 1 failed");
- //Test 5
- strings = new string[]{"abc", "def", "ghi"};
- correctAnswer = "[abc, def, ghi]";
- answer = mee.Algorithms.PrintArray(strings);
- Assert.AreEqual(correctAnswer, answer, "PrintArray 2 failed");
- }
}
-}
+}
\ No newline at end of file
diff --git a/TestCSClasses/TestStringAlgorithms.cs b/TestCSClasses/TestStringAlgorithms.cs
new file mode 100644
index 0000000..ab83cd2
--- /dev/null
+++ b/TestCSClasses/TestStringAlgorithms.cs
@@ -0,0 +1,129 @@
+//C#/CSClasses/TestStringAlgorithms.cs
+//Matthew Ellison
+// Created: 07-04-21
+//Modified: 07-04-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 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 TestPrintList(){
+ //Test 1
+ List nums = new List();
+ string correctAnswer = "[]";
+ string answer = mee.StringAlgorithms.PrintList(nums);
+ Assert.AreEqual(correctAnswer, answer, "PrintList 1 failed");
+ //Test 2
+ nums = new List(){1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ correctAnswer = "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]";
+ answer = mee.StringAlgorithms.PrintList(nums);
+ Assert.AreEqual(correctAnswer, answer, "PrintList 2 failed");
+ //Test 3
+ nums = new List(){-3, -2, -1, 0, 1, 2, 3};
+ correctAnswer = "[-3, -2, -1, 0, 1, 2, 3]";
+ answer = mee.StringAlgorithms.PrintList(nums);
+ Assert.AreEqual(correctAnswer, answer, "PrintList 3 failed");
+
+ //Test 4
+ List strings = new List(){"A", "B", "C"};
+ correctAnswer = "[A, B, C]";
+ answer = mee.StringAlgorithms.PrintList(strings);
+ Assert.AreEqual(correctAnswer, answer, "PrintList 1 failed");
+ //Test 5
+ strings = new List(){"abc", "def", "ghi"};
+ correctAnswer = "[abc, def, ghi]";
+ answer = mee.StringAlgorithms.PrintList(strings);
+ Assert.AreEqual(correctAnswer, answer, "PrintList 2 failed");
+ }
+ [TestMethod]
+ public void TestPrintArray(){
+ //Test 1
+ int[] nums = new int[]{};
+ string correctAnswer = "[]";
+ string answer = mee.StringAlgorithms.PrintArray(nums);
+ Assert.AreEqual(correctAnswer, answer, "PrintArray 1 failed");
+ //Test 2
+ nums = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+ correctAnswer = "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]";
+ answer = mee.StringAlgorithms.PrintArray(nums);
+ Assert.AreEqual(correctAnswer, answer, "PrintArray 2 failed");
+ //Test 3
+ nums = new int[]{-3, -2, -1, 0, 1, 2, 3};
+ correctAnswer = "[-3, -2, -1, 0, 1, 2, 3]";
+ answer = mee.StringAlgorithms.PrintArray(nums);
+ Assert.AreEqual(correctAnswer, answer, "PrintArray 3 failed");
+
+ //Test 4
+ string[] strings = new string[]{"A", "B", "C"};
+ correctAnswer = "[A, B, C]";
+ answer = mee.StringAlgorithms.PrintArray(strings);
+ Assert.AreEqual(correctAnswer, answer, "PrintArray 1 failed");
+ //Test 5
+ strings = new string[]{"abc", "def", "ghi"};
+ correctAnswer = "[abc, def, ghi]";
+ answer = mee.StringAlgorithms.PrintArray(strings);
+ Assert.AreEqual(correctAnswer, answer, "PrintArray 2 failed");
+ }
+ }
+}
\ No newline at end of file