ThicknessTests.cs 32 KB

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