1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-21 21:58:47 +00:00

fix(test): use new NUnit constraint API

This commit is contained in:
Oliver Booth 2024-11-13 18:41:45 +00:00
parent 0b978f5cdf
commit a433244799
Signed by: oliverbooth
GPG Key ID: 2A862C3F46178E8E
36 changed files with 457 additions and 312 deletions

View File

@ -117,11 +117,11 @@ internal partial class EnumerableTests
IEnumerable<DummyClass> source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray();
IEnumerable<int> values = source.Select(o => o.Value);
CollectionAssert.AreEqual(oneToTen, values.ToArray());
Assert.That(values.ToArray(), Is.EqualTo(oneToTen).AsCollection);
source.For((i, o) => o.Value *= i);
values = source.Select(o => o.Value);
CollectionAssert.AreEqual(multipliedByIndex, values.ToArray());
Assert.That(values.ToArray(), Is.EqualTo(multipliedByIndex).AsCollection);
}
[Test]
@ -146,11 +146,11 @@ internal partial class EnumerableTests
IEnumerable<DummyClass> source = oneToTen.Select(i => new DummyClass {Value = i}).ToArray();
IEnumerable<int> values = source.Select(o => o.Value);
CollectionAssert.AreEqual(oneToTen, values.ToArray());
Assert.That(values.ToArray(), Is.EqualTo(oneToTen).AsCollection);
source.ForEach(o => o.Value *= 2);
values = source.Select(o => o.Value);
CollectionAssert.AreEqual(oneToTenDoubled, values.ToArray());
Assert.That(values.ToArray(), Is.EqualTo(oneToTenDoubled).AsCollection);
}
[Test]
@ -245,10 +245,10 @@ internal partial class EnumerableTests
int[] array = Enumerable.Range(1, 52).ToArray(); // 52! chance of being shuffled to the same order
int[] shuffled = array[..];
CollectionAssert.AreEqual(array, shuffled);
Assert.That(shuffled, Is.EqualTo(array).AsCollection);
shuffled = array.Shuffled().ToArray();
CollectionAssert.AreNotEqual(array, shuffled);
Assert.That(shuffled, Is.Not.EqualTo(array).AsCollection);
}
[Test]
@ -256,7 +256,7 @@ internal partial class EnumerableTests
{
var enumerable = new[] {2, 4, 6, 7, 8, 9, 10};
IEnumerable<int> result = enumerable.WhereNot(x => x % 2 == 0);
CollectionAssert.AreEqual(new[] {7, 9}, result.ToArray());
Assert.That(result.ToArray(), Is.EqualTo(new[] { 7, 9 }).AsCollection);
}
[Test]
@ -285,7 +285,7 @@ internal partial class EnumerableTests
foreach (object o in array.WhereNotNull())
{
Assert.IsNotNull(o);
Assert.That(o, Is.Not.Null);
actualCount++;
}

View File

@ -15,14 +15,14 @@ internal class ListTests
int[] all42 = Enumerable.Repeat(42, args.Length).ToArray();
var list = new List<int>(args);
CollectionAssert.AreEqual(args, list);
Assert.That(list, Is.EqualTo(args).AsCollection);
args.Fill(42);
list.Fill(42);
CollectionAssert.AreEqual(args, list);
CollectionAssert.AreEqual(all42, args);
CollectionAssert.AreEqual(all42, list);
Assert.That(list, Is.EqualTo(args).AsCollection);
Assert.That(args, Is.EqualTo(all42).AsCollection);
Assert.That(list, Is.EqualTo(all42).AsCollection);
}
[Test]
@ -36,7 +36,7 @@ internal class ListTests
int[] comparison = Enumerable.Repeat(1, args.Length - 1).ToArray();
Assert.That(args[0], Is.EqualTo(first));
CollectionAssert.AreEqual(comparison, args[1..]);
Assert.That(args[1..], Is.EqualTo(comparison).AsCollection);
}
[Test]
@ -80,7 +80,7 @@ internal class ListTests
[Test]
public void IndexOf_ShouldReturnCorrectValue_FromStartOfList()
{
int[] array = {0, 1, 2, 3, 4};
int[] array = { 0, 1, 2, 3, 4 };
Assert.Multiple(() =>
{
Assert.That(array.IndexOf(2), Is.EqualTo(2));
@ -92,7 +92,7 @@ internal class ListTests
[Test]
public void IndexOf_ShouldReturnCorrectValue_GivenSubRange()
{
int[] array = {0, 1, 2, 3, 4, 0};
int[] array = { 0, 1, 2, 3, 4, 0 };
Assert.Multiple(() =>
{
Assert.That(array.IndexOf(0), Is.Zero);
@ -149,7 +149,7 @@ internal class ListTests
[Test]
public void IndexOf_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair()
{
int[] array = {0, 1, 2};
int[] array = { 0, 1, 2 };
Assert.Throws<ArgumentOutOfRangeException>(() => array.IndexOf(0, 2, 4));
}
@ -184,7 +184,7 @@ internal class ListTests
public void RemoveRange_ShouldThrowArgumentOutOfRangeException_GivenEndIndexGreaterThanOrEqualToCount()
{
Assert.Throws<ArgumentOutOfRangeException>(() => new List<int>().RemoveRange(..0));
Assert.Throws<ArgumentOutOfRangeException>(() => new List<int> {1}.RemoveRange(..2));
Assert.Throws<ArgumentOutOfRangeException>(() => new List<int> { 1 }.RemoveRange(..2));
}
[Test]
@ -208,7 +208,7 @@ internal class ListTests
list.RemoveRange(2..5);
Assert.That(list, Has.Count.EqualTo(6));
CollectionAssert.AreEqual(new[] {1, 2, 7, 8, 9, 10}, list);
Assert.That(list, Is.EqualTo(new[] { 1, 2, 7, 8, 9, 10 }).AsCollection);
}
[Test]
@ -217,11 +217,11 @@ internal class ListTests
var list = new List<int>(Enumerable.Range(1, 52)); // 52! chance of being shuffled to the same order
var shuffled = new List<int>(list);
CollectionAssert.AreEqual(list, shuffled);
Assert.That(shuffled, Is.EqualTo(list).AsCollection);
shuffled.Shuffle();
CollectionAssert.AreNotEqual(list, shuffled);
Assert.That(shuffled, Is.Not.EqualTo(list).AsCollection);
}
[Test]
@ -233,23 +233,23 @@ internal class ListTests
[Test]
public void Slice_ShouldReturnCorrectValue_GivenStartIndex()
{
int[] array = {0, 1, 2, 3, 4, 5};
CollectionAssert.AreEqual(new[] {2, 3, 4, 5}, array.Slice(2).ToArray());
int[] array = { 0, 1, 2, 3, 4, 5 };
Assert.That(array.Slice(2).ToArray(), Is.EqualTo(new[] { 2, 3, 4, 5 }).AsCollection);
}
[Test]
public void Slice_ShouldReturnCorrectValue_GivenStartIndexAndLength()
{
int[] array = {0, 1, 2, 3, 4, 5};
CollectionAssert.AreEqual(new[] {2, 3, 4}, array.Slice(2, 3).ToArray());
int[] array = { 0, 1, 2, 3, 4, 5 };
Assert.That(array.Slice(2, 3).ToArray(), Is.EqualTo(new[] { 2, 3, 4 }).AsCollection);
}
[Test]
public void Slice_ShouldReturnEmptyList_ForEmptyList()
{
int[] array = Array.Empty<int>();
CollectionAssert.AreEqual(Array.Empty<int>(), array.Slice(0).ToArray());
CollectionAssert.AreEqual(Array.Empty<int>(), array.Slice(0, 0).ToArray());
Assert.That(array.Slice(0).ToArray(), Is.EqualTo(Array.Empty<int>()).AsCollection);
Assert.That(array.Slice(0, 0).ToArray(), Is.EqualTo(Array.Empty<int>()).AsCollection);
}
[Test]
@ -278,7 +278,7 @@ internal class ListTests
[Test]
public void Slice_ShouldThrowArgumentOutOfRangeException_GivenInvalidStartIndexCountPair()
{
int[] array = {0, 1, 2};
int[] array = { 0, 1, 2 };
Assert.Throws<ArgumentOutOfRangeException>(() => array.Slice(2, 4));
}
@ -297,18 +297,18 @@ internal class ListTests
[Test]
public void Swap_ShouldSwapElements_GivenMatchingElementCount()
{
var first = new List<int> {1, 2, 3};
var second = new List<int> {4, 5, 6};
var first = new List<int> { 1, 2, 3 };
var second = new List<int> { 4, 5, 6 };
first.Swap(second);
CollectionAssert.AreEqual(new[] {4, 5, 6}, first, string.Join(' ', first));
CollectionAssert.AreEqual(new[] {1, 2, 3}, second, string.Join(' ', second));
Assert.That(first, Is.EqualTo(new[] { 4, 5, 6 }).AsCollection, string.Join(' ', first));
Assert.That(second, Is.EqualTo(new[] { 1, 2, 3 }).AsCollection, string.Join(' ', second));
first.Swap(second);
CollectionAssert.AreEqual(new[] {1, 2, 3}, first, string.Join(' ', first));
CollectionAssert.AreEqual(new[] {4, 5, 6}, second, string.Join(' ', second));
Assert.That(first, Is.EqualTo(new[] { 1, 2, 3 }).AsCollection, string.Join(' ', first));
Assert.That(second, Is.EqualTo(new[] { 4, 5, 6 }).AsCollection, string.Join(' ', second));
}
[Test]
@ -322,16 +322,16 @@ internal class ListTests
4,
5
};
var second = new List<int> {6, 7};
var second = new List<int> { 6, 7 };
first.Swap(second);
CollectionAssert.AreEqual(new[] {6, 7}, first, string.Join(' ', first));
CollectionAssert.AreEqual(new[] {1, 2, 3, 4, 5}, second, string.Join(' ', second));
Assert.That(first, Is.EqualTo(new[] { 6, 7 }).AsCollection, string.Join(' ', first));
Assert.That(second, Is.EqualTo(new[] { 1, 2, 3, 4, 5 }).AsCollection, string.Join(' ', second));
first.Swap(second);
CollectionAssert.AreEqual(new[] {1, 2, 3, 4, 5}, first, string.Join(' ', first));
CollectionAssert.AreEqual(new[] {6, 7}, second, string.Join(' ', second));
Assert.That(first, Is.EqualTo(new[] { 1, 2, 3, 4, 5 }).AsCollection, string.Join(' ', first));
Assert.That(second, Is.EqualTo(new[] { 6, 7 }).AsCollection, string.Join(' ', second));
}
}

View File

@ -31,7 +31,7 @@ internal class SpanTest
[Test]
public void Count_ShouldReturn8_GivenSpanWith8MatchingElements()
{
Span<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2};
Span<int> span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 };
int count = span.Count(2);
@ -41,7 +41,7 @@ internal class SpanTest
[Test]
public void Count_ShouldReturn8_GivenReadOnlySpanWith8MatchingElements()
{
ReadOnlySpan<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2};
ReadOnlySpan<int> span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 };
int count = span.Count(2);
@ -51,25 +51,25 @@ internal class SpanTest
[Test]
public void Replace_ShouldReplaceAllElements_GivenSpanOfInt32()
{
Span<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2};
Span<int> span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 };
span.Replace(2, 4);
Assert.That(span.ToArray(), Is.EqualTo(new[] {1, 4, 3, 4, 5, 4, 7, 4, 9, 4, 11, 4, 13, 4, 15, 4}));
Assert.That(span.ToArray(), Is.EqualTo(new[] { 1, 4, 3, 4, 5, 4, 7, 4, 9, 4, 11, 4, 13, 4, 15, 4 }));
}
[Test]
public void Replace_ShouldReplaceAllElements_GivenSpanOfChar()
{
Span<char> chars = stackalloc char[12] {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!'};
Span<char> chars = stackalloc char[12] { 'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!' };
chars.Replace('l', 'w');
CollectionAssert.AreEqual(chars.ToArray(), "Hewwo worwd!".ToCharArray());
Assert.That("Hewwo worwd!".ToCharArray(), Is.EqualTo(chars.ToArray()).AsCollection);
}
[Test]
public void Replace_ShouldDoNothing_GivenSpanWithNoMatchingElements()
{
Span<int> span = stackalloc int[16] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2};
Span<int> span = stackalloc int[16] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 };
span.Replace(4, 8);
Assert.That(span.ToArray(), Is.EqualTo(new[] {1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2}));
Assert.That(span.ToArray(), Is.EqualTo(new[] { 1, 2, 3, 2, 5, 2, 7, 2, 9, 2, 11, 2, 13, 2, 15, 2 }));
}
#if !NET9_0_OR_GREATER

View File

@ -63,7 +63,7 @@ internal class CoreTests
// ReSharper disable once PossibleMultipleEnumeration
object[] array = enumerable.ToArray();
Assert.That(array, Has.Length.EqualTo(10));
CollectionAssert.AreEqual(new[] {o, o, o, o, o, o, o, o, o, o}, array);
Assert.That(array, Is.EqualTo(new[] { o, o, o, o, o, o, o, o, o, o }).AsCollection);
}
[Test]

View File

@ -1,4 +1,3 @@
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.X86;
using NUnit.Framework;
using X10D.Core;

View File

@ -85,7 +85,7 @@ internal class PolygonFTests
// we cannot use CollectionAssert here for reasons I am not entirely sure of.
// it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay.
CollectionAssert.AreEqual(first.Vertices, second.Vertices);
Assert.That(second.Vertices, Is.EqualTo(first.Vertices).AsCollection);
// assert that the empty polygon was not modified
Assert.That(PolygonF.Empty.VertexCount, Is.Zero);
@ -178,7 +178,7 @@ internal class PolygonFTests
Assert.That(converted, Is.EqualTo((Polygon)polygon));
Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex));
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
CollectionAssert.AreEqual(polygon.Vertices, converted.Vertices.Select(p => (PointF)p));
Assert.That(converted.Vertices.Select(p => (PointF)p), Is.EqualTo(polygon.Vertices).AsCollection);
});
}
@ -194,7 +194,7 @@ internal class PolygonFTests
Assert.That(converted == polygon);
Assert.That(converted.IsConvex, Is.EqualTo(polygon.IsConvex));
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p => (PointF)p));
Assert.That(polygon.Vertices.Select(p => (PointF)p), Is.EqualTo(converted.Vertices).AsCollection);
});
}

View File

@ -75,7 +75,7 @@ internal class PolyhedronTests
// we cannot use CollectionAssert here for reasons I am not entirely sure of.
// it seems to dislike casting from IReadOnlyList<Point> to ICollection. but okay.
CollectionAssert.AreEqual(first.Vertices, second.Vertices);
Assert.That(second.Vertices, Is.EqualTo(first.Vertices).AsCollection);
// assert that the empty polyhedron was not modified
Assert.That(Polyhedron.Empty.VertexCount, Is.Zero);
@ -148,11 +148,11 @@ internal class PolyhedronTests
Assert.That(converted, Is.EqualTo((Polyhedron)polygon));
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p =>
Assert.That(polygon.Vertices.Select(p =>
{
var point = p.ToVector2();
return new Vector3(point.X, point.Y, 0);
}));
}), Is.EqualTo(converted.Vertices).AsCollection);
});
}
@ -166,11 +166,11 @@ internal class PolyhedronTests
{
Assert.That(converted, Is.EqualTo((Polyhedron)polygon));
Assert.That(converted.VertexCount, Is.EqualTo(polygon.VertexCount));
CollectionAssert.AreEqual(converted.Vertices, polygon.Vertices.Select(p =>
Assert.That(converted.Vertices, Is.EqualTo(polygon.Vertices.Select(p =>
{
var point = p.ToVector2();
return new Vector3(point.X, point.Y, 0);
}));
})).AsCollection);
});
}

View File

@ -23,8 +23,8 @@ internal class ServiceCollectionTests
{
Assert.That(service, Is.Not.Null);
Assert.That(hostedService, Is.Not.Null);
Assert.IsAssignableFrom<TestService>(service);
Assert.IsAssignableFrom<TestService>(hostedService);
Assert.That(service, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.SameAs(service));
});
}
@ -44,8 +44,8 @@ internal class ServiceCollectionTests
{
Assert.That(service, Is.Not.Null);
Assert.That(hostedService, Is.Not.Null);
Assert.IsAssignableFrom<TestService>(service);
Assert.IsAssignableFrom<TestService>(hostedService);
Assert.That(service, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.SameAs(service));
});
}
@ -65,8 +65,8 @@ internal class ServiceCollectionTests
{
Assert.That(service, Is.Not.Null);
Assert.That(hostedService, Is.Not.Null);
Assert.IsAssignableFrom<TestService>(service);
Assert.IsAssignableFrom<TestService>(hostedService);
Assert.That(service, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.SameAs(service));
});
}
@ -86,8 +86,8 @@ internal class ServiceCollectionTests
{
Assert.That(service, Is.Not.Null);
Assert.That(hostedService, Is.Not.Null);
Assert.IsAssignableFrom<TestService>(service);
Assert.IsAssignableFrom<TestService>(hostedService);
Assert.That(service, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.AssignableFrom<TestService>());
Assert.That(hostedService, Is.SameAs(service));
});
}

View File

@ -10,7 +10,7 @@ internal class BooleanTests
public void GetBytes_ReturnsArrayContaining1()
{
const bool value = true;
CollectionAssert.AreEqual(new byte[] {1}, value.GetBytes());
Assert.That(value.GetBytes(), Is.EqualTo(new byte[] { 1 }).AsCollection);
}
[Test]
@ -19,7 +19,7 @@ internal class BooleanTests
const bool value = true;
Span<byte> buffer = stackalloc byte[1];
Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(new byte[] {1}, buffer.ToArray());
Assert.That(buffer.ToArray(), Is.EqualTo(new byte[] { 1 }).AsCollection);
}
[Test]

View File

@ -10,16 +10,19 @@ internal class ByteTests
public void GetBytes_ReturnsArrayContainingItself()
{
const byte value = 0xFF;
CollectionAssert.AreEqual(new[] {value}, value.GetBytes());
Assert.That(value.GetBytes(), Is.EqualTo(new[] { value }).AsCollection);
}
[Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan()
{
const byte value = 0xFF;
Assert.Multiple(() =>
{
Span<byte> buffer = stackalloc byte[1];
Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(new[] {value}, buffer.ToArray());
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { value }).AsCollection);
});
}
[Test]

View File

@ -14,7 +14,7 @@ internal class DecimalTests
byte[] bytes = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, bytes);
Assert.That(bytes, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -25,7 +25,7 @@ internal class DecimalTests
byte[] bytes = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, bytes);
Assert.That(bytes, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -34,10 +34,12 @@ internal class DecimalTests
const decimal value = 1234m;
byte[] expected = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 210];
Assert.Multiple(() =>
{
Span<byte> bytes = stackalloc byte[16];
Assert.That(value.TryWriteBigEndianBytes(bytes));
CollectionAssert.AreEqual(expected, bytes.ToArray());
Assert.That(bytes.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]
@ -46,10 +48,12 @@ internal class DecimalTests
const decimal value = 1234m;
byte[] expected = [210, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
Assert.Multiple(() =>
{
Span<byte> bytes = stackalloc byte[16];
Assert.That(value.TryWriteLittleEndianBytes(bytes));
CollectionAssert.AreEqual(expected, bytes.ToArray());
Assert.That(bytes.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]

View File

@ -13,7 +13,7 @@ internal class DoubleTests
var expected = new byte[] { 0x40, 0x45, 0x40, 0, 0, 0, 0, 0 };
byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -23,7 +23,7 @@ internal class DoubleTests
var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 };
byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -32,9 +32,12 @@ internal class DoubleTests
const double value = 42.5;
var expected = new byte[] { 0x40, 0x45, 0x40, 0, 0, 0, 0, 0 };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
Assert.That(value.TryWriteBigEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]
@ -43,9 +46,12 @@ internal class DoubleTests
const double value = 42.5;
var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
Assert.That(value.TryWriteLittleEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]

View File

@ -29,7 +29,7 @@ internal class FileInfoTests
try
{
byte[] hash = new FileInfo(fileName).GetHash<SHA1>();
CollectionAssert.AreEqual(expectedHash, hash);
Assert.That(hash, Is.EqualTo(expectedHash).AsCollection);
}
finally
{
@ -57,11 +57,15 @@ internal class FileInfoTests
};
try
{
Assert.Multiple(() =>
{
Span<byte> hash = stackalloc byte[20];
new FileInfo(fileName).TryWriteHash<SHA1>(hash, out int bytesWritten);
Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length));
CollectionAssert.AreEqual(expectedHash, hash.ToArray());
Assert.That(hash.ToArray(), Is.EqualTo(expectedHash).AsCollection);
});
}
finally
{

View File

@ -13,7 +13,7 @@ internal class Int16Tests
byte[] expected = { 0x0F, 0 };
byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -23,7 +23,7 @@ internal class Int16Tests
byte[] expected = { 0, 0x0F };
byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -32,9 +32,12 @@ internal class Int16Tests
const short value = 0x0F;
byte[] expected = { 0x0F, 0 };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[2];
Assert.That(value.TryWriteLittleEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]
@ -43,9 +46,12 @@ internal class Int16Tests
const short value = 0x0F;
byte[] expected = { 0, 0x0F };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[2];
Assert.That(value.TryWriteBigEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]

View File

@ -13,7 +13,7 @@ internal class Int32Tests
var expected = new byte[] { 0, 0, 0, 0x0F };
byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -23,7 +23,7 @@ internal class Int32Tests
var expected = new byte[] { 0x0F, 0, 0, 0 };
byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -32,9 +32,12 @@ internal class Int32Tests
const int value = 0x0F;
var expected = new byte[] { 0, 0, 0, 0x0F };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
Assert.That(value.TryWriteBigEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]
@ -43,9 +46,12 @@ internal class Int32Tests
const int value = 0x0F;
var expected = new byte[] { 0x0F, 0, 0, 0 };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
Assert.That(value.TryWriteLittleEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]

View File

@ -13,7 +13,7 @@ internal class Int64Tests
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -23,7 +23,7 @@ internal class Int64Tests
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -32,9 +32,12 @@ internal class Int64Tests
const long value = 0x0F;
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
Assert.That(value.TryWriteLittleEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]
@ -43,9 +46,12 @@ internal class Int64Tests
const long value = 0x0F;
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
Assert.That(value.TryWriteBigEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]

View File

@ -10,16 +10,19 @@ internal class SByteTests
public void GetBytes_ReturnsArrayContainingItself()
{
const sbyte value = 0x0F;
CollectionAssert.AreEqual(new[] {(byte)value}, value.GetBytes());
Assert.That(value.GetBytes(), Is.EqualTo(new[] { (byte)value }).AsCollection);
}
[Test]
public void TryWriteBytes_ReturnsTrue_FillsSpanContainingItself_GivenLargeEnoughSpan()
{
const sbyte value = 0x0F;
Assert.Multiple(() =>
{
Span<byte> buffer = stackalloc byte[1];
Assert.That(value.TryWriteBytes(buffer));
CollectionAssert.AreEqual(new[] {(byte)value}, buffer.ToArray());
Assert.That(buffer.ToArray(), Is.EqualTo(new[] { (byte)value }).AsCollection);
});
}
[Test]

View File

@ -13,7 +13,7 @@ internal class SingleTests
var expected = new byte[] { 0x42, 0x2A, 0, 0 };
byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -23,7 +23,7 @@ internal class SingleTests
var expected = new byte[] { 0, 0, 0x2A, 0x42 };
byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -32,9 +32,12 @@ internal class SingleTests
const float value = 42.5f;
var expected = new byte[] { 0x42, 0x2A, 0, 0 };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
Assert.That(value.TryWriteBigEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]
@ -43,9 +46,12 @@ internal class SingleTests
const float value = 42.5f;
var expected = new byte[] { 0, 0, 0x2A, 0x42 };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
Assert.That(value.TryWriteLittleEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]

View File

@ -45,6 +45,8 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(16));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[16];
ReadOnlySpan<byte> expected = stackalloc byte[]
{
@ -54,7 +56,8 @@ internal partial class StreamTests
Trace.WriteLine(string.Join(' ', actual.ToArray()));
Assert.That(read, Is.EqualTo(16));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
[Test]
@ -65,6 +68,8 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(16));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[16];
ReadOnlySpan<byte> expected = stackalloc byte[]
{
@ -75,6 +80,7 @@ internal partial class StreamTests
Trace.WriteLine(string.Join(", ", actual.ToArray().Select(b => $"0x{b:X2}")));
Assert.That(read, Is.EqualTo(16));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
}

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x40, 0x7A, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
[Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x7A, 0x40 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
}

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
[Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
}

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
[Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
}

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
[Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
}

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x43, 0xD2, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
[Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0xD2, 0x43 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
}

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
[Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(2));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[2];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(2));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
}

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
[Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(4));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(4));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
}

View File

@ -44,12 +44,15 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA4 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
[Test]
@ -60,11 +63,14 @@ internal partial class StreamTests
Assert.That(stream.Position, Is.EqualTo(8));
stream.Position = 0;
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
ReadOnlySpan<byte> expected = stackalloc byte[] { 0xA4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int read = stream.Read(actual);
Assert.That(read, Is.EqualTo(8));
CollectionAssert.AreEqual(expected.ToArray(), actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected.ToArray()).AsCollection);
});
}
}

View File

@ -26,7 +26,7 @@ internal partial class StreamTests
byte[] hash = stream.GetHash<SHA1>();
Trace.WriteLine($"Hash: {BitConverter.ToString(hash)}");
Trace.WriteLine($"Expected: {BitConverter.ToString(expectedHash)}");
CollectionAssert.AreEqual(expectedHash, hash);
Assert.That(hash, Is.EqualTo(expectedHash).AsCollection);
}
[Test]
@ -54,7 +54,7 @@ internal partial class StreamTests
Span<byte> hash = stackalloc byte[20];
stream.TryWriteHash<SHA1>(hash, out int bytesWritten);
Assert.That(bytesWritten, Is.EqualTo(expectedHash.Length));
CollectionAssert.AreEqual(expectedHash, hash.ToArray());
Assert.That(hash.ToArray(), Is.EqualTo(expectedHash).AsCollection);
}
[Test]

View File

@ -13,7 +13,7 @@ internal class UInt16Tests
byte[] expected = { 0x0F, 0 };
byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -23,7 +23,7 @@ internal class UInt16Tests
byte[] expected = { 0, 0x0F };
byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -32,10 +32,12 @@ internal class UInt16Tests
const ushort value = 0x0F;
byte[] expected = { 0x0F, 0 };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[2];
Assert.That(value.TryWriteLittleEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]
@ -44,10 +46,12 @@ internal class UInt16Tests
const ushort value = 0x0F;
byte[] expected = { 0, 0x0F };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[2];
Assert.That(value.TryWriteBigEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]

View File

@ -13,7 +13,7 @@ internal class UInt32Tests
byte[] expected = { 0x0F, 0, 0, 0 };
byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -23,7 +23,7 @@ internal class UInt32Tests
byte[] expected = { 0, 0, 0, 0x0F };
byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -32,10 +32,12 @@ internal class UInt32Tests
const uint value = 0x0F;
byte[] expected = { 0x0F, 0, 0, 0 };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
Assert.That(value.TryWriteLittleEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]
@ -44,10 +46,12 @@ internal class UInt32Tests
const uint value = 0x0F;
byte[] expected = { 0, 0, 0, 0x0F };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[4];
Assert.That(value.TryWriteBigEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]

View File

@ -13,7 +13,7 @@ internal class UInt64Tests
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
byte[] actual = value.GetLittleEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -23,7 +23,7 @@ internal class UInt64Tests
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
byte[] actual = value.GetBigEndianBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -32,10 +32,12 @@ internal class UInt64Tests
const ulong value = 0x0F;
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
Assert.That(value.TryWriteLittleEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]
@ -44,10 +46,12 @@ internal class UInt64Tests
const ulong value = 0x0F;
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
Assert.Multiple(() =>
{
Span<byte> actual = stackalloc byte[8];
Assert.That(value.TryWriteBigEndianBytes(actual));
CollectionAssert.AreEqual(expected, actual.ToArray());
Assert.That(actual.ToArray(), Is.EqualTo(expected).AsCollection);
});
}
[Test]

View File

@ -142,7 +142,7 @@ internal class IsPrimeTests
private static IReadOnlyList<int> LoadPrimes()
{
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("X10D.Tests.1000primes.txt");
Assert.IsNotNull(stream);
Assert.That(stream, Is.Not.Null);
using var reader = new StreamReader(stream, Encoding.UTF8);
var primes = new List<int>();

View File

@ -20,7 +20,11 @@ internal class CoreTests
int[] source = Enumerable.Range(1, 100).ToArray();
string json = source.ToJson();
int[]? target = json.FromJson<int[]>();
CollectionAssert.AreEqual(source, target);
CollectionAssert.AreEquivalent(source, target);
Assert.Multiple(() =>
{
Assert.That(target, Is.EqualTo(source).AsCollection);
Assert.That(target, Is.EquivalentTo(source));
});
}
}

View File

@ -10,13 +10,13 @@ internal class EnumerableTests
public void Grep_ShouldFilterCorrectly_GivenPattern()
{
int year = DateTime.Now.Year;
var source = new[] {"Hello", "World", "String 123", $"The year is {year}"};
var expectedResult = new[] {"String 123", $"The year is {year}"};
var source = new[] { "Hello", "World", "String 123", $"The year is {year}" };
var expectedResult = new[] { "String 123", $"The year is {year}" };
const string pattern = /*lang=regex*/@"[0-9]+";
string[] actualResult = source.Grep(pattern).ToArray();
CollectionAssert.AreEqual(expectedResult, actualResult);
Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection);
}
[Test]
@ -28,27 +28,27 @@ internal class EnumerableTests
const string pattern = /*lang=regex*/@"[0-9]+";
string[] actualResult = source.Grep(pattern).ToArray();
CollectionAssert.AreEqual(expectedResult, actualResult);
Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection);
}
[Test]
public void Grep_ShouldMatchUpperCase_GivenIgnoreCaseTrue()
{
int year = DateTime.Now.Year;
var source = new[] {"Hello", "WORLD", "String 123", $"The year is {year}"};
var expectedResult = new[] {"WORLD"};
var source = new[] { "Hello", "WORLD", "String 123", $"The year is {year}" };
var expectedResult = new[] { "WORLD" };
const string pattern = /*lang=regex*/@"world";
string[] actualResult = source.Grep(pattern, true).ToArray();
CollectionAssert.AreEqual(expectedResult, actualResult);
Assert.That(actualResult, Is.EqualTo(expectedResult).AsCollection);
}
[Test]
public void Grep_ShouldNotMatchUpperCase_GivenIgnoreCaseFalse()
{
int year = DateTime.Now.Year;
var source = new[] {"Hello", "WORLD", "String 123", $"The year is {year}"};
var source = new[] { "Hello", "WORLD", "String 123", $"The year is {year}" };
const string pattern = /*lang=regex*/@"world";
string[] actualResult = source.Grep(pattern, false).ToArray();
@ -60,22 +60,28 @@ internal class EnumerableTests
public void Grep_ShouldThrowArgumentNullException_GivenNullPattern()
{
IEnumerable<string> source = Enumerable.Empty<string>();
Assert.Multiple(() =>
{
Assert.Throws<ArgumentNullException>(() => source.Grep(null!).ToArray());
Assert.Throws<ArgumentNullException>(() => source.Grep(null!, false).ToArray());
});
}
[Test]
public void Grep_ShouldThrowArgumentNullException_GivenNullSource()
{
IEnumerable<string> source = null!;
Assert.Multiple(() =>
{
Assert.Throws<ArgumentNullException>(() => source.Grep("foo").ToArray());
Assert.Throws<ArgumentNullException>(() => source.Grep("foo", false).ToArray());
});
}
[Test]
public void Grep_ShouldYieldNoElements_GivenNoMatchingStrings()
{
var source = new[] {"Hello", "World", "String"};
var source = new[] { "Hello", "World", "String" };
const string pattern = /*lang=regex*/@"[0-9]+";
string[] actualResult = source.Grep(pattern).ToArray();

View File

@ -22,6 +22,8 @@ internal class StringBuilderReaderTests
{
using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld"));
Assert.Multiple(() =>
{
Assert.That(reader.Read(), Is.EqualTo('H'));
Assert.That(reader.Read(), Is.EqualTo('e'));
Assert.That(reader.Read(), Is.EqualTo('l'));
@ -34,6 +36,7 @@ internal class StringBuilderReaderTests
Assert.That(reader.Read(), Is.EqualTo('l'));
Assert.That(reader.Read(), Is.EqualTo('d'));
Assert.That(reader.Read(), Is.EqualTo(-1));
});
reader.Close();
}
@ -45,9 +48,12 @@ internal class StringBuilderReaderTests
var array = new char[5];
int read = reader.Read(array, 0, 5);
Assert.That(read, Is.EqualTo(5));
CollectionAssert.AreEqual("Hello".ToCharArray(), array);
Assert.Multiple(() =>
{
Assert.That(read, Is.EqualTo(5));
Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection);
});
reader.Close();
}
@ -114,11 +120,14 @@ internal class StringBuilderReaderTests
{
using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld"));
Assert.Multiple(() =>
{
Span<char> span = stackalloc char[5];
int read = reader.Read(span);
Assert.That(read, Is.EqualTo(5));
CollectionAssert.AreEqual("Hello".ToCharArray(), span.ToArray());
Assert.That(read, Is.EqualTo(5));
Assert.That(span.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection);
});
reader.Close();
}
@ -130,9 +139,12 @@ internal class StringBuilderReaderTests
var array = new char[5];
int read = reader.ReadAsync(array, 0, 5).GetAwaiter().GetResult();
Assert.That(read, Is.EqualTo(5));
CollectionAssert.AreEqual("Hello".ToCharArray(), array);
Assert.Multiple(() =>
{
Assert.That(read, Is.EqualTo(5));
Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection);
});
reader.Close();
}
@ -144,9 +156,12 @@ internal class StringBuilderReaderTests
Memory<char> memory = new char[5];
int read = reader.ReadAsync(memory).GetAwaiter().GetResult();
Assert.That(read, Is.EqualTo(5));
CollectionAssert.AreEqual("Hello".ToCharArray(), memory.ToArray());
Assert.Multiple(() =>
{
Assert.That(read, Is.EqualTo(5));
Assert.That(memory.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection);
});
reader.Close();
}
@ -158,9 +173,12 @@ internal class StringBuilderReaderTests
var array = new char[5];
int read = reader.ReadBlock(array, 0, 5);
Assert.That(read, Is.EqualTo(5));
CollectionAssert.AreEqual("Hello".ToCharArray(), array);
Assert.Multiple(() =>
{
Assert.That(read, Is.EqualTo(5));
Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection);
});
reader.Close();
}
@ -170,11 +188,14 @@ internal class StringBuilderReaderTests
{
using var reader = new StringBuilderReader(new StringBuilder("Hello\nWorld"));
Assert.Multiple(() =>
{
Span<char> span = stackalloc char[5];
int read = reader.ReadBlock(span);
Assert.That(read, Is.EqualTo(5));
CollectionAssert.AreEqual("Hello".ToCharArray(), span.ToArray());
Assert.That(read, Is.EqualTo(5));
Assert.That(span.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection);
});
reader.Close();
}
@ -200,9 +221,12 @@ internal class StringBuilderReaderTests
var array = new char[5];
int read = reader.ReadBlockAsync(array, 0, 5).GetAwaiter().GetResult();
Assert.That(read, Is.EqualTo(5));
CollectionAssert.AreEqual("Hello".ToCharArray(), array);
Assert.Multiple(() =>
{
Assert.That(read, Is.EqualTo(5));
Assert.That(array, Is.EqualTo("Hello".ToCharArray()).AsCollection);
});
reader.Close();
}
@ -214,9 +238,12 @@ internal class StringBuilderReaderTests
Memory<char> memory = new char[5];
int read = reader.ReadBlockAsync(memory).GetAwaiter().GetResult();
Assert.That(read, Is.EqualTo(5));
CollectionAssert.AreEqual("Hello".ToCharArray(), memory.ToArray());
Assert.Multiple(() =>
{
Assert.That(read, Is.EqualTo(5));
Assert.That(memory.ToArray(), Is.EqualTo("Hello".ToCharArray()).AsCollection);
});
reader.Close();
}

View File

@ -423,7 +423,7 @@ internal class StringTests
var target = json.FromJson<SampleStructure>();
Assert.Multiple(() =>
{
Assert.IsInstanceOf<SampleStructure>(target);
Assert.That(target, Is.InstanceOf<SampleStructure>());
Assert.That(target.Values, Is.Not.Null);
Assert.That(target.Values.Length, Is.EqualTo(3));
Assert.That(target.Values[0], Is.EqualTo(1));
@ -438,7 +438,7 @@ internal class StringTests
var expected = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
byte[] actual = "Hello World".GetBytes();
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -447,7 +447,7 @@ internal class StringTests
var expected = new byte[] { 0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 };
byte[] actual = "Hello World".GetBytes(Encoding.ASCII);
CollectionAssert.AreEqual(expected, actual);
Assert.That(actual, Is.EqualTo(expected).AsCollection);
}
[Test]
@ -1004,7 +1004,6 @@ internal class StringTests
private struct SampleStructure
{
[JsonPropertyName("values")]
public int[] Values { get; set; }
[JsonPropertyName("values")] public int[] Values { get; set; }
}
}