ThicknessTests.cs 32 KB

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