PointTests.cs 1.5 KB

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