示例#1
0
 public void CheckLargePrimes()
 {
     foreach (var prime in _largePrimes)
     {
         Assert.True(PrimeChecker.IsPrime(prime));
     }
 }
        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();
        }
示例#3
0
        public void StartProgram()
        {
            int[] arrFactor;

            ConsoleOutput  consoleOutput  = new ConsoleOutput();
            ConsoleInput   consoleInput   = new ConsoleInput();
            FactorFinder   factorFinder   = new FactorFinder();
            PerfectChecker perfectChecker = new PerfectChecker();
            PrimeChecker   primeChecker   = new PrimeChecker();

            consoleOutput.OutputMessage("Which number Do you want to factor: ");
            consoleInput.UserInput = int.Parse(Console.ReadLine());
            arrFactor = factorFinder.FactorArray(consoleInput.UserInput);
            consoleOutput.OutputMessage("The Factors are: \n");
            consoleOutput.StringJoinArray(arrFactor);
            if (perfectChecker.PerfectNumber(consoleInput.UserInput))
            {
                consoleOutput.OutputMessage($"{consoleInput.UserInput} is a Perfect Number. \n");
            }
            else
            {
                consoleOutput.OutputMessage($"{consoleInput.UserInput} is NOT a Perfect Number. \n");
            }

            if (primeChecker.PrimeNumber(consoleInput.UserInput))
            {
                consoleOutput.OutputMessage($"{consoleInput.UserInput} is a Prime Number. \n");
            }
            else
            {
                consoleOutput.OutputMessage($"{consoleInput.UserInput} is NOT a Prime Number.\n");
            }

            Console.ReadKey();
        }
示例#4
0
        public void TestIfPrimeIsPrime()
        {
            PrimeChecker pc      = new PrimeChecker();
            bool         isPrime = pc.CheckIfNumberIsPrime(3);

            Assert.IsTrue(isPrime);
        }
 private void Calculate()
 {
     _factors = FactorFinder.FindFactorList(_target);
     _factors.Add(_target);
     _isPrime   = PrimeChecker.IsPrime(_target);
     _isPerfect = PerfectChecker.IsPerfect(_target);
 }
示例#6
0
        public Jam()
        {
            this.random       = new Random();
            this.primeChecker = new PrimeChecker(100000000);

            this.divisors = new string[10];
        }
示例#7
0
        public void TestSpecialCharactersAreHandeled()
        {
            PrimeChecker pc      = new PrimeChecker();
            var          message = pc.PrimeInput("!_:;23");

            Assert.AreSame(message, "Wrong type of input, requires a number. Please try again!");
        }
示例#8
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!");
            }
        }
示例#9
0
 // A button that takes the user inputed number and checks if it is prime by passing it through the PrimeChecker class when it is clicked
 private void btnCheck_Click(object sender, EventArgs e)
 {
     // Convert number so it can be passed through the IsPrime method, which uses BigInteger
     if (PrimeChecker.IsPrime(Convert.ToInt64(nudUserInput.Value)) == true)
     {
         // Displays label for that shows the number is prime
         lblPrime.Show();
         lblNotPrime.Hide();
         // Changes background color to green for prime numbers
         this.BackColor = Color.Green;
         // A happy cat is displayed :)
         picHappyCat.Show();
         picSadCat.Hide();
     }
     else
     {
         // Displays label for that shows the number is not prime
         lblNotPrime.Show();
         lblPrime.Hide();
         // Changes background color to red for non-prime numbers
         this.BackColor = Color.Red;
         // A sad cat is displayed :(
         picSadCat.Show();
         picHappyCat.Hide();
     }
 }
示例#10
0
        public void TestPrimeNumber(int x, bool expected)
        {
            PrimeChecker primeNumber = new PrimeChecker();
            bool         result      = primeNumber.PrimeNumber(x);

            Assert.AreEqual(expected, result);
        }
示例#11
0
        public void RunProg()
        {
            ConsoleOutput.DisplayTitle();
            Console.Clear();
            ConsoleKeyInfo keyPressed;

            do
            {
                MyManager = new WorkManager();

                int enteredNumber = ConsoleInput.GetNumberFromUser();

                FactorFinder factorResults = MyManager.ProcessNumber(enteredNumber);
                ConsoleOutput.DisplayFactors(factorResults);

                PerfectChecker perfectResults = MyManager.ProcessPerfect(enteredNumber);
                ConsoleOutput.DisplayPerfect(perfectResults);

                PrimeChecker primeResults = MyManager.ProcessPrime(enteredNumber);
                ConsoleOutput.DisplayPrime(primeResults);

                ConsoleOutput.ContinueOrQuitMessage();
                keyPressed = ConsoleInput.ContinueOrQuit();

                Console.Clear();
            } while (!(keyPressed.Key == ConsoleKey.Q));
        }
示例#12
0
        public void PrimeTests(int x, bool expected)
        {
            PrimeChecker prime  = new PrimeChecker();
            bool         result = prime.IsPrime(x);

            Assert.AreEqual(expected, result);
        }
示例#13
0
 public void CheckSmallPrimes()
 {
     foreach (var prime in _smallPrimes)
     {
         Assert.True(PrimeChecker.IsPrime(prime));
     }
 }
示例#14
0
 public void CheckMediumPrimes()
 {
     foreach (var prime in _mediumPrimes)
     {
         Assert.True(PrimeChecker.IsPrime(prime));
     }
 }
示例#15
0
        public void TestIfNumbersLessThan2Fails()
        {
            PrimeChecker pc      = new PrimeChecker();
            bool         isPrime = pc.CheckIfNumberIsPrime(-12);

            Assert.IsFalse(isPrime);
        }
示例#16
0
        public void PrimeNumberTest(int number, bool expected)
        {
            PrimeChecker pc = new PrimeChecker();

            bool actual = pc.IsPrimeNumber(number);

            Assert.AreEqual(expected, actual);
        }
示例#17
0
        public static void Main()
        {
            var substr = StringHandler.Subsequence("Hello!".ToCharArray(), 2, 3);

            Console.WriteLine(substr);

            var subarr = StringHandler.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 2);

            Console.WriteLine(String.Join(" ", subarr));

            var allarr = StringHandler.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 4);

            Console.WriteLine(String.Join(" ", allarr));

            var emptyarr = StringHandler.Subsequence(new int[] { -1, 3, 2, 1 }, 0, 0);

            Console.WriteLine(String.Join(" ", emptyarr));

            Console.WriteLine(StringHandler.ExtractEnding("I love C#", 2));
            Console.WriteLine(StringHandler.ExtractEnding("Nakov", 4));
            Console.WriteLine(StringHandler.ExtractEnding("beer", 4));

            // if uncommented, crashes the program, because of the predefined validations!
            // Console.WriteLine(StringHandler.ExtractEnding("Hi", 100));

            try
            {
                PrimeChecker.CheckPrime(23);
                Console.WriteLine("23 is prime.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            try
            {
                PrimeChecker.CheckPrime(33);
                Console.WriteLine("33 is prime.");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            List <Exam> peterExams = new List <Exam>()
            {
                new SimpleMathExam(2),
                new CSharpExam(55),
                new CSharpExam(100),
                new SimpleMathExam(1),
                new CSharpExam(0),
            };
            Student peter = new Student("Peter", "Petrov", peterExams);
            double  peterAverageResult = peter.CalcAverageExamResultInPercents();

            Console.WriteLine("Average results = {0:p0}", peterAverageResult);
        }
示例#18
0
        public void StartFactoring()
        {
            var num     = Input.GetNumberFromUser();                // get # from user
            var factors = FactorFinder.FactFinder(num);             // get factor
            var prime   = PrimeChecker.Prime(factors);              // is prime
            var perfect = PerfectChecker.Perfect(factors, num);     // is perfect

            Output.Results(num, factors, prime, perfect);           // send results to Output.cs
        }
示例#19
0
        public void TestIfGetNextPrimeNumberGetsTheRightNumber()
        {
            PrimeChecker pc = new PrimeChecker();

            pc.PrimeInput("5");
            pc.PrimeInput("3");
            pc.CheckNextPrime();
            Assert.AreEqual(pc.primeNumbers[2], 7);
        }
示例#20
0
        public int Run()
        {
            ulong i = 600851475143;

            PrimeChecker pc = new PrimeChecker();
            var factors = pc.GetFactors(i);
            var primeFactors = factors.Where(f => pc.GetFactors(f).Count() == 2).ToList();

            return (int) primeFactors.Max();
        }
示例#21
0
        public void SevenIsPrimeTest()
        {
            WorkManager testInstance = new WorkManager();

            testInstance.Start();

            PrimeChecker actual = testInstance.ProcessPrime(7);

            Assert.AreEqual(true, actual.IsPrime);
        }
示例#22
0
 public static void DisplayPrime(PrimeChecker value)
 {
     if (value.IsPrime)
     {
         Console.WriteLine($"{value.GetMyNumber()} is prime.");
     }
     else
     {
         Console.WriteLine($"{value.GetMyNumber()} is not prime.");
     }
 }
示例#23
0
        public void TestThatPrimeIsSavedToList()
        {
            PrimeChecker pc = new PrimeChecker();

            pc.PrimeInput("3");
            pc.PrimeInput("5");
            pc.PrimeInput("6");
            pc.PrimeInput("7");

            Assert.AreEqual(pc.primeNumbers.Count, 3);
        }
示例#24
0
        public int Run()
        {
            Console.WriteLine("Prime Checker");
            PrimeChecker pc = new PrimeChecker();
            for (ulong v = 1; v < 5000; v++)
            {
                var factorList = pc.GetFactors(v);
                factorList.Sort();
                Console.WriteLine(factorList.Aggregate("", (disp, val) => disp + val.ToString() + ","));
            }

            return 1337;
        }
    private static void PrintIsPrime(int number)
    {
        PrimeChecker primeChecker = new PrimeChecker();

        if (primeChecker.CheckPrime(number))
        {
            Console.WriteLine("{0} is prime", number);
        }
        else
        {
            Console.WriteLine("{0} is not prime", number);
        }
    }
示例#26
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());
        }
示例#27
0
    public static string CheckForPrimes()
    {
        var primeCheckerLogger = new Logger();
        var primeChecker       = new PrimeChecker(primeCheckerLogger);

        var primeCandidates = GetPrimeCandidatesCollection();

        foreach (var candidate in primeCandidates)
        {
            primeChecker.CheckPrime(candidate);
        }

        return(primeCheckerLogger.ToString());
    }
示例#28
0
        public void RunFactorFinder()
        {
            ConsoleOutput.DisplayTitle();
            int          input       = ConsoleInput.GetUserInput();
            FactorFinder findFactors = new FactorFinder();

            int[] factors = findFactors.FactorArray(input);

            PrimeChecker   checkPrime   = new PrimeChecker();
            bool           isPrime      = checkPrime.IsPrime(input);
            PerfectChecker checkPerfect = new PerfectChecker();
            bool           isPerfect    = checkPerfect.IsPerfect(input);

            ConsoleOutput.DisplayResults(input, factors, isPrime, isPerfect);
        }
示例#29
0
        public static void DisplayPrimeNumber(int number)
        {
            PrimeChecker pc      = new PrimeChecker();
            bool         isPrime = pc.IsPrimeNumber(number);

            Console.WriteLine("|-------------------------------------------|\n");
            Console.ForegroundColor = ConsoleColor.Magenta;
            if (isPrime)
            {
                Console.WriteLine($"The number {number} is a prime number.\n");
            }
            else
            {
                Console.WriteLine($"The number {number} is NOT a prime number.\n");
            }
            Console.ResetColor();
            Console.WriteLine("|-------------------------------------------|\n");

            Console.WriteLine("Press any key to continue...\n");
            Console.ReadKey();
        }
示例#30
0
        public void Execute()
        {
            //get number to factorize
            int number = ConsoleInput.GetNumberFromUser("What number would you like to factor? ", 1);

            //determine factors (static)
            int[] factors = FactorFinder.Execute(number);
            ConsoleOutput.Factors(number, factors);

            //prime it (is not static)
            PrimeChecker primeChecker = new PrimeChecker();
            bool         result       = primeChecker.IsPrimeNumber(number);

            ConsoleOutput.PrimeNumberResult(number, result);

            //perfect num
            PerfectChecker perfectChecker = new PerfectChecker();

            perfectChecker.Number = number;
            bool isPerfect = perfectChecker.IsPerfectNumber();

            ConsoleOutput.PerfectNumberResult(number, result);
        }
        public void PrimeCheckerTest(int[] x, bool expected)
        {
            bool actual = PrimeChecker.IsItPrime(x);

            Assert.AreEqual(expected, actual);
        }
 public void _2_Should_Be_Prime()
 {
     Assert.True(PrimeChecker.IsPrime(2));
 }
 public void Should_Return_True_For_All_Primes_Less_Than_10(int n)
 {
     Assert.True(PrimeChecker.IsPrime(n));
 }