ThicknessTests.cs 32 KB

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