Private
Public Access
Written more tests and corrected more bugs
This commit is contained in:
1 parent
54de63eeb3
commit
63794a39d7
4 files changed
+87
-6
No files matched your search
@@ -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<string, int[]> commandParamaterNumber = new Dictionary<string, int[]>
|
||||
{
|
||||
{"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<int> inputParameters = new List<int>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+24
-5
@@ -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 ", "" };
|
||||
@@ -130,14 +149,14 @@ namespace Advanced_Software_Engineering_Tests {
|
||||
[TestMethod]
|
||||
public void CommandAndParameterParser_Random1() {
|
||||
|
||||
string[] randomCommands = {"test", "moveto", "lineto", "markiplier", "clear", "shape", "etc" };
|
||||
string[] randomCommands = { "test", "moveto", "lineto", "markiplier", "clear", "shape", "etc" };
|
||||
|
||||
for(int test = 0; test < 10000; test++) {
|
||||
for (int test = 0; test < 10000; test++) {
|
||||
string command = randomCommands[rand.Next(randomCommands.Length)];
|
||||
string input = randomSpaces() + command;
|
||||
|
||||
List<string> parameters = new List<string>();
|
||||
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++]);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<string, string[]> commandAndParameters = SettingsAndHelperFunctions.CommandAndParameterParser(fullCommand);
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace Advanced_Software_Engineering {
|
||||
}
|
||||
catch(Exception windowError) {
|
||||
Console.WriteLine("Failed to display error window!");
|
||||
throw windowError;
|
||||
}
|
||||
RemoveAllCommands();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user