From d5a74c12a86b019c667a15e13c58915dd0b018f0 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Fri, 22 Apr 2022 08:50:06 +0100 Subject: [PATCH] Move Span.Any/All to Linq namespace (#7) --- X10D.Tests/src/Linq/ReadOnlySpanTests.cs | 58 +++++++++++++++++++ X10D.Tests/src/Linq/SpanTests.cs | 58 +++++++++++++++++++ .../ReadOnlySpanExtensions.cs | 2 +- .../SpanExtensions.cs | 2 +- 4 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 X10D.Tests/src/Linq/ReadOnlySpanTests.cs create mode 100644 X10D.Tests/src/Linq/SpanTests.cs rename X10D/src/{SpanExtensions => Linq}/ReadOnlySpanExtensions.cs (99%) rename X10D/src/{SpanExtensions => Linq}/SpanExtensions.cs (99%) diff --git a/X10D.Tests/src/Linq/ReadOnlySpanTests.cs b/X10D.Tests/src/Linq/ReadOnlySpanTests.cs new file mode 100644 index 0000000..e33f5cd --- /dev/null +++ b/X10D.Tests/src/Linq/ReadOnlySpanTests.cs @@ -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(); + Assert.IsTrue(span.All(x => x > 0)); + } + + [TestMethod] + public void AllShouldBeCorrect() + { + var span = new ReadOnlySpan(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(); + Assert.IsFalse(span.Any(x => x > 0)); + } + + [TestMethod] + public void AnyShouldBeCorrect() + { + var span = new ReadOnlySpan(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(() => + { + var span = new ReadOnlySpan(); + return span.All(null!); + }); + } + + [TestMethod] + public void AnyNullPredicateShouldThrow() + { + Assert.ThrowsException(() => + { + var span = new ReadOnlySpan(); + return span.Any(null!); + }); + } +} diff --git a/X10D.Tests/src/Linq/SpanTests.cs b/X10D.Tests/src/Linq/SpanTests.cs new file mode 100644 index 0000000..98c5fe3 --- /dev/null +++ b/X10D.Tests/src/Linq/SpanTests.cs @@ -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(); + Assert.IsTrue(span.All(x => x > 0)); + } + + [TestMethod] + public void AllShouldBeCorrect() + { + var span = new Span(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(); + Assert.IsFalse(span.Any(x => x > 0)); + } + + [TestMethod] + public void AnyShouldBeCorrect() + { + var span = new Span(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(() => + { + var span = new Span(); + return span.All(null!); + }); + } + + [TestMethod] + public void AnyNullPredicateShouldThrow() + { + Assert.ThrowsException(() => + { + var span = new Span(); + return span.Any(null!); + }); + } +} diff --git a/X10D/src/SpanExtensions/ReadOnlySpanExtensions.cs b/X10D/src/Linq/ReadOnlySpanExtensions.cs similarity index 99% rename from X10D/src/SpanExtensions/ReadOnlySpanExtensions.cs rename to X10D/src/Linq/ReadOnlySpanExtensions.cs index 66dc7e9..3d1981c 100644 --- a/X10D/src/SpanExtensions/ReadOnlySpanExtensions.cs +++ b/X10D/src/Linq/ReadOnlySpanExtensions.cs @@ -1,4 +1,4 @@ -namespace X10D; +namespace X10D.Linq; /// /// Extension methods for . diff --git a/X10D/src/SpanExtensions/SpanExtensions.cs b/X10D/src/Linq/SpanExtensions.cs similarity index 99% rename from X10D/src/SpanExtensions/SpanExtensions.cs rename to X10D/src/Linq/SpanExtensions.cs index f1e9a9d..641c54b 100644 --- a/X10D/src/SpanExtensions/SpanExtensions.cs +++ b/X10D/src/Linq/SpanExtensions.cs @@ -1,4 +1,4 @@ -namespace X10D; +namespace X10D.Linq; /// /// Extension methods for .