Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        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)));
        }
Exemplo n.º 4
0
        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");
        }
Exemplo n.º 5
0
        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");
        }