RectTests.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using Xunit;
  3. namespace Terminal.Gui {
  4. public class RectTests {
  5. [Fact]
  6. public void Rect_New ()
  7. {
  8. var rect = new Rect ();
  9. Assert.True (rect.IsEmpty);
  10. rect = new Rect (new Point (), new Size ());
  11. Assert.True (rect.IsEmpty);
  12. rect = new Rect (1, 2, 3, 4);
  13. Assert.False (rect.IsEmpty);
  14. rect = new Rect (-1, -2, 3, 4);
  15. Assert.False (rect.IsEmpty);
  16. Action action = () => new Rect (1, 2, -3, 4);
  17. var ex = Assert.Throws<ArgumentException> (action);
  18. Assert.Equal ("Width must be greater or equal to 0.", ex.Message);
  19. action = () => new Rect (1, 2, 3, -4);
  20. ex = Assert.Throws<ArgumentException> (action);
  21. Assert.Equal ("Height must be greater or equal to 0.", ex.Message);
  22. action = () => new Rect (1, 2, -3, -4);
  23. ex = Assert.Throws<ArgumentException> (action);
  24. Assert.Equal ("Width must be greater or equal to 0.", ex.Message);
  25. }
  26. [Fact]
  27. public void Rect__SetsValue ()
  28. {
  29. var rect = new Rect () {
  30. X = 0,
  31. Y = 0
  32. };
  33. Assert.True (rect.IsEmpty);
  34. rect = new Rect () {
  35. X = -1,
  36. Y = -2
  37. };
  38. Assert.False (rect.IsEmpty);
  39. rect = new Rect () {
  40. Width = 3,
  41. Height = 4
  42. };
  43. Assert.False (rect.IsEmpty);
  44. rect = new Rect () {
  45. X = -1,
  46. Y = -2,
  47. Width = 3,
  48. Height = 4
  49. };
  50. Assert.False (rect.IsEmpty);
  51. Action action = () => {
  52. rect = new Rect () {
  53. X = -1,
  54. Y = -2,
  55. Width = -3,
  56. Height = 4
  57. };
  58. };
  59. var ex = Assert.Throws<ArgumentException> (action);
  60. Assert.Equal ("Width must be greater or equal to 0.", ex.Message);
  61. action = () => {
  62. rect = new Rect () {
  63. X = -1,
  64. Y = -2,
  65. Width = 3,
  66. Height = -4
  67. };
  68. };
  69. ex = Assert.Throws<ArgumentException> (action);
  70. Assert.Equal ("Height must be greater or equal to 0.", ex.Message);
  71. action = () => {
  72. rect = new Rect () {
  73. X = -1,
  74. Y = -2,
  75. Width = -3,
  76. Height = -4
  77. };
  78. };
  79. ex = Assert.Throws<ArgumentException> (action);
  80. Assert.Equal ("Width must be greater or equal to 0.", ex.Message);
  81. }
  82. [Fact]
  83. public void Rect_Equals ()
  84. {
  85. var rect1 = new Rect ();
  86. var rect2 = new Rect ();
  87. Assert.Equal (rect1, rect2);
  88. rect1 = new Rect (1, 2, 3, 4);
  89. rect2 = new Rect (1, 2, 3, 4);
  90. Assert.Equal (rect1, rect2);
  91. rect1 = new Rect (1, 2, 3, 4);
  92. rect2 = new Rect (-1, 2, 3, 4);
  93. Assert.NotEqual (rect1, rect2);
  94. }
  95. }
  96. }