public void CalculateFreguency_InsertDuplicateWords_True() { // Arrange all necessary preconditions and inputs. var listWord = new List <string> { "red", "pink", "red", "yellow", "red" }; var listFrequency = new List <FrequencyWordsList>(); var expected = new List <FrequencyWordsList> { new FrequencyWordsList { Word = "red", Frequency = 3 }, new FrequencyWordsList { Word = "pink", Frequency = 1 }, new FrequencyWordsList { Word = "yellow", Frequency = 1 } }; // Act on the object or method under test. var preparingWords = new PreparingWords(listWord, listFrequency); preparingWords.CalculateFreguency(); var actual = listFrequency; // Assert that the expected results have occurred. Assert.AreEqual(expected.Count, actual.Count); for (var i = 0; i < expected.Count; i++) { Assert.AreEqual(expected[i].Word, actual[i].Word); Assert.AreEqual(expected[i].Frequency, actual[i].Frequency); } }
public void CanCalculateFreguencyWords() { // Arrange all necessary preconditions and inputs. var listFrequency = new List <FrequencyWordsList>(); var rootPath = System.AppContext.BaseDirectory; string inputPath = rootPath + @"/TestFiles/SmallPartOfBookToTest.txt"; var input = new ReadWordsFromFile().GetStringFromFile(inputPath); var listWord = input.ToWordList().ToList(); var expected = new List <FrequencyWordsList> { new FrequencyWordsList { Word = "this", Frequency = 2 }, new FrequencyWordsList { Word = "is", Frequency = 2 }, new FrequencyWordsList { Word = "my", Frequency = 2 }, new FrequencyWordsList { Word = "test", Frequency = 1 }, new FrequencyWordsList { Word = "first", Frequency = 1 }, new FrequencyWordsList { Word = "word", Frequency = 1 }, new FrequencyWordsList { Word = "finish", Frequency = 2 } }; // Act on the object or method under test. var preparingWords = new PreparingWords(listWord, listFrequency); preparingWords.CalculateFreguency(); var actual = listFrequency; // Assert that the expected results have occurred. Assert.AreEqual(expected.Count, actual.Count); for (var i = 0; i < expected.Count; i++) { Assert.AreEqual(expected[i].Word, actual[i].Word); Assert.AreEqual(expected[i].Frequency, actual[i].Frequency, " Word: " + expected[i].Word); } }