ThicknessTests.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. using System.Text;
  2. using UnitTests;
  3. using Xunit.Abstractions;
  4. namespace UnitTests_Parallelizable.DrawingTests;
  5. public class ThicknessTests (ITestOutputHelper output) : FakeDriverBase
  6. {
  7. [Fact]
  8. public void Constructor_Defaults ()
  9. {
  10. var t = new Thickness ();
  11. Assert.Equal (0, t.Left);
  12. Assert.Equal (0, t.Top);
  13. Assert.Equal (0, t.Right);
  14. Assert.Equal (0, t.Bottom);
  15. }
  16. [Fact]
  17. public void Constructor_params ()
  18. {
  19. var t = new Thickness (1, 2, 3, 4);
  20. Assert.Equal (1, t.Left);
  21. Assert.Equal (2, t.Top);
  22. Assert.Equal (3, t.Right);
  23. Assert.Equal (4, t.Bottom);
  24. t = new (0, 0, 0, 0);
  25. Assert.Equal (0, t.Left);
  26. Assert.Equal (0, t.Top);
  27. Assert.Equal (0, t.Right);
  28. Assert.Equal (0, t.Bottom);
  29. t = new (-1, 0, 0, 0);
  30. Assert.Equal (-1, t.Left);
  31. Assert.Equal (0, t.Top);
  32. Assert.Equal (0, t.Right);
  33. Assert.Equal (0, t.Bottom);
  34. }
  35. [Fact]
  36. public void Constructor_Width ()
  37. {
  38. var t = new Thickness (1);
  39. Assert.Equal (1, t.Left);
  40. Assert.Equal (1, t.Top);
  41. Assert.Equal (1, t.Right);
  42. Assert.Equal (1, t.Bottom);
  43. }
  44. [Fact]
  45. public void Empty_Is_empty ()
  46. {
  47. var t = Thickness.Empty;
  48. Assert.Equal (0, t.Left);
  49. Assert.Equal (0, t.Top);
  50. Assert.Equal (0, t.Right);
  51. Assert.Equal (0, t.Bottom);
  52. }
  53. // TODO: Add more test cases:
  54. // - Negative thickness values
  55. [Fact]
  56. public void EqualsTest ()
  57. {
  58. var t = new Thickness (1, 2, 3, 4);
  59. var t2 = new Thickness (1, 2, 3, 4);
  60. Assert.True (t.Equals (t2));
  61. Assert.True (t == t2);
  62. Assert.False (t != t2);
  63. }
  64. [Fact]
  65. public void GetHashCodeTest ()
  66. {
  67. var t = new Thickness (1, 2, 3, 4);
  68. Assert.Equal (t.GetHashCode (), t.GetHashCode ());
  69. }
  70. // Test Thickness.GetInside(Rectangle)
  71. [Theory]
  72. [InlineData (0, 0, 10, 10, 1, 1, 8, 8)]
  73. [InlineData (1, 0, 10, 10, 2, 1, 8, 8)]
  74. [InlineData (0, 1, 10, 10, 1, 2, 8, 8)]
  75. public void GetInside_Uniform (int x, int y, int width, int height, int expectedX, int expectedY, int expectedWidth, int expectedHeight)
  76. {
  77. var t = new Thickness (1, 1, 1, 1); // Uniform thickness for simplicity
  78. var r = new Rectangle (x, y, width, height);
  79. Rectangle inside = t.GetInside (r);
  80. Assert.Equal (expectedX, inside.X);
  81. Assert.Equal (expectedY, inside.Y);
  82. Assert.Equal (expectedWidth, inside.Width);
  83. Assert.Equal (expectedHeight, inside.Height);
  84. }
  85. [Fact]
  86. public void GetInsideTests_Mixed_Pos_Neg_Thickness_Non_Empty_Size ()
  87. {
  88. var t = new Thickness (-1, 1, -1, 1);
  89. var r = new Rectangle (0, 0, 3, 3);
  90. Rectangle inside = t.GetInside (r);
  91. Assert.Equal (-1, inside.X);
  92. Assert.Equal (1, inside.Y);
  93. Assert.Equal (5, inside.Width);
  94. Assert.Equal (1, inside.Height);
  95. t = new (-1, 1, -1, 1);
  96. r = new (-1, -1, 3, 3);
  97. inside = t.GetInside (r);
  98. Assert.Equal (-2, inside.X);
  99. Assert.Equal (0, inside.Y);
  100. Assert.Equal (5, inside.Width);
  101. Assert.Equal (1, inside.Height);
  102. t = new (-1, 1, -1, 1);
  103. r = new (1, 1, 3, 3);
  104. inside = t.GetInside (r);
  105. Assert.Equal (0, inside.X);
  106. Assert.Equal (2, inside.Y);
  107. Assert.Equal (5, inside.Width);
  108. Assert.Equal (1, inside.Height);
  109. t = new (-2, -1, 0, 1);
  110. r = new (-1, 0, 50, 60);
  111. inside = t.GetInside (r);
  112. Assert.Equal (-3, inside.X);
  113. Assert.Equal (-1, inside.Y);
  114. Assert.Equal (52, inside.Width);
  115. Assert.Equal (60, inside.Height);
  116. }
  117. [Fact]
  118. public void GetInsideTests_Negative_Thickness_Non_Empty_Size ()
  119. {
  120. var t = new Thickness (-1, -1, -1, -1);
  121. var r = new Rectangle (0, 0, 3, 3);
  122. Rectangle inside = t.GetInside (r);
  123. Assert.Equal (-1, inside.X);
  124. Assert.Equal (-1, inside.Y);
  125. Assert.Equal (5, inside.Width);
  126. Assert.Equal (5, inside.Height);
  127. t = new (-1, -1, -1, -1);
  128. r = new (-1, -1, 3, 3);
  129. inside = t.GetInside (r);
  130. Assert.Equal (-2, inside.X);
  131. Assert.Equal (-2, inside.Y);
  132. Assert.Equal (5, inside.Width);
  133. Assert.Equal (5, inside.Height);
  134. t = new (-1, -1, -1, -1);
  135. r = new (1, 1, 3, 3);
  136. inside = t.GetInside (r);
  137. Assert.Equal (0, inside.X);
  138. Assert.Equal (0, inside.Y);
  139. Assert.Equal (5, inside.Width);
  140. Assert.Equal (5, inside.Height);
  141. t = new (-1, -2, -3, -4);
  142. r = new (-1, 0, 50, 60);
  143. inside = t.GetInside (r);
  144. Assert.Equal (-2, inside.X);
  145. Assert.Equal (-2, inside.Y);
  146. Assert.Equal (54, inside.Width);
  147. Assert.Equal (66, inside.Height);
  148. }
  149. [Fact]
  150. public void GetInsideTests_Positive_Thickness_Non_Empty_Size ()
  151. {
  152. var t = new Thickness (1, 1, 1, 1);
  153. var r = new Rectangle (0, 0, 3, 3);
  154. Rectangle inside = t.GetInside (r);
  155. Assert.Equal (1, inside.X);
  156. Assert.Equal (1, inside.Y);
  157. Assert.Equal (1, inside.Width);
  158. Assert.Equal (1, inside.Height);
  159. t = new (1, 1, 1, 1);
  160. r = new (-1, -1, 3, 3);
  161. inside = t.GetInside (r);
  162. Assert.Equal (0, inside.X);
  163. Assert.Equal (0, inside.Y);
  164. Assert.Equal (1, inside.Width);
  165. Assert.Equal (1, inside.Height);
  166. t = new (1, 1, 1, 1);
  167. r = new (1, 1, 3, 3);
  168. inside = t.GetInside (r);
  169. Assert.Equal (2, inside.X);
  170. Assert.Equal (2, inside.Y);
  171. Assert.Equal (1, inside.Width);
  172. Assert.Equal (1, inside.Height);
  173. t = new (1, 2, 3, 4);
  174. r = new (-1, 0, 50, 60);
  175. inside = t.GetInside (r);
  176. Assert.Equal (0, inside.X);
  177. Assert.Equal (2, inside.Y);
  178. Assert.Equal (46, inside.Width);
  179. Assert.Equal (54, inside.Height);
  180. }
  181. [Fact]
  182. public void GetInsideTests_Positive_Thickness_Too_Small_Rect_Means_Empty_Size ()
  183. {
  184. var t = new Thickness (1, 1, 1, 1);
  185. var r = Rectangle.Empty;
  186. Rectangle inside = t.GetInside (r);
  187. Assert.Equal (1, inside.X);
  188. Assert.Equal (1, inside.Y);
  189. Assert.Equal (0, inside.Width);
  190. Assert.Equal (0, inside.Height);
  191. t = new (1, 1, 1, 1);
  192. r = new (0, 0, 1, 1);
  193. inside = t.GetInside (r);
  194. Assert.Equal (1, inside.X);
  195. Assert.Equal (1, inside.Y);
  196. Assert.Equal (0, inside.Width);
  197. Assert.Equal (0, inside.Height);
  198. t = new (1, 1, 1, 1);
  199. r = new (1, 1, 1, 1);
  200. inside = t.GetInside (r);
  201. Assert.Equal (2, inside.X);
  202. Assert.Equal (2, inside.Y);
  203. Assert.Equal (0, inside.Width);
  204. Assert.Equal (0, inside.Height);
  205. t = new (1, 1, 1, 1);
  206. r = new (0, 0, 1, 0);
  207. inside = t.GetInside (r);
  208. Assert.Equal (1, inside.X);
  209. Assert.Equal (1, inside.Y);
  210. Assert.Equal (0, inside.Width);
  211. Assert.Equal (0, inside.Height);
  212. t = new (1, 1, 1, 1);
  213. r = new (0, 0, 0, 1);
  214. inside = t.GetInside (r);
  215. Assert.Equal (1, inside.X);
  216. Assert.Equal (1, inside.Y);
  217. Assert.Equal (0, inside.Width);
  218. Assert.Equal (0, inside.Height);
  219. t = new (1, 1, 1, 1);
  220. r = new (-1, -1, 0, 1);
  221. inside = t.GetInside (r);
  222. Assert.Equal (0, inside.X);
  223. Assert.Equal (0, inside.Y);
  224. Assert.Equal (0, inside.Width);
  225. Assert.Equal (0, inside.Height);
  226. t = new (1, 1, 1, 1);
  227. r = new (0, 0, 2, 2);
  228. inside = t.GetInside (r);
  229. Assert.Equal (1, inside.X);
  230. Assert.Equal (1, inside.Y);
  231. Assert.Equal (0, inside.Width);
  232. Assert.Equal (0, inside.Height);
  233. t = new (1, 1, 1, 1);
  234. r = new (-1, -1, 2, 2);
  235. inside = t.GetInside (r);
  236. Assert.Equal (0, inside.X);
  237. Assert.Equal (0, inside.Y);
  238. Assert.Equal (0, inside.Width);
  239. Assert.Equal (0, inside.Height);
  240. t = new (1, 1, 1, 1);
  241. r = new (1, 1, 2, 2);
  242. inside = t.GetInside (r);
  243. Assert.Equal (2, inside.X);
  244. Assert.Equal (2, inside.Y);
  245. Assert.Equal (0, inside.Width);
  246. Assert.Equal (0, inside.Height);
  247. t = new (1, 2, 3, 4);
  248. r = new (-1, 0, 4, 6);
  249. inside = t.GetInside (r);
  250. Assert.Equal (0, inside.X);
  251. Assert.Equal (2, inside.Y);
  252. Assert.Equal (0, inside.Width);
  253. Assert.Equal (0, inside.Height);
  254. }
  255. [Fact]
  256. public void GetInsideTests_Zero_Thickness ()
  257. {
  258. var t = new Thickness (0, 0, 0, 0);
  259. var r = Rectangle.Empty;
  260. Rectangle inside = t.GetInside (r);
  261. Assert.Equal (0, inside.X);
  262. Assert.Equal (0, inside.Y);
  263. Assert.Equal (0, inside.Width);
  264. Assert.Equal (0, inside.Height);
  265. t = new (0, 0, 0, 0);
  266. r = new (0, 0, 1, 1);
  267. inside = t.GetInside (r);
  268. Assert.Equal (0, inside.X);
  269. Assert.Equal (0, inside.Y);
  270. Assert.Equal (1, inside.Width);
  271. Assert.Equal (1, inside.Height);
  272. t = new (0, 0, 0, 0);
  273. r = new (1, 1, 1, 1);
  274. inside = t.GetInside (r);
  275. Assert.Equal (1, inside.X);
  276. Assert.Equal (1, inside.Y);
  277. Assert.Equal (1, inside.Width);
  278. Assert.Equal (1, inside.Height);
  279. t = new (0, 0, 0, 0);
  280. r = new (0, 0, 1, 0);
  281. inside = t.GetInside (r);
  282. Assert.Equal (0, inside.X);
  283. Assert.Equal (0, inside.Y);
  284. Assert.Equal (1, inside.Width);
  285. Assert.Equal (0, inside.Height);
  286. t = new (0, 0, 0, 0);
  287. r = new (0, 0, 0, 1);
  288. inside = t.GetInside (r);
  289. Assert.Equal (0, inside.X);
  290. Assert.Equal (0, inside.Y);
  291. Assert.Equal (0, inside.Width);
  292. Assert.Equal (1, inside.Height);
  293. t = new (0, 0, 0, 0);
  294. r = new (-1, -1, 0, 1);
  295. inside = t.GetInside (r);
  296. Assert.Equal (-1, inside.X);
  297. Assert.Equal (-1, inside.Y);
  298. Assert.Equal (0, inside.Width);
  299. Assert.Equal (1, inside.Height);
  300. }
  301. [Fact]
  302. public void Horizontal_get ()
  303. {
  304. var t = new Thickness (1, 2, 3, 4);
  305. Assert.Equal (4, t.Horizontal);
  306. t = new (0);
  307. Assert.Equal (0, t.Horizontal);
  308. }
  309. [Fact]
  310. public void Horizontal_set ()
  311. {
  312. var t = new Thickness ();
  313. t.Horizontal = 10;
  314. Assert.Equal (10, t.Horizontal);
  315. Assert.Equal (5, t.Left);
  316. Assert.Equal (0, t.Top);
  317. Assert.Equal (5, t.Right);
  318. Assert.Equal (0, t.Bottom);
  319. Assert.Equal (0, t.Vertical);
  320. t.Horizontal = 11;
  321. Assert.Equal (10, t.Horizontal);
  322. Assert.Equal (5, t.Left);
  323. Assert.Equal (0, t.Top);
  324. Assert.Equal (5, t.Right);
  325. Assert.Equal (0, t.Bottom);
  326. Assert.Equal (0, t.Vertical);
  327. t.Horizontal = 1;
  328. Assert.Equal (0, t.Horizontal);
  329. Assert.Equal (0, t.Left);
  330. Assert.Equal (0, t.Top);
  331. Assert.Equal (0, t.Right);
  332. Assert.Equal (0, t.Bottom);
  333. Assert.Equal (0, t.Vertical);
  334. }
  335. [Theory]
  336. [InlineData (0, 0, 10, 10, 3, 3, false)] // Inside the inner rectangle
  337. [InlineData (0, 0, 10, 10, 0, 0, true)] // On corner, in thickness
  338. [InlineData (0, 0, 10, 10, 9, 9, true)] // On opposite corner, in thickness
  339. [InlineData (0, 0, 10, 10, 5, 5, false)] // Inside the inner rectangle
  340. [InlineData (0, 0, 10, 10, -1, -1, false)] // Outside the outer rectangle
  341. [InlineData (0, 0, 0, 0, 3, 3, false)] // Inside the inner rectangle
  342. [InlineData (0, 0, 0, 0, 0, 0, false)] // On corner, in thickness
  343. [InlineData (0, 0, 0, 0, 9, 9, false)] // On opposite corner, in thickness
  344. [InlineData (0, 0, 0, 0, 5, 5, false)] // Inside the inner rectangle
  345. [InlineData (0, 0, 0, 0, -1, -1, false)] // Outside the outer rectangle
  346. [InlineData (1, 1, 10, 10, 1, 1, true)] // On corner, in thickness
  347. [InlineData (1, 1, 10, 10, 10, 10, true)] // On opposite corner, in thickness
  348. [InlineData (1, 1, 10, 10, 6, 6, false)] // Inside the inner rectangle
  349. [InlineData (1, 1, 10, 10, 0, 0, false)] // Outside the outer rectangle
  350. [InlineData (-1, -1, 10, 10, -1, -1, true)] // On corner, in thickness
  351. [InlineData (-1, -1, 10, 10, 8, 8, true)] // On opposite corner, in thickness
  352. [InlineData (-1, -1, 10, 10, 4, 4, false)] // Inside the inner rectangle
  353. [InlineData (-1, -1, 10, 10, -2, -2, false)] // Outside the outer rectangle
  354. public void TestContains_Uniform1 (int x, int y, int width, int height, int pointX, int pointY, bool expected)
  355. {
  356. var rect = new Rectangle (x, y, width, height);
  357. var thickness = new Thickness (1, 1, 1, 1); // Uniform thickness for simplicity
  358. bool result = thickness.Contains (rect, new (pointX, pointY));
  359. Assert.Equal (expected, result);
  360. }
  361. [Theory]
  362. [InlineData (0, 0, 10, 10, 3, 3, false)] // Inside the inner rectangle
  363. [InlineData (0, 0, 10, 10, 0, 0, true)] // On corner, in thickness
  364. [InlineData (0, 0, 10, 10, 1, 1, true)] // On corner, in thickness
  365. [InlineData (0, 0, 10, 10, 9, 9, true)] // On opposite corner, in thickness
  366. [InlineData (0, 0, 10, 10, 5, 5, false)] // Inside the inner rectangle
  367. [InlineData (0, 0, 10, 10, 8, 8, true)] // On opposite corner, in thickness
  368. [InlineData (0, 0, 10, 10, -1, -1, false)] // Outside the outer rectangle
  369. // Test with a rectangle that is same size as the thickness (inner is empty)
  370. [InlineData (0, 0, 4, 4, 0, 0, true)] // in thickness
  371. [InlineData (0, 0, 4, 4, 1, 1, true)] // in thickness
  372. [InlineData (0, 0, 4, 4, 2, 2, true)] // in thickness
  373. [InlineData (0, 0, 4, 4, 3, 3, true)] // in thickness
  374. [InlineData (0, 0, 4, 4, 5, 5, false)] // outside outer rect
  375. [InlineData (0, 0, 4, 4, 4, 4, false)] // outside outer rect
  376. [InlineData (1, 1, 10, 10, 4, 4, false)] // Inside the inner rectangle
  377. [InlineData (1, 1, 10, 10, 1, 1, true)] // On corner, in thickness
  378. [InlineData (1, 1, 10, 10, 2, 2, true)] // On corner, in thickness
  379. [InlineData (1, 1, 10, 10, 10, 10, true)] // On opposite corner, in thickness
  380. [InlineData (1, 1, 10, 10, 6, 6, false)] // Inside the inner rectangle
  381. [InlineData (1, 1, 10, 10, 9, 9, true)] // On opposite corner, in thickness
  382. [InlineData (1, 1, 10, 10, 0, 0, false)] // Outside the outer rectangle
  383. // Test with a rectangle that is same size as the thickness (inner is empty)
  384. [InlineData (-1, -1, 4, 4, -1, -1, true)] // in thickness
  385. [InlineData (-1, -1, 4, 4, 0, 0, true)] // in thickness
  386. [InlineData (-1, -1, 4, 4, 1, 1, true)] // in thickness
  387. [InlineData (-1, -1, 4, 4, 2, 2, true)] // in thickness
  388. [InlineData (-1, -1, 4, 4, 4, 4, false)] // outside outer rect
  389. [InlineData (-1, -1, 4, 4, 3, 3, false)] // outside outer rect
  390. public void TestContains_Uniform2 (int x, int y, int width, int height, int pointX, int pointY, bool expected)
  391. {
  392. var rect = new Rectangle (x, y, width, height);
  393. var thickness = new Thickness (2, 2, 2, 2); // Uniform thickness for simplicity
  394. bool result = thickness.Contains (rect, new (pointX, pointY));
  395. Assert.Equal (expected, result);
  396. }
  397. [Theory]
  398. [InlineData (0, 0, 10, 10, 3, 3, false)] // Inside the inner rectangle
  399. [InlineData (0, 0, 10, 10, 0, 0, false)] // On corner, in thickness
  400. [InlineData (0, 0, 10, 10, 9, 9, false)] // On opposite corner, in thickness
  401. [InlineData (0, 0, 10, 10, 5, 5, false)] // Inside the inner rectangle
  402. [InlineData (0, 0, 10, 10, -1, -1, false)] // Outside the outer rectangle
  403. [InlineData (0, 0, 0, 0, 3, 3, false)] // Inside the inner rectangle
  404. [InlineData (0, 0, 0, 0, 0, 0, false)] // On corner, in thickness
  405. [InlineData (0, 0, 0, 0, 9, 9, false)] // On opposite corner, in thickness
  406. [InlineData (0, 0, 0, 0, 5, 5, false)] // Inside the inner rectangle
  407. [InlineData (0, 0, 0, 0, -1, -1, false)] // Outside the outer rectangle
  408. [InlineData (1, 1, 10, 10, 1, 1, false)] // On corner, in thickness
  409. [InlineData (1, 1, 10, 10, 10, 10, false)] // On opposite corner, in thickness
  410. [InlineData (1, 1, 10, 10, 6, 6, false)] // Inside the inner rectangle
  411. [InlineData (1, 1, 10, 10, 0, 0, false)] // Outside the outer rectangle
  412. [InlineData (-1, -1, 10, 10, -1, -1, false)] // On corner, in thickness
  413. [InlineData (-1, -1, 10, 10, 8, 8, false)] // On opposite corner, in thickness
  414. [InlineData (-1, -1, 10, 10, 4, 4, false)] // Inside the inner rectangle
  415. [InlineData (-1, -1, 10, 10, -2, -2, false)] // Outside the outer rectangle
  416. public void TestContains_ZeroThickness (
  417. int x,
  418. int y,
  419. int width,
  420. int height,
  421. int pointX,
  422. int pointY,
  423. bool expected
  424. )
  425. {
  426. var rect = new Rectangle (x, y, width, height);
  427. var thickness = new Thickness (0, 0, 0, 0); // Uniform thickness for simplicity
  428. bool result = thickness.Contains (rect, new (pointX, pointY));
  429. Assert.Equal (expected, result);
  430. }
  431. [Theory]
  432. [InlineData (0, 0, 0, 0, 0, 0, false)]
  433. [InlineData (0, 0, 0, 1, 0, 0, false)]
  434. [InlineData (0, 0, 1, 0, 0, 0, false)]
  435. [InlineData (0, 0, 1, 1, 0, 0, true)]
  436. [InlineData (1, 1, 0, 0, 0, 0, false)]
  437. [InlineData (1, 1, 0, 1, 0, 0, false)]
  438. [InlineData (1, 1, 1, 0, 0, 0, false)]
  439. [InlineData (1, 1, 1, 0, 0, 1, false)]
  440. [InlineData (1, 1, 1, 1, 1, 0, false)]
  441. [InlineData (1, 1, 1, 1, 1, 1, true)]
  442. public void TestContains_Left_Only (int x, int y, int width, int height, int pointX, int pointY, bool expected)
  443. {
  444. var outside = new Rectangle (x, y, width, height);
  445. var thickness = new Thickness (1, 0, 0, 0);
  446. bool result = thickness.Contains (outside, new (pointX, pointY));
  447. Assert.Equal (expected, result);
  448. }
  449. [Fact]
  450. public void ToStringTest ()
  451. {
  452. var t = new Thickness (1, 2, 3, 4);
  453. Assert.Equal ("(Left=1,Top=2,Right=3,Bottom=4)", t.ToString ());
  454. }
  455. [Fact]
  456. public void Vertical_get ()
  457. {
  458. var t = new Thickness (1, 2, 3, 4);
  459. Assert.Equal (6, t.Vertical);
  460. t = new (0);
  461. Assert.Equal (0, t.Vertical);
  462. }
  463. [Fact]
  464. public void Vertical_set ()
  465. {
  466. var t = new Thickness ();
  467. t.Vertical = 10;
  468. Assert.Equal (10, t.Vertical);
  469. Assert.Equal (0, t.Left);
  470. Assert.Equal (5, t.Top);
  471. Assert.Equal (0, t.Right);
  472. Assert.Equal (5, t.Bottom);
  473. Assert.Equal (0, t.Horizontal);
  474. t.Vertical = 11;
  475. Assert.Equal (10, t.Vertical);
  476. Assert.Equal (0, t.Left);
  477. Assert.Equal (5, t.Top);
  478. Assert.Equal (0, t.Right);
  479. Assert.Equal (5, t.Bottom);
  480. Assert.Equal (0, t.Horizontal);
  481. t.Vertical = 1;
  482. Assert.Equal (0, t.Vertical);
  483. Assert.Equal (0, t.Left);
  484. Assert.Equal (0, t.Top);
  485. Assert.Equal (0, t.Right);
  486. Assert.Equal (0, t.Bottom);
  487. Assert.Equal (0, t.Horizontal);
  488. }
  489. // Test Thickness.Add
  490. [Theory]
  491. [InlineData (
  492. 1,
  493. 2,
  494. 3,
  495. 4,
  496. 1,
  497. 2,
  498. 3,
  499. 4,
  500. 2,
  501. 4,
  502. 6,
  503. 8)]
  504. [InlineData (
  505. 1,
  506. 2,
  507. 3,
  508. 4,
  509. 0,
  510. 0,
  511. 0,
  512. 0,
  513. 1,
  514. 2,
  515. 3,
  516. 4)]
  517. [InlineData (
  518. 1,
  519. 2,
  520. 3,
  521. 4,
  522. -1,
  523. -2,
  524. -3,
  525. -4,
  526. 0,
  527. 0,
  528. 0,
  529. 0)]
  530. [InlineData (
  531. 1,
  532. 2,
  533. 3,
  534. 4,
  535. 1,
  536. 1,
  537. 1,
  538. 1,
  539. 2,
  540. 3,
  541. 4,
  542. 5)]
  543. public void AddTest (
  544. int left,
  545. int top,
  546. int right,
  547. int bottom,
  548. int left2,
  549. int top2,
  550. int right2,
  551. int bottom2,
  552. int expectedLeft,
  553. int expectedTop,
  554. int expectedRight,
  555. int expectedBottom
  556. )
  557. {
  558. var t = new Thickness (left, top, right, bottom);
  559. var t2 = new Thickness (left2, top2, right2, bottom2);
  560. Thickness result = t.Add (t2);
  561. Assert.Equal (expectedLeft, result.Left);
  562. Assert.Equal (expectedTop, result.Top);
  563. Assert.Equal (expectedRight, result.Right);
  564. Assert.Equal (expectedBottom, result.Bottom);
  565. }
  566. [Fact]
  567. public void DrawTests ()
  568. {
  569. IDriver driver = CreateFakeDriver ();
  570. driver.SetScreenSize (60, 40);
  571. var t = new Thickness (0, 0, 0, 0);
  572. var r = new Rectangle (5, 5, 40, 15);
  573. driver.FillRect (
  574. new (0, 0, driver!.Cols, driver!.Rows),
  575. (Rune)' '
  576. );
  577. t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
  578. DriverAssert.AssertDriverContentsWithFrameAre (
  579. @"
  580. Test (Left=0,Top=0,Right=0,Bottom=0)",
  581. output,
  582. driver
  583. );
  584. t = new (1, 1, 1, 1);
  585. r = new (5, 5, 40, 15);
  586. driver.FillRect (
  587. new (0, 0, driver!.Cols, driver!.Rows),
  588. (Rune)' '
  589. );
  590. t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
  591. DriverAssert.AssertDriverContentsWithFrameAre (
  592. @"
  593. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  594. T T
  595. T T
  596. T T
  597. T T
  598. T T
  599. T T
  600. T T
  601. T T
  602. T T
  603. T T
  604. T T
  605. T T
  606. T T
  607. TTTest (Left=1,Top=1,Right=1,Bottom=1)TT",
  608. output,
  609. driver
  610. );
  611. t = new (1, 2, 3, 4);
  612. r = new (5, 5, 40, 15);
  613. driver?.FillRect (
  614. new (0, 0, driver!.Cols, driver!.Rows),
  615. (Rune)' '
  616. );
  617. t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
  618. DriverAssert.AssertDriverContentsWithFrameAre (
  619. @"
  620. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  621. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  622. T TTT
  623. T TTT
  624. T TTT
  625. T TTT
  626. T TTT
  627. T TTT
  628. T TTT
  629. T TTT
  630. T TTT
  631. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  632. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  633. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  634. TTTest (Left=1,Top=2,Right=3,Bottom=4)TT",
  635. output,
  636. driver
  637. );
  638. t = new (-1, 1, 1, 1);
  639. r = new (5, 5, 40, 15);
  640. driver?.FillRect (
  641. new (0, 0, driver!.Cols, driver!.Rows),
  642. (Rune)' '
  643. );
  644. t.Draw (r, ViewDiagnosticFlags.Thickness, "Test", driver);
  645. DriverAssert.AssertDriverContentsWithFrameAre (
  646. @"
  647. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  648. T
  649. T
  650. T
  651. T
  652. T
  653. T
  654. T
  655. T
  656. T
  657. T
  658. T
  659. T
  660. T
  661. TTest (Left=-1,Top=1,Right=1,Bottom=1)TT",
  662. output,
  663. driver
  664. );
  665. }
  666. [Fact]
  667. public void DrawTests_Ruler ()
  668. {
  669. IDriver driver = CreateFakeDriver ();
  670. // Add a frame so we can see the ruler
  671. var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill (), BorderStyle = LineStyle.Single };
  672. f.Driver = driver;
  673. driver.SetScreenSize (45, 20);
  674. var top = new Toplevel () { Width = driver.Cols, Height = driver.Rows };
  675. top.Driver = driver;
  676. top.Add (f);
  677. top.Layout ();
  678. var t = new Thickness (0, 0, 0, 0);
  679. var r = new Rectangle (2, 2, 40, 15);
  680. top.Draw ();
  681. t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
  682. DriverAssert.AssertDriverContentsAre (
  683. @"
  684. ┌───────────────────────────────────────────┐
  685. │ │
  686. │ │
  687. │ │
  688. │ │
  689. │ │
  690. │ │
  691. │ │
  692. │ │
  693. │ │
  694. │ │
  695. │ │
  696. │ │
  697. │ │
  698. │ │
  699. │ │
  700. │ │
  701. │ │
  702. │ │
  703. └───────────────────────────────────────────┘",
  704. output,
  705. driver
  706. );
  707. t = new (1, 1, 1, 1);
  708. r = new (1, 1, 40, 15);
  709. top.SetNeedsDraw ();
  710. top.Draw ();
  711. t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
  712. DriverAssert.AssertDriverContentsAre (
  713. @"
  714. ┌───────────────────────────────────────────┐
  715. │|123456789|123456789|123456789|123456789 │
  716. │1 1 │
  717. │2 2 │
  718. │3 3 │
  719. │4 4 │
  720. │5 5 │
  721. │6 6 │
  722. │7 7 │
  723. │8 8 │
  724. │9 9 │
  725. │- - │
  726. │1 1 │
  727. │2 2 │
  728. │3 3 │
  729. │|123456789|123456789|123456789|123456789 │
  730. │ │
  731. │ │
  732. │ │
  733. └───────────────────────────────────────────┘",
  734. output,
  735. driver
  736. );
  737. t = new (1, 2, 3, 4);
  738. r = new (2, 2, 40, 15);
  739. top.SetNeedsDraw ();
  740. top.Draw ();
  741. t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
  742. DriverAssert.AssertDriverContentsWithFrameAre (
  743. @"
  744. ┌───────────────────────────────────────────┐
  745. │ │
  746. │ |123456789|123456789|123456789|123456789 │
  747. │ 1 1 │
  748. │ 2 2 │
  749. │ 3 3 │
  750. │ 4 4 │
  751. │ 5 5 │
  752. │ 6 6 │
  753. │ 7 7 │
  754. │ 8 8 │
  755. │ 9 9 │
  756. │ - - │
  757. │ 1 1 │
  758. │ 2 2 │
  759. │ 3 3 │
  760. │ |123456789|123456789|123456789|123456789 │
  761. │ │
  762. │ │
  763. └───────────────────────────────────────────┘",
  764. output,
  765. driver
  766. );
  767. t = new (-1, 1, 1, 1);
  768. r = new (5, 5, 40, 15);
  769. top.SetNeedsDraw ();
  770. top.Draw ();
  771. t.Draw (r, ViewDiagnosticFlags.Ruler, "Test", driver);
  772. DriverAssert.AssertDriverContentsWithFrameAre (
  773. @"
  774. ┌───────────────────────────────────────────┐
  775. │ │
  776. │ │
  777. │ │
  778. │ │
  779. │ |123456789|123456789|123456789|123456789
  780. │ 1
  781. │ 2
  782. │ 3
  783. │ 4
  784. │ 5
  785. │ 6
  786. │ 7
  787. │ 8
  788. │ 9
  789. │ -
  790. │ 1
  791. │ 2
  792. │ 3
  793. └────|123456789|123456789|123456789|123456789",
  794. output,
  795. driver
  796. );
  797. top.Dispose ();
  798. }
  799. }