public void CheckNumber_GivenPrimeNumber_ReturnsRightMessage() { List <int> temp = new List <int>(); int updatedCurrentHighest; Assert.AreEqual("Yep, that's a prime number. It's added to the list", ResponseGenerator.CheckNumber("5", temp, 0, out updatedCurrentHighest)); }
public void CheckNumber_GivenNegativeNumber_ReturnsRightMessage() { List <int> temp = new List <int>(); int updatedCurrentHighest; Assert.AreEqual("No, that's not a prime number", ResponseGenerator.CheckNumber("-7", temp, 0, out updatedCurrentHighest)); }
public void CheckNumber_GivenPrimeNumber_AddsPrimeNumberToList() { List <int> temp = new List <int>(); int updatedCurrentHighest; ResponseGenerator.CheckNumber("5", temp, 0, out updatedCurrentHighest); Assert.AreEqual(1, temp.Count); Assert.AreEqual(5, temp[0]); }
public void CheckNumber_GivenPrimeNumberLargerThanCurrentHighestPrime_UpdatesCurrentHighestPrime() { List <int> temp = new List <int>(); int currentHighestPrime = 5; int updatedCurrentHighest; ResponseGenerator.CheckNumber("7", temp, currentHighestPrime, out updatedCurrentHighest); currentHighestPrime = updatedCurrentHighest; Assert.AreEqual(7, currentHighestPrime); }
static void Main(string[] args) { //Instructions for player Console.WriteLine("Welcome!"); Console.WriteLine("This application can evaluate any number between 0 and 2'147'483'647 and tell you if it is prime or not."); Console.WriteLine("All the prime numbers are saved in a list. You can reffer to the list any time you want."); Console.WriteLine("Your can also get suggestion of next prime number, compared to the current highest prime number in the list."); Console.WriteLine("[1] Evaluate number"); Console.WriteLine("[2] Print prime number list"); Console.WriteLine("[3] Suggest next prime number"); Console.WriteLine("[4] Exit"); //Game loop bool running = true; while (running) { Console.Write(">>"); string input = Console.ReadLine(); //Some methods return a new updated value for CurrentHighestPrime. This variable catches these //values and is used to update the property accordingly. int updatedCurrentHighestPrime; switch (input) { case "1": Console.WriteLine("Type a number"); input = Console.ReadLine(); Console.WriteLine(ResponseGenerator.CheckNumber(input, PrimeNumbers, CurrentHighestPrime, out updatedCurrentHighestPrime)); CurrentHighestPrime = updatedCurrentHighestPrime; break; case "2": Console.WriteLine(ResponseGenerator.PrintPrimeNumberList(PrimeNumbers)); break; case "3": Console.WriteLine(ResponseGenerator.PrintNextPrimeNumber(CurrentHighestPrime, PrimeNumbers, out updatedCurrentHighestPrime)); CurrentHighestPrime = updatedCurrentHighestPrime; break; case "4": Console.WriteLine("Bye bye!"); running = false; break; default: Console.WriteLine("Invalid command"); break; } } }