static void Main(string[] args)
        {
            string userInput    = null;
            bool   userContinue = true;

            while (userContinue)
            {
                userInput = StandardInputMessage.RequestInput();

                if (DataValidation.ValidateInput(userInput) == false)
                {
                    bool retry = StandardInputMessage.RePrompt();
                    if (retry == false)
                    {
                        userContinue         = false;
                        Environment.ExitCode = 22;
                    }
                }
                else
                {
                    long userNumber = DataManipulation.ReturnValue(userInput);
                    if (DataValidation.ValidateComposite(userNumber) == false)
                    {
                        bool retry = StandardInputMessage.RePrompt(); //refactor using userContinue from RePrompt()
                        if (retry == false)
                        {
                            userContinue         = false;
                            Environment.ExitCode = 44;
                        }
                    }
                    else
                    {
                        CompositeNumber userComposite = new CompositeNumber(userNumber);

                        LinkedList <IFactor> factors = Factorize.Factor(userComposite);

                        List <IFactor>    primeNumbers     = DataManipulation.ReturnPrimes(factors);     //Should be list of primes
                        List <IFactor>    compositeNumbers = DataManipulation.ReturnComposites(factors); //Should be list of composites
                        FactorizationTree factorTree       = DataManipulation.ReturnPopulatedTree(factors);

                        StandardOutputMessage.OutputFactors(compositeNumbers, userNumber);
                        StandardOutputMessage.OutputFactors(primeNumbers, userNumber);
                        StandardOutputMessage.OutputFactorizationTree(factorTree, userNumber);

                        bool retry = StandardInputMessage.RePrompt();
                        if (retry == false)
                        {
                            userContinue         = false;
                            Environment.ExitCode = 100;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public void Factorize_CompleteFactoring(long number)
        {
            // Arrange
            CompositeNumber compositeNumber = new CompositeNumber(number);

            // Act
            var factors  = Factorize.Factor(compositeNumber);
            var expected = new LinkedList <IFactor>();

            // Assert
            Assert.IsType(factors.GetType(), expected);
            Assert.True(factors.Count >= 2);
        }
Beispiel #3
0
        public void Start()
        {
            bool running = true;

            while (running)
            {
                ConsoleOutput.DisplayIntroduction();
                int number = ConsoleInput.GetUserInput();
                ConsoleOutput.DisplayResult(number, Factorize.Factor(number), Factorize.IsPerfect(number),
                                            Factorize.IsPrime(number));
                running = ConsoleInput.GetUserStringInput();
                if (!running)
                {
                    ConsoleOutput.DisplayClosing();
                }
            }
        }
 public void FactorNumberTests(int x, int[] expected)
 {
     int[] actual = Factorize.Factor(x);
     Console.Write(actual);
     Assert.AreEqual(expected, actual);
 }