Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.38 KB | None | 0 0
  1. using System;
  2. using Game;
  3. using System.Drawing;
  4.  
  5. namespace CustomRectangle {
  6. class Program {
  7.  
  8. static void Wait() {
  9. Console.WriteLine("");
  10. Console.ReadKey();
  11. }
  12.  
  13. static void Main(string[] args) {
  14. // Constructor: default
  15. {
  16. Rect def = new Rect();
  17. if (def.X != 0 || def.Y != 0 || def.W != 0 || def.H != 0) {
  18. Console.WriteLine("Error:");
  19. Console.WriteLine("Rect def = new Rect();");
  20. Console.WriteLine("def.X != 0 || def.Y != 0 || def.W != 0 || def.H != 0");
  21. Console.WriteLine(def.X + " != 0 || " + def.Y + " != 0 || " + def.W + " != 0 || " + def.H +" != 0");
  22. Wait();
  23. return;
  24. }
  25. if (def.Left != 0 || def.Top != 0 || def.Right != 0 || def.Bottom != 0) {
  26. Console.WriteLine("Error:");
  27. Console.WriteLine("Rect def = new Rect();");
  28. Console.WriteLine("def.Left != 0 || def.Top != 0 || def.Right != 0 || def.Bottom != 0");
  29. Console.WriteLine(def.Left + " != 0 || " + def.Top + " != 0 || " + def.Right + " != 0 || " + def.Bottom + " != 0");
  30. Wait();
  31. return;
  32. }
  33. if (def.Area != 0) {
  34. Console.WriteLine("Error:");
  35. Console.WriteLine("Rect def = new Rect();");
  36. Console.WriteLine("def.Area != 0");
  37. Console.WriteLine(def.Area + " != 0");
  38. Wait();
  39. return;
  40. }
  41. }
  42.  
  43. // Constructor: int x, int y, int w, int h
  44. {
  45. Rect def = new Rect(-20, 6, 4, 7);
  46. if (def.X != -20 || def.Y != 6 || def.W != 4 || def.H != 7) {
  47. Console.WriteLine("Error:");
  48. Console.WriteLine("Rect def = new Rect(-20, 6, 4, 7);");
  49. Console.WriteLine("def.X != -20 || def.Y != 6 || def.W != 4 || def.H != 7");
  50. Console.WriteLine(def.X + " != -20 || " + def.Y + " != 6 || " + def.W + " != 4 || " + def.H + " != 7");
  51. Wait();
  52. return;
  53. }
  54. if (def.Left != -20 || def.Top != 6 || def.Right != -16 || def.Bottom != 13) {
  55. Console.WriteLine("Error:");
  56. Console.WriteLine("Rect def = new Rect(-20, 6, 4, 7);");
  57. Console.WriteLine("def.Left != -20 || def.Top != 6 || def.Right != -16 || def.Bottom != 13");
  58. Console.WriteLine(def.Left + " != -20 || " + def.Top + " != 6 || " + def.Right + " != -16 || " + def.Bottom + " != 13");
  59. Wait();
  60. return;
  61. }
  62. if (def.Area != 28) {
  63. Console.WriteLine("Error:");
  64. Console.WriteLine("Rect def = new Rect(-20, 6, 4, 7);");
  65. Console.WriteLine("def.Area != 28");
  66. Console.WriteLine(def.Area + " != 28");
  67. Wait();
  68. return;
  69. }
  70. }
  71.  
  72. // Constructor: int x, int y, int w, int h
  73. {
  74. Rect def = new Rect(5, 5, -5, -10);
  75. if (def.X != 0 || def.W != 5 || def.Y != -5 || def.H != 10) {
  76. Console.WriteLine("Error:");
  77. Console.WriteLine("Rect def = new Rect(5, 5, -5, -10);");
  78. Console.WriteLine("def.X != 0 || def.W != 5 || def.Y != -5 || def.H != 10");
  79. Console.WriteLine(def.X + " != 0 || " + def.Y + " != 5 || " + def.W + " != -5 || " + def.H + " != 10");
  80. Wait();
  81. return;
  82. }
  83. if (def.Left != 0 || def.Top != -5 || def.Right != 5 || def.Bottom != 5) {
  84. Console.WriteLine("Error:");
  85. Console.WriteLine("Rect def = new Rect(5, 5, -5, -10);");
  86. Console.WriteLine("def.Left != 0 || def.Top != -5 || def.Right != 5 || def.Bottom != 5");
  87. Console.WriteLine(def.Left + " != 0 || " + def.Top + " != -5 || " + def.Right + " != 5 || " + def.Bottom + " != 5");
  88. Wait();
  89. return;
  90. }
  91. if (def.Area != 50) {
  92. Console.WriteLine("Error:");
  93. Console.WriteLine("Rect def = new Rect(5, 5, -5, -10);");
  94. Console.WriteLine("def.Area != 50");
  95. Console.WriteLine(def.Area + " != 50");
  96. Wait();
  97. return;
  98. }
  99. }
  100.  
  101. // X, Y, W, H Setters and getters
  102. {
  103. Rect rect = new Rect();
  104. rect.X = 5;
  105. if (rect.X != 5 || rect.Y != 0 || rect.W != 0 || rect.H != 0) {
  106. Console.WriteLine("Error");
  107. Console.WriteLine("rect.X = 5;");
  108. Console.WriteLine("rect.X != 5 || rect.Y != 0 || rect.W != 0 || rect.H != 0");
  109. Console.WriteLine(rect.X + " != 5 || " + rect.Y + " != 0 || " + rect.W + " != 0 || " + rect.H + " != 0");
  110. Wait();
  111. return;
  112. }
  113. if (rect.Left != 5 || rect.Top != 0 || rect.Right != 5 || rect.Bottom != 0) {
  114. Console.WriteLine("Error");
  115. Console.WriteLine("rect.X = 5;");
  116. Console.WriteLine("rect.Left != 5 || rect.Top != 0 || rect.Right != 5 || rect.Bottom != 0");
  117. Console.WriteLine(rect.Left + " != 5 || " + rect.Top + " != 0 || " + rect.Right + " != 5 || " + rect.Bottom + " != 0");
  118. Wait();
  119. return;
  120. }
  121.  
  122. rect = new Rect();
  123. rect.Y = 5;
  124. if (rect.X != 0 || rect.Y != 5 || rect.W != 0 || rect.H != 0) {
  125. Console.WriteLine("Error");
  126. Console.WriteLine("rect.Y = 5;");
  127. Console.WriteLine("rect.X != 0 || rect.Y != 5 || rect.W != 0 || rect.H != 0");
  128. Console.WriteLine(rect.X + " != 0 || " + rect.Y + " != 5 || " + rect.W + " != 0 || " + rect.H + " != 0");
  129. Wait();
  130. return;
  131. }
  132. if (rect.Left != 0 || rect.Top != 5 || rect.Right != 0 || rect.Bottom != 5) {
  133. Console.WriteLine("Error");
  134. Console.WriteLine("rect.X = 5;");
  135. Console.WriteLine("rect.Left != 0 || rect.Top != 5 || rect.Right != 0 || rect.Bottom != 5");
  136. Console.WriteLine(rect.Left + " != 0 || " + rect.Top + " != 5 || " + rect.Right + " != 0 || " + rect.Bottom + " != 5");
  137. Wait();
  138. return;
  139. }
  140.  
  141. rect = new Rect();
  142. rect.W = 5;
  143. if (rect.X != 0 || rect.Y != 0 || rect.W != 5 || rect.H != 0) {
  144. Console.WriteLine("Error");
  145. Console.WriteLine("rect.W = 5;");
  146. Console.WriteLine("rect.X != 0 || rect.Y != 0 || rect.W != 5 || rect.H != 0");
  147. Console.WriteLine(rect.X + " != 0 || " + rect.Y + " != 0 || " + rect.W + " != 5 || " + rect.H + " != 0");
  148. Wait();
  149. return;
  150. }
  151.  
  152. rect = new Rect();
  153. rect.H = 5;
  154. if (rect.X != 0 || rect.Y != 0 || rect.W != 0 || rect.H != 5) {
  155. Console.WriteLine("Error");
  156. Console.WriteLine("rect.W = 5;");
  157. Console.WriteLine("rect.X != 0 || rect.Y != 0 || rect.W != 0 || rect.H != 5");
  158. Console.WriteLine(rect.X + " != 0 || " + rect.Y + " != 0 || " + rect.W + " != 0 || " + rect.H + " != 5");
  159. Wait();
  160. return;
  161. }
  162.  
  163. rect = new Rect();
  164. rect.X = 2;
  165. rect.W = -5;
  166. if (rect.X != -3 || rect.Y != 0 || rect.W != 5 || rect.H != 0) {
  167. Console.WriteLine("Error");
  168. Console.WriteLine("rect.X = 2; rect.W = -5;");
  169. Console.WriteLine("rect.X != -3 || rect.Y != 0 || rect.W != 5 || rect.H != 0");
  170. Console.WriteLine(rect.X + " != -3 || " + rect.Y + " != 0 || " + rect.W + " != 5 || " + rect.H + " != 0");
  171. Wait();
  172. return;
  173. }
  174.  
  175. rect = new Rect();
  176. rect.Y = 2;
  177. rect.H = -5;
  178. if (rect.X != 0 || rect.Y != -3 || rect.W != 0 || rect.H != 5) {
  179. Console.WriteLine("Error");
  180. Console.WriteLine("rect.Y = 2; rect.H = -5;");
  181. Console.WriteLine("rect.X != 0 || rect.Y != -3 || rect.W != 0 || rect.H != 5");
  182. Console.WriteLine(rect.X + " != 0 || " + rect.Y + " != -3 || " + rect.W + " != 0 || " + rect.H + " != 5");
  183. Wait();
  184. return;
  185. }
  186. }
  187. // Rectangle getter function
  188. {
  189. Rect r1 = new Rect(5, 10, 15, 20);
  190. System.Drawing.Rectangle r2 = r1.Rectangle;
  191.  
  192. if (r1.X != r2.X || r1.Y != r2.Y || r1.W != r2.Width || r1.H != r2.Height) {
  193. Console.WriteLine("Error");
  194. Console.WriteLine("Rect r1 = new Rect(5, 10, 15, 20);");
  195. Console.WriteLine("System.Drawing.Rectangle r2 = r1.Rectangle;");
  196. Console.WriteLine("r1.X != r2.X || r1.Y != r2.Y || r1.W != r2.Width || r1.H != r2.Height");
  197. Console.WriteLine(r1.X + " != " + r2.X + " || " + r1.Y + " != " + r2.Y + " || " + r1.W + " != " + r2.Width + " || " + r1.H + " != " + r2.Height);
  198. Wait();
  199. return;
  200. }
  201. }
  202.  
  203. // Constructor: Point, Size
  204. {
  205. Rect def = new Rect(new System.Drawing.Point(5, 5), new System.Drawing.Size(-5, -10));
  206. if (def.X != 0 || def.W != 5 || def.Y != -5 || def.H != 10) {
  207. Console.WriteLine("Error:");
  208. Console.WriteLine("Rect def = new Rect(new .Point(5, -5), new Size(5, -10));");
  209. Console.WriteLine("def.X != 0 || def.W != 5 || def.Y != -5 || def.H != 10");
  210. Console.WriteLine(def.X + " != 0 || " + def.Y + " != 5 || " + def.W + " != -5 || " + def.H + " != 10");
  211. Wait();
  212. return;
  213. }
  214. if (def.Left != 0 || def.Top != -5 || def.Right != 5 || def.Bottom != 5) {
  215. Console.WriteLine("Error:");
  216. Console.WriteLine("Rect def = new Rect(new .Point(5, -5), new Size(5, -10));");
  217. Console.WriteLine("def.Left != 0 || def.Top != -5 || def.Right != 5 || def.Bottom != 5");
  218. Console.WriteLine(def.Left + " != 0 || " + def.Top + " != -5 || " + def.Right + " != 5 || " + def.Bottom + " != 5");
  219. Wait();
  220. return;
  221. }
  222. if (def.Area != 50) {
  223. Console.WriteLine("Error:");
  224. Console.WriteLine("Rect def = new Rect(new .Point(5, -5), new Size(5, -10));");
  225. Console.WriteLine("def.Area != 50");
  226. Console.WriteLine(def.Area + " != 50");
  227. Wait();
  228. return;
  229. }
  230. }
  231. // Constructor point, point
  232. {
  233. Rect def = new Rect(new Point(0, 0), new Point(5, 5));
  234.  
  235. if (def.X != 0 || def.Y != 0 || def.W != 5 || def.H != 5) {
  236. Console.WriteLine("Error:");
  237. Console.WriteLine("Rect def = new Rect(new Point(0, 0), new Point(5, 5));");
  238. Console.WriteLine("def.X != 0 || def.Y != 0 || def.W != 5 || def.H != 5");
  239. Console.WriteLine(def.X + " != 0 || " + def.Y + " != 0 || " + def.W + " != 5 || " + def.H + " != 5");
  240. Wait();
  241. return;
  242. }
  243.  
  244. def = new Rect(new Point(2, 2), new Point(-5, -5));
  245. if (def.X != -5 || def.Y != -5 || def.W != 7 || def.H != 7) {
  246. Console.WriteLine("Error:");
  247. Console.WriteLine("def = new Rect(new Point(2, 2), new Point(-5, -5));");
  248. Console.WriteLine("def.X != -5 || def.Y != -5 || def.W != 7 || def.H != 7");
  249. Console.WriteLine(def.X + " != -5 || " + def.Y + " != -5 || " + def.W + " != 7 || " + def.H + " != 7");
  250. Wait();
  251. return;
  252. }
  253. }
  254. // Intersects
  255. {
  256. Rect r1 = new Rect(new Point(1, 1), new Point(2, 2));
  257. Rect r2 = new Rect(new Point(3, 3), new Point(4, 4));
  258. if (r1.Intersects(r2)) {
  259. Console.WriteLine("Error:");
  260. Console.WriteLine("Rect r1 = new Rect(new Point(1, 1), new Point(2, 2));");
  261. Console.WriteLine("Rect r2 = new Rect(new Point(3, 3), new Point(4, 4));");
  262. Console.WriteLine("Rectangles should not intersect");
  263. Wait();
  264. return;
  265. }
  266.  
  267. r1 = new Rect(new Point(1, 1), new Point(5, 5));
  268. r2 = new Rect(new Point(2, 2), new Point(3, 4));
  269. if (!r1.Intersects(r2)) {
  270. Console.WriteLine("Error:");
  271. Console.WriteLine("r1 = new Rect(new Point(1, 1), new Point(5, 5));");
  272. Console.WriteLine("r2 = new Rect(new Point(2, 2), new Point(3, 4));");
  273. Console.WriteLine("r2 is fully contained inside of r1");
  274. Console.WriteLine("The rectangles should be intersecting");
  275. Wait();
  276. return;
  277. }
  278.  
  279. r1 = new Rect(new Point(1, 1), new Point(3, 3));
  280. r2 = new Rect(new Point(2, 2), new Point(4, 4));
  281. if (!r1.Intersects(r2)) {
  282. Console.WriteLine("Error:");
  283. Console.WriteLine("r1 = new Rect(new Point(1, 1), new Point(3, 3));");
  284. Console.WriteLine("r2 = new Rect(new Point(2, 2), new Point(4, 4));");
  285. Console.WriteLine("The rectangles should be intersecting");
  286. Wait();
  287. return;
  288. }
  289. }
  290. // Contains
  291. {
  292. Rect rect = new Rect(new Point(1, 1), new Point(3, 3));
  293. Point point = new Point(2, 2);
  294. if (!rect.Contains(point)) {
  295. Console.WriteLine("Error");
  296. Console.WriteLine("rect = new Rect(new Point(1, 1), new Point(3, 3));");
  297. Console.WriteLine("point = new Point(2, 2);");
  298. Console.WriteLine("Rect should contain point");
  299. Wait();
  300. return;
  301. }
  302.  
  303. rect = new Rect(new Point(1, 1), new Point(3, 3));
  304. point = new Point(7, 7);
  305. if (rect.Contains(point)) {
  306. Console.WriteLine("Error");
  307. Console.WriteLine("rect = new Rect(new Point(1, 1), new Point(3, 3));");
  308. Console.WriteLine("point = new Point(7, 7);");
  309. Console.WriteLine("Rect should NOT contain point");
  310. Wait();
  311. return;
  312. }
  313. }
  314. // Intersection
  315. {
  316. Rect r1 = new Rect(new Point(1, 1), new Point(2, 2));
  317. Rect r2 = new Rect(new Point(3, 3), new Point(4, 4));
  318. Rect result = r1.Intersection(r2);
  319. if (result.X != 0 || result.Y != 0 || result.W != 0 || result.H != 0) {
  320. Console.WriteLine("Error, (They don't touch)");
  321. Console.WriteLine("Rect r1 = new Rect(new Point(1, 1), new Point(2, 2));");
  322. Console.WriteLine("Rect r2 = new Rect(new Point(3, 3), new Point(4, 4));");
  323. Console.WriteLine("Rect result = r1.Intersection(r2);");
  324. Console.WriteLine("result.X != 0 || result.Y != 0 || result.W != 0 || result.H != 0");
  325. Console.WriteLine(result.X + " != 0 || " + result.Y + " != 0 || " + result.W + " != 0 || " + result.H + " != 0");
  326. Wait();
  327. return;
  328. }
  329.  
  330. r1 = new Rect(new Point(1, 1), new Point(5, 5));
  331. r2 = new Rect(new Point(2, 2), new Point(4, 4));
  332. result = r1.Intersection(r2);
  333. if (result.X != 2 || result.Y != 2 || result.W != 2 || result.H != 2) {
  334. Console.WriteLine("Error, (R2 is fully in R1)");
  335. Console.WriteLine("Rect r1 = new Rect(new Point(1, 1), new Point(5, 5));");
  336. Console.WriteLine("Rect r2 = new Rect(new Point(2, 2), new Point(4, 4));");
  337. Console.WriteLine("Rect result = r1.Intersection(r2);");
  338. Console.WriteLine("result.X != 2 || result.Y != 2 || result.W != 2 || result.H != 2");
  339. Console.WriteLine(result.X + " != 2 || " + result.Y + " != 2 || " + result.W + " != 2 || " + result.H + " != 2");
  340. Wait();
  341. return;
  342. }
  343.  
  344. r1 = new Rect(new Point(1, 1), new Point(3, 3));
  345. r2 = new Rect(new Point(2, 2), new Point(4, 4));
  346. result = r1.Intersection(r2);
  347. if (result.X != 2 || result.Y != 2 || result.W != 1 || result.H != 1) {
  348. Console.WriteLine("Error, (They intersect)");
  349. Console.WriteLine("Rect r1 = new Rect(new Point(1, 1), new Point(3, 3));");
  350. Console.WriteLine("Rect r2 = new Rect(new Point(2, 2), new Point(4, 4));");
  351. Console.WriteLine("Rect result = r1.Intersection(r2);");
  352. Console.WriteLine("result.X != 2 || result.Y != 2 || result.W != 1 || result.H != 1");
  353. Console.WriteLine(result.X + " != 2 || " + result.Y + " != 2 || " + result.W + " != 1 || " + result.H + " != 1");
  354. Wait();
  355. return;
  356. }
  357. }
  358.  
  359. // Don't close the program
  360. Console.WriteLine("All unit tests have passed.");
  361. Console.ReadLine();
  362. }
  363. }
  364. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement