Added more unit tests

This commit is contained in:
Lukasz Baldyga committed 2020-10-21 20:31:49 +01:00
1 parent 353558420e
commit f198b609f2
1 file changed
+51 -1
@@ -1,16 +1,17 @@
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using Advanced_Software_Engineering; using Advanced_Software_Engineering;
using System; using System;
using System.Collections.Generic;
namespace Advanced_Software_Engineering_Tests { namespace Advanced_Software_Engineering_Tests {
[TestClass] [TestClass]
public class SettingsAndHelperFunctionsTester { public class SettingsAndHelperFunctionsTester {
string alphabet = "abcdefghijklmnopqrstuvwxzy"; string alphabet = "abcdefghijklmnopqrstuvwxzy";
char space = " "[0]; char space = " "[0];
Random rand = new Random();
[TestMethod] [TestMethod]
public void TestStrip_Random1() { public void TestStrip_Random1() {
Random rand = new Random();
for (int test = 0; test < 200; test++) { for (int test = 0; test < 200; test++) {
int until = rand.Next(50); int until = rand.Next(50);
@@ -45,5 +46,54 @@ namespace Advanced_Software_Engineering_Tests {
Assert.AreEqual(expected, SettingsAndHelperFunctions.Strip(input)); Assert.AreEqual(expected, SettingsAndHelperFunctions.Strip(input));
} }
[TestMethod]
public void TestStrip_Manual2() {
string input = " a simple sentence surrounded by spaces ";
string expected = "a simple sentence surrounded by spaces";
Assert.AreEqual(expected, SettingsAndHelperFunctions.Strip(input));
}
[TestMethod]
public void ConvertToInt_Random1() {
for (int i = 0; i < 100000; i++) {
int expected = rand.Next(int.MinValue, int.MaxValue);
string input = expected.ToString();
Assert.AreEqual(expected, SettingsAndHelperFunctions.ConvertToInt(input));
}
}
[TestMethod]
public void ConvertToDouble_Random1() {
for(int i = 0; i < 100000; i++) {
double expected = rand.NextDouble();
string input = expected.ToString();
Assert.AreEqual(expected, SettingsAndHelperFunctions.ConvertToDouble(input));
}
}
[TestMethod]
public void StripStringArray_Manual1() {
string[] input = { " ", " a ", " test", "t", "asdf ", "" };
string[] expected = (new List<string> { "a", "test", "t", "asdf" }).ToArray();
int i = 0;
foreach(string s in SettingsAndHelperFunctions.StripStringArray(input)) {
Assert.AreEqual(expected[i++], s);
}
}
[TestMethod]
public void StripStringArray_Manual2() {
string[] input = "a simple sentence surrounded by spaces".Split(" "[0]);
string[] expected = (new List<string> { "a", "simple", "sentence", "surrounded", "by", "spaces" }).ToArray();
int i = 0;
foreach (string s in SettingsAndHelperFunctions.StripStringArray(input)) {
Assert.AreEqual(expected[i++], s);
}
}
} }
} }