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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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]); } }
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]); } }