ThicknessTests.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. using System.Text;
  2. using Xunit.Abstractions;
  3. //using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
  4. // Alias Console to MockConsole so we don't accidentally use Console
  5. namespace Terminal.Gui.DrawingTests;
  6. public class ThicknessTests
  7. {
  8. private readonly ITestOutputHelper _output;
  9. public ThicknessTests (ITestOutputHelper output) { _output = output; }
  10. [Fact]
  11. public void Constructor_Defaults ()
  12. {
  13. var t = new Thickness ();
  14. Assert.Equal (0, t.Left);
  15. Assert.Equal (0, t.Top);
  16. Assert.Equal (0, t.Right);
  17. Assert.Equal (0, t.Bottom);
  18. }
  19. [Fact]
  20. public void Constructor_params ()
  21. {
  22. var t = new Thickness (1, 2, 3, 4);
  23. Assert.Equal (1, t.Left);
  24. Assert.Equal (2, t.Top);
  25. Assert.Equal (3, t.Right);
  26. Assert.Equal (4, t.Bottom);
  27. t = new Thickness (0, 0, 0, 0);
  28. Assert.Equal (0, t.Left);
  29. Assert.Equal (0, t.Top);
  30. Assert.Equal (0, t.Right);
  31. Assert.Equal (0, t.Bottom);
  32. t = new Thickness (-1, 0, 0, 0);
  33. Assert.Equal (-1, t.Left);
  34. Assert.Equal (0, t.Top);
  35. Assert.Equal (0, t.Right);
  36. Assert.Equal (0, t.Bottom);
  37. }
  38. [Fact]
  39. public void Constructor_Width ()
  40. {
  41. var t = new Thickness (1);
  42. Assert.Equal (1, t.Left);
  43. Assert.Equal (1, t.Top);
  44. Assert.Equal (1, t.Right);
  45. Assert.Equal (1, t.Bottom);
  46. }
  47. [Fact]
  48. [AutoInitShutdown]
  49. public void DrawTests ()
  50. {
  51. ((FakeDriver)Application.Driver).SetBufferSize (60, 60);
  52. var t = new Thickness (0, 0, 0, 0);
  53. var r = new Rectangle (5, 5, 40, 15);
  54. ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FramePadding;
  55. Application.Driver.FillRect (
  56. new Rectangle (0, 0, Application.Driver.Cols, Application.Driver.Rows),
  57. (Rune)' '
  58. );
  59. t.Draw (r, "Test");
  60. ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
  61. TestHelpers.AssertDriverContentsWithFrameAre (
  62. @"
  63. Test (Left=0,Top=0,Right=0,Bottom=0)",
  64. _output
  65. );
  66. t = new Thickness (1, 1, 1, 1);
  67. r = new Rectangle (5, 5, 40, 15);
  68. ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FramePadding;
  69. Application.Driver.FillRect (
  70. new Rectangle (0, 0, Application.Driver.Cols, Application.Driver.Rows),
  71. (Rune)' '
  72. );
  73. t.Draw (r, "Test");
  74. ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
  75. TestHelpers.AssertDriverContentsWithFrameAre (
  76. @"
  77. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  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. T T
  88. T T
  89. T T
  90. T T
  91. TTTest (Left=1,Top=1,Right=1,Bottom=1)TT",
  92. _output
  93. );
  94. t = new Thickness (1, 2, 3, 4);
  95. r = new Rectangle (5, 5, 40, 15);
  96. ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FramePadding;
  97. Application.Driver.FillRect (
  98. new Rectangle (0, 0, Application.Driver.Cols, Application.Driver.Rows),
  99. (Rune)' '
  100. );
  101. t.Draw (r, "Test");
  102. ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
  103. TestHelpers.AssertDriverContentsWithFrameAre (
  104. @"
  105. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  106. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  107. T TTT
  108. T TTT
  109. T TTT
  110. T TTT
  111. T TTT
  112. T TTT
  113. T TTT
  114. T TTT
  115. T TTT
  116. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  117. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  118. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  119. TTTest (Left=1,Top=2,Right=3,Bottom=4)TT",
  120. _output
  121. );
  122. t = new Thickness (-1, 1, 1, 1);
  123. r = new Rectangle (5, 5, 40, 15);
  124. ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FramePadding;
  125. Application.Driver.FillRect (
  126. new Rectangle (0, 0, Application.Driver.Cols, Application.Driver.Rows),
  127. (Rune)' '
  128. );
  129. t.Draw (r, "Test");
  130. ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
  131. TestHelpers.AssertDriverContentsWithFrameAre (
  132. @"
  133. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  134. T
  135. T
  136. T
  137. T
  138. T
  139. T
  140. T
  141. T
  142. T
  143. T
  144. T
  145. T
  146. T
  147. TTest (Left=-1,Top=1,Right=1,Bottom=1)TT",
  148. _output
  149. );
  150. }
  151. [Fact]
  152. [AutoInitShutdown]
  153. public void DrawTests_Ruler ()
  154. {
  155. // Add a frame so we can see the ruler
  156. var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
  157. Application.Top.Add (f);
  158. Application.Begin (Application.Top);
  159. ((FakeDriver)Application.Driver).SetBufferSize (45, 20);
  160. var t = new Thickness (0, 0, 0, 0);
  161. var r = new Rectangle (2, 2, 40, 15);
  162. Application.Refresh ();
  163. ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FrameRuler;
  164. t.Draw (r, "Test");
  165. ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
  166. TestHelpers.AssertDriverContentsAre (
  167. @"
  168. ┌───────────────────────────────────────────┐
  169. │ │
  170. │ │
  171. │ │
  172. │ │
  173. │ │
  174. │ │
  175. │ │
  176. │ │
  177. │ │
  178. │ │
  179. │ │
  180. │ │
  181. │ │
  182. │ │
  183. │ │
  184. │ │
  185. │ │
  186. │ │
  187. └───────────────────────────────────────────┘",
  188. _output
  189. );
  190. t = new Thickness (1, 1, 1, 1);
  191. r = new Rectangle (1, 1, 40, 15);
  192. Application.Refresh ();
  193. ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FrameRuler;
  194. t.Draw (r, "Test");
  195. ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
  196. TestHelpers.AssertDriverContentsAre (
  197. @"
  198. ┌───────────────────────────────────────────┐
  199. │|123456789|123456789|123456789|123456789 │
  200. │1 1 │
  201. │2 2 │
  202. │3 3 │
  203. │4 4 │
  204. │5 5 │
  205. │6 6 │
  206. │7 7 │
  207. │8 8 │
  208. │9 9 │
  209. │- - │
  210. │1 1 │
  211. │2 2 │
  212. │3 3 │
  213. │|123456789|123456789|123456789|123456789 │
  214. │ │
  215. │ │
  216. │ │
  217. └───────────────────────────────────────────┘",
  218. _output
  219. );
  220. t = new Thickness (1, 2, 3, 4);
  221. r = new Rectangle (2, 2, 40, 15);
  222. Application.Refresh ();
  223. ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FrameRuler;
  224. t.Draw (r, "Test");
  225. ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
  226. TestHelpers.AssertDriverContentsWithFrameAre (
  227. @"
  228. ┌───────────────────────────────────────────┐
  229. │ │
  230. │ |123456789|123456789|123456789|123456789 │
  231. │ 1 1 │
  232. │ 2 2 │
  233. │ 3 3 │
  234. │ 4 4 │
  235. │ 5 5 │
  236. │ 6 6 │
  237. │ 7 7 │
  238. │ 8 8 │
  239. │ 9 9 │
  240. │ - - │
  241. │ 1 1 │
  242. │ 2 2 │
  243. │ 3 3 │
  244. │ |123456789|123456789|123456789|123456789 │
  245. │ │
  246. │ │
  247. └───────────────────────────────────────────┘",
  248. _output
  249. );
  250. t = new Thickness (-1, 1, 1, 1);
  251. r = new Rectangle (5, 5, 40, 15);
  252. Application.Refresh ();
  253. ConsoleDriver.Diagnostics |= ConsoleDriver.DiagnosticFlags.FrameRuler;
  254. t.Draw (r, "Test");
  255. ConsoleDriver.Diagnostics = ConsoleDriver.DiagnosticFlags.Off;
  256. TestHelpers.AssertDriverContentsWithFrameAre (
  257. @"
  258. ┌───────────────────────────────────────────┐
  259. │ │
  260. │ │
  261. │ │
  262. │ │
  263. │ |123456789|123456789|123456789|123456789
  264. │ 1
  265. │ 2
  266. │ 3
  267. │ 4
  268. │ 5
  269. │ 6
  270. │ 7
  271. │ 8
  272. │ 9
  273. │ -
  274. │ 1
  275. │ 2
  276. │ 3
  277. └────|123456789|123456789|123456789|123456789",
  278. _output
  279. );
  280. }
  281. [Fact]
  282. public void Empty_Is_empty ()
  283. {
  284. var t = Thickness.Empty;
  285. Assert.Equal (0, t.Left);
  286. Assert.Equal (0, t.Top);
  287. Assert.Equal (0, t.Right);
  288. Assert.Equal (0, t.Bottom);
  289. }
  290. // TODO: Add more test cases:
  291. // - Negative thickness values
  292. [Fact]
  293. public void EqualsTest ()
  294. {
  295. var t = new Thickness (1, 2, 3, 4);
  296. var t2 = new Thickness (1, 2, 3, 4);
  297. Assert.True (t.Equals (t2));
  298. Assert.True (t == t2);
  299. Assert.False (t != t2);
  300. }
  301. [Fact]
  302. public void GetHashCodeTest ()
  303. {
  304. var t = new Thickness (1, 2, 3, 4);
  305. Assert.Equal (t.GetHashCode (), t.GetHashCode ());
  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, 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, 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, pointX, pointY);
  651. Assert.Equal (expected, result);
  652. }
  653. [Fact]
  654. public void ToStringTest ()
  655. {
  656. var t = new Thickness (1, 2, 3, 4);
  657. Assert.Equal ("(Left=1,Top=2,Right=3,Bottom=4)", t.ToString ());
  658. }
  659. [Fact]
  660. public void Vertical_get ()
  661. {
  662. var t = new Thickness (1, 2, 3, 4);
  663. Assert.Equal (6, t.Vertical);
  664. t = new Thickness (0);
  665. Assert.Equal (0, t.Vertical);
  666. }
  667. [Fact]
  668. public void Vertical_set ()
  669. {
  670. var t = new Thickness ();
  671. t.Vertical = 10;
  672. Assert.Equal (10, t.Vertical);
  673. Assert.Equal (0, t.Left);
  674. Assert.Equal (5, t.Top);
  675. Assert.Equal (0, t.Right);
  676. Assert.Equal (5, t.Bottom);
  677. Assert.Equal (0, t.Horizontal);
  678. t.Vertical = 11;
  679. Assert.Equal (10, t.Vertical);
  680. Assert.Equal (0, t.Left);
  681. Assert.Equal (5, t.Top);
  682. Assert.Equal (0, t.Right);
  683. Assert.Equal (5, t.Bottom);
  684. Assert.Equal (0, t.Horizontal);
  685. t.Vertical = 1;
  686. Assert.Equal (0, t.Vertical);
  687. Assert.Equal (0, t.Left);
  688. Assert.Equal (0, t.Top);
  689. Assert.Equal (0, t.Right);
  690. Assert.Equal (0, t.Bottom);
  691. Assert.Equal (0, t.Horizontal);
  692. }
  693. }