public void NullNeedle() { // Arrange 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 searchableStringString = new SearchableStringStream(memStream)) { // Act var foundPosition = searchableStringString.IndexOf(null); } }
public void SingleOccuranceAtBeginning() { // Arrange var haystackByteArray = Encoding.ASCII.GetBytes("needle in a haystack"); var needle = "needle"; using (var memStream = new MemoryStream(haystackByteArray)) using (var searchableStringStream = new SearchableStringStream(memStream)) { // Act var foundPosition = searchableStringStream.IndexOf(needle); // Assert Assert.AreEqual(0, foundPosition); } }
public void NotInStream() { // Arrange var haystackByteArray = Encoding.ASCII.GetBytes("This haystack does not contain a n-e-e-d-l-e"); var needle = "needle"; using (var memStream = new MemoryStream(haystackByteArray)) using (var searchableStringStream = new SearchableStringStream(memStream)) { // Act var foundPosition = searchableStringStream.IndexOf(needle); // Assert Assert.AreEqual(-1, foundPosition); } }
public void EmptyStream() { // Arrange var emptyByteArray = new byte[0]; var needle = "needle"; using (var memStream = new MemoryStream(emptyByteArray)) using (var searchableStringStream = new SearchableStringStream(memStream)) { // Act var foundPosition = searchableStringStream.IndexOf(needle); // Assert Assert.AreEqual(-1, foundPosition); } }
public void MultipleOccurance_Unicode() { // Arrange var haystackByteArray = Encoding.Unicode.GetBytes("This hay stack has a needle here and another needle here and another needle here"); var needle = "needle"; using (var memStream = new MemoryStream(haystackByteArray)) using (var searchableStringStream = new SearchableStringStream(memStream, Encoding.Unicode)) { // Act var foundPosition = searchableStringStream.IndexOf(needle); // Assert Assert.AreEqual(42, foundPosition); } }