Пример #1
0
        public void Run()
        {
            int var = GetNumberFromUser();

            Console.WriteLine($"The factors of {var} are: ");
            int countOfFactors = FactorFinder.GetFactorsCount(var);

            int[] foundFactors = FactorFinder.GetFactors(countOfFactors, var);

            Console.WriteLine($"{string.Join(", ", foundFactors)}");



            if (PrimeChecker.IsPrimeNumber(var) == true)
            {
                Console.WriteLine($"{var} is PRIME");
            }

            else
            {
                Console.WriteLine($"{var} is NOT PRIME ");
            }

            if (PerfectChecker.GetPerfectNumber(var) == true)
            {
                Console.WriteLine($"{var} is a PERFECT number!");
            }
            else
            {
                Console.WriteLine($"{var} is NOT a PERFECT number!");
            }
        }
Пример #2
0
        public void Start()
        {
            FactorFinder ff  = new FactorFinder();
            int          num = InputClass.GetIntFromUser("Enter number to process");

            int[] factors = ff.GetFactors(num);
            OutputClass.SentToConsole($"\nThe factors of {num} are as follows:\n");
            for (int i = 0; i < factors.Length; i++)
            {
                OutputClass.SentToConsole($"{factors[i]}");
            }

            if (PerfectChecker.IsItPerfect(factors))
            {
                OutputClass.SentToConsole($"\n{num} is a perfect number!");
            }
            else
            {
                OutputClass.SentToConsole($"\n{num} is NOT a perfect number!");
            }


            if (PrimeChecker.IsItPrime(factors))
            {
                OutputClass.SentToConsole($"\n{num} is a prime number!");
            }
            else
            {
                OutputClass.SentToConsole($"\n{num} is NOT a prime number!");
            }

            OutputClass.SentToConsole("\nPress any key to end.");
            Console.ReadKey();
        }
        public void FactorFinderTest(int x, int[] expected)
        {
            FactorFinder ff = new FactorFinder();

            int[] actual = ff.GetFactors(x);

            Assert.AreEqual(expected, actual);
        }
Пример #4
0
        public void FactorFinderTest4()
        {
            FactorFinder ff = new FactorFinder();

            List <int> actual = ff.GetFactors(0);

            Assert.AreEqual(new List <int> {
                0
            }, actual);
        }
Пример #5
0
        public void FactorFinderTest1()
        {
            FactorFinder ff = new FactorFinder();

            List <int> actual = ff.GetFactors(120);

            Assert.AreEqual(new List <int> {
                1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120
            }, actual);
        }
Пример #6
0
        //the workflow should invoke methods to perform tasks.
        //It should not contain any calculations.

        public void Run()
        {
            Console.WriteLine("Welcome to Factorizer");
            do
            {
                Console.WriteLine("Please enter an integer: ");
                int number = ConsoleInput.AwaitUserInput();
                Console.WriteLine();
                ConsoleOutput.ReportFactors(number, FactorFinder.GetFactors(number));
                ConsoleOutput.ReportAttribte(number, PrimeChecker.isPrime(number), "prime");
                ConsoleOutput.ReportAttribte(number, PerfectChecker.isPerfect(number), "prefect");
                Console.WriteLine("Press ESC to quit or any kep to continue");
            } while (!ConsoleInput.UserEscapes());
        }