using System; using UnitTestSharp; namespace Prism.Glass.UnitTests { public class CheckerboardTests : TestFixture { public class FillTests : TestFixture { private static readonly Color Light = Color.FromArgb(0x11, 0xFF, 0xEE, 0xDD); private static readonly Color Dark = Color.FromArgb(0x22, 0x01, 0x02, 0x03); private static byte[] Board(int width, int height, int cellSize) { var pixels = new byte[Rgba.ByteCount(width, height)]; Checkerboard.Fill(pixels, width, height, cellSize, Light, Dark); return pixels; } public void TheTopLeftCell_IsLight() { CheckEqual("#FFEEDD11", PixelText.At(Board(4, 4, 2), width: 4, column: 0, row: 0)); } public void ACellStaysOneColorAcrossItsWholeArea() { byte[] pixels = Board(4, 4, 2); CheckEqual("#FFEEDD11", PixelText.At(pixels, width: 4, column: 1, row: 1)); } public void TheCellToTheRight_IsDark() { CheckEqual("#01020322", PixelText.At(Board(4, 4, 2), width: 4, column: 2, row: 0)); } public void TheCellBelow_IsDark() { CheckEqual("#01020322", PixelText.At(Board(4, 4, 2), width: 4, column: 0, row: 2)); } public void TheDiagonalCell_IsLightAgain() { CheckEqual("#FFEEDD11", PixelText.At(Board(4, 4, 2), width: 4, column: 3, row: 3)); } public void ACellSizeOfOne_AlternatesEveryPixel() { byte[] pixels = Board(2, 2, 1); CheckEqual("#01020322", PixelText.At(pixels, width: 2, column: 1, row: 0)); CheckEqual("#01020322", PixelText.At(pixels, width: 2, column: 0, row: 1)); CheckEqual("#FFEEDD11", PixelText.At(pixels, width: 2, column: 1, row: 1)); } public void AWidthThatEndsMidCell_StillAlternates() { CheckEqual("#01020322", PixelText.At(Board(3, 2, 2), width: 3, column: 2, row: 0)); } public void ACellSizeOfZero_Throws() { CheckThrow(typeof(ArgumentOutOfRangeException)); Checkerboard.Fill(new byte[16], width: 2, height: 2, cellSize: 0, light: Light, dark: Dark); } public void ABufferOfAnotherLength_Throws() { CheckThrow(typeof(ArgumentException)); Checkerboard.Fill(new byte[15], width: 2, height: 2, cellSize: 1, light: Light, dark: Dark); } } } }