Esempio n. 1
0
        public void RunTest01()
        {
            ZeroMatrix test   = new ZeroMatrix(Test01Matrix);
            var        result = test.Run();

            CollectionAssert.AreEqual(result, Test01Result, new CollectionAssertComperator());
        }
Esempio n. 2
0
        public void Zero2(int[,] input, int[,] expected)
        {
            var solution = new ZeroMatrix();

            var actual = solution.Zero2(input);

            Assert.Equal(expected, actual);
        }
Esempio n. 3
0
        public void ZeroMatrixTest2()
        {
            var input = new int[4, 4];

            input[0, 0] = 0;
            input[0, 1] = 1;
            input[0, 2] = 1;
            input[0, 3] = 1;
            input[1, 0] = 1;
            input[1, 1] = 1;
            input[1, 2] = 1;
            input[1, 3] = 1;
            input[2, 0] = 1;
            input[2, 1] = 1;
            input[2, 2] = 1;
            input[2, 3] = 1;
            input[3, 0] = 1;
            input[3, 1] = 1;
            input[3, 2] = 0;
            input[3, 3] = 1;

            var result = ZeroMatrix.ZeroMatricAlgo(input);

            for (int i = 0; i < result.GetLength(0); i++)
            {
                for (int j = 0; j < result.GetLength(1); j++)
                {
                    if (i == 1 && j == 1)
                    {
                        result[i, j].Should().Be(1);
                    }
                    else if (i == 1 && j == 3)
                    {
                        result[i, j].Should().Be(1);
                    }
                    else if (i == 2 && j == 1)
                    {
                        result[i, j].Should().Be(1);
                    }
                    else if (i == 2 && j == 3)
                    {
                        result[i, j].Should().Be(1);
                    }
                    else
                    {
                        result[i, j].Should().Be(0);
                    }
                }
            }
        }
Esempio n. 4
0
 public void ZeroMatrixTest()
 {
     int[,] matrix = new int[4, 4] {
         { 1, 2, 0, 4 }, { 5, 6, 7, 8 }, { 1, 0, 1, 2 }, { 3, 4, 5, 6 }
     };
     int[,] zeroedMatrix = new int[4, 4] {
         { 0, 0, 0, 0 }, { 5, 0, 0, 8 }, { 0, 0, 0, 0 }, { 3, 0, 0, 6 }
     };
     ZeroMatrix.Solution1(matrix);
     for (int i = 0; i < matrix.GetLength(0); i++)
     {
         for (int j = 0; j < matrix.GetLength(1); j++)
         {
             Assert.AreEqual(zeroedMatrix[i, j], matrix[i, j]);
         }
     }
 }
Esempio n. 5
0
        public void ZeroMatrixTest()
        {
            var input  = TestHelpers.BuildJaggedGridFive();
            var result = ZeroMatrix.Run(input);

            Assert.Equal("1004000090060000", TestHelpers.ToString(result));

            var inputTwo  = TestHelpers.BuildJaggedGridSix();
            var resultTwo = ZeroMatrix.Run(inputTwo);

            Assert.Equal("000000000", TestHelpers.ToString(resultTwo));

            var inputThree  = TestHelpers.BuildJaggedGridSeven();
            var resultThree = ZeroMatrix.Run(inputThree);

            Assert.Equal("120400009806", TestHelpers.ToString(resultThree));
        }
Esempio n. 6
0
        /// <summary>
        /// Initial method - Write an algo such that if an element in an MxN matrix is 0, its entire row and column are set to 0
        /// </summary>
        private static void ZeroMatrixImplementation()
        {
            int[][] matrix = new int[][] {
                new int[] { 0, 1, 2, 0, 4, 5 },
                new int[] { 1, 1, 2, 3, 4, 5 },
                new int[] { 1, 1, 2, 3, 4, 5 },
                new int[] { 1, 1, 2, 3, 4, 5 },
                new int[] { 1, 1, 2, 3, 4, 0 }
            };
            Console.WriteLine($"row = " + matrix.Length + " column = " + matrix[0].Length);

            //ZeroMatrix.ZeroMatrixResult(matrix);
            ZeroMatrix.ZeroMatrixResultBitVector(matrix);

            Console.WriteLine("After setZero:");
            for (int i = 0; i < matrix.Length; i++)
            {
                for (int j = 0; j < matrix[0].Length; j++)
                {
                    Console.WriteLine(matrix[i][j] + " ");
                    Console.WriteLine();
                }
            }
        }
Esempio n. 7
0
 public void Zero(int[,] input, int[,] expected)
 {
     ZeroMatrix.Zero(input);
     Assert.Equal(expected, input);
 }
Esempio n. 8
0
 public void Test(string source, string target)
 {
     Assert.Equal(StringToMatrix(target), ZeroMatrix.Execute(StringToMatrix(source)));
 }
Esempio n. 9
0
 public void Setup()
 {
     zeroMatrix = new ZeroMatrix();
 }
Esempio n. 10
0
 static void Main(string[] args)
 {
     ZeroMatrix.UpdateZeros();
 }