public void Test_RabinKarpRollingHash_StringContains()
        {
            var searcher = new SubstringSearch();

            Assert.AreEqual(2, searcher.RabinKarpRollingHash("asdfxcv", "dfxc"));
            Assert.AreEqual(0, searcher.RabinKarpRollingHash("asdfxcv", "asdfx"));
            Assert.AreEqual(5, searcher.RabinKarpRollingHash("01234asdfxcv", "a"));
            Assert.AreEqual(5, searcher.RabinKarpRollingHash("01234asdf", "asdf"));
        }
Пример #2
0
        public void ExceptionForEmptyStringSecondArgumentTest()
        {
            // Arrange
            var toMatch  = "abc";
            var toSearch = string.Empty;

            // Act
            SubstringSearch.IsSubstring(toMatch, toSearch);
        }
Пример #3
0
    public static void Main(string[] args)
    {
        string          str       = "abcxabcdabcdabcy";
        string          subString = "abcdabcy";
        SubstringSearch ss        = new SubstringSearch();
        bool            result    = ss.KMP(str.ToCharArray(), subString.ToCharArray());

        Console.WriteLine(result);
    }
Пример #4
0
        public void ExceptionForNullSecondArgumentTest()
        {
            // Arrange
            var    toMatch  = "abc";
            string toSearch = null;

            // Act
            SubstringSearch.IsSubstring(toMatch, toSearch);
        }
Пример #5
0
        public void NoMatchForNonadjacentStringTest()
        {
            // Arrange
            var toMatch  = "abc";
            var toSearch = "a_b_c";
            var expected = false;

            // Act
            var actual = SubstringSearch.IsSubstring(toMatch, toSearch);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #6
0
        public void MultipleMatchesTest()
        {
            // Arrange
            var toMatch  = "abc";
            var toSearch = "abcabc";
            var expected = true;

            // Act
            var actual = SubstringSearch.IsSubstring(toMatch, toSearch);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #7
0
        public void EndsWithMatchTest()
        {
            // Arrange
            var toMatch  = "abc";
            var toSearch = "_abc";
            var expected = true;

            // Act
            var actual = SubstringSearch.IsSubstring(toMatch, toSearch);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Пример #8
0
        public void NoMatchForDifferentCasingTest()
        {
            // Arrange
            var toMatch  = "abc";
            var toSearch = "ABC";
            var expected = false;

            // Act
            var actual = SubstringSearch.IsSubstring(toMatch, toSearch);

            // Assert
            Assert.AreEqual(expected, actual);
        }