示例#1
0
 public void setMementoTest()
 {
     Convolution target = new Convolution();
     int[,] expectedMatrix = new int[6, 6];
     Memento memento = new Memento("Conv", new int[6, 6]);
     target.setMemento(memento);
     Assert.IsTrue(target.matrix is int[,], "Memento.state is not a Matrix.");
     int[,] actualMatrix = (int[,])target.getMemento().state;
     for (int dim1 = 0; dim1 < expectedMatrix.GetLength(0); dim1++)
     {
         for (int dim2 = 0; dim2 < expectedMatrix.GetLength(1); dim2++)
         {
             Assert.AreEqual(expectedMatrix[dim1, dim2], actualMatrix[dim1, dim2], "Matrix is not expected matrix.");
         }
     }
 }
示例#2
0
        public static void MyClassInitialize(TestContext testContext)
        {
            Convolution conv = new Convolution();
            testBitmap = new Bitmap(testPixel, testPixel);
            for (int height = 0; height < testBitmap.Height; height++)
            {
                for (int width = 0; width < testBitmap.Width; width++)
                {
                    testBitmap.SetPixel(width, height, Color.White);
                    width++;
                    testBitmap.SetPixel(width, height, Color.Black);
                    width++;
                    testBitmap.SetPixel(width, height, Color.Red);
                    width++;
                    testBitmap.SetPixel(width, height, Color.Green);
                    width++;
                    testBitmap.SetPixel(width, height, Color.Blue);
                }
            }

            //create blur matrix
            int square = 3;
            matrix = new int[square, square];
            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    matrix[i, j] = 1;
                }
            }
            blur = new Memento("Blur", matrix);
            //get blured Bitmap
            original = conv.getMemento();
            conv.setMemento(blur);
            processedBitmap = conv.process(testBitmap);
            conv.setMemento(original);
        }
示例#3
0
 public void processTest()
 {
     Convolution target = new Convolution();
     Bitmap frame = testBitmap;
     Bitmap expected = processedBitmap;
     Bitmap actual;
     target.setMemento(blur);
     actual = target.process(frame);
     for (int height = 0; height < expected.Height; height++)
     {
         for (int width = 0; width < expected.Width; width++)
         {
             Assert.AreEqual(expected.GetPixel(height, width), actual.GetPixel(height, width), "Process is working randomly");
         }
     }
 }