Exemple #1
0
        public void Must_Correctly_Evaluate_Diagonal_Rows()
        {
            var expectedMatrix = MatrixExtensions.CreateMatrix(7, 7, _data);
            var diagonalRows   = expectedMatrix.EvaluateDiagonalRows();

            Assert.That(diagonalRows.MaxCharacter, Is.EqualTo("DDDDD"));
        }
Exemple #2
0
        public void Must_Correctly_Evaluate_Vertical_Row()
        {
            var expectedMatrix  = MatrixExtensions.CreateMatrix(7, 7, _data);
            var rowAsString     = expectedMatrix.GetHorizontalOrVertical(4, false);
            var expectedCounter = rowAsString.EvaluateString();

            Assert.That(expectedCounter.Values, Is.EqualTo("DDD"));
            Assert.That(expectedCounter.Count, Is.EqualTo(3));
        }
Exemple #3
0
        public void Must_Correctly_Get_Vertical_Row()
        {
            var expectedMatrix      = MatrixExtensions.CreateMatrix(7, 7, _data);
            var expectedVerticalRow = expectedMatrix.GetHorizontalOrVertical(0, false);

            Assert.That(expectedVerticalRow, Is.EqualTo(_firstVerticalRow));
            expectedVerticalRow = expectedMatrix.GetHorizontalOrVertical(1, false);
            Assert.That(expectedVerticalRow, Is.EqualTo(_secondVerticalRow));
        }
Exemple #4
0
        public void Must_Correctly_Evaluate_Diagonal_Row()
        {
            var pivotX         = 3;
            var pivotY         = 0;
            var expectedMatrix = MatrixExtensions.CreateMatrix(7, 7, _data);
            var diagonalRow    = expectedMatrix.InternalEvaluateDiagonalRow(pivotX, pivotY);

            Assert.That(diagonalRow, Is.EqualTo("RYCA"));
        }
Exemple #5
0
        public void Must_Correctly_Evaluate_Matrix()
        {
            var expectedMatrix = MatrixExtensions.CreateMatrix(7, 7, _data);

            PrintMatrix(expectedMatrix);
            Console.WriteLine("**************************************************");
            var expectedCounterValues = expectedMatrix.EvaluateMatrix();

            Console.WriteLine($"Resultado: {expectedCounterValues.MaxCharacter}");
            Assert.That(expectedCounterValues.MaxCharacter, Is.EqualTo("DDDDD"));
        }
Exemple #6
0
        public void Must_Correctly_Evaluate_Matrix_Horizontal_Character()
        {
            _data = new[] { "1YI3DD3", "2YI3DD3", "3YI3DD3", "9999999", "HYSPE0D", "HYCDDEF", "HXDDDJK" };
            var expectedMatrix = MatrixExtensions.CreateMatrix(7, 7, _data);

            PrintMatrix(expectedMatrix);
            Console.WriteLine("**************************************************");
            var expectedCounterValues = expectedMatrix.EvaluateMatrix();

            Console.WriteLine($"Resultado: {expectedCounterValues.MaxCharacter}");
            Assert.That(expectedCounterValues.MaxCharacter, Is.EqualTo("9999999"));
        }
Exemple #7
0
 public void Must_Evaluate_Correctly_Size(int width, int height, bool isValid)
 {
     if (isValid)
     {
         Assert.DoesNotThrow(() => MatrixExtensions.CreateMatrix(width, height, Array.Empty <string>()));
     }
     else
     {
         var expectedException = Assert.Throws <MatrixInvalidSizeException>(() => MatrixExtensions.CreateMatrix(width, height));
         Assert.IsNotNull(expectedException);
         Assert.That(expectedException.Message, Is.EqualTo($"The Height:{height} and Width: {width} must be greater than 1."));
     }
 }
Exemple #8
0
 public void Must_Evaluate_If_Matrix_Is_Square(int width, int height, bool isValid)
 {
     if (isValid)
     {
         Assert.DoesNotThrow(() => MatrixExtensions.CreateMatrix(width, height, Array.Empty <string>()));
     }
     else
     {
         var expectedException = Assert.Throws <MatrixSquareException>(() => MatrixExtensions.CreateMatrix(width, height));
         Assert.IsNotNull(expectedException);
         Assert.That(expectedException.Message, Is.EqualTo($"It is not a square matrix. The Height: {height} must equal to Width: {width}."));
     }
 }
Exemple #9
0
        public void Must_Correctly_Evaluate_Vertical_Rows()
        {
            var expectedMatrix = MatrixExtensions.CreateMatrix(7, 7, _data);
            var verticalRows   = MatrixExtensions.EvaluateRows(i => expectedMatrix.GetHorizontalOrVertical(i, false));

            Assert.That(verticalRows.MaxCharacter, Is.EqualTo("DDD"));
            var expectedCounter = verticalRows.Values.ToList();

            Assert.That(expectedCounter.Count, Is.EqualTo(4));
            Assert.That(expectedCounter[0].Values, Is.EqualTo("BB"));
            Assert.That(expectedCounter[1].Values, Is.EqualTo("DD"));
            Assert.That(expectedCounter[2].Values, Is.EqualTo("DDD"));
            Assert.That(expectedCounter[3].Values, Is.EqualTo("DD"));
        }
Exemple #10
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Reto: Encuentra la subcadena más larga presente en una matriz");
            var data           = new[] { "BBDADEF", "BXCDDJK", "HYI3DD3", "R7OÑGD2", "WNSPE0D", "A9CDDEF", "BXDDDJK" };
            var expectedMatrix = MatrixExtensions.CreateMatrix(WidthAndHeightMatrix, WidthAndHeightMatrix, data);

            System.Console.WriteLine("---------------------------------------");
            PrintMatrix(expectedMatrix);
            System.Console.WriteLine("---------------------------------------");
            System.Console.WriteLine("Debería devolver la cadena D, D, D, D, D, porque hay una diagonal de D de longitud 5 que es la más larga");
            System.Console.WriteLine("Presione una tecla para evaluar la matrix.");
            System.Console.ReadLine();
            System.Console.WriteLine("Evaluando Matrix  ..........................");

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var counterValues = expectedMatrix.EvaluateMatrix(WidthAndHeightMatrix);

            stopwatch.Stop();
            System.Console.WriteLine($"Resultado: {counterValues.MaxCharacter}, tiempo: {stopwatch.ElapsedMilliseconds} ms. ");
            System.Console.ReadLine();
        }