Pos.CenterTests.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Xunit.Abstractions;
  2. using static Terminal.Gui.Pos;
  3. namespace Terminal.Gui.LayoutTests;
  4. public class PosCenterTests (ITestOutputHelper output)
  5. {
  6. private readonly ITestOutputHelper _output = output;
  7. [Fact]
  8. public void PosCenter_Constructor ()
  9. {
  10. var posCenter = new PosCenter ();
  11. Assert.NotNull (posCenter);
  12. }
  13. [Fact]
  14. public void PosCenter_ToString ()
  15. {
  16. var posCenter = new PosCenter ();
  17. var expectedString = "Center";
  18. Assert.Equal (expectedString, posCenter.ToString ());
  19. }
  20. [Fact]
  21. public void PosCenter_GetAnchor ()
  22. {
  23. var posCenter = new PosCenter ();
  24. var width = 50;
  25. int expectedAnchor = width / 2;
  26. Assert.Equal (expectedAnchor, posCenter.GetAnchor (width));
  27. }
  28. [Fact]
  29. public void PosCenter_CreatesCorrectInstance ()
  30. {
  31. Pos pos = Center ();
  32. Assert.IsType<PosCenter> (pos);
  33. }
  34. [Theory]
  35. [InlineData (10, 2, 4)]
  36. [InlineData (10, 10, 0)]
  37. [InlineData (10, 11, 0)]
  38. [InlineData (10, 12, -1)]
  39. [InlineData (19, 20, 0)]
  40. public void PosCenter_Calculate_ReturnsExpectedValue (int superviewDimension, int width, int expectedX)
  41. {
  42. var posCenter = new PosCenter ();
  43. int result = posCenter.Calculate (superviewDimension, new DimAbsolute (width), null!, Dimension.Width);
  44. Assert.Equal (expectedX, result);
  45. }
  46. [Fact]
  47. public void PosCenter_Bigger_Than_SuperView ()
  48. {
  49. var superView = new View { Width = 10, Height = 10 };
  50. var view = new View { X = Center (), Y = Center (), Width = 20, Height = 20 };
  51. superView.Add (view);
  52. superView.LayoutSubViews ();
  53. Assert.Equal (-5, view.Frame.Left);
  54. Assert.Equal (-5, view.Frame.Top);
  55. }
  56. }