public void BasicConstructorTest()
        {
            Random r      = new Random();
            int    width  = r.Next(20);
            int    height = r.Next(20);
            int    scale  = r.Next(20);

            // Create a new random grid
            DrawingGrid grid = new DrawingGrid(width, height, scale);

            // Verify that the grid maintains the correct parameters
            AreEqual(grid.Scale, scale);
            AreEqual(grid.size.Width, width);
            AreEqual(grid.size.Height, height);
            AreEqual(grid.Grid.GetLength(0), width);
            AreEqual(grid.Grid.GetLength(1), height);

            // Verify that the interior grid is entirely the default color
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    AreEqual(grid.GetCell(x, y), Color.White);
                }
            }
        }
        public void NativeScalingTest()
        {
            // Generate a randomly scaled 20 x 20 bitmap

            Random r           = new Random();
            int    nativeScale = r.Next(2, 11);
            Bitmap bmp         = new Bitmap(20 * nativeScale, 20 * nativeScale);
            string pngPath     = "NativeScalingTest.png";

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.FromArgb(r.Next()));
                }
            }

            // Save as a .png temporarily
            FileStream bmpFile = new FileStream(pngPath, FileMode.Create);

            BitmapConverters.SaveBitmapAsPNG(bmp, bmpFile);
            bmpFile.Close();

            // Convert the saved png back into a bitmap
            FileStream pngFile = new FileStream(pngPath, FileMode.Open);

            // Create a grid from the png saved
            DrawingGrid grid = new DrawingGrid(pngFile, 2, nativeScale);

            pngFile.Close();

            // Clean up png
            if (File.Exists(pngPath))
            {
                File.Delete(pngPath);
            }

            // Verify that the grid maintains the same parameters
            AreEqual(grid.Scale, 2);
            AreEqual(grid.size.Width, 20);
            AreEqual(grid.size.Height, 20);
            AreEqual(grid.Grid.GetLength(0), 20);
            AreEqual(grid.Grid.GetLength(1), 20);

            // Verify that the interior grid has the same colors as the bitmap saved
            for (int x = 0; x < 20; x++)
            {
                for (int y = 0; y < 20; y++)
                {
                    AreEqual(grid.GetCell(x, y), bmp.GetPixel(x * nativeScale, y * nativeScale));
                }
            }
        }
        public void ClearRegionTest()
        {
            // Generate a random 20 x 20 bitmap
            Bitmap bmp = new Bitmap(20, 20);
            Random r   = new Random();

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.FromArgb(255, Color.FromArgb(r.Next())));
                }
            }

            // Initialize a grid of the random bitmap
            DrawingGrid grid = new DrawingGrid(bmp, 10, 1);

            // Generate a random inbounds rectangle
            Rectangle inBounds = new Rectangle(0, 0, r.Next(20), r.Next(20));

            // Clear the region
            grid.ClearRegion(inBounds);

            // Verify that the region was actually cleared
            for (int x = 0; x < inBounds.Width; x++)
            {
                for (int y = 0; y < inBounds.Height; y++)
                {
                    AreEqual(grid.GetCell(x, y), Color.White);
                }
            }

            // Now Generate a random out of bounds rectangle
            Rectangle outBounds = new Rectangle(r.Next(5, 10), r.Next(5, 10), 20, 20);

            // Clear that region
            grid = new DrawingGrid(bmp, 10, 1);
            grid.ClearRegion(outBounds);

            // Verify that the region was cleared
            for (int x = 0; x < inBounds.Width; x++)
            {
                for (int y = 0; y < inBounds.Height; y++)
                {
                    if (x + outBounds.X < grid.size.Width && y + outBounds.Y < grid.size.Height)
                    {
                        AreEqual(grid.GetCell(x + outBounds.X, y + outBounds.Y), Color.White);
                    }
                }
            }
        }
 private void copyVerifier(DrawingGrid.GridCell[,] copy, DrawingGrid source)
 {
     for (int x = 0; x < copy.GetLength(0); x++)
     {
         for (int y = 0; y < copy.GetLength(1); y++)
         {
             if (x < source.size.Width && y < source.size.Height)
             {
                 AreEqual(copy[x, y].color, source.GetCell(x, y));
             }
             else
             {
                 AreEqual(copy[x, y].color, Color.White);
             }
         }
     }
 }
        public void PasteRegionTest()
        {
            // Generate a white 20 x 20 bitmap
            Bitmap bmp = new Bitmap(20, 20);
            Random r   = new Random();

            for (int x = 0; x < bmp.Width; x++)
            {
                for (int y = 0; y < bmp.Height; y++)
                {
                    bmp.SetPixel(x, y, Color.White);
                }
            }

            // Generate a grid from the bitmap
            DrawingGrid grid = new DrawingGrid(bmp, 10, 1);

            // Generate a randomly colored 5 x 5 region
            DrawingGrid.GridCell[,] region = new DrawingGrid.GridCell[5, 5];
            for (int x = 0; x < region.GetLength(0); x++)
            {
                for (int y = 0; y < region.GetLength(1); y++)
                {
                    region[x, y] = new DrawingGrid.GridCell(Color.FromArgb(255, Color.FromArgb(r.Next())));
                }
            }

            // Paste the region in at (0,0)
            grid.PasteRegion(0, 0, region);

            // Verify that the region was correctly copied
            for (int x = 0; x < region.GetLength(0); x++)
            {
                for (int y = 0; y < region.GetLength(1); y++)
                {
                    AreEqual(region[x, y].color, grid.GetCell(x, y));
                }
            }
        }
Beispiel #6
0
 /*
  * Gets the color at the specified point
  */
 public Color GetPixel(int x, int y)
 {
     return(Grid.GetCell(x, y));
 }