1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 19:58:49 +00:00

Move Span.Any/All to Linq namespace (#7)

This commit is contained in:
Oliver Booth 2022-04-22 08:50:06 +01:00
parent 0fb01726db
commit d5a74c12a8
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
4 changed files with 118 additions and 2 deletions

View File

@ -0,0 +1,58 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Linq;
namespace X10D.Tests.Linq;
[TestClass]
public class ReadOnlySpanTests
{
[TestMethod]
public void AllShouldReturnTrueForEmptySpan()
{
var span = new ReadOnlySpan<int>();
Assert.IsTrue(span.All(x => x > 0));
}
[TestMethod]
public void AllShouldBeCorrect()
{
var span = new ReadOnlySpan<int>(new[] {2, 4, 6, 8, 10});
Assert.IsTrue(span.All(x => x % 2 == 0));
Assert.IsFalse(span.All(x => x % 2 == 1));
}
[TestMethod]
public void AnyShouldReturnFalseForEmptySpan()
{
var span = new ReadOnlySpan<int>();
Assert.IsFalse(span.Any(x => x > 0));
}
[TestMethod]
public void AnyShouldBeCorrect()
{
var span = new ReadOnlySpan<int>(new[] {2, 4, 6, 8, 10});
Assert.IsTrue(span.Any(x => x % 2 == 0));
Assert.IsFalse(span.Any(x => x % 2 == 1));
}
[TestMethod]
public void AllNullPredicateShouldThrow()
{
Assert.ThrowsException<ArgumentNullException>(() =>
{
var span = new ReadOnlySpan<int>();
return span.All(null!);
});
}
[TestMethod]
public void AnyNullPredicateShouldThrow()
{
Assert.ThrowsException<ArgumentNullException>(() =>
{
var span = new ReadOnlySpan<int>();
return span.Any(null!);
});
}
}

View File

@ -0,0 +1,58 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using X10D.Linq;
namespace X10D.Tests.Linq;
[TestClass]
public class SpanTests
{
[TestMethod]
public void AllShouldReturnTrueForEmptySpan()
{
var span = new Span<int>();
Assert.IsTrue(span.All(x => x > 0));
}
[TestMethod]
public void AllShouldBeCorrect()
{
var span = new Span<int>(new[] {2, 4, 6, 8, 10});
Assert.IsTrue(span.All(x => x % 2 == 0));
Assert.IsFalse(span.All(x => x % 2 == 1));
}
[TestMethod]
public void AnyShouldReturnFalseForEmptySpan()
{
var span = new Span<int>();
Assert.IsFalse(span.Any(x => x > 0));
}
[TestMethod]
public void AnyShouldBeCorrect()
{
var span = new Span<int>(new[] {2, 4, 6, 8, 10});
Assert.IsTrue(span.Any(x => x % 2 == 0));
Assert.IsFalse(span.Any(x => x % 2 == 1));
}
[TestMethod]
public void AllNullPredicateShouldThrow()
{
Assert.ThrowsException<ArgumentNullException>(() =>
{
var span = new Span<int>();
return span.All(null!);
});
}
[TestMethod]
public void AnyNullPredicateShouldThrow()
{
Assert.ThrowsException<ArgumentNullException>(() =>
{
var span = new Span<int>();
return span.Any(null!);
});
}
}

View File

@ -1,4 +1,4 @@
namespace X10D;
namespace X10D.Linq;
/// <summary>
/// Extension methods for <see cref="ReadOnlySpan{T}" />.

View File

@ -1,4 +1,4 @@
namespace X10D;
namespace X10D.Linq;
/// <summary>
/// Extension methods for <see cref="Span{T}" />.