BitmapPixelChangesTests.cs 2.6 KB

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