public void IfThereIsNoAdjacentIndexes()
        {
            int[] A = new int[] { 1 };

            int result        = AdjacentMaxDistance.Solution(A);
            int expectedValue = -2;

            Assert.AreEqual(expectedValue, result);
        }
        public void MustReturnTheMaxDistance()
        {
            int[] A      = new int[] { 0, -3, 3, -12, 5, -3, 7, -1 };
            int   result = AdjacentMaxDistance.Solution(A);

            // Max Distance: A[1] - A[3] = -3 - (-12) = 9
            int expectedValue = 9;

            Assert.AreEqual(expectedValue, result);
        }
        public void MustReturnTheMaxDistanceForNegativeValues()
        {
            int[] A      = new int[] { 0, -3, -3, -2, -5, -3, -7, -1 };
            int   result = AdjacentMaxDistance.Solution(A);

            // Max Distance: A[1] - A[4] = -3 - (-5) = 2
            int expectedValue = 2;

            Assert.AreEqual(expectedValue, result);
        }
        public void MustReturnTheMaxDistanceForPositiveValues()
        {
            int[] A      = new int[] { 0, 3, 3, 12, 5, 3, 7, 1 };
            int   result = AdjacentMaxDistance.Solution(A);

            // Max Distance: A[3] - A[6] = 12 - 5 = 5
            int expectedValue = 5;

            Assert.AreEqual(expectedValue, result);
        }
        static void Main(string[] args)
        {
            string opcao  = string.Empty;
            var    mat    = new List <int>();
            int    index1 = 0;
            int    index2 = 0;

            Console.WriteLine("Calculate Adjacent Max Distance");
            Console.WriteLine(string.Empty);
            Console.WriteLine("Enter 1 to inform the matrix or 2 to use the existing model?");
            opcao = Console.ReadLine();

            while (opcao != "2")
            {
                if (opcao == "1")
                {
                    ExecutarOpcao1(ref mat);
                }
                else
                {
                    Console.WriteLine(string.Empty);
                    Console.WriteLine("Invalid option");
                    Console.WriteLine(string.Empty);
                    System.Threading.Thread.Sleep(4000);
                    Console.Clear();
                    Console.WriteLine("Enter 1 to inform the matrix or 2 to use the existing model?");
                    opcao = Console.ReadLine();
                }
            }

            if (opcao == "2")
            {
                Console.WriteLine("The example matrix will be:  0 | 3 | 3 | 12 | 5 | 3 | 7 | 1");

                // Matriz Exemplo 2:
                mat.Add(0);
                mat.Add(3);
                mat.Add(3);
                mat.Add(12);
                mat.Add(5);
                mat.Add(3);
                mat.Add(7);
                mat.Add(1);
            }

            do
            {
                Console.WriteLine(string.Empty);
                Console.WriteLine("Enter the first index:");
                opcao = Console.ReadLine();
                int.TryParse(opcao, out index1);

                if (index1 <= 0 || index1 > mat.Count())
                {
                    Console.WriteLine("Invalid option");
                    Console.WriteLine(string.Empty);
                }
            } while (index1 <= 0 || index1 > mat.Count());

            do
            {
                Console.WriteLine(string.Empty);
                Console.WriteLine("Enter the second index:");
                opcao = Console.ReadLine();
                int.TryParse(opcao, out index2);

                if (index2 <= 0 || index2 > mat.Count())
                {
                    Console.WriteLine("Invalid option");
                    Console.WriteLine(string.Empty);
                }
            } while (index2 <= 0 || index2 > mat.Count());


            var distancia = new AdjacentMaxDistance();

            Console.WriteLine($"The maximum distance between the indexes are: { distancia.Solucao(mat, index1 - 1, index2 - 1) }");
        }
        public void MustThrowExceptionIfArrayBiggerThen40000Items()
        {
            int[] A = new int[40001];

            Assert.ThrowsException <System.ArgumentException>(() => AdjacentMaxDistance.Solution(A));
        }