Example #1
0
        public void The_text_analyser_has_a_bad_time_with_null_inputs()
        {
            // Arrange
            var systemUnderTest = new TextAnalyzer();

            // Act
            // Assert
            Assert.Throws<ArgumentNullException>(()=>systemUnderTest.FullAnalysis(null));
        }
Example #2
0
        public void Empty_strings_are_not_handled()
        {
            // Arrange
            var systemUnderTest = new TextAnalyzer();

            // Act
            // Assert
            Assert.Throws<InvalidOperationException>(()=>systemUnderTest.FullAnalysis(string.Empty));
        }
Example #3
0
        // <summary>
        // FullAnalysis is a method in the TextAnalyzer class. It accepts any string and displays the relevant information in the console.
        // For this challenge, I have defined 'words' as any character string between white-spaces, and sentences as strings split between these punctuators: . ! ?
        // </summary>
        static void Main(string[] args) // BA removed unused argument
        {
            TextAnalyzer TomsReader = new TextAnalyzer(); // BA tomsReader. lowerCamelCase is the norm for inline variables. textAnalyzer might be a better name.
            // BA use either var or explicit typing - doesn't matter which, but be consistent.

            var result = TomsReader.FullAnalysis(SampleText);

            Console.WriteLine("There are {0} sentences.", result.NumberOfSentences); // BA use string.format rather than + concatenation. Console.WriteLine automagically does string.Format for you under the hood.
            Console.WriteLine("There are {0} total words.", result.NumberOfWords);
            Console.WriteLine(string.Join("The longest sentence is: ", result.LongestSentence)); // BA or string.Join if appropriate
            Console.WriteLine("The most frequently used word is: \"{0}\"", result.MostFrequentWord);
            Console.WriteLine("The third longest word(s): {0}   Number of characters: {1}", result.ThirdLargestWord, result.LengthOfThirdLargestWord);
            Console.ReadLine();
        }
Example #4
0
        public void A_sensible_set_of_sentences_produces_the_expected_result()
        {
            // Arrange
            const string paragraph =
                @"Intergen is New Zealand's most experienced provider of Microsoft based business solutions. We focus on delivering business value in our solutions and work closely with Microsoft to ensure we have the best possible understanding of their technologies and directions. Intergen is a Microsoft Gold Certified Partner with this status recognising us as an 'elite business partner' for implementing solutions based on our capabilities and experience with Microsoft products.";

            var systemUnderTest = new TextAnalyzer();

            // Act
            var result = systemUnderTest.FullAnalysis(paragraph);

            // Assert
            Assert.That(result.NumberOfSentences, Is.EqualTo(3));
            Assert.That(result.NumberOfWords, Is.EqualTo(68));
            Assert.That(result.LongestSentence.StartsWith("Intergen is a Microsoft"));
            Assert.That(result.MostFrequentWord, Is.EqualTo("Microsoft"));
            Assert.That(result.LengthOfThirdLargestWord, Is.EqualTo(11));
        }