BitmapPixelChangesTests.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using PixiEditor.Exceptions;
  2. using PixiEditor.Models.DataHolders;
  3. using PixiEditor.Models.Position;
  4. using SkiaSharp;
  5. using Xunit;
  6. namespace PixiEditorTests.ModelsTests.DataHoldersTests
  7. {
  8. public class BitmapPixelChangesTests
  9. {
  10. [Fact]
  11. public void TestThatFromSingleColoredArrayCreatesCorrectArray()
  12. {
  13. Coordinates[] cords = { new Coordinates(0, 0), new Coordinates(1, 0), new Coordinates(3, 2) };
  14. BitmapPixelChanges bmpChanges = BitmapPixelChanges.FromSingleColoredArray(cords, SKColors.Lime);
  15. Assert.All(bmpChanges.ChangedPixels.Values, changeColor => Assert.Equal(SKColors.Lime, changeColor));
  16. Assert.True(bmpChanges.WasBuiltAsSingleColored);
  17. }
  18. [Fact]
  19. public void TestThatCombineCombineOverrideCombinesValues()
  20. {
  21. Coordinates[] cords1 = { new Coordinates(0, 0), new Coordinates(1, 0), new Coordinates(3, 2) };
  22. Coordinates[] cords2 = { new Coordinates(3, 2), new Coordinates(0, 0), new Coordinates(5, 5) };
  23. BitmapPixelChanges changes = BitmapPixelChanges.FromSingleColoredArray(cords1, SKColors.Lime);
  24. BitmapPixelChanges changes2 = BitmapPixelChanges.FromSingleColoredArray(cords2, SKColors.Red);
  25. BitmapPixelChanges output = BitmapPixelChanges.CombineOverride(new[] { changes, changes2 });
  26. Assert.Equal(4, output.ChangedPixels.Count);
  27. Assert.Equal(SKColors.Red, output.ChangedPixels[new Coordinates(3, 2)]);
  28. Assert.Equal(SKColors.Red, output.ChangedPixels[new Coordinates(0, 0)]);
  29. Assert.Equal(SKColors.Lime, output.ChangedPixels[new Coordinates(1, 0)]);
  30. }
  31. [Fact]
  32. public void TestThatFromArraysThrowsError()
  33. {
  34. Assert.Throws<ArrayLengthMismatchException>(
  35. () => BitmapPixelChanges.FromArrays(new[] { new Coordinates(0, 0) }, new[] { SKColors.Red, SKColors.Lime }));
  36. }
  37. [Fact]
  38. public void TestThatFormArraysWorks()
  39. {
  40. Coordinates[] coordinatesArray = { new Coordinates(0, 0), new Coordinates(2, 3), new Coordinates(5, 5) };
  41. SKColor[] colorsArray = { SKColors.Red, SKColors.Lime, SKColors.Blue };
  42. BitmapPixelChanges result = BitmapPixelChanges.FromArrays(coordinatesArray, colorsArray);
  43. for (int i = 0; i < coordinatesArray.Length; i++)
  44. {
  45. Coordinates cords = coordinatesArray[i];
  46. Assert.Equal(colorsArray[i], result.ChangedPixels[cords]);
  47. }
  48. Assert.False(result.WasBuiltAsSingleColored);
  49. }
  50. }
  51. }