public void NullStream()
        {
            // Arrange
            var needleByteArray = Encoding.ASCII.GetBytes("needle");

            using (var seekableStream = new SearchableStream(null)) { }
        }
        public void NullNeedle()
        {
            var haystackByteArray = Encoding.ASCII.GetBytes("This haystack does not contain a n-e-e-d-l-e");

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var seekableStream = new SearchableStream(memStream))
                {
                    // Act
                    var foundPosition = seekableStream.IndexOfAllBackwards(null);
                }
        }
Exemplo n.º 3
0
        public void EmptyNeedle()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("This haystack does not contain a n-e-e-d-l-e");
            var emptyNeedle       = new byte[0];

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var seekableStream = new SearchableStream(memStream))
                {
                    // Act
                    var foundPosition = seekableStream.LastIndexOf(emptyNeedle);
                }
        }
Exemplo n.º 4
0
        public void SingleOccuranceAtEnd()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("haystack with a needle");
            var needleByteArray   = Encoding.ASCII.GetBytes("needle");

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var seekableStream = new SearchableStream(memStream))
                {
                    // Act
                    var foundPosition = seekableStream.LastIndexOf(needleByteArray);

                    // Assert
                    Assert.AreEqual(16, foundPosition);
                }
        }
Exemplo n.º 5
0
        public void NotInStream()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("This haystack does not contain a n-e-e-d-l-e");
            var needleByteArray   = Encoding.ASCII.GetBytes("needle");

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var seekableStream = new SearchableStream(memStream))
                {
                    // Act
                    var foundPosition = seekableStream.LastIndexOf(needleByteArray);

                    // Assert
                    Assert.AreEqual(-1, foundPosition);
                }
        }
Exemplo n.º 6
0
        public void EmptyStream()
        {
            // Arrange
            var emptyByteArray  = new byte[0];
            var needleByteArray = Encoding.ASCII.GetBytes("needle");

            using (var memStream = new MemoryStream(emptyByteArray))
                using (var seekableStream = new SearchableStream(memStream))
                {
                    // Act
                    var foundPosition = seekableStream.LastIndexOf(needleByteArray);

                    // Assert
                    Assert.AreEqual(-1, foundPosition);
                }
        }
Exemplo n.º 7
0
        public void MultipleOccurance()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("This hay stack has a needle here and another needle here and another needle here");
            var needleByteArray   = Encoding.ASCII.GetBytes("needle");

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var seekableStream = new SearchableStream(memStream))
                {
                    // Act
                    var foundPosition = seekableStream.LastIndexOf(needleByteArray);

                    // Assert
                    Assert.AreEqual(69, foundPosition);
                }
        }
        public void EmptyStream()
        {
            // Arrange
            var emptyByteArray  = new byte[0];
            var needleByteArray = Encoding.ASCII.GetBytes("needle");

            using (var memStream = new MemoryStream(emptyByteArray))
                using (var seekableStream = new SearchableStream(memStream))
                {
                    seekableStream.Seek(0, SeekOrigin.End);
                    // Act
                    var foundPositions = seekableStream.IndexOfAllBackwards(needleByteArray);

                    // Assert
                    Assert.AreEqual(0, foundPositions.Length);
                }
        }
Exemplo n.º 9
0
        public void SingleOccuranceAtBeginning()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("needle in a haystack");
            var needleByteArray   = Encoding.ASCII.GetBytes("needle");

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var seekableStream = new SearchableStream(memStream))
                {
                    // Act
                    var foundPositions = seekableStream.IndexOfAll(needleByteArray);

                    // Assert
                    Assert.AreEqual(1, foundPositions.Length);
                    Assert.AreEqual(0, foundPositions[0]);
                }
        }
        public void NotInStream()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("This haystack does not contain a n-e-e-d-l-e");
            var needleByteArray   = Encoding.ASCII.GetBytes("needle");

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var seekableStream = new SearchableStream(memStream))
                {
                    seekableStream.Seek(0, SeekOrigin.End);

                    // Act
                    var foundPositions = seekableStream.IndexOfAllBackwards(needleByteArray);

                    // Assert
                    Assert.AreEqual(0, foundPositions.Length);
                }
        }
        public void SingleOccuranceAtEnd()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("haystack with a needle");
            var needleByteArray   = Encoding.ASCII.GetBytes("needle");

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var seekableStream = new SearchableStream(memStream))
                {
                    seekableStream.Seek(0, SeekOrigin.End);
                    // Act
                    var foundPositions = seekableStream.IndexOfAllBackwards(needleByteArray);

                    // Assert
                    Assert.AreEqual(1, foundPositions.Length);
                    Assert.AreEqual(16, foundPositions[0]);
                }
        }
Exemplo n.º 12
0
        public void MultipleOccuranceSelectTwo()
        {
            // Arrange
            var haystackByteArray = Encoding.ASCII.GetBytes("This hay stack has a needle here and another needle here and another needle here");
            var needleByteArray   = Encoding.ASCII.GetBytes("needle");

            using (var memStream = new MemoryStream(haystackByteArray))
                using (var seekableStream = new SearchableStream(memStream))
                {
                    // Act
                    var foundPositions = seekableStream.IndexOfAll(needleByteArray, 2);

                    // Assert
                    Assert.AreEqual(2, foundPositions.Length);
                    Assert.AreEqual(21, foundPositions[0]);
                    Assert.AreEqual(45, foundPositions[1]);
                }
        }