ThicknessTests.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. using System.Text;
  2. using Xunit.Abstractions;
  3. namespace Terminal.Gui.DrawingTests;
  4. public class ThicknessTests (ITestOutputHelper output)
  5. {
  6. [Fact]
  7. public void Constructor_Defaults ()
  8. {
  9. var t = new Thickness ();
  10. Assert.Equal (0, t.Left);
  11. Assert.Equal (0, t.Top);
  12. Assert.Equal (0, t.Right);
  13. Assert.Equal (0, t.Bottom);
  14. }
  15. [Fact]
  16. public void Constructor_params ()
  17. {
  18. var t = new Thickness (1, 2, 3, 4);
  19. Assert.Equal (1, t.Left);
  20. Assert.Equal (2, t.Top);
  21. Assert.Equal (3, t.Right);
  22. Assert.Equal (4, t.Bottom);
  23. t = new Thickness (0, 0, 0, 0);
  24. Assert.Equal (0, t.Left);
  25. Assert.Equal (0, t.Top);
  26. Assert.Equal (0, t.Right);
  27. Assert.Equal (0, t.Bottom);
  28. t = new Thickness (-1, 0, 0, 0);
  29. Assert.Equal (-1, t.Left);
  30. Assert.Equal (0, t.Top);
  31. Assert.Equal (0, t.Right);
  32. Assert.Equal (0, t.Bottom);
  33. }
  34. [Fact]
  35. public void Constructor_Width ()
  36. {
  37. var t = new Thickness (1);
  38. Assert.Equal (1, t.Left);
  39. Assert.Equal (1, t.Top);
  40. Assert.Equal (1, t.Right);
  41. Assert.Equal (1, t.Bottom);
  42. }
  43. [Fact]
  44. [AutoInitShutdown]
  45. public void DrawTests ()
  46. {
  47. ((FakeDriver)Application.Driver!).SetBufferSize (60, 60);
  48. var t = new Thickness (0, 0, 0, 0);
  49. var r = new Rectangle (5, 5, 40, 15);
  50. View.Diagnostics |= ViewDiagnosticFlags.Padding;
  51. Application.Driver?.FillRect (
  52. new Rectangle (0, 0, Application.Driver!.Cols, Application.Driver!.Rows),
  53. (Rune)' '
  54. );
  55. t.Draw (r, "Test");
  56. View.Diagnostics = ViewDiagnosticFlags.Off;
  57. TestHelpers.AssertDriverContentsWithFrameAre (
  58. @"
  59. Test (Left=0,Top=0,Right=0,Bottom=0)",
  60. output
  61. );
  62. t = new Thickness (1, 1, 1, 1);
  63. r = new Rectangle (5, 5, 40, 15);
  64. View.Diagnostics |= ViewDiagnosticFlags.Padding;
  65. Application.Driver?.FillRect (
  66. new Rectangle (0, 0, Application.Driver!.Cols, Application.Driver!.Rows),
  67. (Rune)' '
  68. );
  69. t.Draw (r, "Test");
  70. View.Diagnostics = ViewDiagnosticFlags.Off;
  71. TestHelpers.AssertDriverContentsWithFrameAre (
  72. @"
  73. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  74. T T
  75. T T
  76. T T
  77. T T
  78. T T
  79. T T
  80. T T
  81. T T
  82. T T
  83. T T
  84. T T
  85. T T
  86. T T
  87. TTTest (Left=1,Top=1,Right=1,Bottom=1)TT",
  88. output
  89. );
  90. t = new Thickness (1, 2, 3, 4);
  91. r = new Rectangle (5, 5, 40, 15);
  92. View.Diagnostics |= ViewDiagnosticFlags.Padding;
  93. Application.Driver?.FillRect (
  94. new Rectangle (0, 0, Application.Driver!.Cols, Application.Driver!.Rows),
  95. (Rune)' '
  96. );
  97. t.Draw (r, "Test");
  98. View.Diagnostics = ViewDiagnosticFlags.Off;
  99. TestHelpers.AssertDriverContentsWithFrameAre (
  100. @"
  101. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  102. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  103. T TTT
  104. T TTT
  105. T TTT
  106. T TTT
  107. T TTT
  108. T TTT
  109. T TTT
  110. T TTT
  111. T TTT
  112. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  113. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  114. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  115. TTTest (Left=1,Top=2,Right=3,Bottom=4)TT",
  116. output
  117. );
  118. t = new Thickness (-1, 1, 1, 1);
  119. r = new Rectangle (5, 5, 40, 15);
  120. View.Diagnostics |= ViewDiagnosticFlags.Padding;
  121. Application.Driver?.FillRect (
  122. new Rectangle (0, 0, Application.Driver!.Cols, Application.Driver!.Rows),
  123. (Rune)' '
  124. );
  125. t.Draw (r, "Test");
  126. View.Diagnostics = ViewDiagnosticFlags.Off;
  127. TestHelpers.AssertDriverContentsWithFrameAre (
  128. @"
  129. TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
  130. T
  131. T
  132. T
  133. T
  134. T
  135. T
  136. T
  137. T
  138. T
  139. T
  140. T
  141. T
  142. T
  143. TTest (Left=-1,Top=1,Right=1,Bottom=1)TT",
  144. output
  145. );
  146. }
  147. [Fact]
  148. [AutoInitShutdown]
  149. public void DrawTests_Ruler ()
  150. {
  151. // Add a frame so we can see the ruler
  152. var f = new FrameView { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () };
  153. var top = new Toplevel ();
  154. top.Add (f);
  155. RunState rs = Application.Begin (top);
  156. ((FakeDriver)Application.Driver!).SetBufferSize (45, 20);
  157. var t = new Thickness (0, 0, 0, 0);
  158. var r = new Rectangle (2, 2, 40, 15);
  159. Application.RunIteration (ref rs);
  160. View.Diagnostics |= ViewDiagnosticFlags.Ruler;
  161. t.Draw (r, "Test");
  162. View.Diagnostics = ViewDiagnosticFlags.Off;
  163. TestHelpers.AssertDriverContentsAre (
  164. @"
  165. ┌───────────────────────────────────────────┐
  166. │ │
  167. │ │
  168. │ │
  169. │ │
  170. │ │
  171. │ │
  172. │ │
  173. │ │
  174. │ │
  175. │ │
  176. │ │
  177. │ │
  178. │ │
  179. │ │
  180. │ │
  181. │ │
  182. │ │
  183. │ │
  184. └───────────────────────────────────────────┘",
  185. output
  186. );
  187. t = new Thickness (1, 1, 1, 1);
  188. r = new Rectangle (1, 1, 40, 15);
  189. top.SetNeedsDisplay ();
  190. Application.RunIteration (ref rs);
  191. View.Diagnostics |= ViewDiagnosticFlags.Ruler;
  192. t.Draw (r, "Test");
  193. View.Diagnostics = ViewDiagnosticFlags.Off;
  194. TestHelpers.AssertDriverContentsAre (
  195. @"
  196. ┌───────────────────────────────────────────┐
  197. │|123456789|123456789|123456789|123456789 │
  198. │1 1 │
  199. │2 2 │
  200. │3 3 │
  201. │4 4 │
  202. │5 5 │
  203. │6 6 │
  204. │7 7 │
  205. │8 8 │
  206. │9 9 │
  207. │- - │
  208. │1 1 │
  209. │2 2 │
  210. │3 3 │
  211. │|123456789|123456789|123456789|123456789 │
  212. │ │
  213. │ │
  214. │ │
  215. └───────────────────────────────────────────┘",
  216. output
  217. );
  218. t = new Thickness (1, 2, 3, 4);
  219. r = new Rectangle (2, 2, 40, 15);
  220. top.SetNeedsDisplay ();
  221. Application.RunIteration (ref rs);
  222. View.Diagnostics |= ViewDiagnosticFlags.Ruler;
  223. t.Draw (r, "Test");
  224. View.Diagnostics = ViewDiagnosticFlags.Off;
  225. TestHelpers.AssertDriverContentsWithFrameAre (
  226. @"
  227. ┌───────────────────────────────────────────┐
  228. │ │
  229. │ |123456789|123456789|123456789|123456789 │
  230. │ 1 1 │
  231. │ 2 2 │
  232. │ 3 3 │
  233. │ 4 4 │
  234. │ 5 5 │
  235. │ 6 6 │
  236. │ 7 7 │
  237. │ 8 8 │
  238. │ 9 9 │
  239. │ - - │
  240. │ 1 1 │
  241. │ 2 2 │
  242. │ 3 3 │
  243. │ |123456789|123456789|123456789|123456789 │
  244. │ │
  245. │ │
  246. └───────────────────────────────────────────┘",
  247. output
  248. );
  249. t = new Thickness (-1, 1, 1, 1);
  250. r = new Rectangle (5, 5, 40, 15);
  251. top.SetNeedsDisplay ();
  252. Application.RunIteration (ref rs);
  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. top.Dispose ();
  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. [Theory]
  670. [InlineData (0, 0, 0, 0, 0, 0, false)]
  671. [InlineData (0, 0, 0, 1, 0, 0, false)]
  672. [InlineData (0, 0, 1, 0, 0, 0, false)]
  673. [InlineData (0, 0, 1, 1, 0, 0, true)]
  674. [InlineData (1, 1, 0, 0, 0, 0, false)]
  675. [InlineData (1, 1, 0, 1, 0, 0, false)]
  676. [InlineData (1, 1, 1, 0, 0, 0, false)]
  677. [InlineData (1, 1, 1, 0, 0, 1, false)]
  678. [InlineData (1, 1, 1, 1, 1, 0, false)]
  679. [InlineData (1, 1, 1, 1, 1, 1, true)]
  680. public void TestContains_Left_Only (int x, int y, int width, int height, int pointX, int pointY, bool expected)
  681. {
  682. var outside = new Rectangle (x, y, width, height);
  683. var thickness = new Thickness (1, 0, 0, 0);
  684. bool result = thickness.Contains (outside, new (pointX, pointY));
  685. Assert.Equal (expected, result);
  686. }
  687. [Fact]
  688. public void ToStringTest ()
  689. {
  690. var t = new Thickness (1, 2, 3, 4);
  691. Assert.Equal ("(Left=1,Top=2,Right=3,Bottom=4)", t.ToString ());
  692. }
  693. [Fact]
  694. public void Vertical_get ()
  695. {
  696. var t = new Thickness (1, 2, 3, 4);
  697. Assert.Equal (6, t.Vertical);
  698. t = new Thickness (0);
  699. Assert.Equal (0, t.Vertical);
  700. }
  701. [Fact]
  702. public void Vertical_set ()
  703. {
  704. var t = new Thickness ();
  705. t.Vertical = 10;
  706. Assert.Equal (10, t.Vertical);
  707. Assert.Equal (0, t.Left);
  708. Assert.Equal (5, t.Top);
  709. Assert.Equal (0, t.Right);
  710. Assert.Equal (5, t.Bottom);
  711. Assert.Equal (0, t.Horizontal);
  712. t.Vertical = 11;
  713. Assert.Equal (10, t.Vertical);
  714. Assert.Equal (0, t.Left);
  715. Assert.Equal (5, t.Top);
  716. Assert.Equal (0, t.Right);
  717. Assert.Equal (5, t.Bottom);
  718. Assert.Equal (0, t.Horizontal);
  719. t.Vertical = 1;
  720. Assert.Equal (0, t.Vertical);
  721. Assert.Equal (0, t.Left);
  722. Assert.Equal (0, t.Top);
  723. Assert.Equal (0, t.Right);
  724. Assert.Equal (0, t.Bottom);
  725. Assert.Equal (0, t.Horizontal);
  726. }
  727. // Test Thickness.Add
  728. [Theory]
  729. [InlineData (
  730. 1,
  731. 2,
  732. 3,
  733. 4,
  734. 1,
  735. 2,
  736. 3,
  737. 4,
  738. 2,
  739. 4,
  740. 6,
  741. 8)]
  742. [InlineData (
  743. 1,
  744. 2,
  745. 3,
  746. 4,
  747. 0,
  748. 0,
  749. 0,
  750. 0,
  751. 1,
  752. 2,
  753. 3,
  754. 4)]
  755. [InlineData (
  756. 1,
  757. 2,
  758. 3,
  759. 4,
  760. -1,
  761. -2,
  762. -3,
  763. -4,
  764. 0,
  765. 0,
  766. 0,
  767. 0)]
  768. [InlineData (
  769. 1,
  770. 2,
  771. 3,
  772. 4,
  773. 1,
  774. 1,
  775. 1,
  776. 1,
  777. 2,
  778. 3,
  779. 4,
  780. 5)]
  781. public void AddTest (
  782. int left,
  783. int top,
  784. int right,
  785. int bottom,
  786. int left2,
  787. int top2,
  788. int right2,
  789. int bottom2,
  790. int expectedLeft,
  791. int expectedTop,
  792. int expectedRight,
  793. int expectedBottom
  794. )
  795. {
  796. var t = new Thickness (left, top, right, bottom);
  797. var t2 = new Thickness (left2, top2, right2, bottom2);
  798. var result = t.Add (t2);
  799. Assert.Equal (expectedLeft, result.Left);
  800. Assert.Equal (expectedTop, result.Top);
  801. Assert.Equal (expectedRight, result.Right);
  802. Assert.Equal (expectedBottom, result.Bottom);
  803. }
  804. }