Esempio n. 1
0
 public void TestFirstNegative()
 {
     // Extend your function to count negatively if the input was negative.
     CollectionAssert.AreEqual(new List <int> {
         -1, -2, -3, -4, -5
     }, RecursiveFunctions.FirstNNaturalNumbers(-5));
 }
Esempio n. 2
0
 public void TestFirstPositive()
 {
     CollectionAssert.AreEqual(new List <int> (), RecursiveFunctions.FirstNNaturalNumbers(0));
     CollectionAssert.AreEqual(new List <int> {
         1, 2, 3, 4, 5
     }, RecursiveFunctions.FirstNNaturalNumbers(5));
 }
Esempio n. 3
0
 public void TestFib()
 {
     //Write a function to return a list of the first n Fibonacci numbers for a given integer.
     //Write it iteratively
     //Write it recursively
     CollectionAssert.AreEqual(new List <int> {
         1, 1, 2, 3, 5, 8
     }, RecursiveFunctions.Fibonacci(6));
 }
Esempio n. 4
0
        public void TestPrime()
        {
            // Write a function that returns a Boolean saying whether a given integer is prime or not using recursion.
            Assert.IsFalse(RecursiveFunctions.IsPrime(1));
            Assert.IsFalse(RecursiveFunctions.IsPrime(100));
            Assert.IsTrue(RecursiveFunctions.IsPrime(2));
            Assert.IsTrue(RecursiveFunctions.IsPrime(17));

            Assert.AreEqual(true, RecursiveFunctions.IsPrime(31));
        }
Esempio n. 5
0
 public void TestSplit()
 {
     // Write a function to return a list of the individual digits of a given integer.
     CollectionAssert.AreEqual(new List <int> {
         1, 2, 3, 4, 5
     }, RecursiveFunctions.Split(12345));
     CollectionAssert.AreEqual(new List <int> {
         3, 7, 0, 9, 4
     }, RecursiveFunctions.Split(37094));
 }
Esempio n. 6
0
        static void Main(string[] args)
        {
            RecursiveFunctions recursiveFunctions = new RecursiveFunctions();
            bool estaRodando = true;

            while (estaRodando)
            {
                Console.WriteLine("0 - Finalizar Programa");
                Console.WriteLine("1- Imprimir Media e Quantidade de elementos maiores que a media");
                Console.WriteLine("2 - Imprimir vetor em ordem inversa");
                Console.WriteLine("3 - Imprimir vetor em ordem");
                int opcaoMenu = Convert.ToInt32(Console.ReadLine());
                switch (opcaoMenu)
                {
                case 0:
                    estaRodando = false;
                    break;

                case 1:
                    int[] valores = recursiveFunctions.funcaoMenu1();
                    Console.WriteLine("A media dos elementos do vetor é {0}", valores[0]);
                    Console.WriteLine("A quantidade de elementos do vetor maiores que a media é {0}", valores[1]);
                    Console.WriteLine();
                    break;

                case 2:
                    recursiveFunctions.printarVetorInverso(0);
                    Console.WriteLine();
                    break;

                case 3:
                    recursiveFunctions.printarVetorOrdem();
                    Console.WriteLine();
                    break;

                default:
                    Console.WriteLine("Selecione uma opcao valida do menu!");
                    Console.WriteLine();
                    break;
                }
            }
        }
 public static bool TestFactorial()
 {
     return(RecursiveFunctions.GetFactorial(5) == 120);
 }
 public static bool TestFibonacci()
 {
     return(RecursiveFunctions.GetFibonacci(7) == 13);
 }