public void GetFrequencyDictionary_ShouldReturnFail_OnFailParserResult() { var result = Result.Fail <string[]>("asdf"); A.CallTo(() => textParser.GetWords(fileName)).Returns(result); frequencyAnalyzer.GetFrequencyDictionary(fileName).Should() .BeEquivalentTo(Result.Fail <Dictionary <string, double> >("asdf")); }
public Dictionary <string, double> GetFrequencyDictionary(string fileName) { var words = parser.GetWords(fileName); return(words .GroupBy(str => str) .ToDictionary(group => group.Key, group => group.Count() / (double)words.Length)); }
public Result <Dictionary <string, double> > GetFrequencyDictionary(string fileName) { var wordsResult = parser.GetWords(fileName); return(wordsResult.Then(lines => lines .GroupBy(str => str) .ToDictionary(group => group.Key, group => group.Count() / (double)wordsResult.Value.Length))); }
public void GetWords_ReturnFail_OnUncorrectPatCreator() { var pathCreater = A.Fake <IPathCreator>(); A.CallTo(() => pathCreater.GetCurrentPath()).Returns("Incorrect path"); A.CallTo(() => textReader.ReadStrings(null)) .WithAnyArguments().Returns(new string[] { "asdf" }); parser = new TextProcessing.LiteratureTextParser(pathCreater, textReader); var parseResult = parser.GetWords(null); parseResult.IsSuccess.Should().BeFalse(); parseResult.Error.Should().Contain("Not found dictionaries"); }
public void GetWords_ReturnFail_OnFailedReadStrings() { var result = Result.Fail <string[]>("asdf"); A.CallTo(() => textReader.ReadStrings(null)) .WithAnyArguments().Returns(result); var parseResult = parser.GetWords(null); parseResult.IsSuccess.Should().BeFalse(); parseResult.Error.Should().Be("asdf"); }