Esempio n. 1
0
        public void SSNaive()
        {
            NaiveStringSearch          Naive   = new NaiveStringSearch();
            IEnumerable <ISearchMatch> result1 = Naive.Search(find1, test);

            Assert.AreEqual(exp1.Length, result1.First <ISearchMatch>().Length);
            Assert.AreEqual(exp1.Start, result1.First <ISearchMatch>().Start);

            IEnumerable <ISearchMatch> result2 = Naive.Search(find2, test);

            Assert.AreEqual(exp2.Length, result2.First <ISearchMatch>().Length);
            Assert.AreEqual(exp2.Start, result2.First <ISearchMatch>().Start);
        }
        public void NaiveStringSearch_EmptySourceString()
        {
            // Arrange
            IStringSearchAlgorithm algorithm = new NaiveStringSearch();
            var toFind   = string.Empty;
            var toSearch = "this string does not contain the missing string data";

            // Act
            var matches = algorithm.Search(toFind, toSearch).ToArray();

            // Assert
            matches.Should().BeEmpty();
        }
        public void NaiveStringSearch_MultipleMatchesMiddleString()
        {
            // Arrange
            IStringSearchAlgorithm algorithm = new NaiveStringSearch();
            var toFind   = "found";
            var toSearch = "found and found";

            // Act
            var matches = algorithm.Search(toFind, toSearch).ToArray();

            // Assert
            matches.Should().HaveCount(2);
            matches[0].Start.Should().Be(0);
            matches[0].Length.Should().Be(toFind.Length);
            matches[1].Start.Should().Be(10);
            matches[1].Length.Should().Be(toFind.Length);
        }