Private
Public Access
Written more tests and corrected more bugs
This commit is contained in:
1 parent
54de63eeb3
commit
63794a39d7
4 files changed
+83
-2
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
-1
@@ -8,7 +8,6 @@ namespace Advanced_Software_Engineering_Tests {
|
|||||||
[TestClass]
|
[TestClass]
|
||||||
public class SettingsAndHelperFunctionsTester {
|
public class SettingsAndHelperFunctionsTester {
|
||||||
string alphabet = "abcdefghijklmnopqrstuvwxzy";
|
string alphabet = "abcdefghijklmnopqrstuvwxzy";
|
||||||
char space = " "[0];
|
|
||||||
Random rand = new Random();
|
Random rand = new Random();
|
||||||
|
|
||||||
[TestMethod]
|
[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]
|
[TestMethod]
|
||||||
public void StripStringArray_Manual1() {
|
public void StripStringArray_Manual1() {
|
||||||
string[] input = { " ", " a ", " test", "t", "asdf ", "" };
|
string[] input = { " ", " a ", " test", "t", "asdf ", "" };
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using System.Drawing;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace Advanced_Software_Engineering {
|
namespace Advanced_Software_Engineering {
|
||||||
class VerbFactory {
|
public class VerbFactory {
|
||||||
public static Verb MakeVerb(Drawer drawer, string fullCommand) {
|
public static Verb MakeVerb(Drawer drawer, string fullCommand) {
|
||||||
|
|
||||||
Dictionary<string, string[]> commandAndParameters = SettingsAndHelperFunctions.CommandAndParameterParser(fullCommand);
|
Dictionary<string, string[]> commandAndParameters = SettingsAndHelperFunctions.CommandAndParameterParser(fullCommand);
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ namespace Advanced_Software_Engineering {
|
|||||||
}
|
}
|
||||||
catch(Exception windowError) {
|
catch(Exception windowError) {
|
||||||
Console.WriteLine("Failed to display error window!");
|
Console.WriteLine("Failed to display error window!");
|
||||||
|
throw windowError;
|
||||||
}
|
}
|
||||||
RemoveAllCommands();
|
RemoveAllCommands();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user