예제 #1
0
 static void LaunchSentenceProcessing(IInputDataProvider inputDataProvider, IOutputDataPersistor dataPersistor)
 {
     using (var reader = inputDataProvider.GetInputDataReader())
     {
         ISentenceProcessor sentenceProcessor = new SentenceProcessor(new char[] { ' ', ',', '.', ';', ':', '\t' });
         var dictionary = sentenceProcessor.Process(reader);
         dataPersistor.PersistData(dictionary);
     }
 }
        public void WhenTextReaderReturnsEmptyStringThenCreateEmptyDictionary()
        {
            var mockedTextReader = new Mock<TextReader>();
            mockedTextReader.SetupSequence(p => p.ReadLine())
                .Returns("");

            ISentenceProcessor sentenceProvider = new SentenceProcessor(_standardDelimiters);
            var result = sentenceProvider.Process(mockedTextReader.Object);

            Assert.That(result.Count, Is.EqualTo(0));            
        }
        public void WhenInputPassedThenCountWithoutCaseSensitivity()
        {
            var mockedTextReader = new Mock<TextReader>();
            mockedTextReader.SetupSequence(p => p.ReadLine())
                .Returns("test")
                .Returns("Test");

            ISentenceProcessor sentenceProvider = new SentenceProcessor(_standardDelimiters);
            var result = sentenceProvider.Process(mockedTextReader.Object);

            Assert.That(result["test"], Is.EqualTo(2));            
        }
        public void WhenInputPassedThenCountWordOccurrences()
        {
            var mockedTextReader = new Mock<TextReader>();
            mockedTextReader.SetupSequence(p => p.ReadLine())
                .Returns(GetFirstTestLine())
                .Returns(GetSecondTestLine());

            ISentenceProcessor sentenceProvider = new SentenceProcessor(_standardDelimiters);

            var result = sentenceProvider.Process(mockedTextReader.Object);
            Assert.That(result["line"], Is.EqualTo(4));
            Assert.That(result["test"], Is.EqualTo(2));
            Assert.That(result["first"], Is.EqualTo(1));
            Assert.That(result["second"], Is.EqualTo(1));
        }
        public void WhenNoDelimitersPassedThenOnlySplitBySpace()
        {
            var testLine = "line line.line";

            var mockedTextReader = new Mock<TextReader>();
            mockedTextReader.SetupSequence(p => p.ReadLine())
                .Returns(testLine);

            ISentenceProcessor sentenceProvider = new SentenceProcessor(new List<char>());
            var result = sentenceProvider.Process(mockedTextReader.Object);

            Assert.That(result.Count, Is.EqualTo(2));
            Assert.That(result["line"], Is.EqualTo(1));
            Assert.That(result["line.line"], Is.EqualTo(1));
        }
 public void WhenCreatingSentenceProcessorAndNullReaderProvidedThenThrowNullArgumentException()
 {
     var sentenceProcessor = new SentenceProcessor(new List<char>());
     Assert.Throws<ArgumentNullException>(() => sentenceProcessor.Process(null));
 }