UnitTest1.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using NUnit.Framework;
  2. namespace Tests
  3. {
  4. public class Tests
  5. {
  6. [SetUp]
  7. public void Setup()
  8. {
  9. }
  10. [Test]
  11. public void Test1()
  12. {
  13. Assert.AreEqual(true, true);
  14. }
  15. }
  16. /*
  17. [TestClass]
  18. public class LineTests
  19. {
  20. //========================//
  21. //= Bresenham Line Tests =//
  22. //========================//
  23. [TestMethod]
  24. public void BresenhamLineTest1()
  25. {
  26. //Test point
  27. List<Point> expectedResult = new List<Point>();
  28. expectedResult.Add(new Point(1, 2));
  29. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(1, 2), new Point(1, 2));
  30. Assert.AreEqual(1, actualResult.Count);
  31. for (int i = 0; i < actualResult.Count; i++)
  32. {
  33. Assert.AreEqual(expectedResult[i], actualResult[i]);
  34. }
  35. }
  36. [TestMethod]
  37. public void BresenhamLineTest2()
  38. {
  39. //Test line going from left to right
  40. List<Point> expectedResult = new List<Point>();
  41. for (int i = 1; i <= 6; i++) { expectedResult.Add(new Point(i, 2)); }
  42. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(1, 2), new Point(6, 2));
  43. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  44. for (int i = 0; i < actualResult.Count; i++)
  45. {
  46. Assert.AreEqual(expectedResult[i], actualResult[i]);
  47. }
  48. }
  49. [TestMethod]
  50. public void BresenhamLineTest3()
  51. {
  52. //Test line going from right to left
  53. List<Point> expectedResult = new List<Point>();
  54. for (int i = 6; i >= 1; i--) { expectedResult.Add(new Point(i, 2)); }
  55. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(6, 2), new Point(1, 2));
  56. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  57. for (int i = 0; i < actualResult.Count; i++)
  58. {
  59. Assert.AreEqual(expectedResult[i], actualResult[i]);
  60. }
  61. }
  62. [TestMethod]
  63. public void BresenhamLineTest4()
  64. {
  65. //Test line going from top to bottom
  66. List<Point> expectedResult = new List<Point>();
  67. for (int i = 5; i <= 25; i++) { expectedResult.Add(new Point(7, i)); }
  68. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(7, 5), new Point(7, 25));
  69. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  70. for (int i = 0; i < actualResult.Count; i++)
  71. {
  72. Assert.AreEqual(expectedResult[i], actualResult[i]);
  73. }
  74. }
  75. [TestMethod]
  76. public void BresenhamLineTest5()
  77. {
  78. //Test line going from bottom to top
  79. List<Point> expectedResult = new List<Point>();
  80. for (int i = 25; i >= 5; i--) { expectedResult.Add(new Point(7, i)); }
  81. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(7, 25), new Point(7, 5));
  82. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  83. for (int i = 0; i < actualResult.Count; i++)
  84. {
  85. Assert.AreEqual(expectedResult[i], actualResult[i]);
  86. }
  87. }
  88. [TestMethod]
  89. public void BresenhamLineTest6()
  90. {
  91. //Test exactly diagonal line from top left to bottom right
  92. List<Point> expectedResult = new List<Point>();
  93. for (int i = 5; i <= 25; i++) { expectedResult.Add(new Point(i + 2, i)); }
  94. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(7, 5), new Point(27, 25));
  95. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  96. for (int i = 0; i < actualResult.Count; i++)
  97. {
  98. Assert.AreEqual(expectedResult[i], actualResult[i]);
  99. }
  100. }
  101. [TestMethod]
  102. public void BresenhamLineTest7()
  103. {
  104. //Test exactly diagonal line from bottom right to top left
  105. List<Point> expectedResult = new List<Point>();
  106. for (int i = 25; i >= 5; i--) { expectedResult.Add(new Point(i + 2, i)); }
  107. List<Point> actualResult = SketchAssistant.GeometryCalculator.BresenhamLineAlgorithm(new Point(27, 25), new Point(7, 5));
  108. Assert.AreEqual(expectedResult.Count, actualResult.Count);
  109. for (int i = 0; i < actualResult.Count; i++)
  110. {
  111. Assert.AreEqual(expectedResult[i], actualResult[i]);
  112. }
  113. }
  114. //===========================//
  115. //= Matrix Population Tests =//
  116. //===========================//
  117. [TestMethod]
  118. public void MatrixTest1()
  119. {
  120. //Populate Matrix for temporary Line
  121. List<Point> thePoints = new List<Point>();
  122. thePoints.Add(new Point(1, 1));
  123. thePoints.Add(new Point(1, 2));
  124. bool[,] testBoolMatrix = new bool[5, 5];
  125. List<int>[,] testLineMatrix = new List<int>[5, 5];
  126. bool[,] resultBoolMatrix = new bool[5, 5];
  127. HashSet<int>[,] resultLineMatrix = new HashSet<int>[5, 5];
  128. Line testLine = new Line(thePoints);
  129. testLine.PopulateMatrixes(resultBoolMatrix, resultLineMatrix);
  130. for (int i = 0; i < 5; i++)
  131. {
  132. for (int j = 0; j < 5; j++)
  133. {
  134. Assert.AreEqual(testBoolMatrix[i, j], resultBoolMatrix[i, j]);
  135. Assert.AreEqual(testLineMatrix[i, j], resultLineMatrix[i, j]);
  136. }
  137. }
  138. }
  139. [TestMethod]
  140. public void MatrixTest2()
  141. {
  142. //Populate Matrix for non-temporary Line
  143. List<Point> thePoints = new List<Point>();
  144. thePoints.Add(new Point(1, 1));
  145. thePoints.Add(new Point(3, 3));
  146. bool[,] testBoolMatrix = new bool[5, 5];
  147. HashSet<int>[,] testLineMatrix = new HashSet<int>[5, 5];
  148. for (int i = 1; i <= 3; i++)
  149. {
  150. testBoolMatrix[i, i] = true;
  151. HashSet<int> temp = new HashSet<int>();
  152. temp.Add(5);
  153. testLineMatrix[i, i] = temp;
  154. }
  155. bool[,] resultBoolMatrix = new bool[5, 5];
  156. HashSet<int>[,] resultLineMatrix = new HashSet<int>[5, 5];
  157. Line testLine = new Line(thePoints, 5);
  158. testLine.PopulateMatrixes(resultBoolMatrix, resultLineMatrix);
  159. for (int i = 0; i < 5; i++)
  160. {
  161. for (int j = 0; j < 5; j++)
  162. {
  163. Assert.AreEqual(testBoolMatrix[i, j], resultBoolMatrix[i, j]);
  164. if (testLineMatrix[i, j] != null && resultLineMatrix[i, j] != null)
  165. {
  166. for (int k = 0; k < resultLineMatrix[i, j].Count; k++)
  167. {
  168. Assert.AreEqual(true, testLineMatrix[i, j].SetEquals(resultLineMatrix[i, j]));
  169. }
  170. }
  171. }
  172. }
  173. }
  174. //=========================//
  175. //= Line Constructor Test =//
  176. //=========================//
  177. [TestMethod]
  178. public void ConstructorTest()
  179. {
  180. //Create non-temporary Line and check points
  181. //reference Points
  182. 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),
  183. 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),
  184. 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),
  185. new Point(3, 5), new Point(2, 5), new Point(1, 4)};
  186. //test Points, with intermediate points missing & duplicate points
  187. 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),
  188. 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),
  189. new Point(5, 5), new Point(2, 5), new Point(2, 5), new Point(1, 4) };
  190. Line testLine = new Line(testPoints, 0);
  191. List<Point> returnedPoints = testLine.GetPoints();
  192. Assert.AreEqual(comparisonPoints.Count, returnedPoints.Count);
  193. for (int i = 0; i < returnedPoints.Count; i++)
  194. {
  195. Assert.AreEqual(comparisonPoints[i], returnedPoints[i]);
  196. }
  197. }
  198. }
  199. [TestClass]
  200. public class ActionHistoryTests
  201. {
  202. private ActionHistory GetActionHistory()
  203. {
  204. return new ActionHistory();
  205. }
  206. [DataTestMethod]
  207. [DataRow(SketchAction.ActionType.Start, 5, -1, "A new canvas was created.")]
  208. [DataRow(SketchAction.ActionType.Draw, 5, 5, "Line number 5 was drawn.")]
  209. [DataRow(SketchAction.ActionType.Delete, 10, 10, "Line number 10 was deleted.")]
  210. public void ScetchActionTest1(SketchAction.ActionType type, int id, int exit, String response)
  211. {
  212. HashSet<int> actualResult = new HashSet<int>();
  213. if (!type.Equals(SketchAction.ActionType.Start)) { actualResult.Add(id); }
  214. SketchAction testAction = new SketchAction(type, id);
  215. Assert.AreEqual(type, testAction.GetActionType());
  216. Assert.AreEqual(true, actualResult.SetEquals(testAction.GetLineIDs()));
  217. Assert.AreEqual(response, testAction.GetActionInformation());
  218. }
  219. [DataTestMethod]
  220. [DataRow(SketchAction.ActionType.Start, 1, 2, 3, "A new canvas was created.")]
  221. [DataRow(SketchAction.ActionType.Draw, 3, 3, 3, "Line number 3 was drawn.")]
  222. [DataRow(SketchAction.ActionType.Delete, 20, 30, 40, "Several Lines were deleted.")]
  223. public void ScetchActionTest2(SketchAction.ActionType type, int id1, int id2, int id3, String response)
  224. {
  225. HashSet<int> actualResult = new HashSet<int>();
  226. if (!type.Equals(SketchAction.ActionType.Start))
  227. {
  228. actualResult.Add(id1);
  229. actualResult.Add(id2);
  230. actualResult.Add(id3);
  231. }
  232. SketchAction testAction = new SketchAction(type, actualResult);
  233. Assert.AreEqual(type, testAction.GetActionType());
  234. Assert.AreEqual(true, actualResult.SetEquals(testAction.GetLineIDs()));
  235. Assert.AreEqual(response, testAction.GetActionInformation());
  236. }
  237. [DataTestMethod]
  238. [DataRow(SketchAction.ActionType.Start, SketchAction.ActionType.Start, true)]
  239. [DataRow(SketchAction.ActionType.Draw, SketchAction.ActionType.Delete, false)]
  240. public void ActionHistoryTest1(SketchAction.ActionType action1, SketchAction.ActionType action2, bool isEmpty)
  241. {
  242. ActionHistory testHistory = GetActionHistory();
  243. if (!action1.Equals(SketchAction.ActionType.Start)) { testHistory.AddNewAction(new SketchAction(action1, 5)); }
  244. if (!action2.Equals(SketchAction.ActionType.Start)) { testHistory.AddNewAction(new SketchAction(action2, 5)); }
  245. Assert.AreEqual(isEmpty, testHistory.IsEmpty());
  246. }
  247. [DataTestMethod]
  248. [DataRow(SketchAction.ActionType.Draw, "Last Action: Line number 0 was drawn.")]
  249. [DataRow(SketchAction.ActionType.Delete, "Last Action: Line number 0 was deleted.")]
  250. public void ActionHistoryUndoRedoTest(SketchAction.ActionType actionType, String message)
  251. {
  252. ActionHistory testHistory = GetActionHistory();
  253. SketchAction testAction = new SketchAction(actionType, 0);
  254. testHistory.AddNewAction(testAction);
  255. Assert.AreEqual(true, testHistory.CanUndo());
  256. testHistory.MoveAction(true);
  257. Assert.AreEqual(true, testHistory.CanRedo());
  258. var lastActionLabel = testHistory.MoveAction(false);
  259. Assert.AreEqual(actionType, testHistory.GetCurrentAction().GetActionType());
  260. Assert.AreEqual(message, lastActionLabel);
  261. }
  262. }
  263. */
  264. }