Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please Enter File Path, then press Enter.");
            var filePath = Console.ReadLine();
            if (TextFileHelpers.FileExists(filePath))
            {
                var textFromFile = TextFileHelpers.ReadTextFileToString(filePath);

                var textAnalytics = new TextAnalytics(textFromFile);
                Console.WriteLine("Text that is being checked");
                Console.WriteLine(textAnalytics.OriginalText);
                Console.WriteLine(string.Format("Total characters : {0}", textAnalytics.CharCount()));

                var charDictionary = textAnalytics.TenMostFrequentCharUsingCase();
                Console.WriteLine("Ten most frequent characters.");
                foreach (var x in charDictionary)
                {
                    Console.WriteLine(string.Format("{0} ({1})", x.Key, x.Value));
                }

                var charDictionaryIgnoreCase = textAnalytics.TenMostFrequentCharIgnoreCase();
                Console.WriteLine("Ten most frequent characters ignore case.");
                foreach (var x in charDictionaryIgnoreCase)
                {
                    Console.WriteLine(string.Format("{0} ({1})", x.Key, x.Value));
                }
            }
            else
            {
                Console.WriteLine("File does not exist.");
            }
            Console.ReadKey();
        }
        public void ReadThreeCharWithTabAtMiddle()
        {
            //Arrange
            var value = "A\tBC";
            var textAnalytics = new TextAnalytics(value);

            //Act
            var charCount = textAnalytics.CharCount();

            //Assert
            Assert.AreEqual(3, charCount);
        }
        public void ReadEmptyString()
        {
            //Arrange
            var value = "";
            var textAnalytics = new TextAnalytics(value);

            //Act
            var charCount = textAnalytics.CharCount();

            //Assert
            Assert.AreEqual(0, charCount);
        }
        public void ReadEmptyString()
        {
            //Arrange
            var value = "";
            var textAnalytics = new TextAnalytics(value);

            //Act
            var charDictionary = textAnalytics.TenMostFrequentCharUsingCase();

            //Assert
            Assert.AreEqual(0, charDictionary.Count);
        }
        public void ReadSameThreeChar()
        {
            //Arrange
            var value = "AAA";
            var textAnalytics = new TextAnalytics(value);

            //Act
            var charDictionary = textAnalytics.TenMostFrequentCharUsingCase();

            //Assert
            Assert.AreEqual(1, charDictionary.Count);
            Assert.AreEqual(3, charDictionary['A']);
        }
        public void ReadThreeWithDuplicateChar()
        {
            //Arrange
            var value = "AAAABBBCC";
            var textAnalytics = new TextAnalytics(value);

            //Act
            var charDictionary = textAnalytics.TenMostFrequentCharUsingCase();

            //Assert
            Assert.AreEqual(3, charDictionary.Count);
            Assert.AreEqual(4, charDictionary['A']);
            Assert.AreEqual(3, charDictionary['B']);
            Assert.AreEqual(2, charDictionary['C']);
        }
        public void TestTextString()
        {
            //Arrange
            var value = "The three did feed the deer The quick brown fox jumped over the lazy dog";
            var textAnalytics = new TextAnalytics(value);

            //Act
            var charDictionary = textAnalytics.TenMostFrequentCharUsingCase();

            //Assert
            Assert.AreEqual(10, charDictionary.Count);
            Assert.AreEqual(12, charDictionary['e'], "Error on e");
            Assert.AreEqual(6, charDictionary['d'], "Error on d");
            Assert.AreEqual(5, charDictionary['h'], "Error on h");
            Assert.AreEqual(4, charDictionary['r'], "Error on r");
            Assert.AreEqual(4, charDictionary['o'], "Error on o");
            Assert.AreEqual(2, charDictionary['u'], "Error on u");
            Assert.AreEqual(3, charDictionary['t'], "Error on t");
            Assert.AreEqual(2, charDictionary['u'], "Error on u");
            Assert.AreEqual(2, charDictionary['f'], "Error on f");
            Assert.AreEqual(2, charDictionary['T'], "Error on T");
        }
        public void TestTextStringIgnoreCase()
        {
            //Arrange
            var value = "Aa BBbb CCc";
            var textAnalytics = new TextAnalytics(value);

            //Act
            var charDictionary = textAnalytics.TenMostFrequentCharIgnoreCase();

            //Assert
            Assert.AreEqual(3, charDictionary.Count);
            Assert.AreEqual(2, charDictionary['a']);
            Assert.AreEqual(4, charDictionary['b']);
            Assert.AreEqual(3, charDictionary['c']);
        }