GradientTests.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 
  2. namespace Terminal.Gui.DrawingTests;
  3. public class GradientTests
  4. {
  5. // Static method to provide all enum values
  6. public static IEnumerable<object []> GradientDirectionValues ()
  7. {
  8. return typeof (GradientDirection).GetEnumValues ()
  9. .Cast<GradientDirection> ()
  10. .Select (direction => new object [] { direction });
  11. }
  12. [Theory]
  13. [MemberData (nameof (GradientDirectionValues))]
  14. public void GradientIsInclusive_2_by_2 (GradientDirection direction)
  15. {
  16. // Define the colors of the gradient stops
  17. var stops = new List<Color>
  18. {
  19. new Color(255, 0, 0), // Red
  20. new Color(0, 0, 255) // Blue
  21. };
  22. // Define the number of steps between each color
  23. var steps = new List<int> { 10 }; // 10 steps between Red -> Blue
  24. var g = new Gradient (stops, steps, loop: false);
  25. Assert.Equal (4, g.BuildCoordinateColorMapping (1, 1, direction).Count);
  26. }
  27. [Theory]
  28. [MemberData (nameof (GradientDirectionValues))]
  29. public void GradientIsInclusive_1_by_1 (GradientDirection direction)
  30. {
  31. // Define the colors of the gradient stops
  32. var stops = new List<Color>
  33. {
  34. new Color(255, 0, 0), // Red
  35. new Color(0, 0, 255) // Blue
  36. };
  37. // Define the number of steps between each color
  38. var steps = new List<int> { 10 }; // 10 steps between Red -> Blue
  39. var g = new Gradient (stops, steps, loop: false);
  40. // Note that
  41. var c = Assert.Single (g.BuildCoordinateColorMapping (0, 0, direction));
  42. Assert.Equal (c.Key, new Point(0,0));
  43. Assert.Equal (c.Value, new Color (0, 0, 255));
  44. }
  45. }