BitmapPixelChangesTests.cs 2.6 KB

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