예제 #1
0
        public void TextSplitTests_Analyze_Stopword_a_Mary_has_a_little_lamb_with_Newlines_Expect_5_Words()
        {
            TextSplitResult actual = _systemUnderTest.Split(
                text: $"Mary had{Environment.NewLine}a little{Environment.NewLine}lamb");

            Assert.Equal(expected: 5, actual: actual.Words.Count);
        }
예제 #2
0
        public void TextSplitTests_Analyze_Text_a_with_dot_Expect_1_Word()
        {
            TextSplitResult actual = _systemUnderTest.Split(text: "a.");

            Assert.Single(collection: actual.Words);
            Assert.Equal(expected: "a", actual: actual.Words[0]);
        }
예제 #3
0
        public void TextSplitTests_Analyze_Stopword_a_This_is_a_Text_Expect_4_Words()
        {
            TextSplitResult actual = _systemUnderTest.Split(
                text: "This is a Text");

            Assert.Equal(expected: 4, actual: actual.Words.Count);
        }
예제 #4
0
        public WordCountAnalyzerResult Analyze(string text)
        {
            TextSplitResult textSplitResult = TextSplit.Split(text: text);

            if (!textSplitResult.WordsAvailable)
            {
                return(new WordCountAnalyzerResult());
            }

            StopwordRemoverResult stopwordRemoverResult = StopwordRemover.RemoveStopwords(words: textSplitResult.Words);

            List <string> words         = stopwordRemoverResult.Words;
            List <string> distinctWords = words.Distinct().ToList();

            int    numberOfWords       = words.Count;
            int    numberOfUniqueWords = distinctWords.Count;
            double averageWordLength   = words.Any() ? words.Average(selector: s => s.Length) : 0.0;
            int    numberOfchapters    = text.Split(separator: new[] { Environment.NewLine + Environment.NewLine }, options: StringSplitOptions.None).Count();

            return(new WordCountAnalyzerResult
            {
                NumberOfWords = numberOfWords,
                NumberOfUniqueWords = numberOfUniqueWords,
                AverageWordLength = averageWordLength,
                DistinctWords = distinctWords,
                NumberOfChapters = numberOfchapters
            });
        }
예제 #5
0
        public void TextSplitTests_Humpty_Dumpty_Text_Expect_10_Words()
        {
            const string    text   = "Humpty-Dumpty sat on a wall. Humpty-Dumpty had a great fall.";
            TextSplitResult actual = _systemUnderTest.Split(text: text);

            Assert.Equal(
                expected: 10,
                actual: actual.Words.Count);
        }
예제 #6
0
        public void TextSplitTests_Analyze_empty_strings_Expect_0_Words(
            string inputtext)
        {
            TextSplitResult actual = _systemUnderTest.Split(text: inputtext);

            Assert.NotNull(@object: actual);
            Assert.NotNull(@object: actual.Words);
            Assert.Empty(collection: actual.Words);
        }
예제 #7
0
        public void TextSplitTests_Text_with_Unicode_Expect_2_Words()
        {
            const string    text   = "Hello André";
            TextSplitResult actual = _systemUnderTest.Split(text: text);

            List <string> expected = new List <string> {
                "Hello", "André"
            };

            Assert.Equal(
                expected: expected,
                actual: actual.Words);
        }
예제 #8
0
        public void TextSplitTests_Words_with_Comma_expect_no_Comma()
        {
            const string    text   = "Longworth, however, in desperate need of money, killed the preacher with Hamlet's sword and  stole the manuscript";
            TextSplitResult actual = _systemUnderTest.Split(text: text);

            List <string> expected = new List <string>()
            {
                "Longworth", "however", "in", "desperate", "need", "of", "money", "killed", "the", "preacher", "with", "Hamlet's", "sword", "and", "stole", "the", "manuscript"
            };

            Assert.Equal(expected: expected,
                         actual: actual.Words);
        }
예제 #9
0
        public void TextSplitTests_Text_with_Digit_Expect_without_Digit()
        {
            const string    text   = "Draußen ist es schön 1";
            TextSplitResult actual = _systemUnderTest.Split(text: text);

            List <string> expected = new List <string> {
                "Draußen", "ist", "es", "schön"
            };

            Assert.Equal(
                expected: expected,
                actual: actual.Words);
        }
예제 #10
0
        public void TextSplitTests_Text_with_MinusAtEnd_Expect_word_Without_Minus()
        {
            const string    text   = "pre- pre-condition";
            TextSplitResult actual = _systemUnderTest.Split(text: text);

            List <string> expected = new List <string> {
                "pre", "pre-condition"
            };

            Assert.Equal(
                expected: expected,
                actual: actual.Words);
        }
예제 #11
0
        public void TextSplitTests_empty_strings_Expect_ValuesAvailable_false(string inputtext)
        {
            TextSplitResult actual = _systemUnderTest.Split(text: inputtext);

            Assert.False(condition: actual.WordsAvailable);
        }
예제 #12
0
        public void TextSplitTests_Analyze_Text_Bla_bla_Expect_2_Words()
        {
            TextSplitResult actual = _systemUnderTest.Split(text: "Bla bla");

            Assert.Equal(expected: 2, actual: actual.Words.Count);
        }