ClearRegionOperationTests.cs 1.4 KB

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