UnitTest1.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using System.Drawing;
  4. using System.Collections.Generic;
  5. using SketchAssistant;
  6. using System.Windows.Forms;
  7. namespace Tests
  8. {
  9. [TestClass]
  10. public class LineTests
  11. {
  12. //========================//
  13. //= Bresenham Line Tests =//
  14. //========================//
  15. [TestMethod]
  16. public void BresenhamLineTest1()
  17. {
  18. //Test point
  19. List<Point> expectedResult = new List<Point>();
  20. expectedResult.Add(new Point(1, 2));
  21. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(1, 2), new Point(1, 2));
  22. Assert.AreEqual(1, actualResult.Count);
  23. for (int i = 0; i < actualResult.Count; i++)
  24. {
  25. Assert.AreEqual(expectedResult[i], actualResult[i]);
  26. }
  27. }
  28. [TestMethod]
  29. public void BresenhamLineTest2()
  30. {
  31. //Test line going from left to right
  32. List<Point> expectedResult = new List<Point>();
  33. for (int i = 1; i <= 6; i++) { expectedResult.Add(new Point(i, 2)); }
  34. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(1, 2), new Point(6, 2));
  35. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  36. for (int i = 0; i < actualResult.Count; i++)
  37. {
  38. Assert.AreEqual(expectedResult[i], actualResult[i]);
  39. }
  40. }
  41. [TestMethod]
  42. public void BresenhamLineTest3()
  43. {
  44. //Test line going from right to left
  45. List<Point> expectedResult = new List<Point>();
  46. for (int i = 6; i >= 1; i--) { expectedResult.Add(new Point(i, 2)); }
  47. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(6, 2), new Point(1, 2));
  48. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  49. for (int i = 0; i < actualResult.Count; i++)
  50. {
  51. Assert.AreEqual(expectedResult[i], actualResult[i]);
  52. }
  53. }
  54. [TestMethod]
  55. public void BresenhamLineTest4()
  56. {
  57. //Test line going from top to bottom
  58. List<Point> expectedResult = new List<Point>();
  59. for (int i = 5; i <= 25; i++) { expectedResult.Add(new Point(7, i)); }
  60. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(7, 5), new Point(7, 25));
  61. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  62. for (int i = 0; i < actualResult.Count; i++)
  63. {
  64. Assert.AreEqual(expectedResult[i], actualResult[i]);
  65. }
  66. }
  67. [TestMethod]
  68. public void BresenhamLineTest5()
  69. {
  70. //Test line going from bottom to top
  71. List<Point> expectedResult = new List<Point>();
  72. for (int i = 25; i >= 5; i--) { expectedResult.Add(new Point(7, i)); }
  73. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(7, 25), new Point(7, 5));
  74. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  75. for (int i = 0; i < actualResult.Count; i++)
  76. {
  77. Assert.AreEqual(expectedResult[i], actualResult[i]);
  78. }
  79. }
  80. [TestMethod]
  81. public void BresenhamLineTest6()
  82. {
  83. //Test exactly diagonal line from top left to bottom right
  84. List<Point> expectedResult = new List<Point>();
  85. for (int i = 5; i <= 25; i++) { expectedResult.Add(new Point(i + 2, i)); }
  86. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(7, 5), new Point(27, 25));
  87. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  88. for (int i = 0; i < actualResult.Count; i++)
  89. {
  90. Assert.AreEqual(expectedResult[i], actualResult[i]);
  91. }
  92. }
  93. [TestMethod]
  94. public void BresenhamLineTest7()
  95. {
  96. //Test exactly diagonal line from bottom right to top left
  97. List<Point> expectedResult = new List<Point>();
  98. for (int i = 25; i >= 5; i--) { expectedResult.Add(new Point(i + 2, i)); }
  99. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(27, 25), new Point(7, 5));
  100. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  101. for (int i = 0; i < actualResult.Count; i++)
  102. {
  103. Assert.AreEqual(expectedResult[i], actualResult[i]);
  104. }
  105. }
  106. //===========================//
  107. //= Matrix Population Tests =//
  108. //===========================//
  109. [TestMethod]
  110. public void MatrixTest1()
  111. {
  112. //Populate Matrix for temporary Line
  113. List<Point> thePoints = new List<Point>();
  114. thePoints.Add(new Point(1, 1));
  115. thePoints.Add(new Point(1, 2));
  116. bool[,] testBoolMatrix = new bool[5, 5];
  117. List<int>[,] testLineMatrix = new List<int>[5, 5];
  118. bool[,] resultBoolMatrix = new bool[5, 5];
  119. HashSet<int>[,] resultLineMatrix = new HashSet<int>[5, 5];
  120. Line testLine = new Line(thePoints);
  121. testLine.PopulateMatrixes(resultBoolMatrix, resultLineMatrix);
  122. for (int i = 0; i < 5; i++)
  123. {
  124. for (int j = 0; j < 5; j++)
  125. {
  126. Assert.AreEqual(testBoolMatrix[i, j], resultBoolMatrix[i, j]);
  127. Assert.AreEqual(testLineMatrix[i, j], resultLineMatrix[i, j]);
  128. }
  129. }
  130. }
  131. [TestMethod]
  132. public void MatrixTest2()
  133. {
  134. //Populate Matrix for non-temporary Line
  135. List<Point> thePoints = new List<Point>();
  136. thePoints.Add(new Point(1, 1));
  137. thePoints.Add(new Point(3, 3));
  138. bool[,] testBoolMatrix = new bool[5, 5];
  139. HashSet<int>[,] testLineMatrix = new HashSet<int>[5, 5];
  140. for (int i = 1; i <= 3; i++)
  141. {
  142. testBoolMatrix[i, i] = true;
  143. HashSet<int> temp = new HashSet<int>();
  144. temp.Add(5);
  145. testLineMatrix[i, i] = temp;
  146. }
  147. bool[,] resultBoolMatrix = new bool[5, 5];
  148. HashSet<int>[,] resultLineMatrix = new HashSet<int>[5, 5];
  149. Line testLine = new Line(thePoints, 5);
  150. testLine.PopulateMatrixes(resultBoolMatrix, resultLineMatrix);
  151. for (int i = 0; i < 5; i++)
  152. {
  153. for (int j = 0; j < 5; j++)
  154. {
  155. Assert.AreEqual(testBoolMatrix[i, j], resultBoolMatrix[i, j]);
  156. if (testLineMatrix[i, j] != null && resultLineMatrix[i, j] != null)
  157. {
  158. for (int k = 0; k < resultLineMatrix[i, j].Count; k++)
  159. {
  160. Assert.AreEqual(true, testLineMatrix[i, j].SetEquals(resultLineMatrix[i, j]));
  161. }
  162. }
  163. }
  164. }
  165. }
  166. //=========================//
  167. //= Line Constructor Test =//
  168. //=========================//
  169. [TestMethod]
  170. public void ConstructorTest()
  171. {
  172. //Create non-temporary Line and check points
  173. //reference Points
  174. List<Point> comparisonPoints = new List<Point> {new Point(2,2), new Point(3, 1), new Point(4, 1), new Point(5, 1), new Point(6, 2),
  175. new Point(7, 3), new Point(8, 4), new Point(9, 5), new Point(10, 6), new Point(11, 5), new Point(11, 4), new Point(11, 3),
  176. new Point(10, 2), new Point(9, 1), new Point(8, 2), new Point(7, 3), new Point(6, 4), new Point(5, 5), new Point(4, 5),
  177. new Point(3, 5), new Point(2, 5), new Point(1, 4)};
  178. //test Points, with intermediate points missing & duplicate points
  179. List<Point> testPoints = new List<Point> {new Point(2,2), new Point(3, 1), new Point(5, 1), new Point(5, 1), new Point(5, 1),
  180. new Point(8, 4), new Point(10, 6), new Point(11, 5), new Point(11, 3), new Point(9, 1), new Point(9, 1), new Point(9, 1),
  181. new Point(5, 5), new Point(2, 5), new Point(2, 5), new Point(1, 4) };
  182. Line testLine = new Line(testPoints, 0);
  183. List<Point> returnedPoints = testLine.GetPoints();
  184. Assert.AreEqual(comparisonPoints.Count, returnedPoints.Count);
  185. for (int i = 0; i < returnedPoints.Count; i++)
  186. {
  187. Assert.AreEqual(comparisonPoints[i], returnedPoints[i]);
  188. }
  189. }
  190. }
  191. [TestClass]
  192. public class ActionHistoryTests
  193. {
  194. ToolStripStatusLabel testLabel = new ToolStripStatusLabel();
  195. private ActionHistory GetActionHistory()
  196. {
  197. return new ActionHistory(testLabel);
  198. }
  199. [DataTestMethod]
  200. [DataRow(SketchAction.ActionType.Start, 5, -1, "A new canvas was created.")]
  201. [DataRow(SketchAction.ActionType.Draw, 5, 5, "Line number 5 was drawn.")]
  202. [DataRow(SketchAction.ActionType.Delete, 10, 10, "Line number 10 was deleted.")]
  203. public void ScetchActionTest1(SketchAction.ActionType type, int id, int exit, String response)
  204. {
  205. HashSet<int> actualResult = new HashSet<int>();
  206. if (!type.Equals(SketchAction.ActionType.Start)) { actualResult.Add(id); }
  207. SketchAction testAction = new SketchAction(type, id);
  208. Assert.AreEqual(type, testAction.GetActionType());
  209. Assert.AreEqual(true, actualResult.SetEquals(testAction.GetLineIDs()));
  210. Assert.AreEqual(response, testAction.GetActionInformation());
  211. }
  212. [DataTestMethod]
  213. [DataRow(SketchAction.ActionType.Start, 1, 2, 3, "A new canvas was created.")]
  214. [DataRow(SketchAction.ActionType.Draw, 3, 3, 3, "Line number 3 was drawn.")]
  215. [DataRow(SketchAction.ActionType.Delete, 20, 30, 40, "Several Lines were deleted.")]
  216. public void ScetchActionTest2(SketchAction.ActionType type, int id1, int id2, int id3, String response)
  217. {
  218. HashSet<int> actualResult = new HashSet<int>();
  219. if (!type.Equals(SketchAction.ActionType.Start))
  220. {
  221. actualResult.Add(id1);
  222. actualResult.Add(id2);
  223. actualResult.Add(id3);
  224. }
  225. SketchAction testAction = new SketchAction(type, actualResult);
  226. Assert.AreEqual(type, testAction.GetActionType());
  227. Assert.AreEqual(true, actualResult.SetEquals(testAction.GetLineIDs()));
  228. Assert.AreEqual(response, testAction.GetActionInformation());
  229. }
  230. [DataTestMethod]
  231. [DataRow(SketchAction.ActionType.Start, SketchAction.ActionType.Start, true)]
  232. [DataRow(SketchAction.ActionType.Draw, SketchAction.ActionType.Delete, false)]
  233. public void ActionHistoryTest1(SketchAction.ActionType action1, SketchAction.ActionType action2, bool isEmpty)
  234. {
  235. ActionHistory testHistory = GetActionHistory();
  236. if (!action1.Equals(SketchAction.ActionType.Start)) { testHistory.AddNewAction(new SketchAction(action1, 5)); }
  237. if (!action2.Equals(SketchAction.ActionType.Start)) { testHistory.AddNewAction(new SketchAction(action2, 5)); }
  238. Assert.AreEqual(isEmpty, testHistory.IsEmpty());
  239. }
  240. [DataTestMethod]
  241. [DataRow(SketchAction.ActionType.Draw, "Last Action: Line number 0 was drawn.")]
  242. [DataRow(SketchAction.ActionType.Delete, "Last Action: Line number 0 was deleted.")]
  243. public void ActionHistoryUndoRedoTest(SketchAction.ActionType actionType, String message)
  244. {
  245. ActionHistory testHistory = GetActionHistory();
  246. SketchAction testAction = new SketchAction(actionType, 0);
  247. testHistory.AddNewAction(testAction);
  248. Assert.AreEqual(true, testHistory.CanUndo());
  249. testHistory.MoveAction(true);
  250. Assert.AreEqual(true, testHistory.CanRedo());
  251. testHistory.MoveAction(false);
  252. Assert.AreEqual(actionType, testHistory.GetCurrentAction().GetActionType());
  253. String currLabel = testLabel.Text;
  254. Assert.AreEqual(currLabel, message);
  255. }
  256. }
  257. [TestClass]
  258. public class FileImporterTests
  259. {
  260. [DataTestMethod]
  261. [DataRow(new int[] { 54, 43, 57, 11, 145, 34, 113, 299, 0 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
  262. [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 })]
  263. [DataRow(new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 54, 43, 57, 11, 145, 34, 113, 199, 0 })]
  264. public void ParseISADInputSuccessfulTest(int[] xCoordinates, int[] yCoordinates)
  265. {
  266. Form1 program = new Form1();
  267. FileImporter uut = new SketchAssistant.FileImporter(program);
  268. List<String> file = new List<string>();
  269. file.Add("drawing");
  270. file.Add("300x200");
  271. for (int i = 0; i < xCoordinates.Length - 2; i += 3)
  272. {
  273. file.Add("line");
  274. file.Add(xCoordinates[i] + ";" + yCoordinates[i]);
  275. file.Add(xCoordinates[i + 1] + ";" + yCoordinates[i + 1]);
  276. file.Add(xCoordinates[i + 2] + ";" + yCoordinates[i + 2]);
  277. file.Add("endline");
  278. }
  279. file.Add("enddrawing");
  280. (int, int, List<Line>) values = uut.ParseISADInputForTesting(file.ToArray());
  281. program.CreateCanvasAndSetPictureForTesting(values.Item1, values.Item2, values.Item3);
  282. Line[] drawing = GetLeftImage(program).ToArray();
  283. Assert.AreEqual(xCoordinates.Length / 3, drawing.Length);
  284. for (int i = 0; i < xCoordinates.Length - 2; i += 3)
  285. {
  286. Point[] currentLine = drawing[i / 3].GetPoints().ToArray();
  287. Assert.AreEqual(3, currentLine.Length);
  288. for (int j = 0; j < 3; j++)
  289. {
  290. Assert.IsTrue(currentLine[j].X == xCoordinates[i + j] && currentLine[j].Y == yCoordinates[i + j]);
  291. }
  292. }
  293. }
  294. [DataTestMethod]
  295. [DataRow(new String[] {})]
  296. [DataRow(new String[] { "begindrawing", "300x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
  297. [DataRow(new String[] { "drawing", "300;300", "line", "50;50", "100;50", "endline", "enddrawing" })]
  298. [DataRow(new String[] { "drawing", "30.5x300", "line", "50;50", "100;50", "endline", "enddrawing" })]
  299. [DataRow(new String[] { "drawing", "line", "50;50", "100;50", "endline", "enddrawing" })]
  300. [DataRow(new String[] { "drawing", "300x300", "beginline", "50;50", "100;50", "endline", "enddrawing" })]
  301. [DataRow(new String[] { "drawing", "300x300", "line", "500;50", "100;50", "endline", "enddrawing" })]
  302. [DataRow(new String[] { "drawing", "300x300", "line", "50x50", "100;50", "endline", "enddrawing" })]
  303. [DataRow(new String[] { "drawing", "300x300", "line", "50", "100", "endline", "enddrawing" })]
  304. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "line", "endline", "enddrawing" })]
  305. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "stopline", "enddrawing" })]
  306. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "enddrawing" })]
  307. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline", "endrawing" })]
  308. [DataRow(new String[] { "drawing", "300x300", "line", "50;50", "100;50", "endline" })]
  309. public void ParseISADInputExceptionTest(String[] file)
  310. {
  311. bool exceptionThrown = false;
  312. Form1 program = new Form1();
  313. FileImporter uut = new SketchAssistant.FileImporter(program);
  314. //check that left image initially is uninitialized
  315. Assert.IsNull(GetLeftImage(program));
  316. //initialize left image with a valid isad drawing
  317. (int, int, List<Line>) values = uut.ParseISADInputForTesting(new string[] { "drawing", "300x205", "line", "40;40", "140;140", "endline", "enddrawing" });
  318. program.CreateCanvasAndSetPictureForTesting(values.Item1, values.Item2, values.Item3);
  319. //save left image for later comparison
  320. List<Line> oldLeftImage = GetLeftImage(program);
  321. try
  322. {
  323. //try to initialize the left image with an invalid isad drawing
  324. (int, int, List<Line>) values1 = uut.ParseISADInputForTesting(file);
  325. program.CreateCanvasAndSetPictureForTesting(values1.Item1, values1.Item2, values1.Item3);
  326. }
  327. catch(FileImporterException)
  328. {
  329. //save the occurence of an exception
  330. exceptionThrown = true;
  331. }
  332. //check that an exception has been thrown
  333. Assert.IsTrue(exceptionThrown);
  334. //check that the left image has not been changed by the failed image import
  335. Assert.AreEqual(oldLeftImage, GetLeftImage(program));
  336. }
  337. /// <summary>
  338. /// local helper method retrieving the left image from a Form1 instance
  339. /// </summary>
  340. /// <returns>the left image of the given Form1 instance</returns>
  341. private List<Line> GetLeftImage(Form1 program)
  342. {
  343. //cast is save as long as Form1#GetAllVariables() is conform to its contract
  344. return (List<Line>)program.GetAllVariables().Find(x => x.Item1.Equals("leftLineList")).Item2;
  345. }
  346. }
  347. [TestClass]
  348. public class RedrawAssistantTests
  349. {
  350. private RedrawAssistant GetAssistant(List<Line> input)
  351. {
  352. if(input.Count == 0)
  353. {
  354. return new RedrawAssistant();
  355. }
  356. else
  357. {
  358. return new RedrawAssistant(input);
  359. }
  360. }
  361. [DataTestMethod]
  362. [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)]
  363. [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)]
  364. [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)]
  365. public void InactiveRedrawAssistantTest(int x, int y, int[] xCoords, int[] yCoords, bool lineActive)
  366. {
  367. RedrawAssistant testAssistant = GetAssistant(new List<Line>());
  368. List<Point> testPoints = new List<Point>();
  369. for (int i = 0; i < xCoords.Length; i++)
  370. {
  371. testPoints.Add(new Point(xCoords[i], yCoords[i]));
  372. }
  373. List<Tuple<bool, Line>> testLines = new List<Tuple<bool, Line>> { new Tuple<bool, Line>(lineActive, new Line(testPoints, 0)) };
  374. List<HashSet<Point>> result = testAssistant.Tick(new Point(1, 1), testLines, -1 );
  375. Assert.AreEqual(0, result.Count);
  376. }
  377. [DataTestMethod]
  378. [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)]
  379. [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)]
  380. [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)]
  381. public void ActiveRedrawAssistantTestStartedDrawing(int x, int y, int[] xCoords, int[] yCoords, int resultingCount)
  382. {
  383. List<Point> testPoints = new List<Point>();
  384. for (int i = 0; i < xCoords.Length; i++)
  385. {
  386. testPoints.Add(new Point(xCoords[i], yCoords[i]));
  387. }
  388. List<Tuple<bool, Line>> testInputLines = new List<Tuple<bool, Line>>();
  389. List<Line> testRedrawLines = new List<Line> { new Line(testPoints, 0) };
  390. RedrawAssistant testAssistant = GetAssistant(testRedrawLines);
  391. //Setting Marker Radius to 1 so that only the functionality of the RedrawAssistant is checked
  392. //and not the functionality of the Circle algorithm.
  393. testAssistant.SetMarkerRadius(1);
  394. List<HashSet<Point>> tickResult = testAssistant.Tick(new Point(x, y), testInputLines, -1);
  395. Assert.AreEqual(resultingCount, tickResult.Count);
  396. if(resultingCount == 1)
  397. {
  398. foreach(Point p in tickResult[0])
  399. {
  400. Assert.AreEqual(testPoints[0], p);
  401. }
  402. }
  403. if(resultingCount == 2)
  404. {
  405. foreach (Point p in tickResult[0])
  406. {
  407. Assert.AreEqual(testPoints[0], p);
  408. }
  409. foreach (Point p in tickResult[1])
  410. {
  411. Assert.AreEqual(testPoints[testPoints.Count-1], p);
  412. }
  413. }
  414. }
  415. [DataTestMethod]
  416. [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 },
  417. new int[] { 77, 20, 3, 74, 28 }, new int[] { 40, 50, 20, 77, 28}, 2, false)]
  418. [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 },
  419. new int[] { 42, 140, 30, 30, 30 }, new int[] { 11, 145, 34, 113, 28 }, 2, true)]
  420. [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 },
  421. new int[] { 43, 57, 11, 145 }, new int[] { 33, 42, 140, 30 }, 2, true)]
  422. public void ActiveRedrawAssistantTestMultipleLinesRedrawn(
  423. int x, int y, int[] xCoords_one, int[] yCoords_one, int[] xCoords_two, int[] yCoords_two, int resultingCount, bool showingStartAndEnd)
  424. {
  425. List<Point> testPoints1 = new List<Point>();
  426. for (int i = 0; i < xCoords_one.Length; i++)
  427. {
  428. testPoints1.Add(new Point(xCoords_one[i], yCoords_one[i]));
  429. }
  430. List<Point> testPoints2 = new List<Point>();
  431. for (int i = 0; i < xCoords_two.Length; i++)
  432. {
  433. testPoints2.Add(new Point(xCoords_two[i], yCoords_two[i]));
  434. }
  435. List<Tuple<bool, Line>> testInputLines = new List<Tuple<bool, Line>>();
  436. List<Line> testRedrawLines = new List<Line> { new Line(testPoints1, 0) , new Line(testPoints2, 1) };
  437. RedrawAssistant testAssistant = GetAssistant(testRedrawLines);
  438. //Setting Marker Radius to 1 so that only the functionality of the RedrawAssistant is checked
  439. //and not the functionality of the Circle algorithm.
  440. testAssistant.SetMarkerRadius(1);
  441. List<HashSet<Point>> tickResult = testAssistant.Tick(new Point(x, y), testInputLines, -1);
  442. Assert.AreEqual(resultingCount, tickResult.Count);
  443. if (showingStartAndEnd)
  444. {
  445. foreach (Point p in tickResult[0])
  446. {
  447. Assert.AreEqual(testPoints1[0], p);
  448. }
  449. foreach (Point p in tickResult[1])
  450. {
  451. Assert.AreEqual(testPoints1[testPoints1.Count - 1], p);
  452. }
  453. }
  454. else
  455. {
  456. foreach (Point p in tickResult[0])
  457. {
  458. Assert.AreEqual(testPoints1[0], p);
  459. }
  460. foreach (Point p in tickResult[1])
  461. {
  462. Assert.AreEqual(testPoints2[0], p);
  463. }
  464. }
  465. }
  466. [DataTestMethod]
  467. [DataRow(17, 20, 17, 20, new int[] { 54, 43, 57, 11, 145, 34, 113, 299, 0 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 },
  468. new int[] { 77, 20, 3, 74, 28 }, new int[] { 40, 50, 20, 77, 28 }, 2, 2, false, false)]
  469. [DataRow(33, 33, 2, 2, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 },
  470. new int[] { 42, 140, 30, 30, 30 }, new int[] { 11, 145, 34, 113, 28 }, 2, 1, true, false)]
  471. [DataRow(33, 54, 17, 0, new int[] { 33, 42, 140, 30, 30, 30, 32, 145, 2 }, new int[] { 54, 43, 57, 11, 145, 34, 113, 199, 0 },
  472. new int[] { 43, 57, 11, 145 }, new int[] { 33, 42, 140, 30 }, 2, 2, true, true)]
  473. public void ActiveRedrawAssistantTestLineFinished(
  474. int x_one, int y_one, int x_two, int y_two, int[] xCoords_one, int[] yCoords_one, int[] xCoords_two, int[] yCoords_two,
  475. int count_one, int count_two, bool showingSE_one, bool showingSE_two)
  476. {
  477. List<Point> testPoints1 = new List<Point>();
  478. for (int i = 0; i < xCoords_one.Length; i++)
  479. {
  480. testPoints1.Add(new Point(xCoords_one[i], yCoords_one[i]));
  481. }
  482. List<Point> testPoints2 = new List<Point>();
  483. for (int i = 0; i < xCoords_two.Length; i++)
  484. {
  485. testPoints2.Add(new Point(xCoords_two[i], yCoords_two[i]));
  486. }
  487. List<Tuple<bool, Line>> testInputLines = new List<Tuple<bool, Line>>();
  488. List<Line> testRedrawLines = new List<Line> { new Line(testPoints1, 0), new Line(testPoints2, 1) };
  489. RedrawAssistant testAssistant = GetAssistant(testRedrawLines);
  490. //Setting Marker Radius to 1 so that only the functionality of the RedrawAssistant is checked
  491. //and not the functionality of the Circle algorithm.
  492. testAssistant.SetMarkerRadius(1);
  493. List<HashSet<Point>> tickResult1 = testAssistant.Tick(new Point(x_one, y_one), testInputLines, -1);
  494. List<HashSet<Point>> tickResult2 = testAssistant.Tick(new Point(x_two, y_two), testInputLines, 0);
  495. Assert.AreEqual(count_one, tickResult1.Count);
  496. if (showingSE_one)
  497. {
  498. foreach(Point p in tickResult1[0])
  499. {
  500. Assert.AreEqual(testPoints1[0], p);
  501. }
  502. foreach (Point p in tickResult1[1])
  503. {
  504. Assert.AreEqual(testPoints1[testPoints1.Count - 1], p);
  505. }
  506. }
  507. else
  508. {
  509. foreach (Point p in tickResult1[0])
  510. {
  511. Assert.AreEqual(testPoints1[0], p);
  512. }
  513. foreach (Point p in tickResult1[1])
  514. {
  515. Assert.AreEqual(testPoints2[0], p);
  516. }
  517. }
  518. Assert.AreEqual(count_two, tickResult2.Count);
  519. if(count_two == 2)
  520. {
  521. if (showingSE_two)
  522. {
  523. foreach (Point p in tickResult2[0])
  524. {
  525. Assert.AreEqual(testPoints1[0], p);
  526. }
  527. foreach (Point p in tickResult2[1])
  528. {
  529. Assert.AreEqual(testPoints1[testPoints1.Count - 1], p);
  530. }
  531. }
  532. else
  533. {
  534. foreach (Point p in tickResult2[0])
  535. {
  536. Assert.AreEqual(testPoints1[0], p);
  537. }
  538. foreach (Point p in tickResult2[1])
  539. {
  540. Assert.AreEqual(testPoints2[0], p);
  541. }
  542. }
  543. }
  544. if(count_two == 1)
  545. {
  546. foreach (Point p in tickResult2[0])
  547. {
  548. Assert.AreEqual(testPoints2[0], p);
  549. }
  550. }
  551. }
  552. }
  553. }