|
@@ -205,11 +205,10 @@ namespace Tests
|
|
|
[TestClass]
|
|
|
public class ActionHistoryTests
|
|
|
{
|
|
|
- ToolStripStatusLabel testLabel = new ToolStripStatusLabel();
|
|
|
|
|
|
private ActionHistory GetActionHistory()
|
|
|
{
|
|
|
- return new ActionHistory(testLabel);
|
|
|
+ return new ActionHistory();
|
|
|
}
|
|
|
|
|
|
[DataTestMethod]
|
|
@@ -267,329 +266,10 @@ namespace Tests
|
|
|
Assert.AreEqual(true, testHistory.CanUndo());
|
|
|
testHistory.MoveAction(true);
|
|
|
Assert.AreEqual(true, testHistory.CanRedo());
|
|
|
- testHistory.MoveAction(false);
|
|
|
+ var lastActionLabel = testHistory.MoveAction(false);
|
|
|
Assert.AreEqual(actionType, testHistory.GetCurrentAction().GetActionType());
|
|
|
- String currLabel = testLabel.Text;
|
|
|
- Assert.AreEqual(currLabel, message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- [TestClass]
|
|
|
- public class FileImporterTests
|
|
|
- {
|
|
|
- [DataTestMethod]
|
|
|
- [DataRow(new int[] { 54, 43, 57, 11, 145, 34, 113, 299, 0 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
|
|
|
- [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
|
|
|
- [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 54, 43, 57, 11, 145, 34, 113, 199, 0 })]
|
|
|
- public void ParseISADInputSuccessfulTest(int[] xCoordinates, int[] yCoordinates)
|
|
|
- {
|
|
|
- Form1 program = new Form1();
|
|
|
- FileImporter uut = new SketchAssistant.FileImporter(program);
|
|
|
-
|
|
|
- List<String> file = new List<string>();
|
|
|
- file.Add("drawing");
|
|
|
- file.Add("300x200");
|
|
|
- for (int i = 0; i < xCoordinates.Length - 2; i += 3)
|
|
|
- {
|
|
|
- file.Add("line");
|
|
|
- file.Add(xCoordinates[i] + ";" + yCoordinates[i]);
|
|
|
- file.Add(xCoordinates[i + 1] + ";" + yCoordinates[i + 1]);
|
|
|
- file.Add(xCoordinates[i + 2] + ";" + yCoordinates[i + 2]);
|
|
|
- file.Add("endline");
|
|
|
- }
|
|
|
- file.Add("enddrawing");
|
|
|
-
|
|
|
- (int, int, List<Line>) values = uut.ParseISADInputForTesting(file.ToArray());
|
|
|
- program.CreateCanvasAndSetPictureForTesting(values.Item1, values.Item2, values.Item3);
|
|
|
-
|
|
|
- Line[] drawing = GetLeftImage(program).ToArray();
|
|
|
-
|
|
|
- Assert.AreEqual(xCoordinates.Length / 3, drawing.Length);
|
|
|
- for (int i = 0; i < xCoordinates.Length - 2; i += 3)
|
|
|
- {
|
|
|
- Point[] currentLine = drawing[i / 3].GetPoints().ToArray();
|
|
|
- Assert.AreEqual(3, currentLine.Length);
|
|
|
- for (int j = 0; j < 3; j++)
|
|
|
- {
|
|
|
- Assert.IsTrue(currentLine[j].X == xCoordinates[i + j] && currentLine[j].Y == yCoordinates[i + j]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- [DataTestMethod]
|
|
|
- [DataRow(new String[] {})]
|
|
|
- [DataRow(new String[] { "begindrawing", "300x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "300;300", "line", "50;50", "100;50", "endline", "enddrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "30.5x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "line", "50;50", "100;50", "endline", "enddrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "300x300", "beginline", "50;50", "100;50", "endline", "enddrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "300x300", "line", "500;50", "100;50", "endline", "enddrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "300x300", "line", "50x50", "100;50", "endline", "enddrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "300x300", "line", "50", "100", "endline", "enddrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "line", "endline", "enddrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "stopline", "enddrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "enddrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline", "endrawing" })]
|
|
|
- [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline" })]
|
|
|
- public void ParseISADInputExceptionTest(String[] file)
|
|
|
- {
|
|
|
- bool exceptionThrown = false;
|
|
|
- Form1 program = new Form1();
|
|
|
- FileImporter uut = new SketchAssistant.FileImporter(program);
|
|
|
-
|
|
|
- Assert.IsNull(GetLeftImage(program));
|
|
|
-
|
|
|
- (int, int, List<Line>) values = uut.ParseISADInputForTesting(new string[] { "drawing", "300x205", "line", "40;40", "140;140", "endline", "enddrawing" });
|
|
|
- program.CreateCanvasAndSetPictureForTesting(values.Item1, values.Item2, values.Item3);
|
|
|
-
|
|
|
- List<Line> oldLeftImage = GetLeftImage(program);
|
|
|
- try
|
|
|
- {
|
|
|
-
|
|
|
- (int, int, List<Line>) values1 = uut.ParseISADInputForTesting(file);
|
|
|
- program.CreateCanvasAndSetPictureForTesting(values1.Item1, values1.Item2, values1.Item3);
|
|
|
- }
|
|
|
- catch(FileImporterException)
|
|
|
- {
|
|
|
-
|
|
|
- exceptionThrown = true;
|
|
|
- }
|
|
|
-
|
|
|
- Assert.IsTrue(exceptionThrown);
|
|
|
-
|
|
|
- Assert.AreEqual(oldLeftImage, GetLeftImage(program));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- private List<Line> GetLeftImage(Form1 program)
|
|
|
- {
|
|
|
-
|
|
|
- return (List<Line>)program.GetAllVariables().Find(x => x.Item1.Equals("leftLineList")).Item2;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- [TestClass]
|
|
|
- public class RedrawAssistantTests
|
|
|
- {
|
|
|
- private RedrawAssistant GetAssistant(List<Line> input)
|
|
|
- {
|
|
|
- if(input.Count == 0)
|
|
|
- {
|
|
|
- return new RedrawAssistant();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return new RedrawAssistant(input);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- [DataTestMethod]
|
|
|
- [DataRow(17, 20, new int[] { 54, 43, 57, 11, 145, 34, 113, 299, 0 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, true)]
|
|
|
- [DataRow(-50, 30, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, false)]
|
|
|
- [DataRow(-70, -20, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 54, 43, 57, 11, 145, 34, 113, 199, 0 }, true)]
|
|
|
- public void InactiveRedrawAssistantTest(int x, int y, int[] xCoords, int[] yCoords, bool lineActive)
|
|
|
- {
|
|
|
- RedrawAssistant testAssistant = GetAssistant(new List<Line>());
|
|
|
- List<Point> testPoints = new List<Point>();
|
|
|
- for (int i = 0; i < xCoords.Length; i++)
|
|
|
- {
|
|
|
- testPoints.Add(new Point(xCoords[i], yCoords[i]));
|
|
|
- }
|
|
|
- List<Tuple<bool, Line>> testLines = new List<Tuple<bool, Line>> { new Tuple<bool, Line>(lineActive, new Line(testPoints, 0)) };
|
|
|
- List<HashSet<Point>> result = testAssistant.Tick(new Point(1, 1), testLines, -1, false);
|
|
|
- Assert.AreEqual(0, result.Count);
|
|
|
- }
|
|
|
-
|
|
|
- [DataTestMethod]
|
|
|
- [DataRow(17, 20, new int[] { 54, 43, 57, 11, 145, 34, 113, 299, 0 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, 1)]
|
|
|
- [DataRow(-50, 30, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, 1)]
|
|
|
- [DataRow(33, 54, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 54, 43, 57, 11, 145, 34, 113, 199, 0 }, 2)]
|
|
|
- public void ActiveRedrawAssistantTestStartedDrawing(int x, int y, int[] xCoords, int[] yCoords, int resultingCount)
|
|
|
- {
|
|
|
- List<Point> testPoints = new List<Point>();
|
|
|
- for (int i = 0; i < xCoords.Length; i++)
|
|
|
- {
|
|
|
- testPoints.Add(new Point(xCoords[i], yCoords[i]));
|
|
|
- }
|
|
|
- List<Tuple<bool, Line>> testInputLines = new List<Tuple<bool, Line>>();
|
|
|
- List<Line> testRedrawLines = new List<Line> { new Line(testPoints, 0) };
|
|
|
- RedrawAssistant testAssistant = GetAssistant(testRedrawLines);
|
|
|
-
|
|
|
-
|
|
|
- testAssistant.SetMarkerRadius(1);
|
|
|
- List<HashSet<Point>> tickResult = testAssistant.Tick(new Point(x, y), testInputLines, -1, false);
|
|
|
-
|
|
|
-
|
|
|
- Assert.AreEqual(resultingCount, tickResult.Count);
|
|
|
- if(resultingCount == 1)
|
|
|
- {
|
|
|
- foreach(Point p in tickResult[0])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints[0], p);
|
|
|
- }
|
|
|
- }
|
|
|
- if(resultingCount == 2)
|
|
|
- {
|
|
|
- foreach (Point p in tickResult[0])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints[0], p);
|
|
|
- }
|
|
|
- foreach (Point p in tickResult[1])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints[testPoints.Count-1], p);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- [DataTestMethod]
|
|
|
- [DataRow(17, 20, new int[] { 54, 43, 57, 11, 145, 34, 113, 299, 0 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 },
|
|
|
- new int[] { 77, 20, 3, 74, 28 }, new int[] { 40, 50, 20, 77, 28}, 2, false)]
|
|
|
- [DataRow(33, 33, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 },
|
|
|
- new int[] { 42, 140, 30, 30, 30 }, new int[] { 11, 145, 34, 113, 28 }, 2, true)]
|
|
|
- [DataRow(33, 54, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 54, 43, 57, 11, 145, 34, 113, 199, 0 },
|
|
|
- new int[] { 43, 57, 11, 145 }, new int[] { 33, 42, 140, 30 }, 2, true)]
|
|
|
- public void ActiveRedrawAssistantTestMultipleLinesRedrawn(
|
|
|
- int x, int y, int[] xCoords_one, int[] yCoords_one, int[] xCoords_two, int[] yCoords_two, int resultingCount, bool showingStartAndEnd)
|
|
|
- {
|
|
|
- List<Point> testPoints1 = new List<Point>();
|
|
|
- for (int i = 0; i < xCoords_one.Length; i++)
|
|
|
- {
|
|
|
- testPoints1.Add(new Point(xCoords_one[i], yCoords_one[i]));
|
|
|
- }
|
|
|
- List<Point> testPoints2 = new List<Point>();
|
|
|
- for (int i = 0; i < xCoords_two.Length; i++)
|
|
|
- {
|
|
|
- testPoints2.Add(new Point(xCoords_two[i], yCoords_two[i]));
|
|
|
- }
|
|
|
- List<Tuple<bool, Line>> testInputLines = new List<Tuple<bool, Line>>();
|
|
|
-
|
|
|
- List<Line> testRedrawLines = new List<Line> { new Line(testPoints1, 0) , new Line(testPoints2, 1) };
|
|
|
- RedrawAssistant testAssistant = GetAssistant(testRedrawLines);
|
|
|
-
|
|
|
-
|
|
|
- testAssistant.SetMarkerRadius(1);
|
|
|
-
|
|
|
- List<HashSet<Point>> tickResult = testAssistant.Tick(new Point(x, y), testInputLines, -1, false);
|
|
|
-
|
|
|
- Assert.AreEqual(resultingCount, tickResult.Count);
|
|
|
- if (showingStartAndEnd)
|
|
|
- {
|
|
|
- foreach (Point p in tickResult[0])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints1[0], p);
|
|
|
- }
|
|
|
- foreach (Point p in tickResult[1])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints1[testPoints1.Count - 1], p);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- foreach (Point p in tickResult[0])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints1[0], p);
|
|
|
- }
|
|
|
- foreach (Point p in tickResult[1])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints2[0], p);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- [DataTestMethod]
|
|
|
- [DataRow(17, 20, 17, 20, -1 ,false, new int[] { 54, 43, 57, 11, 145, 34, 113, 299, 0 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 },
|
|
|
- new int[] { 77, 20, 3, 74, 28 }, new int[] { 40, 50, 20, 77, 28 }, 2, 2, false, false)]
|
|
|
-
|
|
|
- [DataRow(33, 33, 2, 2, 0, true, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 },
|
|
|
- new int[] { 42, 140, 30, 30, 30 }, new int[] { 11, 145, 34, 113, 28 }, 2, 1, true, false)]
|
|
|
-
|
|
|
- [DataRow(33, 54, 17, 0, 0, true, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 54, 43, 57, 11, 145, 34, 113, 199, 0 },
|
|
|
- new int[] { 43, 57, 11, 145 }, new int[] { 33, 42, 140, 30 }, 2, 2, true, false)]
|
|
|
- public void ActiveRedrawAssistantTestLineFinished(
|
|
|
- int x_one, int y_one, int x_two, int y_two, int lineID, bool finishedDrawing, int[] xCoords_one, int[] yCoords_one, int[] xCoords_two, int[] yCoords_two,
|
|
|
- int count_one, int count_two, bool showingSE_one, bool showingSE_two)
|
|
|
- {
|
|
|
- List<Point> testPoints1 = new List<Point>();
|
|
|
- for (int i = 0; i < xCoords_one.Length; i++)
|
|
|
- {
|
|
|
- testPoints1.Add(new Point(xCoords_one[i], yCoords_one[i]));
|
|
|
- }
|
|
|
- List<Point> testPoints2 = new List<Point>();
|
|
|
- for (int i = 0; i < xCoords_two.Length; i++)
|
|
|
- {
|
|
|
- testPoints2.Add(new Point(xCoords_two[i], yCoords_two[i]));
|
|
|
- }
|
|
|
- List<Tuple<bool, Line>> testInputLines = new List<Tuple<bool, Line>>();
|
|
|
-
|
|
|
- List<Line> testRedrawLines = new List<Line> { new Line(testPoints1, 0), new Line(testPoints2, 1) };
|
|
|
- RedrawAssistant testAssistant = GetAssistant(testRedrawLines);
|
|
|
-
|
|
|
-
|
|
|
- testAssistant.SetMarkerRadius(1);
|
|
|
-
|
|
|
- List<HashSet<Point>> tickResult1 = testAssistant.Tick(new Point(x_one, y_one), testInputLines, lineID, false);
|
|
|
- List<HashSet<Point>> tickResult2 = testAssistant.Tick(new Point(x_two, y_two), testInputLines, lineID, finishedDrawing);
|
|
|
-
|
|
|
- Assert.AreEqual(count_one, tickResult1.Count);
|
|
|
- if (showingSE_one)
|
|
|
- {
|
|
|
- foreach(Point p in tickResult1[0])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints1[0], p);
|
|
|
- }
|
|
|
- foreach (Point p in tickResult1[1])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints1[testPoints1.Count - 1], p);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- foreach (Point p in tickResult1[0])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints1[0], p);
|
|
|
- }
|
|
|
- foreach (Point p in tickResult1[1])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints2[0], p);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Assert.AreEqual(count_two, tickResult2.Count);
|
|
|
- if(count_two == 2)
|
|
|
- {
|
|
|
- if (showingSE_two)
|
|
|
- {
|
|
|
- foreach (Point p in tickResult2[0])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints1[0], p);
|
|
|
- }
|
|
|
- foreach (Point p in tickResult2[1])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints1[testPoints1.Count - 1], p);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- foreach (Point p in tickResult2[0])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints1[0], p);
|
|
|
- }
|
|
|
- foreach (Point p in tickResult2[1])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints2[0], p);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if(count_two == 1)
|
|
|
- {
|
|
|
- foreach (Point p in tickResult2[0])
|
|
|
- {
|
|
|
- Assert.AreEqual(testPoints2[0], p);
|
|
|
- }
|
|
|
- }
|
|
|
+ Assert.AreEqual(message, lastActionLabel);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|