ClearRegionOperationTests.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections.Generic;
  2. using ChunkyImageLib;
  3. using ChunkyImageLib.DataHolders;
  4. using ChunkyImageLib.Operations;
  5. using PixiEditor.DrawingApi.Core.Numerics;
  6. using PixiEditor.Numerics;
  7. using Xunit;
  8. namespace ChunkyImageLibTest;
  9. public class ClearRegionOperationTests
  10. {
  11. const int chunkSize = ChunkPool.FullChunkSize;
  12. [Fact]
  13. public void FindAffectedChunks_SingleChunk_ReturnsSingleChunk()
  14. {
  15. ClearRegionOperation operation = new(new(new(chunkSize, chunkSize), new(chunkSize, chunkSize)));
  16. var expected = new HashSet<VecI>() { new(1, 1) };
  17. var actual = operation.FindAffectedArea(new(chunkSize)).Chunks;
  18. Assert.Equal(expected, actual);
  19. }
  20. // to keep expected aligned
  21. #pragma warning disable format
  22. [Fact]
  23. public void FindAffectedChunks_BigArea_ReturnsCorrectChunks()
  24. {
  25. int from = -chunkSize - chunkSize / 2;
  26. int to = chunkSize + chunkSize / 2;
  27. ClearRegionOperation operation = new(new(new(from, from), new(to - from, to - from)));
  28. var expected = new HashSet<VecI>()
  29. {
  30. new(-2, -2), new(-1, -2), new(0, -2), new(1, -2),
  31. new(-2, -1), new(-1, -1), new(0, -1), new(1, -1),
  32. new(-2, -0), new(-1, -0), new(0, -0), new(1, -0),
  33. new(-2, 1), new(-1, 1), new(0, 1), new(1, 1),
  34. };
  35. var actual = operation.FindAffectedArea(new(chunkSize)).Chunks;
  36. Assert.Equal(expected, actual);
  37. }
  38. #pragma warning restore format
  39. }