75 lines
2.7 KiB
C#
75 lines
2.7 KiB
C#
namespace QWERTYkez.Mensura.Tests;
|
|
|
|
public class CollectionsPowNExtensionsTest
|
|
{
|
|
private const double BaseVal = 3.0;
|
|
private const double Expected = 9.0; // 3^2 = 9
|
|
|
|
[Fact]
|
|
public void Test_PowN()
|
|
{
|
|
Length[] arr = [new(BaseVal)];
|
|
Length?[] arrNull = [new(BaseVal), null];
|
|
List<Length> list = [new(BaseVal)];
|
|
List<Length?> listNull = [new(BaseVal), null];
|
|
IReadOnlyCollection<Length> roc = list;
|
|
IEnumerable<Length> en = list;
|
|
IEnumerable<Length?> enNull = listNull;
|
|
|
|
// --- 1. Целые степени (int) ---
|
|
// Span-based Core
|
|
Span<Length> dstSpan = new Length[1];
|
|
arr.AsSpan().PowCore(2, 1, dstSpan);
|
|
Assert.Equal(Expected, dstSpan[0]._Value);
|
|
|
|
arrNull.AsSpan().PowCore(2, 2, new Length?[2]); // Проверка nullable span
|
|
|
|
arr.AsSpan().Pow(2, dstSpan);
|
|
Assert.Equal(Expected, dstSpan[0]._Value);
|
|
|
|
// Arrays
|
|
Assert.Equal(Expected, arr.Pow<Length, Length>(2)[0]._Value);
|
|
Assert.Equal(Expected, arrNull.Pow<Length, Length>(2)[0]?._Value);
|
|
|
|
// Lists
|
|
Assert.Equal(Expected, list.Pow<Length, Length>(2)[0]._Value);
|
|
Assert.Equal(Expected, listNull.Pow<Length, Length>(2)[0]?._Value);
|
|
|
|
// ReadOnlyCollection
|
|
roc.Pow(2, dstSpan);
|
|
Assert.Equal(Expected, dstSpan[0]._Value);
|
|
|
|
// IEnumerable / Iterators
|
|
Assert.Equal(Expected, en.Pow<Length, Length>(2).First()._Value);
|
|
Assert.Equal(Expected, enNull.Pow<Length, Length>(2).First(x => x.HasValue)?._Value);
|
|
|
|
|
|
// --- 2. Дробные степени (double) ---
|
|
// Span-based Core
|
|
arr.AsSpan().PowCore(2.0, 1, dstSpan);
|
|
Assert.Equal(Expected, dstSpan[0]._Value);
|
|
|
|
arr.AsSpan().Pow(2.0, dstSpan);
|
|
Assert.Equal(Expected, dstSpan[0]._Value);
|
|
|
|
// Arrays
|
|
Assert.Equal(Expected, arr.Pow<Length, Length>(2.0)[0]._Value);
|
|
Assert.Equal(Expected, arrNull.Pow<Length, Length>(2.0)[0]?._Value);
|
|
|
|
// Lists
|
|
Assert.Equal(Expected, list.Pow<Length, Length>(2.0)[0]._Value);
|
|
Assert.Equal(Expected, listNull.Pow<Length, Length>(2.0)[0]?._Value);
|
|
|
|
// ReadOnlyCollection
|
|
roc.Pow(2.0, dstSpan);
|
|
Assert.Equal(Expected, dstSpan[0]._Value);
|
|
|
|
// IEnumerable / Iterators
|
|
Assert.Equal(Expected, en.Pow<Length, Length>(2.0).First()._Value);
|
|
Assert.Equal(Expected, enNull.Pow<Length, Length>(2.0).First(x => x.HasValue)?._Value);
|
|
|
|
// Дополнительные итераторы
|
|
Assert.Equal(Expected, en.PowIterator<Length, Length>(2.0).First()._Value);
|
|
Assert.Equal(Expected, enNull.PowNullableIterator<Length, Length>(2.0).First(x => x.HasValue)?._Value);
|
|
}
|
|
} |