2026-06-11 15:42:01 +07:00
|
|
|
|
namespace QWERTYkez.Mensura.Tests;
|
|
|
|
|
|
|
2026-06-12 23:34:00 +07:00
|
|
|
|
public class CollectionsPow2ExtensionsTest
|
2026-06-11 15:42:01 +07:00
|
|
|
|
{
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void Pow2_Array_CalculatesCorrectly()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
Length[] source = [new(2), new(3), new(10)];
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
Length[] result = source.Pow2<Length, Length>();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Equal(4, result[0]._Value);
|
|
|
|
|
|
Assert.Equal(9, result[1]._Value);
|
|
|
|
|
|
Assert.Equal(100, result[2]._Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void Pow2_NullableArray_HandlesNulls()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
Length?[] source = [new(5), null, new(4)];
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
Length?[] result = source.Pow2<Length, Length>();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Equal(25, result[0]?._Value);
|
|
|
|
|
|
Assert.Null(result[1]);
|
|
|
|
|
|
Assert.Equal(16, result[2]?._Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void Pow2_List_ReturnsCorrectResult()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
var source = new List<Length> { new(2), new(8) };
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
var result = source.Pow2<Length, Length>();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Equal(4, result[0]._Value);
|
|
|
|
|
|
Assert.Equal(64, result[1]._Value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void Pow2_IEnumerable_ProcessesCorrectly()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
IEnumerable<Length> source = new HashSet<Length> { new(3), new(7) };
|
|
|
|
|
|
|
|
|
|
|
|
// Act
|
|
|
|
|
|
var result = source.Pow2<Length, Length>().ToList();
|
|
|
|
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
|
|
Assert.Contains(result, x => x._Value == 9);
|
|
|
|
|
|
Assert.Contains(result, x => x._Value == 49);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public void Pow2_DestinationTooShort_ThrowsArgumentException()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Arrange
|
|
|
|
|
|
Length[] source = [new(2), new(3)];
|
|
|
|
|
|
Length[] dest = new Length[1];
|
|
|
|
|
|
|
|
|
|
|
|
// Act & Assert
|
|
|
|
|
|
Assert.Throws<ArgumentException>(() => source.Pow2(dest));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|