コード例 #1
0
        public void CalculateMostFrequentNWords_Given_N_is_Three_Should_Return_Description()
        {
            /*
             * DESCRIPTION
             * If several words have the same frequency, this method should return them in ascendant alphabetical order
             * (for input text “The sun shines over the lake” and n = 3, it should return
             * the list { (“the”, 2), (“lake”, 1), (“over”, 1) }
             */

            //arrange
            string text = "The sun shines over the lake";

            int n = 3;
            var wordFrequencyAnalyser = new WordFrequencyAnalyzer(textPrepareForFrpcessingFunction);

            //act
            var listOfWordFrequencies = wordFrequencyAnalyser.CalculateMostFrequentNWords(text, n);

            // Assert
            Assert.AreEqual("the", listOfWordFrequencies[0].Word);
            Assert.AreEqual(2, listOfWordFrequencies[0].Frequency);

            Assert.AreEqual("lake", listOfWordFrequencies[1].Word);
            Assert.AreEqual(1, listOfWordFrequencies[1].Frequency);

            Assert.AreEqual("over", listOfWordFrequencies[2].Word);
            Assert.AreEqual(1, listOfWordFrequencies[2].Frequency);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            WordFrequencyAnalyzer Workf = new WordFrequencyAnalyzer();
            string s1;

            Console.Write("Enter a sentence: ");
            s1 = Console.ReadLine();
            Workf.CalculateHighestFrequency(s1);
            Console.WriteLine();
            Console.ReadLine();


            Console.Write("Choose your word: ");

            Console.WriteLine(Workf.CalculateFrequencyForWord(s1, Console.ReadLine()));


            Console.Write("Choose n: ");

            string s3 = Console.ReadLine();

            var items = Workf.CalculateMostFrequentNWords(s1, Convert.ToInt32(s3));

            foreach (var item in items)
            {
                Console.WriteLine(item);
            }
        }
コード例 #3
0
        public void CalculateHighestFrequency_Given_Regular_Text_Should_Return()
        {
            //arrange
            string text = "The lake in the lake was the lake's best the thing";
            var    wordFrequencyAnalyser = new WordFrequencyAnalyzer(textPrepareForFrpcessingFunction);

            //act
            int frequency = wordFrequencyAnalyser.CalculateHighestFrequency(text);

            // Assert
            Assert.AreEqual(4, frequency);
        }
コード例 #4
0
        public void CalculateHighestFrequency_Given_EmptyString_Text_Should_Return_Zero()
        {
            //arrange
            string text = string.Empty;
            var    wordFrequencyAnalyser = new WordFrequencyAnalyzer(textPrepareForFrpcessingFunction);

            //act
            int frequency = wordFrequencyAnalyser.CalculateHighestFrequency(text);

            // Assert
            Assert.AreEqual(0, frequency);
        }
コード例 #5
0
        public void CalculateHighestFrequency_Given_Null_Text_Should_Throw()
        {
            //arrange
            string text = null;
            var    wordFrequencyAnalyser = new WordFrequencyAnalyzer(textPrepareForFrpcessingFunction);

            //act
            wordFrequencyAnalyser.CalculateHighestFrequency(text);

            // Assert
            Assert.Fail("Expected exception was not thrown.");
        }
コード例 #6
0
        public void CalculateFrequencyForWord_Given_Regular_Text_And_Search_Empty_String_Frequency()
        {
            //arrange
            string text = "The lake in the lake was the lake best the thing";
            string word = String.Empty;
            var    wordFrequencyAnalyser = new WordFrequencyAnalyzer(textPrepareForFrpcessingFunction);

            //act
            var frequency = wordFrequencyAnalyser.CalculateFrequencyForWord(text, word);

            // Assert
            Assert.AreEqual(0, frequency);
        }
コード例 #7
0
        public void CalculateFrequencyForWord_Given_Regular_Text_Should_Return_Zero()
        {
            //arrange
            string text = "The lake in the lake was the lake best the thing";
            string word = "lake";
            var    wordFrequencyAnalyser = new WordFrequencyAnalyzer(textPrepareForFrpcessingFunction);

            //act
            var frequency = wordFrequencyAnalyser.CalculateFrequencyForWord(text, word);

            // Assert
            Assert.AreEqual(3, frequency);
        }
コード例 #8
0
        public void CalculateFrequencyForWord_Given_Null_Text_and_Null_Word_Should_Throw()
        {
            //arrange
            string text = null;
            string word = null;
            var    wordFrequencyAnalyser = new WordFrequencyAnalyzer(textPrepareForFrpcessingFunction);

            //act
            var _ = wordFrequencyAnalyser.CalculateFrequencyForWord(text, word);

            // Assert
            Assert.Fail("Expected exception was not thrown.");
        }
コード例 #9
0
        public void CalculateMostFrequentNWords_Given_EmptyText_and_Positive_N__Should_Return_EmptySet()
        {
            //arrange
            string text = string.Empty;
            int    n    = 5;
            var    wordFrequencyAnalyser = new WordFrequencyAnalyzer(textPrepareForFrpcessingFunction);

            //act
            var listOfWordFrequencies = wordFrequencyAnalyser.CalculateMostFrequentNWords(text, n);

            // Assert
            Assert.AreEqual(0, listOfWordFrequencies.Count);
        }
コード例 #10
0
        public void CalculateMostFrequentNWords_Given_N_is_Zero_Should_Return_EmptySet()
        {
            //arrange
            string text = "The sun shines over the lake";
            int    n    = 0;
            var    wordFrequencyAnalyser = new WordFrequencyAnalyzer(textPrepareForFrpcessingFunction);

            //act
            var listOfWordFrequencies = wordFrequencyAnalyser.CalculateMostFrequentNWords(text, n);

            // Assert
            Assert.AreEqual(0, listOfWordFrequencies.Count);
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: Darth-Fx/Test
        static void Main(string[] args)
        {
            const string exampleText = @"The pipo sun sun sun sun sunsun sun shines over the lake zeta ypsolon xavi wawa vuut tipo sien rara quentin pipo open";

            Func <string, List <string> > textSeperateFunction = (text) => text.ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();


            var wordprocessor = new WordFrequencyAnalyzer(textSeperateFunction);

            Console.WriteLine($"{wordprocessor.CalculateHighestFrequency(exampleText)}");
            Console.WriteLine($"{wordprocessor.CalculateFrequencyForWord(exampleText, "lake")}");
            var mostFrequent = wordprocessor.CalculateMostFrequentNWords(exampleText, 7);

            mostFrequent.ToList().ForEach(word => Console.WriteLine($"{word.Word}, freq: {word.Frequency}"));
        }
コード例 #12
0
 public void init()
 {
     wordFrequencyAnalyzer = new WordFrequencyAnalyzer();
 }