Beispiel #1
0
        public void TestWordMatcher()
        {
            WordMatcher     matcher   = new WordMatcher(Delimiters);
            StringTokenizer data      = new StringTokenizer("test \"'test test2+end");
            SourcePosition  streamPos = new SourcePosition(0, 0, 0);

            // Match a basic word
            Assert.IsNotNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, " ");
            data.Advance();
            // Ensure that string/name tokens are not considered
            // as they are exempt from the delimiters.
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            data.Advance();
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            data.Advance();
            Assert.AreEqual(matcher.MatchNext(data, ref streamPos, Log).Value, "test");
            Assert.AreEqual(data.CurrentItem, " ");
            data.Advance();
            // Match a word containing a number
            Assert.AreEqual(matcher.MatchNext(data, ref streamPos, Log).Value, "test2");
            Assert.AreEqual(data.CurrentItem, "+");
            data.Advance();
            // Ensure token type and EOF handling
            Assert.AreEqual(matcher.MatchNext(data, ref streamPos, Log).Type, TokenType.Word);

            Assert.IsTrue(data.AtEnd());
        }
        public void CheckNoTreeIsReturnedForWordWithNoMatches()
        {
            var dodgyWordMatcher = new WordMatcher("FFFF", "XXXX", fileReader);
            var result           = dodgyWordMatcher.Run();

            Assert.AreEqual(0, result.Next.Count);
        }
Beispiel #3
0
        public void ScrambledWordMatchesGivenWordInTheList()
        {
            string[] words          = { "cat", "chair", "more" };
            string[] scrambledWords = { "omre" };
            var      matchedWords   = WordMatcher.Match(scrambledWords, words);

            Assert.IsTrue(matchedWords.Count == 1);
            Assert.IsTrue(matchedWords[0].ScrambledWord.Equals("omre"));
            Assert.IsTrue(matchedWords[0].Word.Equals("more"));
        }
Beispiel #4
0
        public static int[] Match(string subject, string query, StringScorerOptions options = null)
        {
            if (string.IsNullOrEmpty(subject) || string.IsNullOrEmpty(query))
            {
                return new int[] {}
            }
            ;

            options = options ?? new StringScorerOptions();
            options.Init(query);

            return(WordMatcher.Match(subject, query, options));
        }
        public void WordMatcher_MatchWord()
        {
            //Arrange
            string[] wordList            = { "hello", "you" };
            string[] splitScrambledWords = { "ouy", "elloh" };

            List <MatchWord> expectedMatchWord = new List <MatchWord> {
                new MatchWord {
                    ScrambleWord = "ouy", Word = "you"
                },
                new MatchWord {
                    ScrambleWord = "elloh", Word = "hello"
                }
            };

            var actualResult = WordMatcher.Match(splitScrambledWords, wordList);

            for (int i = 0; i < 2; i++)
            {
                Assert.AreEqual(expectedMatchWord[i].ScrambleWord, actualResult[i].ScrambleWord);
                Assert.AreEqual(expectedMatchWord[i].Word, actualResult[i].Word);
            }
        }
Beispiel #6
0
 public void Setup()
 {
     wordMatcher = new WordMatcher(new [] { "cat", "chair", "more" });
 }
Beispiel #7
0
 public void TestInvalidWord(
     [Values('1')] char input)
 {
     Assert.Null(WordMatcher.Match(input));
 }
Beispiel #8
0
 public void TestValidWord(
     [Values('a', 'A')] char input)
 {
     Assert.NotNull(WordMatcher.Match(input));
 }
 public void WordMatcherTestsSetup()
 {
     //Input path to dictionary
     fileReader  = new TextFileReader(@"", 4);
     wordMatcher = new WordMatcher("rice", "rift", fileReader);
 }
Beispiel #10
0
        public void TestWordMatcher()
        {
            WordMatcher matcher = new WordMatcher(Delimiters);
            StringTokenizer data = new StringTokenizer("test \"'test test2+end");
            SourcePosition streamPos = new SourcePosition(0, 0, 0);

            // Match a basic word
            Assert.IsNotNull(matcher.MatchNext(data, ref streamPos, Log));
            Assert.AreEqual(data.CurrentItem, " ");
            data.Advance();
            // Ensure that string/name tokens are not considered
            // as they are exempt from the delimiters.
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            data.Advance();
            Assert.IsNull(matcher.MatchNext(data, ref streamPos, Log));
            data.Advance();
            Assert.AreEqual(matcher.MatchNext(data, ref streamPos, Log).Value, "test");
            Assert.AreEqual(data.CurrentItem, " ");
            data.Advance();
            // Match a word containing a number
            Assert.AreEqual(matcher.MatchNext(data, ref streamPos, Log).Value, "test2");
            Assert.AreEqual(data.CurrentItem, "+");
            data.Advance();
            // Ensure token type and EOF handling
            Assert.AreEqual(matcher.MatchNext(data, ref streamPos, Log).Type, TokenType.Word);

            Assert.IsTrue(data.AtEnd());
        }