Exemplo n.º 1
0
        public void SampleAschheim()
        {
            var stream    = AanagramStreamFactory.CreateTestableAnagramStream("Aschheim");
            var collector = new AnagramCollector();

            stream.Results.Subscribe(x => collector.FoundAnagram(x));

            stream.ProcessWord("aches");
            stream.ProcessWord("ash");
            stream.ProcessWord("chase");
            stream.ProcessWord("chime");
            stream.ProcessWord("has");
            stream.ProcessWord("hash");
            stream.ProcessWord("hic");
            stream.ProcessWord("him");
            stream.ProcessWord("mice");
            stream.ProcessWord("shah");
            stream.ProcessWord("shame");

            Assert.IsTrue(collector.CheckWordCollection(new[] { "aches", "him" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "ash", "chime" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "chase", "him" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "chime", "has" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "hash", "mice" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "hic", "shame" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "mice", "shah" }));
            Assert.AreEqual(7, collector.Results.Count);
        }
Exemplo n.º 2
0
        public void InvalidWordAnalysisBadOccurences()
        {
            var stream = AanagramStreamFactory.CreateTestableAnagramStream("BestSecret");
            var word   = stream.CreateTextSegment("eeEttt");

            Assert.AreEqual(-1, word.RemainingCharacterClassCount);
            Assert.AreEqual(-1, word.RemainingLength);
        }
Exemplo n.º 3
0
        public void BadJoinWithCharactersOveruse()
        {
            var stream = AanagramStreamFactory.CreateTestableAnagramStream("BestSecret");
            var word1  = stream.CreateTextSegment("eet");

            // "sscr" is missing
            var joined = stream.JoinTextAndSegment(word1, "beet");

            Assert.AreEqual(-1, joined.RemainingCharacterClassCount);
            Assert.AreEqual(-1, joined.RemainingLength);
        }
Exemplo n.º 4
0
        public void ValidWordAnalysis()
        {
            var stream = AanagramStreamFactory.CreateTestableAnagramStream("BestSecret");
            var word   = stream.CreateTextSegment("eeEtt");

            Assert.AreEqual(4, word.RemainingCharacterClassCount);
            Assert.AreEqual(5, word.RemainingLength);
            Assert.AreEqual(1, word.RemainingCharacters['b']);
            Assert.AreEqual(2, word.RemainingCharacters['s']);
            Assert.AreEqual(1, word.RemainingCharacters['c']);
            Assert.AreEqual(1, word.RemainingCharacters['r']);
        }
Exemplo n.º 5
0
        public void SingleMatch()
        {
            var stream = AanagramStreamFactory.CreateTestableAnagramStream("BestSecret");

            var collector = new AnagramCollector();

            stream.Results.Subscribe(x => collector.FoundAnagram(x));

            stream.ProcessWord("Bestsecret");

            Assert.AreEqual(1, collector.Results.Count, "One match without case must be found");
            Assert.AreEqual(1, collector.Results.First().Count, "One match without case must be found");
        }
Exemplo n.º 6
0
        public void SampleBestSecret()
        {
            var stream    = AanagramStreamFactory.CreateTestableAnagramStream("Best Secret");
            var collector = new AnagramCollector();

            stream.Results.Subscribe(x => collector.FoundAnagram(x));

            stream.ProcessWord("beet");
            stream.ProcessWord("beets");
            stream.ProcessWord("beret");
            stream.ProcessWord("berets");
            stream.ProcessWord("beset");
            stream.ProcessWord("best");
            stream.ProcessWord("bests");
            stream.ProcessWord("bet");
            stream.ProcessWord("bets");
            stream.ProcessWord("better");
            stream.ProcessWord("betters");
            stream.ProcessWord("cess");
            stream.ProcessWord("crest");
            stream.ProcessWord("crests");
            stream.ProcessWord("crete");
            stream.ProcessWord("erect");
            stream.ProcessWord("erects");
            stream.ProcessWord("erst");
            stream.ProcessWord("rest");
            stream.ProcessWord("sec");
            stream.ProcessWord("secret");
            stream.ProcessWord("secrets");
            stream.ProcessWord("sect");
            stream.ProcessWord("sects");

            Assert.IsTrue(collector.CheckWordCollection(new[] { "beet", "crests" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "beets", "crest" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "beret", "sects" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "berets", "sect" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "beset", "crest" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "best", "erects" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "best", "secret" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "bests", "crete" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "bests", "erect" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "bet", "erst", "sec" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "bet", "rest", "sec" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "bet", "secrets" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "bets", "erects" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "bets", "secret" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "better", "cess" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "betters", "sec" }));
            Assert.AreEqual(16, collector.Results.Count);
        }
Exemplo n.º 7
0
        public void ValidWordJoin()
        {
            var stream = AanagramStreamFactory.CreateTestableAnagramStream("BestSecret");
            var word1  = stream.CreateTextSegment("eet");

            // "sscr" is missing
            var joined = stream.JoinTextAndSegment(word1, "bet");

            Assert.AreEqual(3, joined.RemainingCharacterClassCount);
            Assert.AreEqual(4, joined.RemainingLength);
            Assert.AreEqual(2, joined.RemainingCharacters['s']);
            Assert.AreEqual(1, joined.RemainingCharacters['c']);
            Assert.AreEqual(1, joined.RemainingCharacters['r']);
        }
Exemplo n.º 8
0
        public void MisMatchShortWord()
        {
            var stream = AanagramStreamFactory.CreateTestableAnagramStream("BestSecret");

            var collector = new AnagramCollector();

            stream.Results.Subscribe(x => collector.FoundAnagram(x));

            stream.ProcessWord("Best");
            stream.ProcessWord("nonsense");
            stream.ProcessWord("secr");
            stream.ProcessWord("et");

            Assert.AreEqual(0, collector.Results.Count, "One word was too short, must not find a match");
        }
Exemplo n.º 9
0
        public void KeepValidWordsOnly()
        {
            var stream = AanagramStreamFactory.CreateTestableAnagramStream("BestSecret");

            Assert.AreEqual(0, stream.SingleWordSegmentCount);
            stream.ProcessWord("best");
            Assert.AreEqual(1, stream.SingleWordSegmentCount);
            stream.ProcessWord("xyz");
            Assert.AreEqual(1, stream.SingleWordSegmentCount, "Must not register unusable characters");
            stream.ProcessWord("b");
            Assert.AreEqual(1, stream.SingleWordSegmentCount, "Must not register short words");
            stream.ProcessWord("be");
            Assert.AreEqual(1, stream.SingleWordSegmentCount, "Must not register short words");
            stream.ProcessWord("secret");
            Assert.AreEqual(2, stream.SingleWordSegmentCount, "also register words that produce matches");
            stream.ProcessWord("bestsecre");
            Assert.AreEqual(2, stream.SingleWordSegmentCount, "must not register words with too shoort rest length");
        }
Exemplo n.º 10
0
        public void SampleItCrowd()
        {
            var stream    = AanagramStreamFactory.CreateTestableAnagramStream("IT-Crowd");
            var collector = new AnagramCollector();

            stream.Results.Subscribe(x => collector.FoundAnagram(x));

            stream.ProcessWord("cod");
            stream.ProcessWord("cord");
            stream.ProcessWord("cow");
            stream.ProcessWord("dirt");
            stream.ProcessWord("doc");
            stream.ProcessWord("tic");
            stream.ProcessWord("wit");
            stream.ProcessWord("word");
            stream.ProcessWord("writ");

            Assert.IsTrue(collector.CheckWordCollection(new[] { "cow", "dirt" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "cord", "wit" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "tic", "word" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "cod", "writ" }));
            Assert.IsTrue(collector.CheckWordCollection(new[] { "writ", "doc" }));
            Assert.AreEqual(5, collector.Results.Count);
        }