public void TestMethod20() { IList <WordFrequency> expectedResult = new List <WordFrequency>(); expectedResult.Add(new WordFrequency("a", 3)); var actual = wordFrequencyAnalyzer.CalculateMostFrequentNWords("a a a", 1); for (var i = 0; i < actual.Count; i++) { Assert.AreEqual(expectedResult[i].Word, actual[i].Word); Assert.AreEqual(expectedResult[i].Frequency, actual[i].Frequency); } }
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); }
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); } }
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); }
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); }
public void CalculateMostFrequentNWords_Given_Null_Text_Should_Throw() { //arrange string text = null; int n = 3; var wordFrequencyAnalyser = new WordFrequencyAnalyzer(textPrepareForFrpcessingFunction); //act wordFrequencyAnalyser.CalculateMostFrequentNWords(text, n); // Assert Assert.Fail("Expected exception was not thrown."); }
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}")); }