Пример #1
0
        public void primeFactorTest1()
        {
            string actual   = FunctionRepository.BuildOutputString(28);
            string expected = "2,2,7 Product: 28";

            Assert.AreEqual(actual, expected);
        }
Пример #2
0
        public void BuildOutputStringTestSquareOfTwoPrimes()
        {
            string productString;
            string actual   = FunctionRepository.BuildOutputString(9, out productString);
            string expected = "3,3";

            Assert.AreEqual(expected, actual);
        }
Пример #3
0
        public void BuildOutputStringTestOne()
        {
            string productString;
            string actual   = FunctionRepository.BuildOutputString(1, out productString);
            string expected = 1 + " is not prime but has no divisors";

            Assert.AreEqual(expected, actual);
        }
Пример #4
0
        public void BuildOutputStringTestZero()
        {
            string productString;
            string actual   = FunctionRepository.BuildOutputString(0, out productString);
            string expected = 0 + " is a composite number with infinite divisors";

            Assert.AreEqual(expected, actual);
        }
Пример #5
0
        public void BuildOutputStringTestNegativeNumber()
        {
            string productString;
            string actual   = FunctionRepository.BuildOutputString(-1, out productString);
            string expected = -1 + " negative numbers, by definition, cannot be prime";

            Assert.AreEqual(expected, actual);
        }
Пример #6
0
        public void BuildOutputStringTestPrimeNumber()
        {
            string productString;
            string actual   = FunctionRepository.BuildOutputString(47, out productString);
            string expected = 47 + " is Prime";

            Assert.AreEqual(expected, actual);
        }
Пример #7
0
        public void BuildOutputStringTestValidNumber()
        {
            string productString;
            string actual   = FunctionRepository.BuildOutputString(28, out productString);
            string expected = "2,2,7";

            Assert.AreEqual(expected, actual);
        }
Пример #8
0
        public void ListProductTest()
        {
            string productString;

            FunctionRepository.BuildOutputString(28, out productString);
            string actual   = productString;
            string expected = " Product: 28";

            Assert.AreEqual(expected, actual);
        }
Пример #9
0
        private static void Main(string[] args)
        {
            IEnumerable <string> numbersString;

            if (!args.Any()) //if you run the exe by clicking then you wont have an input
            {
                //args = new string[] {Environment.CurrentDirectory + "\\test1.txt"};
                Console.WriteLine(
                    "Please drag txt file onto icon or use the command line to specify a target file to run program \nPress Enter To Continue");
                Console.ReadLine();
                return;
            }
            if (Path.GetExtension(args[0]) != ".txt") //only work with .txt files
            {
                Console.WriteLine("Please Select a File With the '.txt' Extension");
                return;
            }
            try //try to read the sepecified file
            {
                numbersString = File.ReadLines(args[0]);
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("File Not Found.  Please Enter a Valid File ");
                //Inform the user their file was not found at the specified locaton
                return;
            }

            numbersString = numbersString.Where(entry => !string.IsNullOrWhiteSpace(entry));
            //remove empty entries caused by empty lines
            if (numbersString.Any(entry => !FunctionRepository.CheckStringValue(entry)))
            {
                Console.WriteLine(
                    "All values in .txt file must be integers.  Please reference your file for non-integer values \nPress Enter To Continue");
                Console.ReadLine();
                return;
            }

            List <int> numbers = numbersString.Select(int.Parse).ToList();

            //create list of ints from list of strings from file

            foreach (int number in numbers)
            {
                string productString;
                Console.WriteLine(FunctionRepository.BuildOutputString(number, out productString));
            }
            Console.WriteLine("\nPress Enter To Continue");
            Console.ReadLine();
        }
Пример #10
0
        private void computePrimesButton_Click(object sender, EventArgs e)
        {
            if (!File.Exists(_filePath))
            {
                MessageBox.Show("Select a valid .txt file");
                return;
            }
            IEnumerable <string> numbersString = File.ReadLines(_filePath);
            List <int>           numbers       = numbersString.Select(int.Parse).ToList();

            foreach (int number in numbers)
            {
                richTextBox1.Text += FunctionRepository.BuildOutputString(number) + "\n";
            }
        }
Пример #11
0
        private void computePrimesButton_Click(object sender, EventArgs e)
        {
            if (!File.Exists(_filePath))
            {
                MessageBox.Show("Select a valid .txt file");
                return;
            }

            List <int> numbers = _numbersString.Select(int.Parse).ToList();

            foreach (int number in numbers)
            {
                string productString;
                richTextBox1.Text += number + ": Prime Factors: " + FunctionRepository.BuildOutputString(number, out productString) + "\n";
            }
        }