public void GetPrimeFactors_InvalidNumber_ReturnsEmptyList(int number) { var primeFactorService = new PrimeFactorService(new PrimeService()); var result = primeFactorService.GetPrimeFactors(number); Assert.Empty(result); }
public void GetPrimeFactors_PrimeNumber_ReturnsListContainingOnlyInput(int number) { var primeFactorService = new PrimeFactorService(new PrimeService()); var result = primeFactorService.GetPrimeFactors(number); Assert.Equal(number, result.ToList().Single()); }
public void GetPrimeFactors_CompositeNumber_ReturnsCorrectPrimeFactors(int number) { var primeService = new PrimeService(); var primeFactorService = new PrimeFactorService(primeService); var result = primeFactorService.GetPrimeFactors(number); Assert.Equal(number, result.Aggregate(1, (x, y) => x * y)); Assert.All(result, x => primeService.IsPrime(x)); }
static void Main(string[] args) { Console.WriteLine("Enter file path:"); var path = Console.ReadLine(); var fileContents = File.ReadAllText(path); //var fileContents = File.ReadAllText(@"..\..\..\numbers.txt"); var primeFactorService = new PrimeFactorService(new PrimeService()); var primeFactorLists = fileContents.Split('\n') .Select(x => primeFactorService.GetPrimeFactors(int.Parse(x))); foreach (var list in primeFactorLists) { Console.WriteLine(string.Join(", ", list)); } Console.ReadLine(); }