Ejemplo n.º 1
0
 public void FibonacciShouldPrintFirstNumber()
 {
     PrimeNumbers primes = new PrimeNumbers();
     int expected = 2;
     int actual = primes.GetFirst();
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 2
0
 public void PrimeShouldPrintFirstNumber()
 {
     PrimeNumbers Prime = new PrimeNumbers();
     int expected = 2;
     int actual = Prime.GetFirst();
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 3
0
 public void PrimeisPrime()
 {
     PrimeNumbers prime = new PrimeNumbers();
     int input = 74;
     bool expected = false;
     bool actual = prime.IsPrime(input);
     Assert.AreEqual(actual, expected);
 }
Ejemplo n.º 4
0
 public void PrimePrintOfSequenceOfNumbers()
 {
     PrimeNumbers primes = new PrimeNumbers();
     int length = 8;
     string expected = "2 3 5 7 11 13 17 19";
     string actual = primes.ToString(primes.GetSequence(length));
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 5
0
 public void PrimeShouldPrintAVariableSequenceOfNumbers()
 {
     PrimeNumbers Prime = new PrimeNumbers();
     int input = 8;
     int[] expected = new int[] { 2, 3, 5, 7, 11, 13, 17, 19 };
     int[] actual = Prime.GetSequence(input);
     CollectionAssert.AreEqual(expected, actual);
 }
Ejemplo n.º 6
0
 public void PrimesShouldPrintNextNumber()
 {
     PrimeNumbers primes = new PrimeNumbers();
     int input = 2;
     int expected = 3;
     int actual = primes.GetNext(input);
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 7
0
 public void PrimeIsPrime()
 {
     PrimeNumbers prime = new PrimeNumbers();
     int input = 73;
     bool expected = true;
     bool actual = prime.IsPrime(input);
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 8
0
 public void PrimePrintSequenceOfNumbers()
 {
     PrimeNumbers Prime = new PrimeNumbers();
     int length = 7;
     string expected = "2 3 5 7 11 13 17";
     string actual = Prime.ToString(Prime.GetSequence(length));
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 9
0
 public void PrimeFindIndexOfElement()
 {
     PrimeNumbers prime = new PrimeNumbers();
     int input = 73;
     int expected = 20;
     int actual = prime.FindIndex(input);
     Assert.AreEqual(expected, actual);
 }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            string prompt = "> ";
            Console.WriteLine("What do you want me to do?");
            Console.Write(prompt);
            string response = Console.ReadLine();
            if (response.ToLower().Contains("numbers"))
            {
                Console.WriteLine("How many?");
                Console.Write(prompt);
                int length;
                string response_length = Console.ReadLine();
                bool parsed = int.TryParse(response_length, out length);
                if (parsed && Convert.ToInt32(response_length) < 1000)
                {
                    if (response.ToLower().Equals("natural numbers"))
                    {
                        NaturalNumbers nats = new NaturalNumbers();
                        Console.WriteLine(nats.ToString(nats.GetSequence(length)));
                    }
                    else if (response.ToLower().Equals("even numbers"))
                    {
                        EvenNumbers even = new EvenNumbers();
                        Console.WriteLine(even.ToString(even.GetSequence(length)));
                    }
                    else if (response.ToLower().Equals("odd numbers"))
                    {
                        OddNumbers odd = new OddNumbers();
                        Console.WriteLine(odd.ToString(odd.GetSequence(length)));
                    }
                    else if (response.ToLower().Equals("fibonacci numbers"))
                    {
                        Fibonacci fib = new Fibonacci();
                        Console.WriteLine(fib.ToString(fib.GetSequence(length)));
                    }
                    else if (response.ToLower().Equals("prime numbers"))
                    {
                        PrimeNumbers prime = new PrimeNumbers();
                        Console.WriteLine(prime.ToString(prime.GetSequence(length)));
                    }
                    else
                    {
                        Console.WriteLine("Whoops!");
                    }

                }
                else {
                    Console.WriteLine("Whoops!");
                }
            }
            else {
                Console.WriteLine("Nope! Do better next time.");
            }
            Console.WriteLine("Press any key to exit.");
            Console.ReadKey();
        }
Ejemplo n.º 11
0
        public void PrimeShouldPrintAVariableSequenceofNumbers()
        {
            PrimeNumbers prime = new PrimeNumbers();

            //Must create instance of the class before testing the class.
            int input = 8;
            int[] expected = new int[] { 2, 3, 5, 7, 11, 13, 17, 19 };
            int[] actual = prime.GetSequence(input);
            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
 public void PrimeFindIndexOfElementFails()
 {
     PrimeNumbers prime = new PrimeNumbers();
     int input = 103;
     prime.FindIndex(input);
 }
Ejemplo n.º 13
0
 public void PrimeEnsureICanCreateClassInstance()
 {
     PrimeNumbers Prime = new PrimeNumbers();
     Assert.IsNotNull(Prime);
 }
Ejemplo n.º 14
0
 public void GetNextNonPrime()
 {
     PrimeNumbers prime = new PrimeNumbers();
     int input = 105;
     prime.GetNext(input);
 }
Ejemplo n.º 15
0
 public void PrimeEnsureICanCreateClassInstance()
 {
     PrimeNumbers prime = new PrimeNumbers();
     //Will have red lines during test writing. It's OK.
     Assert.IsNotNull(prime);
 }
Ejemplo n.º 16
0
 public void PrimeEnsuerICanCreateClassInstance()
 {
     PrimeNumbers primes = new PrimeNumbers();
     Assert.IsNotNull(primes);
 }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            string prompt = "> ";
            Console.WriteLine("What do you want me to do?");
            Console.Write(prompt);
            string response = Console.ReadLine();
            if (response == "natural numbers")
            {
                Console.WriteLine("How many?");
                Console.Write(prompt);
                string response_length = Console.ReadLine();
                int length;
                bool parsed = int.TryParse(response_length, out length);
                if (parsed)
                {
                    NaturalNumbers nats = new NaturalNumbers();
                    Console.WriteLine(nats.ToString(nats.GetSequence(length)));
                }
                else
                {
                    Console.WriteLine("Whoops!");
                }

            }
            if (response == "even numbers") {
                Console.WriteLine("How many?");
                Console.Write(prompt);
                string response_length = Console.ReadLine();
                int length;
                bool parsed = int.TryParse(response_length, out length);
                if (parsed)
                {
                    EvenNumbers even = new EvenNumbers();
                    Console.WriteLine(even.ToString(even.GetSequence(length)));
                }
                else
                {
                    Console.WriteLine("Whoops!");
                }
            }
            if (response == "odd numbers")
            {
                Console.WriteLine("How many?");
                Console.Write(prompt);
                string response_length = Console.ReadLine();
                int length;
                bool parsed = int.TryParse(response_length, out length);
                if (parsed)
                {
                    OddNumbers odd = new OddNumbers();
                    Console.WriteLine(odd.ToString(odd.GetSequence(length)));
                }
                else
                {
                    Console.WriteLine("Whoops!");
                }
            }
            if (response == "fibonacci numbers")
            {
                Console.WriteLine("How many?");
                Console.Write(prompt);
                string response_length = Console.ReadLine();
                int length;
                bool parsed = int.TryParse(response_length, out length);
                if (parsed)
                {
                    FibonacciNumbers fibonacci = new FibonacciNumbers();
                    Console.WriteLine(fibonacci.ToString(fibonacci.GetSequence(length)));
                }
                else
                {
                    Console.WriteLine("Whoops!");
                }
            }
            if (response == "prime numbers")
            {
                Console.WriteLine("How many?");
                Console.Write(prompt);
                string response_length = Console.ReadLine();
                int length;
                bool parsed = int.TryParse(response_length, out length);
                if (parsed)
                {
                    PrimeNumbers prime = new PrimeNumbers();
                    Console.WriteLine(prime.ToString(prime.GetSequence(length)));
                }
                else
                {
                    Console.WriteLine("Whoops!");
                }
            }
            else
            {
                Console.WriteLine("Nope! Do better next time.");
            }
            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
Ejemplo n.º 18
0
 static void Main(string[] args)
 {
     string prompt = "> ";
     string splash = @"         ,/   *
       _,'/_   |
       `("")' ,'/
        _ _,-M-./ /
        \_\_\.   /    __  __       _   _                           _      _
      )"" |  (    |  \/  | __ _| |_| |__  _ __ ___   __ _  __ _(_) ___(_) __ _ _ __
       __/   M   \__ | |\/| |/ _` | __| '_ \| '_ ` _ \ / _` |/ _` | |/ __| |/ _` | '_ \
       \    /|\    / | |  | | (_| | |_| | | | | | | | | (_| | (_| | | (__| | (_| | | | |
        `--'|||`--'  |_|  |_|\__,_|\__|_| |_|_| |_| |_|\__,_|\__, |_|\___|_|\__,_|_| |_|
       ==^==                                             |___/";
     Console.WriteLine(splash);
     Console.WriteLine("What do you want me to do?");
     Console.Write(prompt);
     string[] valid_responses = new string[] { "natural numbers", "even numbers", "odd numbers", "fibonacci numbers", "prime numbers"};
     string response = Console.ReadLine().ToLower();
     if (valid_responses.Contains(response))
     {
         Console.WriteLine("How many?");
         Console.Write(prompt);
         string response_length = Console.ReadLine();
         int length;
         bool parsed = int.TryParse(response_length, out length);
         if (parsed)
         {
             if (response == "natural numbers")
             {
                 NaturalNumbers nats = new NaturalNumbers();
                 Console.WriteLine(nats.ToString(nats.GetSequence(length)));
             }
             if (response == "even numbers")
             {
                 EvenNumbers even = new EvenNumbers();
                 Console.WriteLine(even.ToString(even.GetSequence(length)));
             }
             if (response == "odd numbers")
             {
                 OddNumbers odd = new OddNumbers();
                 Console.WriteLine(odd.ToString(odd.GetSequence(length)));
             }
             if (response == "fibonacci numbers")
             {
                 FibonacciNumbers fibonacci = new FibonacciNumbers();
                 Console.WriteLine(fibonacci.ToString(fibonacci.GetSequence(length)));
             }
             if (response == "prime numbers")
             {
                 PrimeNumbers prime = new PrimeNumbers();
                 Console.WriteLine(prime.ToString(prime.GetSequence(length)));
             }
         }
         else
         {
             Console.WriteLine("Whoops!");
         }
     }
     else
     {
         Console.WriteLine("Nope! Do better next time.");
     }
     Console.Write("Press any key to exit...");
     Console.ReadKey();
 }
Ejemplo n.º 19
0
 static void Main(string[] args)
 {
     string prompt = "> ";
     Console.WriteLine(@"What do you want me to do?
     Natural Numers
     Even Numbers
     Odd Numbers
     Fibonacci Numbers
     Prime Numbers");
     Console.Write(prompt);
     string input = getValidstring();
     Console.WriteLine("How many?");
     int inputInt = getValidInt();
     //if (response.ToLower() == "natural numbers")
     //{
     //    Console.WriteLine("How many?");
     //    Console.Write(prompt);
     //    string response_length = Console.ReadLine();
     //    int length;
     //    bool parsed = int.TryParse(response_length, out length);
     //    if (parsed)
     //    {
     //        NaturalNumbers nats = new NaturalNumbers();
     //        Console.WriteLine(nats.ToString(nats.GetSequence(length)));
     //    }
     //    else
     //    {
     //        Console.WriteLine("Whoops!");
     //    }
     //}
     //else
     //{
     //    Console.WriteLine("Nope! Do better next time.");
     //}
     switch (input.ToLower())
     {
         case "natural numbers":
             NaturalNumbers nats = new NaturalNumbers();
             Console.WriteLine(nats.ToString(nats.GetSequence(inputInt)));
             break;
         case "even numbers":
             EvenNumbers evens = new EvenNumbers();
             Console.WriteLine(evens.ToString(evens.GetSequence(inputInt)));
             break;
         case "odd numbers":
             OddNumbers odds = new OddNumbers();
             Console.WriteLine(odds.ToString(odds.GetSequence(inputInt)));
             break;
         case "fibonacci numbers":
             FibonacciNumbers fibs = new FibonacciNumbers();
             Console.WriteLine(fibs.ToString(fibs.GetSequence(inputInt)));
             break;
         case "prime numbers":
             PrimeNumbers primes = new PrimeNumbers();
             Console.WriteLine(primes.ToString(primes.GetSequence(inputInt)));
             break;
         default:
             Console.WriteLine("Whoops!");
             break;
     }
     Console.WriteLine("Press any key to finish . . .");
     Console.ReadKey();
 }