static void Main(string[] args) { WriteLine("Program in the PrimeFactors namespace from Program.cs in the PrimeFactorsApp folder"); var Primes = new Primes(); if (args.Length == 0) { WriteLine($"Prime factors for 186 are: {Primes.PrimeFactors(186)}"); } else { bool isNumber = int.TryParse(args[0], out int number); try { if (isNumber && number > 1) { WriteLine($"Prime factors for {number} are: {Primes.PrimeFactors(number)}"); } else { WriteLine($"You entered invalid number to factorise - program stopping."); } } catch (System.Exception ex) { Write($"Exception is {ex.GetType()} with message {ex.Message}"); } } }
static void Main(string[] args) { Write("Enter a number between 1 and 1000: "); if (int.TryParse(ReadLine(), out int number)) { WriteLine(format: "Prime factors of {0} are: {1}", arg0: number, arg1: Primes.PrimeFactors(number)); } }
public void PrimeFactorsOf40() { // arrange int number = 40; string expected = "5 x 2 x 2 x 2"; // act string actual = Primes.PrimeFactors(number); // assert Assert.Equal(expected, actual); }
public void PrimeFactorsOf99() { // arrange int number = 99; string expected = "11 x 3 x 3"; // act string actual = Primes.PrimeFactors(number); // assert Assert.Equal(expected, actual); }
public void TestPrimeFactors2() { // arrange int number = 2; string expected = "2 "; // act string actual = Primes.PrimeFactors(number); // assert Assert.Equal(expected, actual); }