static void Main(string[] args) { PrimeFactors primeFactors = new PrimeFactors(); if (args.Any()) { var path = args[0]; if (File.Exists(path)) { try { using (StreamReader fileReader = new StreamReader(path)) { FileReader fileProcessor = new FileReader(primeFactors, fileReader); fileProcessor.ProcessFile(); } Console.ReadLine(); } catch (Exception e) { Console.Write("The file could not be read: "); Console.WriteLine(e.Message); } } } }
public void TestPrimeNumbersHaveThemselvesAsPrimeFactors() { var primeFactors = new PrimeFactors(2).value(); Assert.IsTrue(primeFactors.SequenceEqual(new List <int> { 2 })); }
public void TestNumbersWithSamePrimeFactorAreFactorizeCorrectly() { var primeFactors = new PrimeFactors(4).value(); Assert.IsTrue(primeFactors.SequenceEqual( new List <int> { 2, 2 })); }
public void TestBigNumbersAreFactorizeCorrectly() { var primeFactors = new PrimeFactors(2 * 2 * 3 * 5 * 7 * 11).value(); Assert.IsTrue(primeFactors.SequenceEqual( new List <int> { 2, 2, 3, 5, 7, 11 })); }
public void TestNumersWithDifferentPrimeFactorsAreFactorizeCorrectly() { var primeFactors = new PrimeFactors(6).value(); Assert.IsTrue(primeFactors.SequenceEqual( new List <int> { 2, 3 })); }
static void Main(string[] args) { Console.WriteLine("enter a number"); int enteredNumber = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("\r\nPrime factors for {0} are:", enteredNumber); PrimeFactors pf = new PrimeFactors(); foreach (var value in pf.GeneratePrimeFactorsFor(enteredNumber)) { Console.WriteLine(value); } }
static void Main(string[] args) { var pf = new PrimeFactors(); int n; Console.Write("Enter a positive integer: "); n = Convert.ToInt32(Console.ReadLine()); Console.Write("\nPrime Factors of " + n + " are: "); pf.primeNumbers(n); Console.ReadLine(); }
public void TestOneHasNoPrimeFactors() { var primeFactors = new PrimeFactors(1).value(); Assert.AreEqual(0, primeFactors.Count); }