Exemplo n.º 1
0
        public void StringSearchingTest()
        {
            var input    = new[] { "Hello,ell", "This is good, is", "CodeEval,C*Eval", "Old,Young" };
            var expected = new[] { "true", "true", "true", "false" };
            var result   = new StringSearching(input).Run();

            AssertExtensions.AreEqual(expected, result);
        }
Exemplo n.º 2
0
        public void StringSearchingRegDoesntMakeRegex()
        {
            var input    = @"C\*Eval";
            var expected = @"C\*Eval";
            var result   = StringSearching.GetRegString(input);

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 3
0
        public void StringSearchingRegMakesRegex()
        {
            var input    = "C*Eval";
            var expected = "C[a-Z]*Eval";
            var result   = StringSearching.GetRegString(input);

            Assert.AreEqual(expected, result);
        }
Exemplo n.º 4
0
        public void HorspoolSearchTest()
        {
            string [] stringsToFind = new string[]
            {
                "abc", "def", "cacd", "mentor", "Triceph", "alliance", "Alliance"
            };

            string[] stringsToSearch = new string[]
            {
                "abcd", "dabc", "defabc", "abcacd", "Humanity had needed a… mentor for a long time. Someone or something to show us the way. Someone or something to deter violence and nurture kindness and compassion. We used to think there was someone – God – who would do this for us. However when the Celestial Alliance showed up most religious people abandoned their faith. If there was anyone to worship, surely it would be the alien races that saved humanity from its stubborn insistence on continuing the hopeless fight with the Triceph?"
            };

            foreach (string phrase in stringsToSearch)
            {
                foreach (string pattern in stringsToFind)
                {
                    Assert.AreEqual(phrase.IndexOf(pattern), StringSearching.HorspoolSearch(phrase, pattern));
                }
            }
        }
Exemplo n.º 5
0
        public void ShiftTableTest()
        {
            string[] testStrings = new string[]
            {
                "abc",
                "abcc",
                "abacdc"
            };

            foreach (string str in testStrings)
            {
                char[] chars       = str.ToCharArray();
                int    charsLength = chars.Length;

                foreach (char c in chars)
                {
                    int [] shiftTable    = StringSearching.CreateShiftTable(chars);
                    int    shiftTableVal = shiftTable[(int)c];

                    Assert.IsTrue(shiftTableVal == charsLength || c == chars[charsLength - shiftTableVal - 1]);
                }
            }
        }
Exemplo n.º 6
0
 public void StringSearchingTest()
 {
     var input = new[] {"Hello,ell", "This is good, is", "CodeEval,C*Eval", "Old,Young"};
     var expected = new[] {"true", "true", "true", "false"};
     var result = new StringSearching(input).Run();
     AssertExtensions.AreEqual(expected,result);
 }