コード例 #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));
        }
コード例 #2
0
        public void Empty_strings_are_not_handled()
        {
            // Arrange
            var systemUnderTest = new TextAnalyzer();

            // Act
            // Assert
            Assert.Throws<InvalidOperationException>(()=>systemUnderTest.FullAnalysis(string.Empty));
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: bamor/Text-Parser
        // <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();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: TomPedersen/Text-Parser
        // <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)
        {
            TextAnalyzer tomsReader = new TextAnalyzer();

            var Text = "Call me Ishmael. Some years ago — never mind how long precisely — having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen, and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people’s hats off — then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me.";

            var thirdLargestWord = string.Join(", ", tomsReader.ThirdLongestWord(tomsReader.ToWordArray(Text)).ToList());
            var thirdLargestWordCharCount = tomsReader.ThirdLongestWord(tomsReader.ToWordArray(Text)).Key;

            Console.WriteLine("There are {0} sentences.", tomsReader.ToSentenceArray(Text).Length);
            Console.WriteLine("There are {0} total words.", tomsReader.ToWordArray(Text).Length);
            Console.WriteLine("The longest sentence is: {0}", tomsReader.LongestSentence(tomsReader.ToSentenceArray(Text)));
            Console.WriteLine("The most frequently used word is: \"{0}\"", tomsReader.MostFrequentWord(tomsReader.ToWordArray(Text)));
            Console.WriteLine("The third longest word(s): {0}  Number of characters: {1}", thirdLargestWord, thirdLargestWordCharCount);
            Console.ReadLine();
        }
コード例 #5
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));
        }