mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 22:55:42 +00:00
test: bring coverage to 100% for Collections, Linq, Math, and Text
This commit is contained in:
parent
918b0b7612
commit
6b1dc2837a
@ -54,8 +54,10 @@ public partial class ArrayTests
|
||||
[TestMethod]
|
||||
public void Clear_ShouldThrowArgumentNullException_WhenArrayIsNull()
|
||||
{
|
||||
int[]? array = null;
|
||||
Assert.ThrowsException<ArgumentNullException>(array!.Clear);
|
||||
int[] array = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => array.Clear());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => array.Clear(0, 1));
|
||||
Assert.ThrowsException<ArgumentNullException>(() => array.Clear(..1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,12 @@ public partial class EnumerableTests
|
||||
Assert.ThrowsException<ArgumentNullException>(() => ((IEnumerable<int>?)null)!.CountWhereNot(x => x % 2 == 0));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CountWhereNot_ShouldThrowArgumentNullException_GivenNullPredicate()
|
||||
{
|
||||
Assert.ThrowsException<ArgumentNullException>(() => Enumerable.Empty<int>().CountWhereNot(null!));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CountWhereNot_ShouldThrowOverflowException_GivenLargeSource()
|
||||
{
|
||||
@ -54,13 +60,13 @@ public partial class EnumerableTests
|
||||
[TestMethod]
|
||||
public void FirstWhereNot_ShouldThrowArgumentNullException_GivenNullPredicate()
|
||||
{
|
||||
Assert.ThrowsException<ArgumentNullException>(() => Array.Empty<int>().FirstWhereNotOrDefault(null!));
|
||||
Assert.ThrowsException<ArgumentNullException>(() => Enumerable.Range(0, 1).FirstWhereNot(null!));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FirstWhereNot_ShouldThrowInvalidOperationException_GivenEmptySource()
|
||||
{
|
||||
Assert.ThrowsException<InvalidOperationException>(() => Array.Empty<int>().FirstWhereNot(x => x % 2 == 0));
|
||||
Assert.ThrowsException<InvalidOperationException>(() => Enumerable.Empty<int>().FirstWhereNot(x => x % 2 == 0));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -86,13 +92,13 @@ public partial class EnumerableTests
|
||||
[TestMethod]
|
||||
public void FirstWhereNotOrDefault_ShouldThrowArgumentNullException_GivenNullPredicate()
|
||||
{
|
||||
Assert.ThrowsException<ArgumentNullException>(() => Array.Empty<int>().FirstWhereNotOrDefault(null!));
|
||||
Assert.ThrowsException<ArgumentNullException>(() => Enumerable.Empty<int>().FirstWhereNotOrDefault(null!));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void FirstWhereNotOrDefault_ShouldReturnDefault_GivenEmptySource()
|
||||
{
|
||||
int result = Array.Empty<int>().FirstWhereNotOrDefault(x => x % 2 == 0);
|
||||
int result = Enumerable.Empty<int>().FirstWhereNotOrDefault(x => x % 2 == 0);
|
||||
Assert.AreEqual(default, result);
|
||||
}
|
||||
|
||||
@ -259,6 +265,12 @@ public partial class EnumerableTests
|
||||
Assert.ThrowsException<ArgumentNullException>(() => ((IEnumerable<int>?)null)!.WhereNot(x => x % 2 == 0));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WhereNot_ShouldThrowArgumentNullException_GivenNullPredicate()
|
||||
{
|
||||
Assert.ThrowsException<ArgumentNullException>(() => Enumerable.Empty<int>().WhereNot(null!));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WhereNotNull_ShouldContainNoNullElements()
|
||||
{
|
||||
@ -280,6 +292,13 @@ public partial class EnumerableTests
|
||||
Assert.AreEqual(expectedCount, actualCount);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void WhereNotNull_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<string> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.WhereNotNull());
|
||||
}
|
||||
|
||||
private class DummyClass
|
||||
{
|
||||
public int Value { get; set; }
|
||||
|
@ -34,6 +34,14 @@ public class ByteTests
|
||||
// Π_(i=1)^n (2i) will overflow at i=4 for byte
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Product_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<byte> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RangeTo_Byte_ShouldYieldCorrectValues()
|
||||
{
|
||||
|
@ -41,4 +41,12 @@ public class DecimalTests
|
||||
Assert.AreEqual(185794560m, Enumerable.Range(1, 9).Product(Double));
|
||||
Assert.AreEqual(3715891200m, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Product_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<decimal> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v));
|
||||
}
|
||||
}
|
||||
|
@ -41,4 +41,12 @@ public class DoubleTests
|
||||
Assert.AreEqual(185794560.0, Enumerable.Range(1, 9).Product(Double));
|
||||
Assert.AreEqual(3715891200.0, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Product_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<double> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System.Collections;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using X10D.Linq;
|
||||
|
||||
namespace X10D.Tests.Linq;
|
||||
@ -94,8 +95,9 @@ public class EnumerableTests
|
||||
[TestMethod]
|
||||
public void MinMax_ShouldThrowArgumentNullException_GivenNullSelector()
|
||||
{
|
||||
Assert.ThrowsException<ArgumentNullException>(() => Enumerable.Range(1, 10).MinMax((Func<int, int>?)null!));
|
||||
Assert.ThrowsException<ArgumentNullException>(() => Enumerable.Range(1, 10).ToArray().MinMax((Func<int, int>?)null!));
|
||||
IEnumerable<int> source = Enumerable.Empty<int>();
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.MinMax((Func<int, int>)(null!)));
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.MinMax((Func<int, int>)(null!), null));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -103,6 +105,9 @@ public class EnumerableTests
|
||||
{
|
||||
IEnumerable<int>? source = null;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMax());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMax(v => v));
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMax(null));
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMax(v => v, null));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -147,18 +152,11 @@ public class EnumerableTests
|
||||
|
||||
[TestMethod]
|
||||
public void MinMaxBy_ShouldThrowArgumentNullException_GivenNullSelector()
|
||||
{
|
||||
Assert.ThrowsException<ArgumentNullException>(() =>
|
||||
{
|
||||
IEnumerable<Person> source = Enumerable.Range(1, 10).Select(i => new Person {Age = i});
|
||||
return source.MinMaxBy((Func<Person, int>?)null!);
|
||||
});
|
||||
|
||||
Assert.ThrowsException<ArgumentNullException>(() =>
|
||||
{
|
||||
Person[] source = Enumerable.Range(1, 10).Select(i => new Person {Age = i}).ToArray();
|
||||
return source.MinMaxBy((Func<Person, int>?)null!);
|
||||
});
|
||||
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.MinMaxBy((Func<Person, int>)null!));
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.MinMaxBy((Func<Person, int>)null!, null));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -166,6 +164,7 @@ public class EnumerableTests
|
||||
{
|
||||
IEnumerable<Person>? source = null;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMaxBy(p => p.Age));
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source!.MinMaxBy(p => p.Age, null));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
@ -38,6 +38,13 @@ public class Int16Tests
|
||||
// Π_(i=1)^n (2i) will overflow at i=6 for short
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Product_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<short> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RangeTo_Int16_ShouldYieldCorrectValues()
|
||||
{
|
||||
|
@ -41,6 +41,14 @@ public class Int32Tests
|
||||
// Π_(i=1)^n (2i) will overflow at i=10 for int
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Product_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<int> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RangeTo_Int32_ShouldYieldCorrectValues()
|
||||
{
|
||||
|
@ -42,6 +42,14 @@ public class Int64Tests
|
||||
Assert.AreEqual(3715891200, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Product_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<long> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RangeTo_Int64_ShouldYieldCorrectValues()
|
||||
{
|
||||
|
@ -34,4 +34,12 @@ public class SByteTests
|
||||
|
||||
// Π_(i=1)^(n(i*2)) will overflow at i=4 for sbyte
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Product_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<sbyte> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v));
|
||||
}
|
||||
}
|
||||
|
@ -41,4 +41,12 @@ public class SingleTests
|
||||
Assert.AreEqual(185794560f, Enumerable.Range(1, 9).Product(Double));
|
||||
Assert.AreEqual(3715891200f, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Product_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<float> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v));
|
||||
}
|
||||
}
|
||||
|
@ -40,4 +40,12 @@ public class UInt16Tests
|
||||
|
||||
// Π_(i=1)^n (2i) will overflow at i=7 for ushort
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Product_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<ushort> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v));
|
||||
}
|
||||
}
|
||||
|
@ -42,4 +42,12 @@ public class UInt32Tests
|
||||
Assert.AreEqual(185794560U, Enumerable.Range(1, 9).Product(Double));
|
||||
Assert.AreEqual(3715891200U, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Product_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<uint> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v));
|
||||
}
|
||||
}
|
||||
|
@ -42,4 +42,12 @@ public class UInt64Tests
|
||||
Assert.AreEqual(185794560UL, Enumerable.Range(1, 9).Product(Double));
|
||||
Assert.AreEqual(3715891200UL, Enumerable.Range(1, 10).Product(Double));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Product_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<ulong> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Product(v => v));
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,13 @@ public class ComparableTests
|
||||
Assert.ThrowsException<ArgumentException>(() => 0.Clamp(6, 5));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Clamp_ShouldThrowArgumentNullException_GivenNullValue()
|
||||
{
|
||||
string comparable = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => comparable.Clamp(string.Empty, string.Empty));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GreaterThan_5_6_ShouldBeFalse()
|
||||
{
|
||||
|
@ -60,14 +60,16 @@ public class EnumerableTests
|
||||
public void Grep_ShouldThrowArgumentNullException_GivenNullPattern()
|
||||
{
|
||||
IEnumerable<string> source = Enumerable.Empty<string>();
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Grep(null!));
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Grep(null!).ToArray());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Grep(null!, false).ToArray());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Grep_ShouldThrowArgumentNullException_GivenNullSource()
|
||||
{
|
||||
IEnumerable<string> source = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Grep("foo"));
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Grep("foo").ToArray());
|
||||
Assert.ThrowsException<ArgumentNullException>(() => source.Grep("foo", false).ToArray());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
@ -380,6 +380,13 @@ public class StringTests
|
||||
Assert.IsFalse("World".IsEmoji());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IsEmoji_ShouldThrowArgumentNullException_GivenNullInput()
|
||||
{
|
||||
string value = null!;
|
||||
Assert.ThrowsException<ArgumentNullException>(() => value.IsEmoji());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IsEmpty_ShouldReturnTrue_GivenEmptyString()
|
||||
{
|
||||
|
@ -418,15 +418,6 @@ public static class EnumerableExtensions
|
||||
|
||||
private static bool TryGetSpan<TSource>(this IEnumerable<TSource> source, out ReadOnlySpan<TSource> span)
|
||||
{
|
||||
#if NET6_0_OR_GREATER
|
||||
ArgumentNullException.ThrowIfNull(source);
|
||||
#else
|
||||
if (source is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(source));
|
||||
}
|
||||
#endif
|
||||
|
||||
var result = true;
|
||||
|
||||
switch (source)
|
||||
|
Loading…
Reference in New Issue
Block a user