RectTests.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Xunit;
  2. namespace Avalonia.Base.UnitTests
  3. {
  4. public class RectTests
  5. {
  6. [Fact]
  7. public void Union_Should_Return_Correct_Value_For_Intersecting_Rects()
  8. {
  9. var result = new Rect(0, 0, 100, 100).Union(new Rect(50, 50, 100, 100));
  10. Assert.Equal(new Rect(0, 0, 150, 150), result);
  11. }
  12. [Fact]
  13. public void Union_Should_Return_Correct_Value_For_NonIntersecting_Rects()
  14. {
  15. var result = new Rect(0, 0, 100, 100).Union(new Rect(150, 150, 100, 100));
  16. Assert.Equal(new Rect(0, 0, 250, 250), result);
  17. }
  18. [Fact]
  19. public void Union_Should_Ignore_Empty_This_rect()
  20. {
  21. var result = new Rect(0, 0, 0, 0).Union(new Rect(150, 150, 100, 100));
  22. Assert.Equal(new Rect(150, 150, 100, 100), result);
  23. }
  24. [Fact]
  25. public void Union_Should_Ignore_Empty_Other_rect()
  26. {
  27. var result = new Rect(0, 0, 100, 100).Union(new Rect(150, 150, 0, 0));
  28. Assert.Equal(new Rect(0, 0, 100, 100), result);
  29. }
  30. [Fact]
  31. public void Normalize_Should_Reverse_Negative_Size()
  32. {
  33. var result = new Rect(new Point(100, 100), new Point(0, 0)).Normalize();
  34. Assert.Equal(new Rect(0, 0, 100, 100), result);
  35. }
  36. [Fact]
  37. public void Normalize_Should_Make_Invalid_Rects_Empty()
  38. {
  39. var result = new Rect(
  40. double.NegativeInfinity, double.PositiveInfinity,
  41. double.PositiveInfinity, double.PositiveInfinity)
  42. .Normalize();
  43. Assert.Equal(default, result);
  44. }
  45. }
  46. }