PointTests.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using Terminal.Gui;
  3. using Xunit;
  4. namespace Terminal.Gui.TypeTests {
  5. public class PointTests {
  6. [Fact]
  7. public void Point_New ()
  8. {
  9. var point = new Point ();
  10. Assert.True (point.IsEmpty);
  11. point = new Point (new Size ());
  12. Assert.True (point.IsEmpty);
  13. point = new Point (1, 2);
  14. Assert.False (point.IsEmpty);
  15. point = new Point (-1, -2);
  16. Assert.False (point.IsEmpty);
  17. }
  18. [Fact]
  19. public void Point_SetsValue ()
  20. {
  21. var point = new Point () {
  22. X = 0,
  23. Y = 0
  24. };
  25. Assert.True (point.IsEmpty);
  26. point = new Point () {
  27. X = 1,
  28. Y = 2
  29. };
  30. Assert.False (point.IsEmpty);
  31. point = new Point () {
  32. X = -1,
  33. Y = -2
  34. };
  35. Assert.False (point.IsEmpty);
  36. }
  37. [Fact]
  38. public void Point_Equals ()
  39. {
  40. var point1 = new Point ();
  41. var point2 = new Point ();
  42. Assert.Equal (point1, point2);
  43. point1 = new Point (1, 2);
  44. point2 = new Point (1, 2);
  45. Assert.Equal (point1, point2);
  46. point1 = new Point (1, 2);
  47. point2 = new Point (0, 2);
  48. Assert.NotEqual (point1, point2);
  49. point1 = new Point (1, 2);
  50. point2 = new Point (0, 3);
  51. Assert.NotEqual (point1, point2);
  52. }
  53. [Fact]
  54. public void Point_Size ()
  55. {
  56. var point = new Point (1, 2);
  57. var size = (Size)point;
  58. Assert.False (size.IsEmpty);
  59. point = new Point (-1, 2);
  60. Action action = () => size = (Size)point;
  61. var ex = Assert.Throws<ArgumentException> (action);
  62. Assert.Equal ("Either Width and Height must be greater or equal to 0.", ex.Message);
  63. }
  64. }
  65. }