diff --git a/Advanced Software Engineering/Advanced Software Engineering Tests/CommandTester.cs b/Advanced Software Engineering/Advanced Software Engineering Tests/CommandTester.cs new file mode 100644 index 0000000..815b251 --- /dev/null +++ b/Advanced Software Engineering/Advanced Software Engineering Tests/CommandTester.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Advanced_Software_Engineering; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Advanced_Software_Engineering_Tests { + [TestClass] + public class CommandTester { + Random rand = new Random(); + + [TestMethod] + public void VerbFactoryTester_Automatic1() { + Dictionary commandParamaterNumber = new Dictionary + { + {"moveto", new int[] { 2 } }, + {"drawto", new int[] { 2 } }, + {"line", new int[] { 2 } }, + {"lineto", new int[] { 2 } }, + {"shape", new int[] { 2, 3 } } + }; + + foreach (string command in commandParamaterNumber.Keys) { + foreach (int commandParameterNumbers in commandParamaterNumber[command]) { + string input = command + " "; + List inputParameters = new List(); + + for (int paramater = 0; paramater < commandParameterNumbers; paramater++) { + int inputParameter = rand.Next(1000); + inputParameters.Add(inputParameter); + input += inputParameter + (paramater - 1 != commandParameterNumbers ? ", " : ""); + } + + Verb verb = VerbFactory.MakeVerb(null, input); + + if (command == "moveto") { + string verbDesc = verb.GetDescription(); + string correctDesc = "Move origin to " + inputParameters[0] + ", " + inputParameters[1]; + Assert.AreEqual(correctDesc, verbDesc); + } else if (command == "drawto" || command == "lineto" || command == "line") { + string verbDesc = verb.GetDescription(); + string correctDesc = "Draw line " + inputParameters[0] + ", " + inputParameters[1]; + Assert.AreEqual(correctDesc, verbDesc); + } else if (command == "shape") { + string verbDesc = verb.GetDescription(); + string correctDesc; + if (commandParameterNumbers == 2) + correctDesc = "Draws a " + inputParameters[0] + " sided regular polygon, with rotation of 0 radians, with inner radius of " + (double) inputParameters[1]; + else + correctDesc = "Draws a " + inputParameters[0] + " sided regular polygon, with rotation of " + (double)(Math.PI * inputParameters[2] / 180) + " radians, with inner radius of " + (double) inputParameters[1]; + Assert.AreEqual(correctDesc, verbDesc); + } + + } + + } + + } + + } +} diff --git a/Advanced Software Engineering/Advanced Software Engineering Tests/SettingsAndHelperFunctionsTester.cs b/Advanced Software Engineering/Advanced Software Engineering Tests/SettingsAndHelperFunctionsTester.cs index 788f0f8..85fac97 100644 --- a/Advanced Software Engineering/Advanced Software Engineering Tests/SettingsAndHelperFunctionsTester.cs +++ b/Advanced Software Engineering/Advanced Software Engineering Tests/SettingsAndHelperFunctionsTester.cs @@ -8,7 +8,6 @@ namespace Advanced_Software_Engineering_Tests { [TestClass] public class SettingsAndHelperFunctionsTester { string alphabet = "abcdefghijklmnopqrstuvwxzy"; - char space = " "[0]; Random rand = new Random(); [TestMethod] @@ -67,6 +66,26 @@ namespace Advanced_Software_Engineering_Tests { } } + [TestMethod] + public void ConvertToDouble_Random2() { + for (int i = 0; i < 100000; i++) { + double expected = rand.Next(100, 100) * rand.NextDouble(); + string input = expected.ToString(); + + Assert.AreEqual(expected, SettingsAndHelperFunctions.ConvertToDouble(input)); + } + } + + [TestMethod] + public void ConvertToDouble_Random3() { + for (int i = 0; i < 100000; i++) { + int expected = rand.Next(100, 100); + string input = ((double)expected).ToString(); + + Assert.AreEqual((double)expected, SettingsAndHelperFunctions.ConvertToDouble(input)); + } + } + [TestMethod] public void StripStringArray_Manual1() { string[] input = { " ", " a ", " test", "t", "asdf ", "" }; @@ -129,15 +148,15 @@ namespace Advanced_Software_Engineering_Tests { [TestMethod] public void CommandAndParameterParser_Random1() { - - string[] randomCommands = {"test", "moveto", "lineto", "markiplier", "clear", "shape", "etc" }; - - for(int test = 0; test < 10000; test++) { + + string[] randomCommands = { "test", "moveto", "lineto", "markiplier", "clear", "shape", "etc" }; + + for (int test = 0; test < 10000; test++) { string command = randomCommands[rand.Next(randomCommands.Length)]; string input = randomSpaces() + command; List parameters = new List(); - for(int parameterI = 0; parameterI < rand.Next(99) + 1; parameterI++) { + for (int parameterI = 0; parameterI < rand.Next(99) + 1; parameterI++) { string parameter = (rand.NextDouble() * rand.Next(-1000, 1000)).ToString(); parameters.Add(parameter); input += randomSpaces() + parameter + randomSpaces() + "," + randomSpaces(); @@ -148,7 +167,7 @@ namespace Advanced_Software_Engineering_Tests { Assert.AreEqual(command, commands["command"][0]); int i = 0; - foreach(string expected in parameters) { + foreach (string expected in parameters) { Assert.AreEqual(expected, commands["parameters"][i++]); } diff --git a/Advanced Software Engineering/Advanced Software Engineering/Command.cs b/Advanced Software Engineering/Advanced Software Engineering/Command.cs index 8304969..6520c82 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Command.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Command.cs @@ -5,7 +5,7 @@ using System.Drawing; using System.Linq; namespace Advanced_Software_Engineering { - class VerbFactory { + public class VerbFactory { public static Verb MakeVerb(Drawer drawer, string fullCommand) { Dictionary commandAndParameters = SettingsAndHelperFunctions.CommandAndParameterParser(fullCommand); diff --git a/Advanced Software Engineering/Advanced Software Engineering/Commander.cs b/Advanced Software Engineering/Advanced Software Engineering/Commander.cs index 9bc4c08..be9f6d6 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Commander.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Commander.cs @@ -76,6 +76,7 @@ namespace Advanced_Software_Engineering { } catch(Exception windowError) { Console.WriteLine("Failed to display error window!"); + throw windowError; } RemoveAllCommands(); }