From f198b609f2d28d8d50974a3e0d2ba93912e2f2c2 Mon Sep 17 00:00:00 2001 From: Lukasz Baldyga Date: Wed, 21 Oct 2020 20:31:49 +0100 Subject: [PATCH] Added more unit tests --- .../SettingsAndHelperFunctionsTester.cs | 52 ++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/Advanced Software Engineering/Advanced Software Engineering Tests/SettingsAndHelperFunctionsTester.cs b/Advanced Software Engineering/Advanced Software Engineering Tests/SettingsAndHelperFunctionsTester.cs index 4ea4845..c65748b 100644 --- a/Advanced Software Engineering/Advanced Software Engineering Tests/SettingsAndHelperFunctionsTester.cs +++ b/Advanced Software Engineering/Advanced Software Engineering Tests/SettingsAndHelperFunctionsTester.cs @@ -1,16 +1,17 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Advanced_Software_Engineering; using System; +using System.Collections.Generic; namespace Advanced_Software_Engineering_Tests { [TestClass] public class SettingsAndHelperFunctionsTester { string alphabet = "abcdefghijklmnopqrstuvwxzy"; char space = " "[0]; + Random rand = new Random(); [TestMethod] public void TestStrip_Random1() { - Random rand = new Random(); for (int test = 0; test < 200; test++) { int until = rand.Next(50); @@ -45,5 +46,54 @@ namespace Advanced_Software_Engineering_Tests { 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 { "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 { "a", "simple", "sentence", "surrounded", "by", "spaces" }).ToArray(); + + int i = 0; + foreach (string s in SettingsAndHelperFunctions.StripStringArray(input)) { + Assert.AreEqual(expected[i++], s); + } + } } }