コード例 #1
0
        public void OnMatching_CompositionMatcher_DoesNotFindCompostion()
        {
            var words = new string[] { "Our", "time", "in", "the", "world", "is", "on", "loan", "we", "must", "pay", "back", "the", "loan", "with", "interest" };
            CompositionMatcher matcher = new CompositionMatcher(words, 7);

            foreach (var word in words)
            {
                matcher.ProcessEach(word);
            }

            Assert.AreEqual(0, matcher.Matches.Count());
        }
コード例 #2
0
        public void OnMatching_CompositionMatcher_DoesNotFindCompostionMissingSecondPart()
        {
            var words = new string[] { "sure", "it", "itself" };
            CompositionMatcher matcher = new CompositionMatcher(words, 6);

            foreach (var word in words)
            {
                matcher.ProcessEach(word);
            }

            var matches = matcher.Matches.ToList();
            Assert.AreEqual(0, matches.Count);
        }
コード例 #3
0
        public void OnMatching_CompositionMatcher_MatchesSingleComposition()
        {
            var words = new string[] { "self", "it", "itself" };
            CompositionMatcher matcher = new CompositionMatcher(words, 6);

            foreach (var word in words)
            {
                matcher.ProcessEach(word);
            }

            var matches = matcher.Matches.ToList();
            Assert.AreEqual(1, matches.Count);
            Assert.AreEqual("it", matches[0].FirstPart);
            Assert.AreEqual("self", matches[0].SecondPart);
            Assert.AreEqual("itself", matches[0].Composition);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: nilez/SimpleWordProcessor
        static void ProcessFile(string file)
        {
            Console.WriteLine(string.Format("Processing File: {0}", file));

            try
            {
                string fileContent = File.ReadAllText(file);

                WordsParser parser = new WordsParser();

                IEnumerable<string> words = parser.GetWords(fileContent);

                StandardWordTraverser traverser = new StandardWordTraverser(words);

                // Part 1
                WordsCounter counter = new WordsCounter();
                traverser.AcceptProcessor(counter);
                counter.ReportTo(Console.WriteLine);

                // Part 2
                CompositionMatcher compositonMatcher = new CompositionMatcher(words, 6);
                traverser.AcceptProcessor(compositonMatcher);
                compositonMatcher.ReportTo(Console.WriteLine);
            }
            catch (IOException ex)
            {
                Console.WriteLine("Unable to read the file.");
                Console.WriteLine(string.Format("Message: {0}", ex.Message));
                Console.WriteLine(string.Format("Details: {0}", ex.StackTrace));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Oops... Unexpected error occurred.");
                Console.WriteLine(string.Format("Message: {0}", ex.Message));
                Console.WriteLine(string.Format("Details: {0}", ex.StackTrace));
            }
        }
コード例 #5
0
        public void OnMatching_CompositionMatcher_MatchesTwoCompositionsWithSameFirstPart()
        {
            var words = new string[] { "alic","self", "it", "itself", "italic"};
            CompositionMatcher matcher = new CompositionMatcher(words, 6);

            foreach (var word in words)
            {
                matcher.ProcessEach(word);
            }

            var matches = matcher.Matches.ToList();
            Assert.AreEqual(2, matches.Count);

            var selfEntry = matches.Find(e => e.SecondPart == "self");
            var alicEntry = matches.Find(e => e.SecondPart == "alic");

            Assert.AreEqual("it", selfEntry.FirstPart);
            Assert.AreEqual("self", selfEntry.SecondPart);
            Assert.AreEqual("itself", selfEntry.Composition);

            Assert.AreEqual("it", alicEntry.FirstPart);
            Assert.AreEqual("alic", alicEntry.SecondPart);
            Assert.AreEqual("italic", alicEntry.Composition);
        }
コード例 #6
0
        public void OnMatching_CompositionMatcher_MatchesTwoCompositionsWithSameSecondPart()
        {
            var words = new string[] { "my", "self", "it", "itself", "myself" };
            CompositionMatcher matcher = new CompositionMatcher(words, 6);

            foreach (var word in words)
            {
                matcher.ProcessEach(word);
            }

            var matches = matcher.Matches.ToList();
            Assert.AreEqual(2, matches.Count);

            var myEntry = matches.Find(e => e.FirstPart == "my");
            var itEntry = matches.Find(e => e.FirstPart == "it");

            Assert.IsNotNull(itEntry);
            Assert.AreEqual("it", itEntry.FirstPart);
            Assert.AreEqual("self", itEntry.SecondPart);
            Assert.AreEqual("itself", itEntry.Composition);

            Assert.IsNotNull(myEntry);
            Assert.AreEqual("my", myEntry.FirstPart);
            Assert.AreEqual("self", myEntry.SecondPart);
            Assert.AreEqual("myself", myEntry.Composition);
        }