Add ByteArraySearcher to CsvLib.

This commit is contained in:
2023-08-21 03:20:24 +02:00
parent 1c291807c8
commit 0c05215b94
2 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
using CsvLib;
namespace CvsLib;
public class ByteArraySearcherTests
{
[Fact]
public void Contains__EmptyNeedle_ReturnsTrue()
{
byte[] haystack = { 1, 2, 3, 4, 5 };
byte[] needle = Array.Empty<byte>();
ByteArraySearcher searcher = new(needle);
bool result = searcher.Contains(haystack);
Assert.True(result);
}
[Fact]
public void Contains__NeedleAtBeginning_ReturnsTrue()
{
byte[] haystack = { 1, 2, 3, 4, 5 };
byte[] needle = { 1, 2, 3 };
ByteArraySearcher searcher = new(needle);
bool result = searcher.Contains(haystack);
Assert.True(result);
}
[Fact]
public void Contains__NeedleInMiddle_ReturnsTrue()
{
byte[] haystack = { 1, 2, 3, 4, 5 };
byte[] needle = { 3, 4 };
ByteArraySearcher searcher = new(needle);
bool result = searcher.Contains(haystack);
Assert.True(result);
}
[Fact]
public void Contains__NeedleAtEnd_ReturnsTrue()
{
byte[] haystack = { 1, 2, 3, 4, 5 };
byte[] needle = { 4, 5 };
ByteArraySearcher searcher = new(needle);
bool result = searcher.Contains(haystack);
Assert.True(result);
}
[Fact]
public void Contains__NeedleNotPresent_ReturnsFalse()
{
byte[] haystack = { 1, 2, 3, 4, 5 };
byte[] needle = { 5, 6, 7 };
ByteArraySearcher searcher = new(needle);
bool result = searcher.Contains(haystack);
Assert.False(result);
}
}