PixelShifterTests.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using DesktopClock.Utilities;
  3. namespace DesktopClock.Tests;
  4. public class PixelShifterTests
  5. {
  6. [Theory]
  7. [InlineData(5, 10)] // Evenly divisible.
  8. [InlineData(3, 10)] // Not evenly divisible.
  9. [InlineData(10, 5)] // Amount is larger than total.
  10. public void ShiftX_ShouldNotExceedMaxTotalShift(int shiftAmount, int maxTotalShift)
  11. {
  12. var shifter = new PixelShifter
  13. {
  14. PixelsPerShift = shiftAmount,
  15. MaxPixelOffset = maxTotalShift,
  16. };
  17. double totalShiftX = 0;
  18. // Test 100 times because it's random.
  19. for (var i = 0; i < 100; i++)
  20. {
  21. var shift = shifter.ShiftX();
  22. totalShiftX += shift;
  23. Assert.InRange(Math.Abs(totalShiftX), 0, maxTotalShift);
  24. }
  25. }
  26. [Theory]
  27. [InlineData(5, 10)] // Evenly divisible.
  28. [InlineData(3, 10)] // Not evenly divisible.
  29. [InlineData(10, 5)] // Amount is larger than total.
  30. public void ShiftY_ShouldNotExceedMaxTotalShift(int shiftAmount, int maxTotalShift)
  31. {
  32. var shifter = new PixelShifter
  33. {
  34. PixelsPerShift = shiftAmount,
  35. MaxPixelOffset = maxTotalShift,
  36. };
  37. double totalShiftY = 0;
  38. // Test 100 times because it's random.
  39. for (var i = 0; i < 100; i++)
  40. {
  41. var shift = shifter.ShiftY();
  42. totalShiftY += shift;
  43. Assert.InRange(Math.Abs(totalShiftY), 0, maxTotalShift);
  44. }
  45. }
  46. }