コード例 #1
0
        public void GetPrimeFactors_InvalidNumber_ReturnsEmptyList(int number)
        {
            var primeFactorService = new PrimeFactorService(new PrimeService());

            var result = primeFactorService.GetPrimeFactors(number);

            Assert.Empty(result);
        }
コード例 #2
0
        public void GetPrimeFactors_PrimeNumber_ReturnsListContainingOnlyInput(int number)
        {
            var primeFactorService = new PrimeFactorService(new PrimeService());

            var result = primeFactorService.GetPrimeFactors(number);

            Assert.Equal(number, result.ToList().Single());
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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();
        }