ThicknessTests.cs 32 KB

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