ThicknessTests.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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. 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. View.Diagnostics |= ViewDiagnosticFlags.Ruler;
  164. t.Draw (r, "Test");
  165. View.Diagnostics = ViewDiagnosticFlags.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. View.Diagnostics |= ViewDiagnosticFlags.Ruler;
  194. t.Draw (r, "Test");
  195. View.Diagnostics = ViewDiagnosticFlags.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. View.Diagnostics |= ViewDiagnosticFlags.Ruler;
  224. t.Draw (r, "Test");
  225. View.Diagnostics = ViewDiagnosticFlags.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. View.Diagnostics |= ViewDiagnosticFlags.Ruler;
  254. t.Draw (r, "Test");
  255. View.Diagnostics = ViewDiagnosticFlags.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. // Test Thickness.GetInside(Rectangle)
  308. [Theory]
  309. [InlineData (0, 0, 10, 10, 1, 1, 8, 8)]
  310. [InlineData (1, 0, 10, 10, 2, 1, 8, 8)]
  311. [InlineData (0, 1, 10, 10, 1, 2, 8, 8)]
  312. public void GetInside_Uniform (int x, int y, int width, int height, int expectedX, int expectedY, int expectedWidth, int expectedHeight)
  313. {
  314. var t = new Thickness (1, 1, 1, 1); // Uniform thickness for simplicity
  315. var r = new Rectangle (x, y, width, height);
  316. Rectangle inside = t.GetInside (r);
  317. Assert.Equal (expectedX, inside.X);
  318. Assert.Equal (expectedY, inside.Y);
  319. Assert.Equal (expectedWidth, inside.Width);
  320. Assert.Equal (expectedHeight, inside.Height);
  321. }
  322. [Fact]
  323. public void GetInsideTests_Mixed_Pos_Neg_Thickness_Non_Empty_Size ()
  324. {
  325. var t = new Thickness (-1, 1, -1, 1);
  326. var r = new Rectangle (0, 0, 3, 3);
  327. Rectangle inside = t.GetInside (r);
  328. Assert.Equal (-1, inside.X);
  329. Assert.Equal (1, inside.Y);
  330. Assert.Equal (5, inside.Width);
  331. Assert.Equal (1, inside.Height);
  332. t = new Thickness (-1, 1, -1, 1);
  333. r = new Rectangle (-1, -1, 3, 3);
  334. inside = t.GetInside (r);
  335. Assert.Equal (-2, inside.X);
  336. Assert.Equal (0, inside.Y);
  337. Assert.Equal (5, inside.Width);
  338. Assert.Equal (1, inside.Height);
  339. t = new Thickness (-1, 1, -1, 1);
  340. r = new Rectangle (1, 1, 3, 3);
  341. inside = t.GetInside (r);
  342. Assert.Equal (0, inside.X);
  343. Assert.Equal (2, inside.Y);
  344. Assert.Equal (5, inside.Width);
  345. Assert.Equal (1, inside.Height);
  346. t = new Thickness (-2, -1, 0, 1);
  347. r = new Rectangle (-1, 0, 50, 60);
  348. inside = t.GetInside (r);
  349. Assert.Equal (-3, inside.X);
  350. Assert.Equal (-1, inside.Y);
  351. Assert.Equal (52, inside.Width);
  352. Assert.Equal (60, inside.Height);
  353. }
  354. [Fact]
  355. public void GetInsideTests_Negative_Thickness_Non_Empty_Size ()
  356. {
  357. var t = new Thickness (-1, -1, -1, -1);
  358. var r = new Rectangle (0, 0, 3, 3);
  359. Rectangle inside = t.GetInside (r);
  360. Assert.Equal (-1, inside.X);
  361. Assert.Equal (-1, inside.Y);
  362. Assert.Equal (5, inside.Width);
  363. Assert.Equal (5, inside.Height);
  364. t = new Thickness (-1, -1, -1, -1);
  365. r = new Rectangle (-1, -1, 3, 3);
  366. inside = t.GetInside (r);
  367. Assert.Equal (-2, inside.X);
  368. Assert.Equal (-2, inside.Y);
  369. Assert.Equal (5, inside.Width);
  370. Assert.Equal (5, inside.Height);
  371. t = new Thickness (-1, -1, -1, -1);
  372. r = new Rectangle (1, 1, 3, 3);
  373. inside = t.GetInside (r);
  374. Assert.Equal (0, inside.X);
  375. Assert.Equal (0, inside.Y);
  376. Assert.Equal (5, inside.Width);
  377. Assert.Equal (5, inside.Height);
  378. t = new Thickness (-1, -2, -3, -4);
  379. r = new Rectangle (-1, 0, 50, 60);
  380. inside = t.GetInside (r);
  381. Assert.Equal (-2, inside.X);
  382. Assert.Equal (-2, inside.Y);
  383. Assert.Equal (54, inside.Width);
  384. Assert.Equal (66, inside.Height);
  385. }
  386. [Fact]
  387. public void GetInsideTests_Positive_Thickness_Non_Empty_Size ()
  388. {
  389. var t = new Thickness (1, 1, 1, 1);
  390. var r = new Rectangle (0, 0, 3, 3);
  391. Rectangle inside = t.GetInside (r);
  392. Assert.Equal (1, inside.X);
  393. Assert.Equal (1, inside.Y);
  394. Assert.Equal (1, inside.Width);
  395. Assert.Equal (1, inside.Height);
  396. t = new Thickness (1, 1, 1, 1);
  397. r = new Rectangle (-1, -1, 3, 3);
  398. inside = t.GetInside (r);
  399. Assert.Equal (0, inside.X);
  400. Assert.Equal (0, inside.Y);
  401. Assert.Equal (1, inside.Width);
  402. Assert.Equal (1, inside.Height);
  403. t = new Thickness (1, 1, 1, 1);
  404. r = new Rectangle (1, 1, 3, 3);
  405. inside = t.GetInside (r);
  406. Assert.Equal (2, inside.X);
  407. Assert.Equal (2, inside.Y);
  408. Assert.Equal (1, inside.Width);
  409. Assert.Equal (1, inside.Height);
  410. t = new Thickness (1, 2, 3, 4);
  411. r = new Rectangle (-1, 0, 50, 60);
  412. inside = t.GetInside (r);
  413. Assert.Equal (0, inside.X);
  414. Assert.Equal (2, inside.Y);
  415. Assert.Equal (46, inside.Width);
  416. Assert.Equal (54, inside.Height);
  417. }
  418. [Fact]
  419. public void GetInsideTests_Positive_Thickness_Too_Small_Rect_Means_Empty_Size ()
  420. {
  421. var t = new Thickness (1, 1, 1, 1);
  422. var r = Rectangle.Empty;
  423. Rectangle inside = t.GetInside (r);
  424. Assert.Equal (1, inside.X);
  425. Assert.Equal (1, inside.Y);
  426. Assert.Equal (0, inside.Width);
  427. Assert.Equal (0, inside.Height);
  428. t = new Thickness (1, 1, 1, 1);
  429. r = new Rectangle (0, 0, 1, 1);
  430. inside = t.GetInside (r);
  431. Assert.Equal (1, inside.X);
  432. Assert.Equal (1, inside.Y);
  433. Assert.Equal (0, inside.Width);
  434. Assert.Equal (0, inside.Height);
  435. t = new Thickness (1, 1, 1, 1);
  436. r = new Rectangle (1, 1, 1, 1);
  437. inside = t.GetInside (r);
  438. Assert.Equal (2, inside.X);
  439. Assert.Equal (2, inside.Y);
  440. Assert.Equal (0, inside.Width);
  441. Assert.Equal (0, inside.Height);
  442. t = new Thickness (1, 1, 1, 1);
  443. r = new Rectangle (0, 0, 1, 0);
  444. inside = t.GetInside (r);
  445. Assert.Equal (1, inside.X);
  446. Assert.Equal (1, inside.Y);
  447. Assert.Equal (0, inside.Width);
  448. Assert.Equal (0, inside.Height);
  449. t = new Thickness (1, 1, 1, 1);
  450. r = new Rectangle (0, 0, 0, 1);
  451. inside = t.GetInside (r);
  452. Assert.Equal (1, inside.X);
  453. Assert.Equal (1, inside.Y);
  454. Assert.Equal (0, inside.Width);
  455. Assert.Equal (0, inside.Height);
  456. t = new Thickness (1, 1, 1, 1);
  457. r = new Rectangle (-1, -1, 0, 1);
  458. inside = t.GetInside (r);
  459. Assert.Equal (0, inside.X);
  460. Assert.Equal (0, inside.Y);
  461. Assert.Equal (0, inside.Width);
  462. Assert.Equal (0, inside.Height);
  463. t = new Thickness (1, 1, 1, 1);
  464. r = new Rectangle (0, 0, 2, 2);
  465. inside = t.GetInside (r);
  466. Assert.Equal (1, inside.X);
  467. Assert.Equal (1, inside.Y);
  468. Assert.Equal (0, inside.Width);
  469. Assert.Equal (0, inside.Height);
  470. t = new Thickness (1, 1, 1, 1);
  471. r = new Rectangle (-1, -1, 2, 2);
  472. inside = t.GetInside (r);
  473. Assert.Equal (0, inside.X);
  474. Assert.Equal (0, inside.Y);
  475. Assert.Equal (0, inside.Width);
  476. Assert.Equal (0, inside.Height);
  477. t = new Thickness (1, 1, 1, 1);
  478. r = new Rectangle (1, 1, 2, 2);
  479. inside = t.GetInside (r);
  480. Assert.Equal (2, inside.X);
  481. Assert.Equal (2, inside.Y);
  482. Assert.Equal (0, inside.Width);
  483. Assert.Equal (0, inside.Height);
  484. t = new Thickness (1, 2, 3, 4);
  485. r = new Rectangle (-1, 0, 4, 6);
  486. inside = t.GetInside (r);
  487. Assert.Equal (0, inside.X);
  488. Assert.Equal (2, inside.Y);
  489. Assert.Equal (0, inside.Width);
  490. Assert.Equal (0, inside.Height);
  491. }
  492. [Fact]
  493. public void GetInsideTests_Zero_Thickness ()
  494. {
  495. var t = new Thickness (0, 0, 0, 0);
  496. var r = Rectangle.Empty;
  497. Rectangle inside = t.GetInside (r);
  498. Assert.Equal (0, inside.X);
  499. Assert.Equal (0, inside.Y);
  500. Assert.Equal (0, inside.Width);
  501. Assert.Equal (0, inside.Height);
  502. t = new Thickness (0, 0, 0, 0);
  503. r = new Rectangle (0, 0, 1, 1);
  504. inside = t.GetInside (r);
  505. Assert.Equal (0, inside.X);
  506. Assert.Equal (0, inside.Y);
  507. Assert.Equal (1, inside.Width);
  508. Assert.Equal (1, inside.Height);
  509. t = new Thickness (0, 0, 0, 0);
  510. r = new Rectangle (1, 1, 1, 1);
  511. inside = t.GetInside (r);
  512. Assert.Equal (1, inside.X);
  513. Assert.Equal (1, inside.Y);
  514. Assert.Equal (1, inside.Width);
  515. Assert.Equal (1, inside.Height);
  516. t = new Thickness (0, 0, 0, 0);
  517. r = new Rectangle (0, 0, 1, 0);
  518. inside = t.GetInside (r);
  519. Assert.Equal (0, inside.X);
  520. Assert.Equal (0, inside.Y);
  521. Assert.Equal (1, inside.Width);
  522. Assert.Equal (0, inside.Height);
  523. t = new Thickness (0, 0, 0, 0);
  524. r = new Rectangle (0, 0, 0, 1);
  525. inside = t.GetInside (r);
  526. Assert.Equal (0, inside.X);
  527. Assert.Equal (0, inside.Y);
  528. Assert.Equal (0, inside.Width);
  529. Assert.Equal (1, inside.Height);
  530. t = new Thickness (0, 0, 0, 0);
  531. r = new Rectangle (-1, -1, 0, 1);
  532. inside = t.GetInside (r);
  533. Assert.Equal (-1, inside.X);
  534. Assert.Equal (-1, inside.Y);
  535. Assert.Equal (0, inside.Width);
  536. Assert.Equal (1, inside.Height);
  537. }
  538. [Fact]
  539. public void Horizontal_get ()
  540. {
  541. var t = new Thickness (1, 2, 3, 4);
  542. Assert.Equal (4, t.Horizontal);
  543. t = new Thickness (0);
  544. Assert.Equal (0, t.Horizontal);
  545. }
  546. [Fact]
  547. public void Horizontal_set ()
  548. {
  549. var t = new Thickness ();
  550. t.Horizontal = 10;
  551. Assert.Equal (10, t.Horizontal);
  552. Assert.Equal (5, t.Left);
  553. Assert.Equal (0, t.Top);
  554. Assert.Equal (5, t.Right);
  555. Assert.Equal (0, t.Bottom);
  556. Assert.Equal (0, t.Vertical);
  557. t.Horizontal = 11;
  558. Assert.Equal (10, t.Horizontal);
  559. Assert.Equal (5, t.Left);
  560. Assert.Equal (0, t.Top);
  561. Assert.Equal (5, t.Right);
  562. Assert.Equal (0, t.Bottom);
  563. Assert.Equal (0, t.Vertical);
  564. t.Horizontal = 1;
  565. Assert.Equal (0, t.Horizontal);
  566. Assert.Equal (0, t.Left);
  567. Assert.Equal (0, t.Top);
  568. Assert.Equal (0, t.Right);
  569. Assert.Equal (0, t.Bottom);
  570. Assert.Equal (0, t.Vertical);
  571. }
  572. [Theory]
  573. [InlineData (0, 0, 10, 10, 3, 3, false)] // Inside the inner rectangle
  574. [InlineData (0, 0, 10, 10, 0, 0, true)] // On corner, in thickness
  575. [InlineData (0, 0, 10, 10, 9, 9, true)] // On opposite corner, in thickness
  576. [InlineData (0, 0, 10, 10, 5, 5, false)] // Inside the inner rectangle
  577. [InlineData (0, 0, 10, 10, -1, -1, false)] // Outside the outer rectangle
  578. [InlineData (0, 0, 0, 0, 3, 3, false)] // Inside the inner rectangle
  579. [InlineData (0, 0, 0, 0, 0, 0, false)] // On corner, in thickness
  580. [InlineData (0, 0, 0, 0, 9, 9, false)] // On opposite corner, in thickness
  581. [InlineData (0, 0, 0, 0, 5, 5, false)] // Inside the inner rectangle
  582. [InlineData (0, 0, 0, 0, -1, -1, false)] // Outside the outer rectangle
  583. [InlineData (1, 1, 10, 10, 1, 1, true)] // On corner, in thickness
  584. [InlineData (1, 1, 10, 10, 10, 10, true)] // On opposite corner, in thickness
  585. [InlineData (1, 1, 10, 10, 6, 6, false)] // Inside the inner rectangle
  586. [InlineData (1, 1, 10, 10, 0, 0, false)] // Outside the outer rectangle
  587. [InlineData (-1, -1, 10, 10, -1, -1, true)] // On corner, in thickness
  588. [InlineData (-1, -1, 10, 10, 8, 8, true)] // On opposite corner, in thickness
  589. [InlineData (-1, -1, 10, 10, 4, 4, false)] // Inside the inner rectangle
  590. [InlineData (-1, -1, 10, 10, -2, -2, false)] // Outside the outer rectangle
  591. public void TestContains_Uniform1 (int x, int y, int width, int height, int pointX, int pointY, bool expected)
  592. {
  593. var rect = new Rectangle (x, y, width, height);
  594. var thickness = new Thickness (1, 1, 1, 1); // Uniform thickness for simplicity
  595. bool result = thickness.Contains (rect, pointX, pointY);
  596. Assert.Equal (expected, result);
  597. }
  598. [Theory]
  599. [InlineData (0, 0, 10, 10, 3, 3, false)] // Inside the inner rectangle
  600. [InlineData (0, 0, 10, 10, 0, 0, true)] // On corner, in thickness
  601. [InlineData (0, 0, 10, 10, 1, 1, true)] // On corner, in thickness
  602. [InlineData (0, 0, 10, 10, 9, 9, true)] // On opposite corner, in thickness
  603. [InlineData (0, 0, 10, 10, 5, 5, false)] // Inside the inner rectangle
  604. [InlineData (0, 0, 10, 10, 8, 8, true)] // On opposite corner, in thickness
  605. [InlineData (0, 0, 10, 10, -1, -1, false)] // Outside the outer rectangle
  606. // Test with a rectangle that is same size as the thickness (inner is empty)
  607. [InlineData (0, 0, 4, 4, 0, 0, true)] // in thickness
  608. [InlineData (0, 0, 4, 4, 1, 1, true)] // in thickness
  609. [InlineData (0, 0, 4, 4, 2, 2, true)] // in thickness
  610. [InlineData (0, 0, 4, 4, 3, 3, true)] // in thickness
  611. [InlineData (0, 0, 4, 4, 5, 5, false)] // outside outer rect
  612. [InlineData (0, 0, 4, 4, 4, 4, false)] // outside outer rect
  613. [InlineData (1, 1, 10, 10, 4, 4, false)] // Inside the inner rectangle
  614. [InlineData (1, 1, 10, 10, 1, 1, true)] // On corner, in thickness
  615. [InlineData (1, 1, 10, 10, 2, 2, true)] // On corner, in thickness
  616. [InlineData (1, 1, 10, 10, 10, 10, true)] // On opposite corner, in thickness
  617. [InlineData (1, 1, 10, 10, 6, 6, false)] // Inside the inner rectangle
  618. [InlineData (1, 1, 10, 10, 9, 9, true)] // On opposite corner, in thickness
  619. [InlineData (1, 1, 10, 10, 0, 0, false)] // Outside the outer rectangle
  620. // Test with a rectangle that is same size as the thickness (inner is empty)
  621. [InlineData (-1, -1, 4, 4, -1, -1, true)] // in thickness
  622. [InlineData (-1, -1, 4, 4, 0, 0, true)] // in thickness
  623. [InlineData (-1, -1, 4, 4, 1, 1, true)] // in thickness
  624. [InlineData (-1, -1, 4, 4, 2, 2, true)] // in thickness
  625. [InlineData (-1, -1, 4, 4, 4, 4, false)] // outside outer rect
  626. [InlineData (-1, -1, 4, 4, 3, 3, false)] // outside outer rect
  627. public void TestContains_Uniform2 (int x, int y, int width, int height, int pointX, int pointY, bool expected)
  628. {
  629. var rect = new Rectangle (x, y, width, height);
  630. var thickness = new Thickness (2, 2, 2, 2); // Uniform thickness for simplicity
  631. bool result = thickness.Contains (rect, pointX, pointY);
  632. Assert.Equal (expected, result);
  633. }
  634. [Theory]
  635. [InlineData (0, 0, 10, 10, 3, 3, false)] // Inside the inner rectangle
  636. [InlineData (0, 0, 10, 10, 0, 0, false)] // On corner, in thickness
  637. [InlineData (0, 0, 10, 10, 9, 9, false)] // On opposite corner, in thickness
  638. [InlineData (0, 0, 10, 10, 5, 5, false)] // Inside the inner rectangle
  639. [InlineData (0, 0, 10, 10, -1, -1, false)] // Outside the outer rectangle
  640. [InlineData (0, 0, 0, 0, 3, 3, false)] // Inside the inner rectangle
  641. [InlineData (0, 0, 0, 0, 0, 0, false)] // On corner, in thickness
  642. [InlineData (0, 0, 0, 0, 9, 9, false)] // On opposite corner, in thickness
  643. [InlineData (0, 0, 0, 0, 5, 5, false)] // Inside the inner rectangle
  644. [InlineData (0, 0, 0, 0, -1, -1, false)] // Outside the outer rectangle
  645. [InlineData (1, 1, 10, 10, 1, 1, false)] // On corner, in thickness
  646. [InlineData (1, 1, 10, 10, 10, 10, false)] // On opposite corner, in thickness
  647. [InlineData (1, 1, 10, 10, 6, 6, false)] // Inside the inner rectangle
  648. [InlineData (1, 1, 10, 10, 0, 0, false)] // Outside the outer rectangle
  649. [InlineData (-1, -1, 10, 10, -1, -1, false)] // On corner, in thickness
  650. [InlineData (-1, -1, 10, 10, 8, 8, false)] // On opposite corner, in thickness
  651. [InlineData (-1, -1, 10, 10, 4, 4, false)] // Inside the inner rectangle
  652. [InlineData (-1, -1, 10, 10, -2, -2, false)] // Outside the outer rectangle
  653. public void TestContains_ZeroThickness (
  654. int x,
  655. int y,
  656. int width,
  657. int height,
  658. int pointX,
  659. int pointY,
  660. bool expected
  661. )
  662. {
  663. var rect = new Rectangle (x, y, width, height);
  664. var thickness = new Thickness (0, 0, 0, 0); // Uniform thickness for simplicity
  665. bool result = thickness.Contains (rect, pointX, pointY);
  666. Assert.Equal (expected, result);
  667. }
  668. [Fact]
  669. public void ToStringTest ()
  670. {
  671. var t = new Thickness (1, 2, 3, 4);
  672. Assert.Equal ("(Left=1,Top=2,Right=3,Bottom=4)", t.ToString ());
  673. }
  674. [Fact]
  675. public void Vertical_get ()
  676. {
  677. var t = new Thickness (1, 2, 3, 4);
  678. Assert.Equal (6, t.Vertical);
  679. t = new Thickness (0);
  680. Assert.Equal (0, t.Vertical);
  681. }
  682. [Fact]
  683. public void Vertical_set ()
  684. {
  685. var t = new Thickness ();
  686. t.Vertical = 10;
  687. Assert.Equal (10, t.Vertical);
  688. Assert.Equal (0, t.Left);
  689. Assert.Equal (5, t.Top);
  690. Assert.Equal (0, t.Right);
  691. Assert.Equal (5, t.Bottom);
  692. Assert.Equal (0, t.Horizontal);
  693. t.Vertical = 11;
  694. Assert.Equal (10, t.Vertical);
  695. Assert.Equal (0, t.Left);
  696. Assert.Equal (5, t.Top);
  697. Assert.Equal (0, t.Right);
  698. Assert.Equal (5, t.Bottom);
  699. Assert.Equal (0, t.Horizontal);
  700. t.Vertical = 1;
  701. Assert.Equal (0, t.Vertical);
  702. Assert.Equal (0, t.Left);
  703. Assert.Equal (0, t.Top);
  704. Assert.Equal (0, t.Right);
  705. Assert.Equal (0, t.Bottom);
  706. Assert.Equal (0, t.Horizontal);
  707. }
  708. // Test Thickness.Add
  709. [Theory]
  710. [InlineData (
  711. 1,
  712. 2,
  713. 3,
  714. 4,
  715. 1,
  716. 2,
  717. 3,
  718. 4,
  719. 2,
  720. 4,
  721. 6,
  722. 8)]
  723. [InlineData (
  724. 1,
  725. 2,
  726. 3,
  727. 4,
  728. 0,
  729. 0,
  730. 0,
  731. 0,
  732. 1,
  733. 2,
  734. 3,
  735. 4)]
  736. [InlineData (
  737. 1,
  738. 2,
  739. 3,
  740. 4,
  741. -1,
  742. -2,
  743. -3,
  744. -4,
  745. 0,
  746. 0,
  747. 0,
  748. 0)]
  749. [InlineData (
  750. 1,
  751. 2,
  752. 3,
  753. 4,
  754. 1,
  755. 1,
  756. 1,
  757. 1,
  758. 2,
  759. 3,
  760. 4,
  761. 5)]
  762. [InlineData (
  763. 1,
  764. 2,
  765. 3,
  766. 4,
  767. 1,
  768. 1,
  769. 1,
  770. 1,
  771. 2,
  772. 3,
  773. 4,
  774. 5)]
  775. public void AddTest (
  776. int left,
  777. int top,
  778. int right,
  779. int bottom,
  780. int left2,
  781. int top2,
  782. int right2,
  783. int bottom2,
  784. int expectedLeft,
  785. int expectedTop,
  786. int expectedRight,
  787. int expectedBottom
  788. )
  789. {
  790. var t = new Thickness (left, top, right, bottom);
  791. var t2 = new Thickness (left2, top2, right2, bottom2);
  792. var result = t.Add (t2);
  793. Assert.Equal (expectedLeft, result.Left);
  794. Assert.Equal (expectedTop, result.Top);
  795. Assert.Equal (expectedRight, result.Right);
  796. Assert.Equal (expectedBottom, result.Bottom);
  797. }
  798. }