diff --git a/src/MissingValues.Tests/Core/CalculatorTests.cs b/src/MissingValues.Tests/Core/CalculatorTests.cs new file mode 100644 index 0000000..7920197 --- /dev/null +++ b/src/MissingValues.Tests/Core/CalculatorTests.cs @@ -0,0 +1,371 @@ +using MissingValues.Internals; +using MissingValues.Tests.Data; +using static MissingValues.Tests.Data.CalculatorDataSources; + +namespace MissingValues.Tests.Core; + +public class CalculatorTests +{ + [Test] + public async Task AddWithCarry_NoOverflow_ReturnsCorrectSumAndZeroCarry() + { + ulong a = 10; + ulong b = 20; + + ulong result = Calculator.AddWithCarry(a, b, out ulong carry); + + using var _ = Assert.Multiple(); + + await Assert.That(result).IsEqualTo(30UL); + await Assert.That(carry).IsEqualTo(0UL); + } + [Test] + public async Task AddWithCarry_MaxValueAndOne_ReturnsZeroAndCarry() + { + ulong a = ulong.MaxValue; + ulong b = 1; + + ulong result = Calculator.AddWithCarry(a, b, out ulong carry); + + using var _ = Assert.Multiple(); + + await Assert.That(result).IsEqualTo(0UL); + await Assert.That(carry).IsEqualTo(1UL); + } + [Test] + public async Task AddWithCarry_OverflowCase_ReturnsCorrectResultAndCarry() + { + ulong a = ulong.MaxValue - 1; + ulong b = 5; + + ulong result = Calculator.AddWithCarry(a, b, out ulong carry); + + using var _ = Assert.Multiple(); + + await Assert.That(result).IsEqualTo(3UL); + await Assert.That(carry).IsEqualTo(1UL); + } + [Test] + public async Task AddWithCarry_AddZero_ReturnsSameValueAndZeroCarry() + { + ulong a = 123456789; + ulong b = 0; + + ulong result = Calculator.AddWithCarry(a, b, out ulong carry); + + using var _ = Assert.Multiple(); + + await Assert.That(result).IsEqualTo(a); + await Assert.That(carry).IsEqualTo(0UL); + } + [Test] + public async Task AddWithCarry_BothZero_ReturnsZeroAndZeroCarry() + { + ulong a = 0; + ulong b = 0; + + ulong result = Calculator.AddWithCarry(a, b, out ulong carry); + + using var _ = Assert.Multiple(); + + await Assert.That(result).IsEqualTo(0UL); + await Assert.That(carry).IsEqualTo(0UL); + } + [Test] + public async Task AddWithCarry_ExactMaxValueSum_ReturnsMaxValueAndZeroCarry() + { + ulong a = ulong.MaxValue / 2; + ulong b = ulong.MaxValue / 2; + + ulong result = Calculator.AddWithCarry(a, b, out ulong carry); + + using var _ = Assert.Multiple(); + + await Assert.That(result).IsEqualTo(ulong.MaxValue - 1); + await Assert.That(carry).IsEqualTo(0UL); + } + [Test] + public async Task AddWithCarry_CarryOnlyTriggeredWhenOverflow() + { + ulong a = ulong.MaxValue; + ulong b = 0; + + ulong result = Calculator.AddWithCarry(a, b, out ulong carry); + + using var _ = Assert.Multiple(); + + await Assert.That(result).IsEqualTo(ulong.MaxValue); + await Assert.That(carry).IsEqualTo(0UL); + } + + [Test] + public async Task BigMulAdd_SimpleMultiplicationAndAddition() + { + ulong a = 2; + ulong b = 3; + ulong c = 5; + + var (hi, lo) = Calculator.BigMulAdd(a, b, c); + + using var _ = Assert.Multiple(); + + await Assert.That(hi).IsEqualTo(0UL); + await Assert.That(lo).IsEqualTo(11UL); + } + [Test] + public async Task BigMulAdd_WithOverflowFromLowToHigh() + { + ulong a = ulong.MaxValue; + ulong b = 2; + ulong c = 1; + + var (hi, lo) = Calculator.BigMulAdd(a, b, c); + + using var _ = Assert.Multiple(); + + await Assert.That(hi).IsEqualTo(1UL); + await Assert.That(lo).IsEqualTo(0xFFFFFFFFFFFFFFFFUL); + } + [Test] + public async Task BigMulAdd_MaxValues() + { + ulong a = ulong.MaxValue; + ulong b = ulong.MaxValue; + ulong c = ulong.MaxValue; + + var (hi, lo) = Calculator.BigMulAdd(a, b, c); + + using var _ = Assert.Multiple(); + + await Assert.That(hi).IsEqualTo(0xFFFFFFFFFFFFFFFFUL); + await Assert.That(lo).IsEqualTo(0UL); + } + [Test] + public async Task BigMulAdd_NoCarryOrOverflow() + { + ulong a = 1000; + ulong b = 1000; + ulong c = 1; + + var (hi, lo) = Calculator.BigMulAdd(a, b, c); + + using var _ = Assert.Multiple(); + + await Assert.That(hi).IsEqualTo(0UL); + await Assert.That(lo).IsEqualTo(1_000_001UL); + } + [Test] + public async Task BigMulAdd_CausesCarryFromAdditionOnly() + { + ulong a = ulong.MaxValue; + ulong b = 1; + ulong c = 1; + + var (hi, lo) = Calculator.BigMulAdd(a, b, c); + + using var _ = Assert.Multiple(); + + await Assert.That(hi).IsEqualTo(1UL); + await Assert.That(lo).IsEqualTo(0UL); + } + [Test] + public async Task BigMulAdd_CausesNoCarryWithZeroInputs() + { + ulong a = 0; + ulong b = 0; + ulong c = 0; + + var (hi, lo) = Calculator.BigMulAdd(a, b, c); + + using var _ = Assert.Multiple(); + + await Assert.That(hi).IsEqualTo(0UL); + await Assert.That(lo).IsEqualTo(0UL); + } + + [Test] + public async Task DivRemByUInt32_BasicDivision() + { + ulong left = 100; + uint right = 7; + + var (quotient, remainder) = Calculator.DivRemByUInt32(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(14UL); + await Assert.That(remainder).IsEqualTo(2U); + } + [Test] + public async Task DivRemByUInt32_DivideByOne() + { + ulong left = 1234567890123456789; + uint right = 1; + + var (quotient, remainder) = Calculator.DivRemByUInt32(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(left); + await Assert.That(remainder).IsEqualTo(0U); + } + [Test] + public async Task DivRemByUInt32_DivideByMaxUInt32() + { + ulong left = (ulong)uint.MaxValue + 1; + uint right = uint.MaxValue; + + var (quotient, remainder) = Calculator.DivRemByUInt32(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(1UL); + await Assert.That(remainder).IsEqualTo(1U); + } + [Test] + public async Task DivRemByUInt32_ZeroDividend() + { + ulong left = 0; + uint right = uint.MaxValue; + + var (quotient, remainder) = Calculator.DivRemByUInt32(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(0UL); + await Assert.That(remainder).IsEqualTo(0U); + } + [Test] + public async Task DivRemByUInt32_ExactDivision() + { + ulong left = 400; + uint right = 20; + + var (quotient, remainder) = Calculator.DivRemByUInt32(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(20UL); + await Assert.That(remainder).IsEqualTo(0U); + } + [Test] + public async Task DivRemByUInt32_MaxValues() + { + ulong left = ulong.MaxValue; + uint right = uint.MaxValue; + + var (quotient, remainder) = Calculator.DivRemByUInt32(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(ulong.MaxValue / uint.MaxValue); + await Assert.That(remainder).IsEqualTo((uint)(ulong.MaxValue % uint.MaxValue)); + } + [Test] + public async Task DivRemByUInt32_DivideByZero_Throws() + { + ulong left = 100; + uint right = 0; + + await Assert.That(() => Calculator.DivRemByUInt32(left, right)).Throws(); + } + + [Test] + public async Task DivRemByUInt64_BasicDivision() + { + UInt128 left = new UInt128(0, 1000); + ulong right = 30; + + var (quotient, remainder) = Calculator.DivRemByUInt64(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(new UInt128(0, 33)); + await Assert.That(remainder).IsEqualTo(10UL); + } + [Test] + public async Task DivRemByUInt64_ZeroDividend() + { + UInt128 left = new UInt128(0, 0); + ulong right = 12345; + + var (quotient, remainder) = Calculator.DivRemByUInt64(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(UInt128.Zero); + await Assert.That(remainder).IsEqualTo(0UL); + } + [Test] + public async Task DivRemByUInt64_DivideByOne() + { + UInt128 left = new UInt128(123456789, 9876543210); + ulong right = 1; + + var (quotient, remainder) = Calculator.DivRemByUInt64(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(new UInt128(123456789, 9876543210)); + await Assert.That(remainder).IsEqualTo(0UL); + } + [Test] + public async Task DivRemByUInt64_ExactDivision() + { + UInt128 left = new UInt128(0, 1000); + ulong right = 1000; + + var (quotient, remainder) = Calculator.DivRemByUInt64(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(new UInt128(0, 1)); + await Assert.That(remainder).IsEqualTo(0UL); + } + [Test] + public async Task DivRemByUInt64_UpperBitsUsed() + { + UInt128 left = new UInt128(1, 0); + ulong right = 2; + + var (quotient, remainder) = Calculator.DivRemByUInt64(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(new UInt128(0, 1UL << 63)); + await Assert.That(remainder).IsEqualTo(0UL); + } + [Test] + public async Task DivRemByUInt64_MaxValues() + { + UInt128 left = UInt128.MaxValue; + ulong right = ulong.MaxValue; + + var (quotient, remainder) = Calculator.DivRemByUInt64(left, right); + + using var _ = Assert.Multiple(); + + await Assert.That(quotient).IsEqualTo(UInt128.MaxValue / ulong.MaxValue); + await Assert.That(remainder).IsEqualTo((ulong)(UInt128.MaxValue % ulong.MaxValue)); + } + [Test] + public async Task DivRemByUInt64_DivideByZero_Throws() + { + UInt128 left = new UInt128(1, 0); + ulong right = 0; + + await Assert.That(() => Calculator.DivRemByUInt64(left, right)).Throws(); + } + + [Test] + [MethodDataSource(typeof(CalculatorDataSources), nameof(Log10TestData))] + public async Task Log10_DataDriven(UInt512 value, int expected) + { + await Assert.That(BitHelper.Log10(in value)).IsEqualTo(expected); + } + [Test] + public async Task Log10_NegativeInput_Throws() + { + await Assert.That(() => BitHelper.Log10(in Int512.NegativeOne)).Throws(); + } +} diff --git a/src/MissingValues.Tests/Core/Int256Test.GenericMath.cs b/src/MissingValues.Tests/Core/Int256Test.GenericMath.cs deleted file mode 100644 index a9d8505..0000000 --- a/src/MissingValues.Tests/Core/Int256Test.GenericMath.cs +++ /dev/null @@ -1,1278 +0,0 @@ -using FluentAssertions; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -using Int = MissingValues.Int256; - -namespace MissingValues.Tests.Core -{ - public partial class Int256Test - { - #region Readonly Variables - private const double Int256MaxValueAsDouble = 57896044618658097711785492504343953926634992332820282019728792003956564819967.0; - private const double Int256MinValueAsDouble = -57896044618658097711785492504343953926634992332820282019728792003956564819968.0d; - - private static readonly Int SByteMaxValue = new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_007F)); - private static readonly Int SByteMinValue = new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF80)); - - private static readonly Int ByteMaxValue = new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_00FF)); - - private static readonly Int Int16MaxValue = new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_7FFF)); - private static readonly Int Int16MinValue = new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_8000)); - - private static readonly Int UInt16MaxValue = new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_FFFF)); - - private static readonly Int Int32MaxValue = new(new(0x0000_0000_0000_0000, 0x0000_0000_7FFF_FFFF)); - private static readonly Int Int32MinValue = new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_8000_0000)); - - private static readonly Int UInt32MaxValue = new(new(0x0000_0000_0000_0000, 0x0000_0000_FFFF_FFFF)); - - private static readonly Int Int64MaxValue = new(new(0x0000_0000_0000_0000, 0x7FFF_FFFF_FFFF_FFFF)); - private static readonly Int Int64MinValue = new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000)); - - private static readonly Int UInt64MaxValue = new(new(0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF)); - - private static readonly Int Int128MaxValue = new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - private static readonly Int Int128MinValue = new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000)); - - private static readonly Int UInt128MaxValue = new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - - private static readonly Int NegativeOne = Int.NegativeOne; - private static readonly Int NegativeTwo = new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)); - private static readonly Int Zero = Int.Zero; - private static readonly Int One = Int.One; - private static readonly Int Two = new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0002)); - private static readonly Int MaxValue = Int.MaxValue; - private static readonly Int MaxValueMinusOne = new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)); - private static readonly Int MinValue = Int.MinValue; - private static readonly Int MinValuePlusOne = new(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)); - #endregion - - #region Generic Math Operators - [Fact] - public static void op_AdditionTest() - { - Assert.Equal(One, MathOperatorsHelper.AdditionOperation(Zero, 1)); - Assert.Equal(Two, MathOperatorsHelper.AdditionOperation(One, 1)); - Assert.Equal(MinValue, MathOperatorsHelper.AdditionOperation(MaxValue, 1)); - Assert.Equal(MinValuePlusOne, MathOperatorsHelper.AdditionOperation(MinValue, 1)); - Assert.Equal(Zero, MathOperatorsHelper.AdditionOperation(NegativeOne, 1)); - } - [Fact] - public static void op_CheckedAdditionTest() - { - Assert.Equal(One, MathOperatorsHelper.CheckedAdditionOperation(Zero, 1)); - Assert.Equal(Two, MathOperatorsHelper.CheckedAdditionOperation(Int.One, 1)); - Assert.Equal(MinValuePlusOne, MathOperatorsHelper.CheckedAdditionOperation(MinValue, 1)); - Assert.Equal(Zero, MathOperatorsHelper.CheckedAdditionOperation(NegativeOne, 1)); - - Assert.Throws(() => MathOperatorsHelper.CheckedAdditionOperation(MaxValue, 1)); - } - [Fact] - public static void op_IncrementTest() - { - MathOperatorsHelper.IncrementOperation(Zero).Should().Be(One); - MathOperatorsHelper.IncrementOperation(One).Should().Be(Two); - MathOperatorsHelper.IncrementOperation(MinValue).Should().Be(MinValuePlusOne); - MathOperatorsHelper.IncrementOperation(MaxValueMinusOne).Should().Be(MaxValue); - MathOperatorsHelper.IncrementOperation(MaxValue).Should().Be(MinValue); - } - [Fact] - public static void op_CheckedIncrementTest() - { - MathOperatorsHelper.CheckedIncrementOperation(Zero).Should().Be(One); - MathOperatorsHelper.CheckedIncrementOperation(One).Should().Be(Two); - MathOperatorsHelper.CheckedIncrementOperation(MinValue).Should().Be(MinValuePlusOne); - MathOperatorsHelper.CheckedIncrementOperation(MaxValueMinusOne).Should().Be(MaxValue); - - Assert.Throws(() => MathOperatorsHelper.CheckedIncrementOperation(MaxValue)); - } - [Fact] - public static void op_SubtractionTest() - { - Assert.Equal(NegativeOne, MathOperatorsHelper.SubtractionOperation(Zero, 1)); - Assert.Equal(One, MathOperatorsHelper.SubtractionOperation(Two, 1)); - Assert.Equal(MaxValue, MathOperatorsHelper.SubtractionOperation(MinValue, 1)); - Assert.Equal(MaxValueMinusOne, MathOperatorsHelper.SubtractionOperation(MaxValue, 1)); - Assert.Equal(NegativeTwo, MathOperatorsHelper.SubtractionOperation(NegativeOne, 1)); - } - [Fact] - public static void op_CheckedSubtractionTest() - { - Assert.Equal(NegativeOne, MathOperatorsHelper.CheckedSubtractionOperation(Zero, 1)); - Assert.Equal(One, MathOperatorsHelper.CheckedSubtractionOperation(Two, 1)); - Assert.Equal(MaxValueMinusOne, MathOperatorsHelper.CheckedSubtractionOperation(MaxValue, 1)); - Assert.Equal(NegativeTwo, MathOperatorsHelper.CheckedSubtractionOperation(NegativeOne, 1)); - - Assert.Throws(() => MathOperatorsHelper.CheckedSubtractionOperation(MinValue, 1)); - } - [Fact] - public static void op_DecrementTest() - { - MathOperatorsHelper.DecrementOperation(Two).Should().Be(One); - MathOperatorsHelper.DecrementOperation(One).Should().Be(Zero); - MathOperatorsHelper.DecrementOperation(MinValuePlusOne).Should().Be(MinValue); - MathOperatorsHelper.DecrementOperation(MaxValue).Should().Be(MaxValueMinusOne); - MathOperatorsHelper.DecrementOperation(MinValue).Should().Be(MaxValue); - } - [Fact] - public static void op_CheckedDecrementTest() - { - MathOperatorsHelper.CheckedDecrementOperation(Two).Should().Be(One); - MathOperatorsHelper.CheckedDecrementOperation(One).Should().Be(Zero); - MathOperatorsHelper.CheckedDecrementOperation(MinValuePlusOne).Should().Be(MinValue); - MathOperatorsHelper.CheckedDecrementOperation(MaxValue).Should().Be(MaxValueMinusOne); - - Assert.Throws(() => MathOperatorsHelper.CheckedDecrementOperation(MinValue)); - } - [Fact] - public static void op_MultiplyTest() - { - Assert.Equal(One, MathOperatorsHelper.MultiplicationOperation(One, One)); - Assert.Equal(Two, MathOperatorsHelper.MultiplicationOperation(Two, One)); - Assert.Equal(NegativeTwo, MathOperatorsHelper.MultiplicationOperation(Two, NegativeOne)); - Assert.Equal(MinValuePlusOne, MathOperatorsHelper.MultiplicationOperation(MaxValue, NegativeOne)); - Assert.Equal(MinValue, MathOperatorsHelper.MultiplicationOperation(MinValue, NegativeOne)); - } - [Fact] - public static void op_CheckedMultiplyTest() - { - Assert.Equal(One, MathOperatorsHelper.CheckedMultiplicationOperation(One, One)); - Assert.Equal(Two, MathOperatorsHelper.CheckedMultiplicationOperation(Two, One)); - Assert.Equal(NegativeTwo, MathOperatorsHelper.CheckedMultiplicationOperation(Two, NegativeOne)); - Assert.Equal(MinValuePlusOne, MathOperatorsHelper.CheckedMultiplicationOperation(MaxValue, NegativeOne)); - - Assert.Throws(() => MathOperatorsHelper.CheckedMultiplicationOperation(MinValue, NegativeOne)); - } - [Fact] - public static void op_DivisionTest() - { - Assert.Equal(new Int(new(0x3FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), MathOperatorsHelper.DivisionOperation(MaxValue, Two)); - Assert.Equal(new Int(new(0xC000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), MathOperatorsHelper.DivisionOperation(MaxValueMinusOne, NegativeTwo)); - Assert.Equal(One, MathOperatorsHelper.DivisionOperation(MaxValue, MaxValue)); - Assert.Equal(NegativeOne, MathOperatorsHelper.DivisionOperation(MaxValue, MinValuePlusOne)); - - Assert.Throws(() => MathOperatorsHelper.DivisionOperation(MinValue, NegativeOne)); - } - [Fact] - public static void op_CheckedDivisionTest() - { - Assert.Equal(new Int(new(0x3FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), MathOperatorsHelper.CheckedDivisionOperation(MaxValue, Two)); - Assert.Equal(new Int(new(0xC000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), MathOperatorsHelper.CheckedDivisionOperation(MaxValueMinusOne, NegativeTwo)); - Assert.Equal(One, MathOperatorsHelper.CheckedDivisionOperation(MaxValue, MaxValue)); - Assert.Equal(NegativeOne, MathOperatorsHelper.CheckedDivisionOperation(MaxValue, MinValuePlusOne)); - - Assert.Throws(() => MathOperatorsHelper.CheckedDivisionOperation(MinValue, NegativeOne)); - } - [Fact] - public static void op_ModulusTest() - { - MathOperatorsHelper.ModulusOperation(Two, Two).Should().Be(Zero); - MathOperatorsHelper.ModulusOperation(One, Two).Should().NotBe(Zero); - MathOperatorsHelper.ModulusOperation(MaxValue, new(10U)).Should().Be(7); - MathOperatorsHelper.ModulusOperation(MinValue, new(10U)).Should().Be(-8); - - Assert.Throws(() => MathOperatorsHelper.ModulusOperation(One, Zero)); - } - - [Fact] - public static void op_BitwiseAndTest() - { - BitwiseOperatorsHelper.BitwiseAndOperation(Zero, 1U).Should().Be(Zero); - BitwiseOperatorsHelper.BitwiseAndOperation(One, 1U).Should().Be(One); - BitwiseOperatorsHelper.BitwiseAndOperation(MaxValue, 1U).Should().Be(One); - BitwiseOperatorsHelper.BitwiseAndOperation(MinValue, 1U).Should().Be(Zero); - BitwiseOperatorsHelper.BitwiseAndOperation(NegativeOne, 1U).Should().Be(One); - } - [Fact] - public static void op_BitwiseOrTest() - { - BitwiseOperatorsHelper.BitwiseOrOperation(Zero, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.BitwiseOrOperation(One, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.BitwiseOrOperation(MaxValue, 1U) - .Should().Be(MaxValue); - BitwiseOperatorsHelper.BitwiseOrOperation(MinValue, 1U) - .Should().Be(new(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001))); - BitwiseOperatorsHelper.BitwiseOrOperation(NegativeOne, 1U) - .Should().Be(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF))); - } - [Fact] - public static void op_ExclusiveOrTest() - { - BitwiseOperatorsHelper.ExclusiveOrOperation(Zero, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.ExclusiveOrOperation(One, 1U) - .Should().Be(Zero); - BitwiseOperatorsHelper.ExclusiveOrOperation(MaxValue, 1U) - .Should().Be(new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE))); - BitwiseOperatorsHelper.ExclusiveOrOperation(MinValue, 1U) - .Should().Be(new(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001))); - BitwiseOperatorsHelper.ExclusiveOrOperation(NegativeOne, 1U) - .Should().Be(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE))); - } - [Fact] - public static void op_OnesComplementTest() - { - BitwiseOperatorsHelper.OnesComplementOperation(Zero) - .Should().Be(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF))); - BitwiseOperatorsHelper.OnesComplementOperation(One) - .Should().Be(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE))); - BitwiseOperatorsHelper.OnesComplementOperation(MaxValue) - .Should().Be(new(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000))); - BitwiseOperatorsHelper.OnesComplementOperation(MinValue) - .Should().Be(new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF))); - BitwiseOperatorsHelper.OnesComplementOperation(NegativeOne) - .Should().Be(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000))); - } - - [Fact] - public static void op_LeftShiftTest() - { - ShiftOperatorsHelper.LeftShiftOperation(One, 1) - .Should().Be(Two); - ShiftOperatorsHelper.LeftShiftOperation(MaxValue, 1) - .Should().Be(NegativeTwo); - ShiftOperatorsHelper.LeftShiftOperation(MinValue, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.LeftShiftOperation(NegativeOne, 1) - .Should().Be(NegativeTwo); - } - [Fact] - public static void op_RightShiftTest() - { - ShiftOperatorsHelper.RightShiftOperation(Zero, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.RightShiftOperation(One, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.RightShiftOperation(MaxValue, 1) - .Should().Be(new(new(0x3FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF))); - ShiftOperatorsHelper.RightShiftOperation(MinValue, 1) - .Should().Be(new(new(0xC000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000))); - ShiftOperatorsHelper.RightShiftOperation(NegativeOne, 1) - .Should().Be(NegativeOne); - - var actual = new Int(0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 1) - .Should().Be(new(0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 2) - .Should().Be(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000, 0x0000_0000_0000_0000)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 3) - .Should().Be(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000)); - } - [Fact] - public static void op_UnsignedRightShiftTest() - { - ShiftOperatorsHelper.UnsignedRightShiftOperation(Zero, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.UnsignedRightShiftOperation(One, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.UnsignedRightShiftOperation(MaxValue, 1) - .Should().Be(new(new(0x3FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF))); - ShiftOperatorsHelper.UnsignedRightShiftOperation(MinValue, 1) - .Should().Be(new(new(0x4000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000))); - ShiftOperatorsHelper.UnsignedRightShiftOperation(NegativeOne, 1) - .Should().Be(MaxValue); - } - - [Fact] - public static void op_EqualityTest() - { - EqualityOperatorsHelper.EqualityOperation(Zero, 1U).Should().BeFalse(); - EqualityOperatorsHelper.EqualityOperation(One, 1U).Should().BeTrue(); - EqualityOperatorsHelper.EqualityOperation(MaxValue, 1U).Should().BeFalse(); - EqualityOperatorsHelper.EqualityOperation(MinValue, 1U).Should().BeFalse(); - EqualityOperatorsHelper.EqualityOperation(NegativeOne, 1U).Should().BeFalse(); - } - [Fact] - public static void op_InequalityTest() - { - EqualityOperatorsHelper.InequalityOperation(Zero, 1U).Should().BeTrue(); - EqualityOperatorsHelper.InequalityOperation(One, 1U).Should().BeFalse(); - EqualityOperatorsHelper.InequalityOperation(MaxValue, 1U).Should().BeTrue(); - EqualityOperatorsHelper.InequalityOperation(MinValue, 1U).Should().BeTrue(); - EqualityOperatorsHelper.InequalityOperation(NegativeOne, 1U).Should().BeTrue(); - } - - [Fact] - public static void op_GreaterThanTest() - { - ComparisonOperatorsHelper.GreaterThanOperation(Zero, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOperation(One, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOperation(MaxValue, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.GreaterThanOperation(MinValue, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOperation(NegativeOne, 1U).Should().BeFalse(); - } - [Fact] - public static void op_GreaterThanOrEqualTest() - { - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(Zero, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(One, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(MaxValue, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(MinValue, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(NegativeOne, 1U).Should().BeFalse(); - } - [Fact] - public static void op_LessThanTest() - { - ComparisonOperatorsHelper.LessThanOperation(Zero, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOperation(One, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.LessThanOperation(MaxValue, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.LessThanOperation(MinValue, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOperation(NegativeOne, 1U).Should().BeTrue(); - } - [Fact] - public static void op_LessThanOrEqualTest() - { - ComparisonOperatorsHelper.LessThanOrEqualOperation(Zero, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(One, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(MaxValue, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(MinValue, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(NegativeOne, 1U).Should().BeTrue(); - } - #endregion - - #region Identities - [Fact] - public static void AdditiveIdentityTest() - { - Assert.Equal(Zero, MathConstantsHelper.AdditiveIdentityHelper()); - } - - [Fact] - public static void MultiplicativeIdentityTest() - { - Assert.Equal(One, MathConstantsHelper.MultiplicativeIdentityHelper()); - } - #endregion - - #region IBinaryInteger - [Fact] - public static void DivRemTest() - { - Assert.Equal((Zero, Zero), BinaryIntegerHelper.DivRem(Zero, Two)); - Assert.Equal((Zero, One), BinaryIntegerHelper.DivRem(One, Two)); - Assert.Equal((new Int(new(0x3FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), One), BinaryIntegerHelper.DivRem(MaxValue, 2)); - Assert.Equal((new Int(new(0xC000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), Zero), BinaryIntegerHelper.DivRem(MinValue, 2)); - Assert.Equal((Zero, NegativeOne), BinaryIntegerHelper.DivRem(NegativeOne, 2)); - } - - [Fact] - public static void LeadingZeroCountTest() - { - Assert.Equal(256, BinaryIntegerHelper.LeadingZeroCount(Zero)); - Assert.Equal(255, BinaryIntegerHelper.LeadingZeroCount(One)); - Assert.Equal(1, BinaryIntegerHelper.LeadingZeroCount(MaxValue)); - Assert.Equal(0, BinaryIntegerHelper.LeadingZeroCount(MinValue)); - Assert.Equal(0, BinaryIntegerHelper.LeadingZeroCount(NegativeOne)); - } - - [Fact] - public static void PopCountTest() - { - Assert.Equal(0, BinaryIntegerHelper.PopCount(Zero)); - Assert.Equal(1, BinaryIntegerHelper.PopCount(One)); - Assert.Equal(255, BinaryIntegerHelper.PopCount(MaxValue)); - Assert.Equal(1, BinaryIntegerHelper.PopCount(MinValue)); - Assert.Equal(256, BinaryIntegerHelper.PopCount(NegativeOne)); - } - - [Fact] - public static void RotateLeftTest() - { - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), BinaryIntegerHelper.RotateLeft(Zero, 1)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0002)), BinaryIntegerHelper.RotateLeft(One, 1)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)), BinaryIntegerHelper.RotateLeft(MaxValue, 1)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), BinaryIntegerHelper.RotateLeft(MinValue, 1)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), BinaryIntegerHelper.RotateLeft(NegativeOne, 1)); - } - - [Fact] - public static void RotateRightTest() - { - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), BinaryIntegerHelper.RotateRight(Zero, 1)); - Assert.Equal(new(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), BinaryIntegerHelper.RotateRight(One, 1)); - Assert.Equal(new(new(0xBFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), BinaryIntegerHelper.RotateRight(MaxValue, 1)); - Assert.Equal(new(new(0x4000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), BinaryIntegerHelper.RotateRight(MinValue, 1)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), BinaryIntegerHelper.RotateRight(NegativeOne, 1)); - } - - [Fact] - public static void TrailingZeroCountTest() - { - Assert.Equal(256, BinaryIntegerHelper.TrailingZeroCount(Zero)); - Assert.Equal(0, BinaryIntegerHelper.TrailingZeroCount(One)); - Assert.Equal(0, BinaryIntegerHelper.TrailingZeroCount(MaxValue)); - Assert.Equal(255, BinaryIntegerHelper.TrailingZeroCount(MinValue)); - Assert.Equal(0, BinaryIntegerHelper.TrailingZeroCount(NegativeOne)); - } - - [Fact] - public static void TryReadBigEndianInt128Test() - { - Int result; - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new Int128(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: false, out result)); - Assert.Equal(new Int128(0x0000_0000_0000_0000, 0x0000_0000_0000_0001), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: false, out result)); - Assert.Equal(new Int128(0x0000_0000_0000_0000, 0x0000_0000_0000_0080), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new Int128(0x0100_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new Int128(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new Int128(0x8000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: false, out result)); - Assert.Equal(new Int128(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new Int128(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), result); - } - - [Fact] - public static void TryReadBigEndianUInt128Test() - { - Int result; - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: true, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - } - - [Fact] - public static void TryReadLittleEndianInt128Test() - { - Int result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - } - - [Fact] - public static void TryReadLittleEndianInt192Test() - { - Int result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0100_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x7FFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - } - - [Fact] - public static void TryReadLittleEndianInt256Test() - { - Int result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - } - - [Fact] - public static void TryReadLittleEndianUInt128Test() - { - Int result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - } - - [Fact] - public static void TryReadLittleEndianUInt192Test() - { - Int result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0100_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x8000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x7FFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - } - - [Fact] - public static void TryReadLittleEndianUInt256Test() - { - Int result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - } - - [Fact] - public static void GetByteCountTest() - { - Assert.Equal(32, BinaryIntegerHelper.GetByteCount(Zero)); - Assert.Equal(32, BinaryIntegerHelper.GetByteCount(One)); - Assert.Equal(32, BinaryIntegerHelper.GetByteCount(MaxValue)); - Assert.Equal(32, BinaryIntegerHelper.GetByteCount(MinValue)); - Assert.Equal(32, BinaryIntegerHelper.GetByteCount(NegativeOne)); - } - - [Fact] - public static void GetShortestBitLengthTest() - { - Assert.Equal(0x00, BinaryIntegerHelper.GetShortestBitLength(Zero)); - Assert.Equal(0x01, BinaryIntegerHelper.GetShortestBitLength(One)); - Assert.Equal(0xFF, BinaryIntegerHelper.GetShortestBitLength(MaxValue)); - Assert.Equal(0x100, BinaryIntegerHelper.GetShortestBitLength(MinValue)); - Assert.Equal(0x01, BinaryIntegerHelper.GetShortestBitLength(NegativeOne)); - } - - [Fact] - public static void TryWriteBigEndianTest() - { - Span destination = stackalloc byte[32]; - int bytesWritten = 0; - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(Zero, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(One, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(MaxValue, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(MinValue, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(NegativeOne, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - - Assert.False(BinaryIntegerHelper.TryWriteBigEndian(default, Span.Empty, out bytesWritten)); - Assert.Equal(0, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - } - - [Fact] - public static void TryWriteLittleEndianTest() - { - Span destination = stackalloc byte[32]; - int bytesWritten = 0; - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(Zero, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(One, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(MaxValue, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(MinValue, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(NegativeOne, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - - Assert.False(BinaryIntegerHelper.TryWriteLittleEndian(default, Span.Empty, out bytesWritten)); - Assert.Equal(0, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - } - #endregion - - #region IBinaryNumber - [Fact] - public static void AllBitsSetTest() - { - Assert.Equal(BinaryNumberHelper.AllBitsSet, ~Zero); - } - [Fact] - public static void IsPow2Test() - { - Assert.True(BinaryNumberHelper.IsPow2(new(0x100))); - Assert.True(BinaryNumberHelper.IsPow2(new(0x1_0000))); - Assert.True(BinaryNumberHelper.IsPow2(new(0x1_0000_0000))); - Assert.True(BinaryNumberHelper.IsPow2(new(new(0x1, 0x0000_0000_0000_0000)))); - Assert.True(BinaryNumberHelper.IsPow2(new(0x1, new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)))); - } - [Fact] - public static void Log2Test() - { - Assert.Equal(8, BinaryNumberHelper.Log2(new(0x100))); - Assert.Equal(16, BinaryNumberHelper.Log2(new(0x1_0000))); - Assert.Equal(32, BinaryNumberHelper.Log2(new(0x1_0000_0000))); - Assert.Equal(64, BinaryNumberHelper.Log2(new(new(0x1, 0x0000_0000_0000_0000)))); - Assert.Equal(128, BinaryNumberHelper.Log2(new(0x1, new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)))); - } - #endregion - - #region IMinMaxValue - [Fact] - public static void MaxValueTest() - { - MaxValue.Should().Be(MathConstantsHelper.MaxValue()); - } - - [Fact] - public static void MinValueTest() - { - MinValue.Should().Be(MathConstantsHelper.MinValue()); - } - #endregion - - #region INumber - [Fact] - public static void ClampTest() - { - NumberHelper.Clamp(MaxValueMinusOne, Int128MaxValue, MaxValue).Should().Be(MaxValueMinusOne); - NumberHelper.Clamp(MinValue, 0, MaxValue).Should().Be(0); - NumberHelper.Clamp(MaxValue, MinValue, 0).Should().Be(0); - - Assert.Throws(() => NumberHelper.Clamp(MinValue, MaxValue, 0)); - } - [Fact] - public static void CopySignTest() - { - NumberHelper.CopySign(MaxValue, NegativeOne).Should().Be(MinValuePlusOne); - NumberHelper.CopySign(MaxValue, One).Should().Be(MaxValue); - NumberHelper.CopySign(NegativeTwo, One).Should().Be(Two); - } - [Fact] - public static void MaxTest() - { - NumberHelper.Max(MaxValue, MinValue).Should().Be(MaxValue); - NumberHelper.Max(One, NegativeTwo).Should().Be(One); - NumberHelper.Max(Two, NegativeOne).Should().Be(Two); - NumberHelper.Max(NegativeOne, NegativeTwo).Should().Be(NegativeOne); - } - [Fact] - public static void MaxNumberTest() - { - NumberHelper.MaxNumber(MaxValue, MinValue).Should().Be(MaxValue); - NumberHelper.MaxNumber(One, NegativeTwo).Should().Be(One); - NumberHelper.MaxNumber(Two, NegativeOne).Should().Be(Two); - NumberHelper.MaxNumber(NegativeOne, NegativeTwo).Should().Be(NegativeOne); - } - [Fact] - public static void MinTest() - { - NumberHelper.Min(MaxValue, MinValue).Should().Be(MinValue); - NumberHelper.Min(One, NegativeTwo).Should().Be(NegativeTwo); - NumberHelper.Min(Two, NegativeOne).Should().Be(NegativeOne); - NumberHelper.Min(NegativeOne, NegativeTwo).Should().Be(NegativeTwo); - } - [Fact] - public static void MinNumberTest() - { - NumberHelper.MinNumber(MaxValue, MinValue).Should().Be(MinValue); - NumberHelper.MinNumber(One, NegativeTwo).Should().Be(NegativeTwo); - NumberHelper.MinNumber(Two, NegativeOne).Should().Be(NegativeOne); - NumberHelper.MinNumber(NegativeOne, NegativeTwo).Should().Be(NegativeTwo); - } - [Fact] - public static void SignTest() - { - NumberHelper.Sign(MinValue).Should().Be(-1); - NumberHelper.Sign(MaxValue).Should().Be(1); - NumberHelper.Sign(Int.Zero).Should().Be(0); - } - #endregion - - #region INumberBase - [Fact] - public static void AbsTest() - { - NumberBaseHelper.Abs(MinValuePlusOne).Should().Be(MaxValue); - NumberBaseHelper.Abs(NegativeTwo).Should().Be(Two); - NumberBaseHelper.Abs(NegativeOne).Should().Be(One); - NumberBaseHelper.Abs(One).Should().Be(One); - - Assert.Throws(() => NumberBaseHelper.Abs(MinValue)); - } - [Fact] - public static void CreateCheckedToInt256Test() - { - NumberBaseHelper.CreateChecked(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateChecked(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateChecked(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateChecked(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateChecked(Int128.MaxValue).Should().Be(Int128MaxValue); - NumberBaseHelper - .CreateChecked(BigInteger.Parse( - "57896044618658097711785492504343953926634992332820282019728792003956564819967")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateChecked(Int256MaxValueAsDouble).Should().Be(MaxValue); - - NumberBaseHelper.CreateChecked(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateChecked(short.MinValue).Should().Be(Int16MinValue); - NumberBaseHelper.CreateChecked(int.MinValue).Should().Be(Int32MinValue); - NumberBaseHelper.CreateChecked(long.MinValue).Should().Be(Int64MinValue); - NumberBaseHelper.CreateChecked(Int128.MinValue).Should().Be(Int128MinValue); - NumberBaseHelper - .CreateChecked(BigInteger.Parse( - "-57896044618658097711785492504343953926634992332820282019728792003956564819968")) - .Should().Be(MinValue); - NumberBaseHelper.CreateChecked(Int256MinValueAsDouble).Should().Be(MinValue); - } - [Fact] - public static void CreateSaturatingToInt256Test() - { - NumberBaseHelper.CreateSaturating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateSaturating(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateSaturating(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateSaturating(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateSaturating(Int128.MaxValue).Should().Be(Int128MaxValue); - NumberBaseHelper - .CreateSaturating(BigInteger.Parse( - "57896044618658097711785492504343953926634992332820282019728792003956564819967")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateSaturating(Int256MaxValueAsDouble).Should().Be(MaxValue); - - NumberBaseHelper.CreateSaturating(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateSaturating(short.MinValue).Should().Be(Int16MinValue); - NumberBaseHelper.CreateSaturating(int.MinValue).Should().Be(Int32MinValue); - NumberBaseHelper.CreateSaturating(long.MinValue).Should().Be(Int64MinValue); - NumberBaseHelper.CreateSaturating(Int128.MinValue).Should().Be(Int128MinValue); - NumberBaseHelper - .CreateSaturating(BigInteger.Parse( - "-57896044618658097711785492504343953926634992332820282019728792003956564819968")) - .Should().Be(MinValue); - NumberBaseHelper.CreateSaturating(Int256MinValueAsDouble).Should().Be(MinValue); - } - [Fact] - public static void CreateTruncatingToInt256Test() - { - NumberBaseHelper.CreateTruncating(sbyte.MaxValue).Should().Be(SByteMaxValue); - NumberBaseHelper.CreateTruncating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateTruncating(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateTruncating(ushort.MaxValue).Should().Be(UInt16MaxValue); - NumberBaseHelper.CreateTruncating(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateTruncating(uint.MaxValue).Should().Be(UInt32MaxValue); - NumberBaseHelper.CreateTruncating(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateTruncating(ulong.MaxValue).Should().Be(UInt64MaxValue); - NumberBaseHelper.CreateTruncating(Int128.MaxValue).Should().Be(Int128MaxValue); - NumberBaseHelper.CreateTruncating(UInt128.MaxValue).Should().Be(UInt128MaxValue); - NumberBaseHelper - .CreateTruncating(BigInteger.Parse( - "57896044618658097711785492504343953926634992332820282019728792003956564819967")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateTruncating(Int256MaxValueAsDouble).Should().Be(MaxValue); - NumberBaseHelper.CreateTruncating(UInt256.MaxValue).Should().Be(NegativeOne); - - NumberBaseHelper.CreateTruncating(sbyte.MinValue).Should().Be(SByteMinValue); - NumberBaseHelper.CreateTruncating(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(short.MinValue).Should().Be(Int16MinValue); - NumberBaseHelper.CreateTruncating(ushort.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(int.MinValue).Should().Be(Int32MinValue); - NumberBaseHelper.CreateTruncating(uint.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(long.MinValue).Should().Be(Int64MinValue); - NumberBaseHelper.CreateTruncating(ulong.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(Int128.MinValue).Should().Be(Int128MinValue); - NumberBaseHelper.CreateTruncating(UInt128.MinValue).Should().Be(Zero); - NumberBaseHelper - .CreateTruncating(BigInteger.Parse( - "-57896044618658097711785492504343953926634992332820282019728792003956564819968")) - .Should().Be(MinValue); - NumberBaseHelper.CreateTruncating(Int256MinValueAsDouble).Should().Be(MinValue); - NumberBaseHelper.CreateTruncating(UInt256.MinValue).Should().Be(Zero); - } - - [Fact] - public static void CreateCheckedFromInt256Test() - { - NumberBaseHelper.CreateChecked(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateChecked(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateChecked(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateChecked(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateChecked(Int128MaxValue).Should().Be(Int128.MaxValue); - NumberBaseHelper.CreateChecked(MaxValue).Should() - .Be(BigInteger.Parse( - "57896044618658097711785492504343953926634992332820282019728792003956564819967")); - NumberBaseHelper.CreateChecked(MaxValue).Should().Be(Int256MaxValueAsDouble); - - NumberBaseHelper.CreateChecked(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateChecked(Int16MinValue).Should().Be(short.MinValue); - NumberBaseHelper.CreateChecked(Int32MinValue).Should().Be(int.MinValue); - NumberBaseHelper.CreateChecked(Int64MinValue).Should().Be(long.MinValue); - NumberBaseHelper.CreateChecked(Int128MinValue).Should().Be(Int128.MinValue); - NumberBaseHelper.CreateChecked(MinValue).Should() - .Be(BigInteger.Parse( - "-57896044618658097711785492504343953926634992332820282019728792003956564819968")); - NumberBaseHelper.CreateChecked(MinValue).Should().Be(Int256MinValueAsDouble); - } - [Fact] - public static void CreateSaturatingFromInt256Test() - { - NumberBaseHelper.CreateSaturating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateSaturating(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateSaturating(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateSaturating(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateSaturating(Int128MaxValue).Should().Be(Int128.MaxValue); - NumberBaseHelper.CreateSaturating(MaxValue).Should() - .Be(BigInteger.Parse( - "57896044618658097711785492504343953926634992332820282019728792003956564819967")); - NumberBaseHelper.CreateSaturating(MaxValue).Should().Be(Int256MaxValueAsDouble); - - NumberBaseHelper.CreateSaturating(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateSaturating(Int16MinValue).Should().Be(short.MinValue); - NumberBaseHelper.CreateSaturating(Int32MinValue).Should().Be(int.MinValue); - NumberBaseHelper.CreateSaturating(Int64MinValue).Should().Be(long.MinValue); - NumberBaseHelper.CreateSaturating(Int128MinValue).Should().Be(Int128.MinValue); - NumberBaseHelper.CreateSaturating(MinValue).Should() - .Be(BigInteger.Parse( - "-57896044618658097711785492504343953926634992332820282019728792003956564819968")); - NumberBaseHelper.CreateSaturating(MinValue).Should().Be(Int256MinValueAsDouble); - } - [Fact] - public static void CreateTruncatingFromInt256Test() - { - NumberBaseHelper.CreateTruncating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateTruncating(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateTruncating(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateTruncating(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateTruncating(Int128MaxValue).Should().Be(Int128.MaxValue); - NumberBaseHelper.CreateTruncating(MaxValue).Should() - .Be(BigInteger.Parse( - "57896044618658097711785492504343953926634992332820282019728792003956564819967")); - NumberBaseHelper.CreateTruncating(MaxValue).Should().Be(Int256MaxValueAsDouble); - - NumberBaseHelper.CreateTruncating(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateTruncating(Int16MinValue).Should().Be(short.MinValue); - NumberBaseHelper.CreateTruncating(Int32MinValue).Should().Be(int.MinValue); - NumberBaseHelper.CreateTruncating(Int64MinValue).Should().Be(long.MinValue); - NumberBaseHelper.CreateTruncating(Int128MinValue).Should().Be(Int128.MinValue); - NumberBaseHelper.CreateTruncating(MinValue).Should() - .Be(BigInteger.Parse( - "-57896044618658097711785492504343953926634992332820282019728792003956564819968")); - NumberBaseHelper.CreateTruncating(MinValue).Should().Be(Int256MinValueAsDouble); - } - - [Fact] - public static void IsCanonicalTest() - { - NumberBaseHelper.IsCanonical(default(Int)).Should().BeTrue(); - } - - [Fact] - public static void IsComplexNumberTest() - { - NumberBaseHelper.IsComplexNumber(default(Int)).Should().BeFalse(); - } - - [Fact] - public static void IsEvenIntegerTest() - { - NumberBaseHelper.IsEvenInteger(One).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(Two).Should().BeTrue(); - } - - [Fact] - public static void IsFiniteTest() - { - NumberBaseHelper.IsFinite(default(Int)).Should().BeTrue(); - } - - [Fact] - public static void IsImaginaryNumberTest() - { - NumberBaseHelper.IsImaginaryNumber(default(Int)).Should().BeFalse(); - } - - [Fact] - public static void IsInfinityTest() - { - NumberBaseHelper.IsInfinity(default(Int)).Should().BeFalse(); - } - - [Fact] - public static void IsIntegerTest() - { - NumberBaseHelper.IsInteger(default(Int)).Should().BeTrue(); - } - - [Fact] - public static void IsNaNTest() - { - NumberBaseHelper.IsNaN(default(Int)).Should().BeFalse(); - } - - [Fact] - public static void IsNegativeTest() - { - NumberBaseHelper.IsNegative(One).Should().BeFalse(); - NumberBaseHelper.IsNegative(NegativeOne).Should().BeTrue(); - } - - [Fact] - public static void IsNegativeInfinityTest() - { - NumberBaseHelper.IsNegativeInfinity(One).Should().BeFalse(); - } - - [Fact] - public static void IsNormalTest() - { - NumberBaseHelper.IsNormal(Zero).Should().BeFalse(); - NumberBaseHelper.IsNormal(One).Should().BeTrue(); - } - - [Fact] - public static void IsOddIntegerTest() - { - NumberBaseHelper.IsOddInteger(One).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(Two).Should().BeFalse(); - } - - [Fact] - public static void IsPositiveTest() - { - NumberBaseHelper.IsPositive(One).Should().BeTrue(); - NumberBaseHelper.IsPositive(NegativeOne).Should().BeFalse(); - } - - [Fact] - public static void IsPositiveInfinityTest() - { - NumberBaseHelper.IsPositiveInfinity(One).Should().BeFalse(); - } - - [Fact] - public static void IsRealNumberTest() - { - NumberBaseHelper.IsRealNumber(default).Should().BeTrue(); - } - - [Fact] - public static void IsSubnormalTest() - { - NumberBaseHelper.IsSubnormal(default).Should().BeFalse(); - } - - [Fact] - public static void IsZeroTest() - { - NumberBaseHelper.IsZero(default).Should().BeTrue(); - NumberBaseHelper.IsZero(Zero).Should().BeTrue(); - NumberBaseHelper.IsZero(One).Should().BeFalse(); - NumberBaseHelper.IsZero(NegativeOne).Should().BeFalse(); - } - - [Fact] - public static void MaxMagnitudeTest() - { - NumberBaseHelper.MaxMagnitude(MaxValue, MinValue).Should().Be(MinValue); - NumberBaseHelper.MaxMagnitude(One, NegativeTwo).Should().Be(NegativeTwo); - NumberBaseHelper.MaxMagnitude(Two, NegativeOne).Should().Be(Two); - NumberBaseHelper.MaxMagnitude(NegativeOne, NegativeTwo).Should().Be(NegativeTwo); - } - - [Fact] - public static void MaxMagnitudeNumberTest() - { - NumberBaseHelper.MaxMagnitudeNumber(MaxValue, MinValue).Should().Be(MinValue); - NumberBaseHelper.MaxMagnitudeNumber(One, NegativeTwo).Should().Be(NegativeTwo); - NumberBaseHelper.MaxMagnitudeNumber(Two, NegativeOne).Should().Be(Two); - NumberBaseHelper.MaxMagnitudeNumber(NegativeOne, NegativeTwo).Should().Be(NegativeTwo); - } - - [Fact] - public static void MinMagnitudeTest() - { - NumberBaseHelper.MinMagnitude(MaxValue, MinValue).Should().Be(MaxValue); - NumberBaseHelper.MinMagnitude(One, NegativeTwo).Should().Be(One); - NumberBaseHelper.MinMagnitude(Two, NegativeOne).Should().Be(NegativeOne); - NumberBaseHelper.MinMagnitude(NegativeOne, NegativeTwo).Should().Be(NegativeOne); - } - - [Fact] - public static void MinMagnitudeNumberTest() - { - NumberBaseHelper.MinMagnitudeNumber(MaxValue, MinValue).Should().Be(MaxValue); - NumberBaseHelper.MinMagnitudeNumber(One, NegativeTwo).Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(Two, NegativeOne).Should().Be(NegativeOne); - NumberBaseHelper.MinMagnitudeNumber(NegativeOne, NegativeTwo).Should().Be(NegativeOne); - } - - [Fact] - public void ParseTest() - { - NumberBaseHelper.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819967", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(Int256MaxValue) - .And.BeRankedEquallyTo(Int256MaxValue); - NumberBaseHelper.Parse("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(Int256MaxValue) - .And.BeRankedEquallyTo(Int256MaxValue); - NumberBaseHelper.Parse("-57896044618658097711785492504343953926634992332820282019728792003956564819968", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(Int256MinValue) - .And.BeRankedEquallyTo(Int256MinValue); - NumberBaseHelper.Parse("8000000000000000000000000000000000000000000000000000000000000000", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(Int256MinValue) - .And.BeRankedEquallyTo(Int256MinValue); - - Assert.Throws(() => NumberBaseHelper.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - Assert.Throws(() => NumberBaseHelper.Parse("-57896044618658097711785492504343953926634992332820282019728792003956564819969", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - } - - [Fact] - public void TryParseTest() - { - NumberBaseHelper.TryParse("57896044618658097711785492504343953926634992332820282019728792003956564819967", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out Int parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int256MaxValue) - .And.BeRankedEquallyTo(Int256MaxValue); - NumberBaseHelper.TryParse("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int256MaxValue) - .And.BeRankedEquallyTo(Int256MaxValue); - NumberBaseHelper.TryParse("-57896044618658097711785492504343953926634992332820282019728792003956564819968", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int256MinValue) - .And.BeRankedEquallyTo(Int256MinValue); - NumberBaseHelper.TryParse("8000000000000000000000000000000000000000000000000000000000000000", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int256MinValue) - .And.BeRankedEquallyTo(Int256MinValue); - - NumberBaseHelper.TryParse("57896044618658097711785492504343953926634992332820282019728792003956564819968", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - NumberBaseHelper.TryParse("-57896044618658097711785492504343953926634992332820282019728792003956564819969", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - } - - [Fact] - public void ParseUtf8Test() - { - NumberBaseHelper.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819967"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(Int256MaxValue) - .And.BeRankedEquallyTo(Int256MaxValue); - NumberBaseHelper.Parse("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(Int256MaxValue) - .And.BeRankedEquallyTo(Int256MaxValue); - NumberBaseHelper.Parse("-57896044618658097711785492504343953926634992332820282019728792003956564819968"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(Int256MinValue) - .And.BeRankedEquallyTo(Int256MinValue); - NumberBaseHelper.Parse("8000000000000000000000000000000000000000000000000000000000000000"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(Int256MinValue) - .And.BeRankedEquallyTo(Int256MinValue); - - Assert.Throws(() => NumberBaseHelper.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - Assert.Throws(() => NumberBaseHelper.Parse("-57896044618658097711785492504343953926634992332820282019728792003956564819969"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - } - - [Fact] - public void TryParseUtf8Test() - { - NumberBaseHelper.TryParse("57896044618658097711785492504343953926634992332820282019728792003956564819967"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out Int parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int256MaxValue) - .And.BeRankedEquallyTo(Int256MaxValue); - NumberBaseHelper.TryParse("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int256MaxValue) - .And.BeRankedEquallyTo(Int256MaxValue); - NumberBaseHelper.TryParse("-57896044618658097711785492504343953926634992332820282019728792003956564819968"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int256MinValue) - .And.BeRankedEquallyTo(Int256MinValue); - NumberBaseHelper.TryParse("8000000000000000000000000000000000000000000000000000000000000000"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int256MinValue) - .And.BeRankedEquallyTo(Int256MinValue); - - NumberBaseHelper.TryParse("57896044618658097711785492504343953926634992332820282019728792003956564819968"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - NumberBaseHelper.TryParse("-57896044618658097711785492504343953926634992332820282019728792003956564819969"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - } - #endregion - - #region ISignedNumber - [Fact] - public static void NegativeOneTest() - { - MathConstantsHelper.NegativeOne().Should().Be(NegativeOne); - } - #endregion - - #region IPowerFunctions - [Fact] - public void PowTest() - { - GenericFloatingPointFunctions.Pow(Zero, int.MaxValue).Should().Be(Zero); - GenericFloatingPointFunctions.Pow(One, int.MaxValue).Should().Be(One); - GenericFloatingPointFunctions.Pow(MaxValue, Zero).Should().Be(One); - GenericFloatingPointFunctions.Pow(MaxValue, One).Should().Be(MaxValue); - GenericFloatingPointFunctions.Pow(Two, Two).Should().Be(4); - GenericFloatingPointFunctions.Pow(Two, 4).Should().Be(16); - GenericFloatingPointFunctions.Pow(16, Two).Should().Be(256); - GenericFloatingPointFunctions.Pow(Two, 254) - .Should().Be(new Int(0x4000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - - Assert.Throws(() => GenericFloatingPointFunctions.Pow(Two, NegativeOne)); - Assert.Throws(() => GenericFloatingPointFunctions.Pow(Two, 255)); - Assert.Throws(() => GenericFloatingPointFunctions.Pow(Two + Two, 254)); - } - #endregion - } -} diff --git a/src/MissingValues.Tests/Core/Int256Test.cs b/src/MissingValues.Tests/Core/Int256Test.cs deleted file mode 100644 index 69edd7d..0000000 --- a/src/MissingValues.Tests/Core/Int256Test.cs +++ /dev/null @@ -1,251 +0,0 @@ -using FluentAssertions; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Text.Json; -using System.Text.Unicode; -using System.Threading.Tasks; -using Xunit; - -using Int = MissingValues.Int256; - -namespace MissingValues.Tests.Core -{ - public partial class Int256Test - { - private static readonly Int Int256MaxValue = new( - new UInt128(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), - new UInt128(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF) - ); - private static readonly Int Int256MinValue = new( - new UInt128(0x8000_0000_0000_0000, 0x0000_0000_0000_0000), - new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0000) - ); - - [Fact] - public void Ctor_Empty() - { - var i = new Int(); - Assert.Equal(0, i); - } - - [Fact] - public void Ctor_Value() - { - var i = new Int(UInt128.Zero, new(0, 7)); - Assert.Equal(7, i); - } - - [Fact] - public void Cast_ToByte() - { - byte.MinValue.Should().Be((byte)Zero); - byte.MaxValue.Should().Be((byte)ByteMaxValue); - } - - [Fact] - public void Cast_ToInt16() - { - short.MinValue.Should().Be((short)Int16MinValue); - short.MaxValue.Should().Be((short)Int16MaxValue); - } - - [Fact] - public void Cast_ToInt32() - { - int.MinValue.Should().Be((int)Int32MinValue); - int.MaxValue.Should().Be((int)Int32MaxValue); - } - - [Fact] - public void Cast_ToInt64() - { - long.MinValue.Should().Be((long)Int64MinValue); - long.MaxValue.Should().Be((long)Int64MaxValue); - } - - [Fact] - public void Cast_ToInt128() - { - Int128.MinValue.Should().Be((Int128)Int128MinValue); - Int128.MaxValue.Should().Be((Int128)Int128MaxValue); - } - - [Fact] - public void Cast_ToBigInteger() - { - BigInteger.One.Should().Be((BigInteger)One); - BigInteger.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819967") - .Should().Be((BigInteger)MaxValue); - BigInteger.Parse("-57896044618658097711785492504343953926634992332820282019728792003956564819968") - .Should().Be((BigInteger)MinValue); - } - - [Fact] - public void Cast_ToDouble() - { - const double max = 57896044618658097711785492504343953926634992332820282019728792003956564819967.0; - const double min = -57896044618658097711785492504343953926634992332820282019728792003956564819968.0; - - max.Should().Be((double)Int256MaxValue); - min.Should().Be((double)Int256MinValue); - } - - [Fact] - public void ToDecStringTest() - { - Zero.ToString("D", CultureInfo.CurrentCulture) - .Should().Be("0"); - One.ToString("D", CultureInfo.CurrentCulture) - .Should().Be("1"); - MaxValue.ToString("D", CultureInfo.CurrentCulture) - .Should().Be("57896044618658097711785492504343953926634992332820282019728792003956564819967"); - MinValue.ToString("D", CultureInfo.CurrentCulture) - .Should().Be("-57896044618658097711785492504343953926634992332820282019728792003956564819968"); - } - [Fact] - public void ToHexStringTest() - { - One.ToString("X", CultureInfo.CurrentCulture) - .Should().Be("1"); - ((Int)sbyte.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("7F"); - ((Int)short.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("7FFF"); - ((Int)int.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("7FFFFFFF"); - ((Int)long.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("7FFFFFFFFFFFFFFF"); - ((Int)Int128.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - - Zero.ToString("X64", CultureInfo.CurrentCulture) - .Should().Be("0000000000000000000000000000000000000000000000000000000000000000"); - MaxValue.ToString("x64", CultureInfo.CurrentCulture) - .Should().Be("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - MaxValue.ToString("X64", CultureInfo.CurrentCulture) - .Should().Be("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - MinValue.ToString("X64", CultureInfo.CurrentCulture) - .Should().Be("8000000000000000000000000000000000000000000000000000000000000000"); - } - [Fact] - public void ToBinStringTest() - { - One.ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1"); - ((Int)sbyte.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1111111"); - ((Int)short.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("111111111111111"); - ((Int)int.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1111111111111111111111111111111"); - ((Int)long.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("111111111111111111111111111111111111111111111111111111111111111"); - ((Int)Int128.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); - - Zero.ToString("B256", CultureInfo.CurrentCulture) - .Should().Be("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); - MaxValue.ToString("B256", CultureInfo.CurrentCulture) - .Should().Be("0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); - MinValue.ToString("B256", CultureInfo.CurrentCulture) - .Should().Be("1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); - } - - [Fact] - public void ToDecFormatStringTest() - { - MaxValue.ToString().Should().Be($"{MaxValue:D}"); - MinValue.ToString().Should().Be($"{MinValue:D}"); - } - [Fact] - public void ToHexFormatStringTest() - { - MaxValue.ToString("X64", CultureInfo.CurrentCulture).Should().Be($"{MaxValue:X64}"); - MinValue.ToString("X64", CultureInfo.CurrentCulture).Should().Be($"{MinValue:X64}"); - } - [Fact] - public void ToBinFormatStringTest() - { - MaxValue.ToString("B256", CultureInfo.CurrentCulture).Should().Be($"{MaxValue:B256}"); - MinValue.ToString("B256", CultureInfo.CurrentCulture).Should().Be($"{MinValue:B256}"); - } - - [Fact] - public void ToDecFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString()!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:D}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - - - toString = Encoding.UTF8.GetBytes(MinValue.ToString()!); - - format = stackalloc byte[toString.Length]; - success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MinValue:D}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - [Fact] - public void ToHexFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString("X64", CultureInfo.CurrentCulture)!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:X64}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - - - toString = Encoding.UTF8.GetBytes(MinValue.ToString("X64", CultureInfo.CurrentCulture)!); - - format = stackalloc byte[toString.Length]; - success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MinValue:X64}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - [Fact] - public void ToBinFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString("B256", CultureInfo.CurrentCulture)!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:B256}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - - - toString = Encoding.UTF8.GetBytes(MinValue.ToString("B256", CultureInfo.CurrentCulture)!); - - format = stackalloc byte[toString.Length]; - success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MinValue:B256}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - - [Fact] - public void JsonWriteTest() - { - JsonSerializer.Serialize(new object[] { MaxValue, MinValue, One, NegativeOne }) - .Should().Be("[57896044618658097711785492504343953926634992332820282019728792003956564819967,-57896044618658097711785492504343953926634992332820282019728792003956564819968,1,-1]"); - } - [Fact] - public void JsonReadTest() - { - JsonSerializer.Deserialize("57896044618658097711785492504343953926634992332820282019728792003956564819967") - .Should().Be(MaxValue); - JsonSerializer.Deserialize("57896044618658097711785492504343953926634992332820282019728792003956564819967"u8) - .Should().Be(MaxValue); - JsonSerializer.Deserialize("-57896044618658097711785492504343953926634992332820282019728792003956564819968") - .Should().Be(MinValue); - JsonSerializer.Deserialize("-57896044618658097711785492504343953926634992332820282019728792003956564819968"u8) - .Should().Be(MinValue); - } - } -} diff --git a/src/MissingValues.Tests/Core/Int512Test.GenericMath.cs b/src/MissingValues.Tests/Core/Int512Test.GenericMath.cs deleted file mode 100644 index fdb887f..0000000 --- a/src/MissingValues.Tests/Core/Int512Test.GenericMath.cs +++ /dev/null @@ -1,1191 +0,0 @@ -using FluentAssertions; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -using Int = MissingValues.Int512; - -namespace MissingValues.Tests.Core -{ - public partial class Int512Test - { - #region Readonly Variables - private const double Int512MaxValueAsDouble = 6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047.0; - private const double Int512MinValueAsDouble = -6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048.0d; - - private static readonly Int ByteMaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_00FF); - - private static readonly Int Int16MaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_7FFF); - private static readonly Int Int16MinValue = new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_8000); - - private static readonly Int Int32MaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_7FFF_FFFF); - private static readonly Int Int32MinValue = new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_8000_0000); - - private static readonly Int Int64MaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x7FFF_FFFF_FFFF_FFFF); - private static readonly Int Int64MinValue = new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000); - - private static readonly Int Int128MaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF); - private static readonly Int Int128MinValue = new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000, 0x0000_0000_0000_0000); - - private static readonly Int Int256MaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF - ); - private static readonly Int Int256MinValue = new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000 - ); - - private static readonly Int NegativeOne = Int.NegativeOne; - private static readonly Int NegativeTwo = new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE); - private static readonly Int Zero = Int.Zero; - private static readonly Int One = Int.One; - private static readonly Int Two = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0002); - private static readonly Int MaxValue = Int.MaxValue; - private static readonly Int MaxValueMinusOne = new( - 0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE); - private static readonly Int MinValue = Int.MinValue; - private static readonly Int MinValuePlusOne = new( - 0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001); - #endregion - - #region Generic Math Operators - [Fact] - public static void op_AdditionTest() - { - Assert.Equal(One, MathOperatorsHelper.AdditionOperation(Zero, 1)); - Assert.Equal(Two, MathOperatorsHelper.AdditionOperation(One, 1)); - Assert.Equal(MinValue, MathOperatorsHelper.AdditionOperation(MaxValue, 1)); - Assert.Equal(MinValuePlusOne, MathOperatorsHelper.AdditionOperation(MinValue, 1)); - Assert.Equal(Zero, MathOperatorsHelper.AdditionOperation(NegativeOne, 1)); - } - [Fact] - public static void op_CheckedAdditionTest() - { - Assert.Equal(One, MathOperatorsHelper.CheckedAdditionOperation(Zero, 1)); - Assert.Equal(Two, MathOperatorsHelper.CheckedAdditionOperation(Int.One, 1)); - Assert.Equal(MinValuePlusOne, MathOperatorsHelper.CheckedAdditionOperation(MinValue, 1)); - Assert.Equal(Zero, MathOperatorsHelper.CheckedAdditionOperation(NegativeOne, 1)); - - Assert.Throws(() => MathOperatorsHelper.CheckedAdditionOperation(MaxValue, 1)); - } - [Fact] - public static void op_IncrementTest() - { - MathOperatorsHelper.IncrementOperation(Zero).Should().Be(One); - MathOperatorsHelper.IncrementOperation(One).Should().Be(Two); - MathOperatorsHelper.IncrementOperation(MinValue).Should().Be(MinValuePlusOne); - MathOperatorsHelper.IncrementOperation(MaxValueMinusOne).Should().Be(MaxValue); - MathOperatorsHelper.IncrementOperation(MaxValue).Should().Be(MinValue); - } - [Fact] - public static void op_CheckedIncrementTest() - { - MathOperatorsHelper.CheckedIncrementOperation(Zero).Should().Be(One); - MathOperatorsHelper.CheckedIncrementOperation(One).Should().Be(Two); - MathOperatorsHelper.CheckedIncrementOperation(MinValue).Should().Be(MinValuePlusOne); - MathOperatorsHelper.CheckedIncrementOperation(MaxValueMinusOne).Should().Be(MaxValue); - - Assert.Throws(() => MathOperatorsHelper.CheckedIncrementOperation(MaxValue)); - } - [Fact] - public static void op_SubtractionTest() - { - Assert.Equal(NegativeOne, MathOperatorsHelper.SubtractionOperation(Zero, 1)); - Assert.Equal(One, MathOperatorsHelper.SubtractionOperation(Two, 1)); - Assert.Equal(MaxValue, MathOperatorsHelper.SubtractionOperation(MinValue, 1)); - Assert.Equal(MaxValueMinusOne, MathOperatorsHelper.SubtractionOperation(MaxValue, 1)); - Assert.Equal(NegativeTwo, MathOperatorsHelper.SubtractionOperation(NegativeOne, 1)); - } - [Fact] - public static void op_CheckedSubtractionTest() - { - Assert.Equal(NegativeOne, MathOperatorsHelper.CheckedSubtractionOperation(Zero, 1)); - Assert.Equal(One, MathOperatorsHelper.CheckedSubtractionOperation(Two, 1)); - Assert.Equal(MaxValueMinusOne, MathOperatorsHelper.CheckedSubtractionOperation(MaxValue, 1)); - Assert.Equal(NegativeTwo, MathOperatorsHelper.CheckedSubtractionOperation(NegativeOne, 1)); - - Assert.Throws(() => MathOperatorsHelper.CheckedSubtractionOperation(MinValue, 1)); - } - [Fact] - public static void op_DecrementTest() - { - MathOperatorsHelper.DecrementOperation(Two).Should().Be(One); - MathOperatorsHelper.DecrementOperation(One).Should().Be(Zero); - MathOperatorsHelper.DecrementOperation(MinValuePlusOne).Should().Be(MinValue); - MathOperatorsHelper.DecrementOperation(MaxValue).Should().Be(MaxValueMinusOne); - MathOperatorsHelper.DecrementOperation(MinValue).Should().Be(MaxValue); - } - [Fact] - public static void op_CheckedDecrementTest() - { - MathOperatorsHelper.CheckedDecrementOperation(Two).Should().Be(One); - MathOperatorsHelper.CheckedDecrementOperation(One).Should().Be(Zero); - MathOperatorsHelper.CheckedDecrementOperation(MinValuePlusOne).Should().Be(MinValue); - MathOperatorsHelper.CheckedDecrementOperation(MaxValue).Should().Be(MaxValueMinusOne); - - Assert.Throws(() => MathOperatorsHelper.CheckedDecrementOperation(MinValue)); - } - [Fact] - public static void op_MultiplyTest() - { - Assert.Equal(One, MathOperatorsHelper.MultiplicationOperation(One, One)); - Assert.Equal(Two, MathOperatorsHelper.MultiplicationOperation(Two, One)); - Assert.Equal(NegativeTwo, MathOperatorsHelper.MultiplicationOperation(Two, NegativeOne)); - Assert.Equal(MinValuePlusOne, MathOperatorsHelper.MultiplicationOperation(MaxValue, NegativeOne)); - Assert.Equal(MinValue, MathOperatorsHelper.MultiplicationOperation(MinValue, NegativeOne)); - } - [Fact] - public static void op_CheckedMultiplyTest() - { - Assert.Equal(One, MathOperatorsHelper.CheckedMultiplicationOperation(One, One)); - Assert.Equal(Two, MathOperatorsHelper.CheckedMultiplicationOperation(Two, One)); - Assert.Equal(NegativeTwo, MathOperatorsHelper.CheckedMultiplicationOperation(Two, NegativeOne)); - Assert.Equal(MinValuePlusOne, MathOperatorsHelper.CheckedMultiplicationOperation(MaxValue, NegativeOne)); - - Assert.Throws(() => MathOperatorsHelper.CheckedMultiplicationOperation(MinValue, NegativeOne)); - } - [Fact] - public static void op_DivisionTest() - { - Assert.Equal(new Int(0x3FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), MathOperatorsHelper.DivisionOperation(MaxValue, Two)); - Assert.Equal(new Int(0xC000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001), MathOperatorsHelper.DivisionOperation(MaxValueMinusOne, NegativeTwo)); - Assert.Equal(One, MathOperatorsHelper.DivisionOperation(MaxValue, MaxValue)); - Assert.Equal(NegativeOne, MathOperatorsHelper.DivisionOperation(MaxValue, MinValuePlusOne)); - - Assert.Throws(() => MathOperatorsHelper.DivisionOperation(MinValue, NegativeOne)); - } - [Fact] - public static void op_CheckedDivisionTest() - { - Assert.Equal(new Int(0x3FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), MathOperatorsHelper.CheckedDivisionOperation(MaxValue, Two)); - Assert.Equal(new Int(0xC000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001), MathOperatorsHelper.CheckedDivisionOperation(MaxValueMinusOne, NegativeTwo)); - Assert.Equal(One, MathOperatorsHelper.CheckedDivisionOperation(MaxValue, MaxValue)); - Assert.Equal(NegativeOne, MathOperatorsHelper.CheckedDivisionOperation(MaxValue, MinValuePlusOne)); - - Assert.Throws(() => MathOperatorsHelper.CheckedDivisionOperation(MinValue, NegativeOne)); - } - [Fact] - public static void op_ModulusTest() - { - MathOperatorsHelper.ModulusOperation(Two, Two).Should().Be(Zero); - MathOperatorsHelper.ModulusOperation(One, Two).Should().NotBe(Zero); - MathOperatorsHelper.ModulusOperation(MaxValue, new(10U)).Should().Be(7); - MathOperatorsHelper.ModulusOperation(MinValue, new(10U)).Should().Be(-8); - - Assert.Throws(() => MathOperatorsHelper.ModulusOperation(One, Zero)); - } - - [Fact] - public static void op_BitwiseAndTest() - { - BitwiseOperatorsHelper.BitwiseAndOperation(Zero, 1U).Should().Be(Zero); - BitwiseOperatorsHelper.BitwiseAndOperation(One, 1U).Should().Be(One); - BitwiseOperatorsHelper.BitwiseAndOperation(MaxValue, 1U).Should().Be(One); - BitwiseOperatorsHelper.BitwiseAndOperation(MinValue, 1U).Should().Be(Zero); - BitwiseOperatorsHelper.BitwiseAndOperation(NegativeOne, 1U).Should().Be(One); - } - [Fact] - public static void op_BitwiseOrTest() - { - BitwiseOperatorsHelper.BitwiseOrOperation(Zero, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.BitwiseOrOperation(One, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.BitwiseOrOperation(MaxValue, 1U) - .Should().Be(MaxValue); - BitwiseOperatorsHelper.BitwiseOrOperation(MinValue, 1U) - .Should().Be(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001)); - BitwiseOperatorsHelper.BitwiseOrOperation(NegativeOne, 1U) - .Should().Be(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - } - [Fact] - public static void op_ExclusiveOrTest() - { - BitwiseOperatorsHelper.ExclusiveOrOperation(Zero, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.ExclusiveOrOperation(One, 1U) - .Should().Be(Zero); - BitwiseOperatorsHelper.ExclusiveOrOperation(MaxValue, 1U) - .Should().Be(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)); - BitwiseOperatorsHelper.ExclusiveOrOperation(MinValue, 1U) - .Should().Be(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001)); - BitwiseOperatorsHelper.ExclusiveOrOperation(NegativeOne, 1U) - .Should().Be(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)); - } - [Fact] - public static void op_OnesComplementTest() - { - BitwiseOperatorsHelper.OnesComplementOperation(Zero) - .Should().Be(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - BitwiseOperatorsHelper.OnesComplementOperation(One) - .Should().Be(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)); - BitwiseOperatorsHelper.OnesComplementOperation(MaxValue) - .Should().Be(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - BitwiseOperatorsHelper.OnesComplementOperation(MinValue) - .Should().Be(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - BitwiseOperatorsHelper.OnesComplementOperation(NegativeOne) - .Should().Be(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - } - - [Fact] - public static void op_LeftShiftTest() - { - ShiftOperatorsHelper.LeftShiftOperation(One, 1) - .Should().Be(Two); - ShiftOperatorsHelper.LeftShiftOperation(MaxValue, 1) - .Should().Be(NegativeTwo); - ShiftOperatorsHelper.LeftShiftOperation(MinValue, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.LeftShiftOperation(NegativeOne, 1) - .Should().Be(NegativeTwo); - } - [Fact] - public static void op_RightShiftTest() - { - ShiftOperatorsHelper.RightShiftOperation(Zero, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.RightShiftOperation(One, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.RightShiftOperation(MaxValue, 1) - .Should().Be(new(0x3FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - ShiftOperatorsHelper.RightShiftOperation(MinValue, 1) - .Should().Be(new(0xC000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - ShiftOperatorsHelper.RightShiftOperation(NegativeOne, 1) - .Should().Be(NegativeOne); - - var actual = new Int(0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 1) - .Should().Be(new( - 0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 2) - .Should().Be(new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 3) - .Should().Be(new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 4) - .Should().Be(new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 5) - .Should().Be(new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 6) - .Should().Be(new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000, 0x0000_0000_0000_0000)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 7) - .Should().Be(new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000)); - } - [Fact] - public static void op_UnsignedRightShiftTest() - { - ShiftOperatorsHelper.UnsignedRightShiftOperation(Zero, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.UnsignedRightShiftOperation(One, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.UnsignedRightShiftOperation(MaxValue, 1) - .Should().Be(new(0x3FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - ShiftOperatorsHelper.UnsignedRightShiftOperation(MinValue, 1) - .Should().Be(new(0x4000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - ShiftOperatorsHelper.UnsignedRightShiftOperation(NegativeOne, 1) - .Should().Be(MaxValue); - } - - [Fact] - public static void op_EqualityTest() - { - EqualityOperatorsHelper.EqualityOperation(Zero, 1U).Should().BeFalse(); - EqualityOperatorsHelper.EqualityOperation(One, 1U).Should().BeTrue(); - EqualityOperatorsHelper.EqualityOperation(MaxValue, 1U).Should().BeFalse(); - EqualityOperatorsHelper.EqualityOperation(MinValue, 1U).Should().BeFalse(); - EqualityOperatorsHelper.EqualityOperation(NegativeOne, 1U).Should().BeFalse(); - } - [Fact] - public static void op_InequalityTest() - { - EqualityOperatorsHelper.InequalityOperation(Zero, 1U).Should().BeTrue(); - EqualityOperatorsHelper.InequalityOperation(One, 1U).Should().BeFalse(); - EqualityOperatorsHelper.InequalityOperation(MaxValue, 1U).Should().BeTrue(); - EqualityOperatorsHelper.InequalityOperation(MinValue, 1U).Should().BeTrue(); - EqualityOperatorsHelper.InequalityOperation(NegativeOne, 1U).Should().BeTrue(); - } - - [Fact] - public static void op_GreaterThanTest() - { - ComparisonOperatorsHelper.GreaterThanOperation(Zero, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOperation(One, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOperation(MaxValue, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.GreaterThanOperation(MinValue, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOperation(NegativeOne, 1U).Should().BeFalse(); - } - [Fact] - public static void op_GreaterThanOrEqualTest() - { - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(Zero, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(One, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(MaxValue, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(MinValue, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(NegativeOne, 1U).Should().BeFalse(); - } - [Fact] - public static void op_LessThanTest() - { - ComparisonOperatorsHelper.LessThanOperation(Zero, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOperation(One, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.LessThanOperation(MaxValue, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.LessThanOperation(MinValue, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOperation(NegativeOne, 1U).Should().BeTrue(); - } - [Fact] - public static void op_LessThanOrEqualTest() - { - ComparisonOperatorsHelper.LessThanOrEqualOperation(Zero, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(One, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(MaxValue, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(MinValue, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(NegativeOne, 1U).Should().BeTrue(); - } - #endregion - - #region Identities - [Fact] - public static void AdditiveIdentityTest() - { - Assert.Equal(Zero, MathConstantsHelper.AdditiveIdentityHelper()); - } - - [Fact] - public static void MultiplicativeIdentityTest() - { - Assert.Equal(One, MathConstantsHelper.MultiplicativeIdentityHelper()); - } - #endregion - - #region IBinaryInteger - [Fact] - public static void DivRemTest() - { - Assert.Equal((Zero, Zero), BinaryIntegerHelper.DivRem(Zero, Two)); - Assert.Equal((Zero, One), BinaryIntegerHelper.DivRem(One, Two)); - Assert.Equal((new Int(0x3FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), One), BinaryIntegerHelper.DivRem(MaxValue, Two)); - Assert.Equal((new Int(0xC000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), Zero), BinaryIntegerHelper.DivRem(MinValue, Two)); - Assert.Equal((Zero, NegativeOne), BinaryIntegerHelper.DivRem(NegativeOne, 2)); - } - - [Fact] - public static void LeadingZeroCountTest() - { - Assert.Equal(512, BinaryIntegerHelper.LeadingZeroCount(Zero)); - Assert.Equal(511, BinaryIntegerHelper.LeadingZeroCount(One)); - Assert.Equal(1, BinaryIntegerHelper.LeadingZeroCount(MaxValue)); - Assert.Equal(0, BinaryIntegerHelper.LeadingZeroCount(MinValue)); - Assert.Equal(0, BinaryIntegerHelper.LeadingZeroCount(NegativeOne)); - } - - [Fact] - public static void PopCountTest() - { - Assert.Equal(0, BinaryIntegerHelper.PopCount(Zero)); - Assert.Equal(1, BinaryIntegerHelper.PopCount(One)); - Assert.Equal(511, BinaryIntegerHelper.PopCount(MaxValue)); - Assert.Equal(1, BinaryIntegerHelper.PopCount(MinValue)); - Assert.Equal(512, BinaryIntegerHelper.PopCount(NegativeOne)); - } - - [Fact] - public static void RotateLeftTest() - { - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), BinaryIntegerHelper.RotateLeft(Zero, 1)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0002), BinaryIntegerHelper.RotateLeft(One, 1)); - Assert.Equal(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE), BinaryIntegerHelper.RotateLeft(MaxValue, 1)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001), BinaryIntegerHelper.RotateLeft(MinValue, 1)); - Assert.Equal(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), BinaryIntegerHelper.RotateLeft(NegativeOne, 1)); - } - - [Fact] - public static void RotateRightTest() - { - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), BinaryIntegerHelper.RotateRight(Zero, 1)); - Assert.Equal(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), BinaryIntegerHelper.RotateRight(One, 1)); - Assert.Equal(new(0xBFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), BinaryIntegerHelper.RotateRight(MaxValue, 1)); - Assert.Equal(new(0x4000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), BinaryIntegerHelper.RotateRight(MinValue, 1)); - Assert.Equal(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), BinaryIntegerHelper.RotateRight(NegativeOne, 1)); - } - - [Fact] - public static void TrailingZeroCountTest() - { - Assert.Equal(512, BinaryIntegerHelper.TrailingZeroCount(Zero)); - Assert.Equal(0, BinaryIntegerHelper.TrailingZeroCount(One)); - Assert.Equal(0, BinaryIntegerHelper.TrailingZeroCount(MaxValue)); - Assert.Equal(511, BinaryIntegerHelper.TrailingZeroCount(MinValue)); - Assert.Equal(0, BinaryIntegerHelper.TrailingZeroCount(NegativeOne)); - } - - [Fact] - public static void TryReadLittleEndianInt256Test() - { - Int result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: false, out result)); - Assert.Equal(new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: false, out result)); - Assert.Equal(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0080), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: false, out result)); - Assert.Equal(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), result); - } - - [Fact] - public static void TryReadLittleEndianUInt256Test() - { - Int result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: true, out result)); - Assert.Equal(new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: true, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0080), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: true, out result)); - Assert.Equal(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - } - - [Fact] - public static void GetByteCountTest() - { - Assert.Equal(64, BinaryIntegerHelper.GetByteCount(Zero)); - Assert.Equal(64, BinaryIntegerHelper.GetByteCount(One)); - Assert.Equal(64, BinaryIntegerHelper.GetByteCount(MaxValue)); - Assert.Equal(64, BinaryIntegerHelper.GetByteCount(MinValue)); - Assert.Equal(64, BinaryIntegerHelper.GetByteCount(NegativeOne)); - } - - [Fact] - public static void GetShortestBitLengthTest() - { - Assert.Equal(0x00, BinaryIntegerHelper.GetShortestBitLength(Zero)); - Assert.Equal(0x01, BinaryIntegerHelper.GetShortestBitLength(One)); - Assert.Equal(0x1FF, BinaryIntegerHelper.GetShortestBitLength(MaxValue)); - Assert.Equal(0x200, BinaryIntegerHelper.GetShortestBitLength(MinValue)); - Assert.Equal(0x01, BinaryIntegerHelper.GetShortestBitLength(NegativeOne)); - } - - [Fact] - public static void TryWriteBigEndianTest() - { - Span destination = stackalloc byte[64]; - int bytesWritten = 0; - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(Zero, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(One, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(MaxValue, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(MinValue, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(NegativeOne, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - - Assert.False(BinaryIntegerHelper.TryWriteBigEndian(default, Span.Empty, out bytesWritten)); - Assert.Equal(0, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - } - - [Fact] - public static void TryWriteLittleEndianTest() - { - Span destination = stackalloc byte[64]; - int bytesWritten = 0; - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(Zero, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(One, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(MaxValue, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(MinValue, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(NegativeOne, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - - Assert.False(BinaryIntegerHelper.TryWriteLittleEndian(default, Span.Empty, out bytesWritten)); - Assert.Equal(0, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - } - #endregion - - #region IBinaryNumber - [Fact] - public static void AllBitsSetTest() - { - Assert.Equal(BinaryNumberHelper.AllBitsSet, ~Zero); - } - [Fact] - public static void IsPow2Test() - { - Assert.True(BinaryNumberHelper.IsPow2(new(0x100))); - Assert.True(BinaryNumberHelper.IsPow2(new(0x1_0000))); - Assert.True(BinaryNumberHelper.IsPow2(new(0x1_0000_0000))); - Assert.True(BinaryNumberHelper.IsPow2(new(0, new(0x1, 0x0000_0000_0000_0000)))); - Assert.True(BinaryNumberHelper.IsPow2(new(0x1, new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)))); - } - [Fact] - public static void Log2Test() - { - Assert.Equal(8, BinaryNumberHelper.Log2(new(0x100))); - Assert.Equal(16, BinaryNumberHelper.Log2(new(0x1_0000))); - Assert.Equal(32, BinaryNumberHelper.Log2(new(0x1_0000_0000))); - Assert.Equal(64, BinaryNumberHelper.Log2(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000))); - Assert.Equal(128, BinaryNumberHelper.Log2(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000))); - } - #endregion - - #region IMinMaxValue - [Fact] - public static void MaxValueTest() - { - MaxValue.Should().Be(MathConstantsHelper.MaxValue()); - } - - [Fact] - public static void MinValueTest() - { - MinValue.Should().Be(MathConstantsHelper.MinValue()); - } - #endregion - - #region INumber - [Fact] - public static void ClampTest() - { - NumberHelper.Clamp(MaxValueMinusOne, Int128MaxValue, MaxValue).Should().Be(MaxValueMinusOne); - NumberHelper.Clamp(MinValue, 0, MaxValue).Should().Be(0); - NumberHelper.Clamp(MaxValue, MinValue, 0).Should().Be(0); - - Assert.Throws(() => NumberHelper.Clamp(MinValue, MaxValue, 0)); - } - [Fact] - public static void CopySignTest() - { - NumberHelper.CopySign(MaxValue, NegativeOne).Should().Be(MinValuePlusOne); - NumberHelper.CopySign(MaxValue, One).Should().Be(MaxValue); - NumberHelper.CopySign(NegativeTwo, One).Should().Be(Two); - } - [Fact] - public static void MaxTest() - { - NumberHelper.Max(MaxValue, MinValue).Should().Be(MaxValue); - NumberHelper.Max(One, NegativeTwo).Should().Be(One); - NumberHelper.Max(Two, NegativeOne).Should().Be(Two); - NumberHelper.Max(NegativeOne, NegativeTwo).Should().Be(NegativeOne); - } - [Fact] - public static void MaxNumberTest() - { - NumberHelper.MaxNumber(MaxValue, MinValue).Should().Be(MaxValue); - NumberHelper.MaxNumber(One, NegativeTwo).Should().Be(One); - NumberHelper.MaxNumber(Two, NegativeOne).Should().Be(Two); - NumberHelper.MaxNumber(NegativeOne, NegativeTwo).Should().Be(NegativeOne); - } - [Fact] - public static void MinTest() - { - NumberHelper.Min(MaxValue, MinValue).Should().Be(MinValue); - NumberHelper.Min(One, NegativeTwo).Should().Be(NegativeTwo); - NumberHelper.Min(Two, NegativeOne).Should().Be(NegativeOne); - NumberHelper.Min(NegativeOne, NegativeTwo).Should().Be(NegativeTwo); - } - [Fact] - public static void MinNumberTest() - { - NumberHelper.MinNumber(MaxValue, MinValue).Should().Be(MinValue); - NumberHelper.MinNumber(One, NegativeTwo).Should().Be(NegativeTwo); - NumberHelper.MinNumber(Two, NegativeOne).Should().Be(NegativeOne); - NumberHelper.MinNumber(NegativeOne, NegativeTwo).Should().Be(NegativeTwo); - } - [Fact] - public static void SignTest() - { - NumberHelper.Sign(MinValue).Should().Be(-1); - NumberHelper.Sign(MaxValue).Should().Be(1); - NumberHelper.Sign(Int.Zero).Should().Be(0); - } - #endregion - - #region INumberBase - [Fact] - public static void AbsTest() - { - NumberBaseHelper.Abs(MinValuePlusOne).Should().Be(MaxValue); - NumberBaseHelper.Abs(NegativeTwo).Should().Be(Two); - NumberBaseHelper.Abs(NegativeOne).Should().Be(One); - NumberBaseHelper.Abs(One).Should().Be(One); - - Assert.Throws(() => NumberBaseHelper.Abs(MinValue)); - } - [Fact] - public static void CreateCheckedToInt512Test() - { - NumberBaseHelper.CreateChecked(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateChecked(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateChecked(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateChecked(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateChecked(Int128.MaxValue).Should().Be(Int128MaxValue); - NumberBaseHelper - .CreateChecked(BigInteger.Parse( - "6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateChecked((double)int.MaxValue).Should().Be(Int32MaxValue); - - NumberBaseHelper.CreateChecked(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateChecked(short.MinValue).Should().Be(Int16MinValue); - NumberBaseHelper.CreateChecked(int.MinValue).Should().Be(Int32MinValue); - NumberBaseHelper.CreateChecked(long.MinValue).Should().Be(Int64MinValue); - NumberBaseHelper.CreateChecked(Int128.MinValue).Should().Be(Int128MinValue); - NumberBaseHelper - .CreateChecked(BigInteger.Parse( - "-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")) - .Should().Be(MinValue); - NumberBaseHelper.CreateChecked((double)int.MinValue).Should().Be(Int32MinValue); - } - [Fact] - public static void CreateSaturatingToInt512Test() - { - NumberBaseHelper.CreateSaturating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateSaturating(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateSaturating(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateSaturating(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateSaturating(Int128.MaxValue).Should().Be(Int128MaxValue); - NumberBaseHelper - .CreateSaturating(BigInteger.Parse( - "6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateSaturating(Int512MaxValueAsDouble).Should().Be(MaxValue); - - NumberBaseHelper.CreateSaturating(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateSaturating(short.MinValue).Should().Be(Int16MinValue); - NumberBaseHelper.CreateSaturating(int.MinValue).Should().Be(Int32MinValue); - NumberBaseHelper.CreateSaturating(long.MinValue).Should().Be(Int64MinValue); - NumberBaseHelper.CreateSaturating(Int128.MinValue).Should().Be(Int128MinValue); - NumberBaseHelper - .CreateSaturating(BigInteger.Parse( - "-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")) - .Should().Be(MinValue); - NumberBaseHelper.CreateSaturating(Int512MinValueAsDouble).Should().Be(MinValue); - } - [Fact] - public static void CreateTruncatingToInt512Test() - { - NumberBaseHelper.CreateTruncating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateTruncating(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateTruncating(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateTruncating(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateTruncating(Int128.MaxValue).Should().Be(Int128MaxValue); - NumberBaseHelper - .CreateTruncating(BigInteger.Parse( - "6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateTruncating(Int512MaxValueAsDouble).Should().Be(MaxValue); - - NumberBaseHelper.CreateTruncating(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(short.MinValue).Should().Be(Int16MinValue); - NumberBaseHelper.CreateTruncating(int.MinValue).Should().Be(Int32MinValue); - NumberBaseHelper.CreateTruncating(long.MinValue).Should().Be(Int64MinValue); - NumberBaseHelper.CreateTruncating(Int128.MinValue).Should().Be(Int128MinValue); - NumberBaseHelper - .CreateTruncating(BigInteger.Parse( - "-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")) - .Should().Be(MinValue); - NumberBaseHelper.CreateTruncating(Int512MinValueAsDouble).Should().Be(MinValue); - } - - [Fact] - public static void CreateCheckedFromInt512Test() - { - NumberBaseHelper.CreateChecked(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateChecked(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateChecked(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateChecked(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateChecked(Int128MaxValue).Should().Be(Int128.MaxValue); - NumberBaseHelper.CreateChecked(MaxValue).Should() - .Be(BigInteger.Parse( - "6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047")); - NumberBaseHelper.CreateChecked(MaxValue).Should().Be(Int512MaxValueAsDouble); - - NumberBaseHelper.CreateChecked(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateChecked(Int16MinValue).Should().Be(short.MinValue); - NumberBaseHelper.CreateChecked(Int32MinValue).Should().Be(int.MinValue); - NumberBaseHelper.CreateChecked(Int64MinValue).Should().Be(long.MinValue); - NumberBaseHelper.CreateChecked(Int128MinValue).Should().Be(Int128.MinValue); - NumberBaseHelper.CreateChecked(MinValue).Should() - .Be(BigInteger.Parse( - "-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")); - NumberBaseHelper.CreateChecked(MinValue).Should().Be(Int512MinValueAsDouble); - } - [Fact] - public static void CreateSaturatingFromInt512Test() - { - NumberBaseHelper.CreateSaturating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateSaturating(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateSaturating(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateSaturating(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateSaturating(Int128MaxValue).Should().Be(Int128.MaxValue); - NumberBaseHelper.CreateSaturating(MaxValue).Should() - .Be(BigInteger.Parse( - "6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047")); - NumberBaseHelper.CreateSaturating(MaxValue).Should().Be(Int512MaxValueAsDouble); - - NumberBaseHelper.CreateSaturating(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateSaturating(Int16MinValue).Should().Be(short.MinValue); - NumberBaseHelper.CreateSaturating(Int32MinValue).Should().Be(int.MinValue); - NumberBaseHelper.CreateSaturating(Int64MinValue).Should().Be(long.MinValue); - NumberBaseHelper.CreateSaturating(Int128MinValue).Should().Be(Int128.MinValue); - NumberBaseHelper.CreateSaturating(MinValue).Should() - .Be(BigInteger.Parse( - "-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")); - NumberBaseHelper.CreateSaturating(MinValue).Should().Be(Int512MinValueAsDouble); - } - [Fact] - public static void CreateTruncatingFromInt512Test() - { - NumberBaseHelper.CreateTruncating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateTruncating(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateTruncating(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateTruncating(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateTruncating(Int128MaxValue).Should().Be(Int128.MaxValue); - NumberBaseHelper.CreateTruncating(MaxValue).Should() - .Be(BigInteger.Parse( - "6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047")); - NumberBaseHelper.CreateTruncating(MaxValue).Should().Be(Int512MaxValueAsDouble); - - NumberBaseHelper.CreateTruncating(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateTruncating(Int16MinValue).Should().Be(short.MinValue); - NumberBaseHelper.CreateTruncating(Int32MinValue).Should().Be(int.MinValue); - NumberBaseHelper.CreateTruncating(Int64MinValue).Should().Be(long.MinValue); - NumberBaseHelper.CreateTruncating(Int128MinValue).Should().Be(Int128.MinValue); - NumberBaseHelper.CreateTruncating(MinValue).Should() - .Be(BigInteger.Parse( - "-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")); - NumberBaseHelper.CreateTruncating(MinValue).Should().Be(Int512MinValueAsDouble); - } - - [Fact] - public static void IsCanonicalTest() - { - NumberBaseHelper.IsCanonical(default(Int)).Should().BeTrue(); - } - - [Fact] - public static void IsComplexNumberTest() - { - NumberBaseHelper.IsComplexNumber(default(Int)).Should().BeFalse(); - } - - [Fact] - public static void IsEvenIntegerTest() - { - NumberBaseHelper.IsEvenInteger(One).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(Two).Should().BeTrue(); - } - - [Fact] - public static void IsFiniteTest() - { - NumberBaseHelper.IsFinite(default(Int)).Should().BeTrue(); - } - - [Fact] - public static void IsImaginaryNumberTest() - { - NumberBaseHelper.IsImaginaryNumber(default(Int)).Should().BeFalse(); - } - - [Fact] - public static void IsInfinityTest() - { - NumberBaseHelper.IsInfinity(default(Int)).Should().BeFalse(); - } - - [Fact] - public static void IsIntegerTest() - { - NumberBaseHelper.IsInteger(default(Int)).Should().BeTrue(); - } - - [Fact] - public static void IsNaNTest() - { - NumberBaseHelper.IsNaN(default(Int)).Should().BeFalse(); - } - - [Fact] - public static void IsNegativeTest() - { - NumberBaseHelper.IsNegative(One).Should().BeFalse(); - NumberBaseHelper.IsNegative(NegativeOne).Should().BeTrue(); - } - - [Fact] - public static void IsNegativeInfinityTest() - { - NumberBaseHelper.IsNegativeInfinity(One).Should().BeFalse(); - } - - [Fact] - public static void IsNormalTest() - { - NumberBaseHelper.IsNormal(Zero).Should().BeFalse(); - NumberBaseHelper.IsNormal(One).Should().BeTrue(); - } - - [Fact] - public static void IsOddIntegerTest() - { - NumberBaseHelper.IsOddInteger(One).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(Two).Should().BeFalse(); - } - - [Fact] - public static void IsPositiveTest() - { - NumberBaseHelper.IsPositive(One).Should().BeTrue(); - NumberBaseHelper.IsPositive(NegativeOne).Should().BeFalse(); - } - - [Fact] - public static void IsPositiveInfinityTest() - { - NumberBaseHelper.IsPositiveInfinity(One).Should().BeFalse(); - } - - [Fact] - public static void IsRealNumberTest() - { - NumberBaseHelper.IsRealNumber(default).Should().BeTrue(); - } - - [Fact] - public static void IsSubnormalTest() - { - NumberBaseHelper.IsSubnormal(default).Should().BeFalse(); - } - - [Fact] - public static void IsZeroTest() - { - NumberBaseHelper.IsZero(default).Should().BeTrue(); - NumberBaseHelper.IsZero(Zero).Should().BeTrue(); - NumberBaseHelper.IsZero(One).Should().BeFalse(); - NumberBaseHelper.IsZero(NegativeOne).Should().BeFalse(); - } - - [Fact] - public static void MaxMagnitudeTest() - { - NumberBaseHelper.MaxMagnitude(MaxValue, MinValue).Should().Be(MinValue); - NumberBaseHelper.MaxMagnitude(One, NegativeTwo).Should().Be(NegativeTwo); - NumberBaseHelper.MaxMagnitude(Two, NegativeOne).Should().Be(Two); - NumberBaseHelper.MaxMagnitude(NegativeOne, NegativeTwo).Should().Be(NegativeTwo); - } - - [Fact] - public static void MaxMagnitudeNumberTest() - { - NumberBaseHelper.MaxMagnitudeNumber(MaxValue, MinValue).Should().Be(MinValue); - NumberBaseHelper.MaxMagnitudeNumber(One, NegativeTwo).Should().Be(NegativeTwo); - NumberBaseHelper.MaxMagnitudeNumber(Two, NegativeOne).Should().Be(Two); - NumberBaseHelper.MaxMagnitudeNumber(NegativeOne, NegativeTwo).Should().Be(NegativeTwo); - } - - [Fact] - public static void MinMagnitudeTest() - { - NumberBaseHelper.MinMagnitude(MaxValue, MinValue).Should().Be(MaxValue); - NumberBaseHelper.MinMagnitude(One, NegativeTwo).Should().Be(One); - NumberBaseHelper.MinMagnitude(Two, NegativeOne).Should().Be(NegativeOne); - NumberBaseHelper.MinMagnitude(NegativeOne, NegativeTwo).Should().Be(NegativeOne); - } - - [Fact] - public static void MinMagnitudeNumberTest() - { - NumberBaseHelper.MinMagnitudeNumber(MaxValue, MinValue).Should().Be(MaxValue); - NumberBaseHelper.MinMagnitudeNumber(One, NegativeTwo).Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(Two, NegativeOne).Should().Be(NegativeOne); - NumberBaseHelper.MinMagnitudeNumber(NegativeOne, NegativeTwo).Should().Be(NegativeOne); - } - - [Fact] - public void ParseTest() - { - NumberBaseHelper.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(Int512MaxValue) - .And.BeRankedEquallyTo(Int512MaxValue); - NumberBaseHelper.Parse("7FFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(Int512MaxValue) - .And.BeRankedEquallyTo(Int512MaxValue); - NumberBaseHelper.Parse("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(Int512MinValue) - .And.BeRankedEquallyTo(Int512MinValue); - NumberBaseHelper.Parse("8000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(Int512MinValue) - .And.BeRankedEquallyTo(Int512MinValue); - - Assert.Throws(() => NumberBaseHelper.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - Assert.Throws(() => NumberBaseHelper.Parse("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042049", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - } - - [Fact] - public void TryParseTest() - { - NumberBaseHelper.TryParse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out Int parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int512MaxValue) - .And.BeRankedEquallyTo(Int512MaxValue); - NumberBaseHelper.TryParse("7FFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int512MaxValue) - .And.BeRankedEquallyTo(Int512MaxValue); - NumberBaseHelper.TryParse("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int512MinValue) - .And.BeRankedEquallyTo(Int512MinValue); - NumberBaseHelper.TryParse("8000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int512MinValue) - .And.BeRankedEquallyTo(Int512MinValue); - - NumberBaseHelper.TryParse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - NumberBaseHelper.TryParse("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042049", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - } - - [Fact] - public void ParseUtf8Test() - { - NumberBaseHelper.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(Int512MaxValue) - .And.BeRankedEquallyTo(Int512MaxValue); - NumberBaseHelper.Parse("7FFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(Int512MaxValue) - .And.BeRankedEquallyTo(Int512MaxValue); - NumberBaseHelper.Parse("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(Int512MinValue) - .And.BeRankedEquallyTo(Int512MinValue); - NumberBaseHelper.Parse("8000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(Int512MinValue) - .And.BeRankedEquallyTo(Int512MinValue); - - Assert.Throws(() => NumberBaseHelper.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - Assert.Throws(() => NumberBaseHelper.Parse("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042049"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - } - - [Fact] - public void TryParseUtf8Test() - { - NumberBaseHelper.TryParse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out Int parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int512MaxValue) - .And.BeRankedEquallyTo(Int512MaxValue); - NumberBaseHelper.TryParse("7FFFFFFFFFFFFFFF"u8 + - "FFFFFFFFFFFFFFFF"u8 + - "FFFFFFFFFFFFFFFF"u8 + - "FFFFFFFFFFFFFFFF"u8 + - "FFFFFFFFFFFFFFFF"u8 + - "FFFFFFFFFFFFFFFF"u8 + - "FFFFFFFFFFFFFFFF"u8 + - "FFFFFFFFFFFFFFFF"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int512MaxValue) - .And.BeRankedEquallyTo(Int512MaxValue); - NumberBaseHelper.TryParse("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int512MinValue) - .And.BeRankedEquallyTo(Int512MinValue); - NumberBaseHelper.TryParse("8000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8 + - "0000000000000000"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(Int512MinValue) - .And.BeRankedEquallyTo(Int512MinValue); - - NumberBaseHelper.TryParse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - NumberBaseHelper.TryParse("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042049"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - } - #endregion - - #region ISignedNumber - [Fact] - public static void NegativeOneTest() - { - MathConstantsHelper.NegativeOne().Should().Be(NegativeOne); - } - #endregion - - #region IPowerFunctions - [Fact] - public void PowTest() - { - GenericFloatingPointFunctions.Pow(Zero, int.MaxValue).Should().Be(Zero); - GenericFloatingPointFunctions.Pow(One, int.MaxValue).Should().Be(One); - GenericFloatingPointFunctions.Pow(MaxValue, Zero).Should().Be(One); - GenericFloatingPointFunctions.Pow(MaxValue, One).Should().Be(MaxValue); - GenericFloatingPointFunctions.Pow(Two, Two).Should().Be(4); - GenericFloatingPointFunctions.Pow(Two, 4).Should().Be(16); - GenericFloatingPointFunctions.Pow(16, Two).Should().Be(256); - GenericFloatingPointFunctions.Pow(Two, 510) - .Should().Be(new Int( - 0x4000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - - Assert.Throws(() => GenericFloatingPointFunctions.Pow(Two, NegativeOne)); - Assert.Throws(() => GenericFloatingPointFunctions.Pow(Two, 511)); - Assert.Throws(() => GenericFloatingPointFunctions.Pow(Two + Two, 510)); - } - #endregion - } -} diff --git a/src/MissingValues.Tests/Core/Int512Test.cs b/src/MissingValues.Tests/Core/Int512Test.cs deleted file mode 100644 index 88a9333..0000000 --- a/src/MissingValues.Tests/Core/Int512Test.cs +++ /dev/null @@ -1,294 +0,0 @@ -using FluentAssertions; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Text.Json; -using System.Text.Unicode; -using System.Threading.Tasks; -using Xunit; - -using Int = MissingValues.Int512; - -namespace MissingValues.Tests.Core -{ - public partial class Int512Test - { - private static readonly Int Int512MaxValue = new( - new UInt256(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), - new UInt256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF) - ); - private static readonly Int Int512MinValue = new( - new UInt256(0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), - new UInt256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000) - ); - - [Fact] - public void Ctor_Empty() - { - var i = new Int(); - Assert.Equal(0, i); - } - - [Fact] - public void Ctor_Value() - { - var i = new Int(7); - Assert.Equal(7, i); - } - - [Fact] - public void Cast_ToByte() - { - byte.MinValue.Should().Be((byte)Zero); - byte.MaxValue.Should().Be((byte)ByteMaxValue); - } - - [Fact] - public void Cast_ToInt16() - { - short.MinValue.Should().Be((short)Int16MinValue); - short.MaxValue.Should().Be((short)Int16MaxValue); - } - - [Fact] - public void Cast_ToInt32() - { - int.MinValue.Should().Be((int)Int32MinValue); - int.MaxValue.Should().Be((int)Int32MaxValue); - } - - [Fact] - public void Cast_ToInt64() - { - long.MinValue.Should().Be((long)Int64MinValue); - long.MaxValue.Should().Be((long)Int64MaxValue); - } - - [Fact] - public void Cast_ToInt128() - { - Int128.MinValue.Should().Be((Int128)Int128MinValue); - Int128.MaxValue.Should().Be((Int128)Int128MaxValue); - } - - [Fact] - public void Cast_ToInt256() - { - Int256.MinValue.Should().Be((Int256)Int256MinValue); - Int256.MaxValue.Should().Be((Int256)Int256MaxValue); - } - - [Fact] - public void Cast_ToBigInteger() - { - BigInteger.One.Should().Be((BigInteger)One); - BigInteger.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047") - .Should().Be((BigInteger)MaxValue); - BigInteger.Parse("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048") - .Should().Be((BigInteger)MinValue); - } - - [Fact] - public void Cast_ToDouble() - { - const double max = 6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047.0; - const double min = -6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048.0; - - max.Should().Be((double)Int512MaxValue); - min.Should().Be((double)Int512MinValue); - } - - [Fact] - public void ToDecStringTest() - { - MaxValue.ToString("D", CultureInfo.CurrentCulture) - .Should().Be("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047"); - MinValue.ToString("D", CultureInfo.CurrentCulture) - .Should().Be("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048"); - } - [Fact] - public void ToHexStringTest() - { - One.ToString("X", CultureInfo.CurrentCulture) - .Should().Be("1"); - ((Int)sbyte.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("7F"); - ((Int)short.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("7FFF"); - ((Int)int.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("7FFFFFFF"); - ((Int)long.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("7FFFFFFFFFFFFFFF"); - ((Int)Int128.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - - MaxValue.ToString("X128", CultureInfo.CurrentCulture) - .Should() - .Be("7FFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF" + - "FFFFFFFFFFFFFFFF"); - MinValue.ToString("X128", CultureInfo.CurrentCulture) - .Should() - .Be("8000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000" + - "0000000000000000"); - } - [Fact] - public void ToBinStringTest() - { - One.ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1"); - ((Int)sbyte.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1111111"); - ((Int)short.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("111111111111111"); - ((Int)int.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1111111111111111111111111111111"); - ((Int)long.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("111111111111111111111111111111111111111111111111111111111111111"); - ((Int)Int128.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); - - MaxValue.ToString("B512", CultureInfo.CurrentCulture) - .Should() - .Be("011111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "111111111111111111111111111111111" + - "11111111111111111111111111111111111111111111111111"); - MinValue.ToString("B512", CultureInfo.CurrentCulture) - .Should() - .Be("100000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "000000000000000000000000000000000" + - "00000000000000000000000000000000000000000000000000"); - } - - [Fact] - public void ToDecFormatStringTest() - { - MaxValue.ToString().Should().Be($"{MaxValue:D}"); - MinValue.ToString().Should().Be($"{MinValue:D}"); - } - [Fact] - public void ToHexFormatStringTest() - { - MaxValue.ToString("X128", CultureInfo.CurrentCulture).Should().Be($"{MaxValue:X128}"); - MinValue.ToString("X128", CultureInfo.CurrentCulture).Should().Be($"{MinValue:X128}"); - } - [Fact] - public void ToBinFormatStringTest() - { - MaxValue.ToString("B512", CultureInfo.CurrentCulture).Should().Be($"{MaxValue:B512}"); - MinValue.ToString("B512", CultureInfo.CurrentCulture).Should().Be($"{MinValue:B512}"); - } - - [Fact] - public void ToDecFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString()!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:D}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - - - toString = Encoding.UTF8.GetBytes(MinValue.ToString()!); - - format = stackalloc byte[toString.Length]; - success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MinValue:D}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - [Fact] - public void ToHexFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString("X128", CultureInfo.CurrentCulture)!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:X128}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - - - toString = Encoding.UTF8.GetBytes(MinValue.ToString("X128", CultureInfo.CurrentCulture)!); - - format = stackalloc byte[toString.Length]; - success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MinValue:X128}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - [Fact] - public void ToBinFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString("B512", CultureInfo.CurrentCulture)!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:B512}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - - - toString = Encoding.UTF8.GetBytes(MinValue.ToString("B512", CultureInfo.CurrentCulture)!); - - format = stackalloc byte[toString.Length]; - success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MinValue:B512}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - - [Fact] - public void JsonWriteTest() - { - JsonSerializer.Serialize(new object[] { MaxValue, MinValue, One, NegativeOne }) - .Should().Be("[6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047,-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048,1,-1]"); - } - [Fact] - public void JsonReadTest() - { - JsonSerializer.Deserialize("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047") - .Should().Be(MaxValue); - JsonSerializer.Deserialize("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042047"u8) - .Should().Be(MaxValue); - JsonSerializer.Deserialize("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048") - .Should().Be(MinValue); - JsonSerializer.Deserialize("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048"u8) - .Should().Be(MinValue); - } - } -} diff --git a/src/MissingValues.Tests/Core/JsonConverterTests.cs b/src/MissingValues.Tests/Core/JsonConverterTests.cs new file mode 100644 index 0000000..ce0a247 --- /dev/null +++ b/src/MissingValues.Tests/Core/JsonConverterTests.cs @@ -0,0 +1,28 @@ +using System.Globalization; +using System.Text.Json; + +namespace MissingValues.Tests.Core; + +public class JsonConverterTests +{ + [Test] + public async Task JsonWriteTest() + { + await Assert.That(JsonSerializer.Serialize(new object[] { UInt256.MaxValue, UInt256.MinValue })).EqualTo($"[{UInt256.MaxValue},{UInt256.MinValue}]"); + await Assert.That(JsonSerializer.Serialize(new object[] { Int256.MaxValue, Int256.MinValue })).EqualTo($"[{Int256.MaxValue},{Int256.MinValue}]"); + await Assert.That(JsonSerializer.Serialize(new object[] { UInt512.MaxValue, UInt512.MinValue })).EqualTo($"[{UInt512.MaxValue},{UInt512.MinValue}]"); + await Assert.That(JsonSerializer.Serialize(new object[] { Int512.MaxValue, Int512.MinValue })).EqualTo($"[{Int512.MaxValue},{Int512.MinValue}]"); + await Assert.That(JsonSerializer.Serialize(new object[] { Quad.MaxValue, Quad.MinValue })).EqualTo($"[{Quad.MaxValue.ToString("G", CultureInfo.InvariantCulture)},{Quad.MinValue.ToString("G", CultureInfo.InvariantCulture)}]"); + await Assert.That(JsonSerializer.Serialize(new object[] { Octo.MaxValue, Octo.MinValue })).EqualTo($"[{Octo.MaxValue.ToString("G", CultureInfo.InvariantCulture)},{Octo.MinValue.ToString("G", CultureInfo.InvariantCulture)}]"); + } + [Test] + public async Task JsonReadTest() + { + await Assert.That(JsonSerializer.Deserialize(UInt256.MaxValue.ToString())).EqualTo(UInt256.MaxValue); + await Assert.That(JsonSerializer.Deserialize($"[{Int256.MaxValue},{Int256.MinValue}]")).IsEquivalentTo([Int256.MaxValue, Int256.MinValue]); + await Assert.That(JsonSerializer.Deserialize(UInt512.MaxValue.ToString())).EqualTo(UInt512.MaxValue); + await Assert.That(JsonSerializer.Deserialize($"[{Int512.MaxValue},{Int512.MinValue}]")).IsEquivalentTo([Int512.MaxValue, Int512.MinValue]); + await Assert.That(JsonSerializer.Deserialize(Quad.MaxValue.ToString("G", CultureInfo.InvariantCulture))).EqualTo(Quad.MaxValue); + await Assert.That(JsonSerializer.Deserialize(Octo.MaxValue.ToString("G", CultureInfo.InvariantCulture))).EqualTo(Octo.MaxValue); + } +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Core/NumberFormatTest.cs b/src/MissingValues.Tests/Core/NumberFormatTest.cs deleted file mode 100644 index 7200d85..0000000 --- a/src/MissingValues.Tests/Core/NumberFormatTest.cs +++ /dev/null @@ -1,104 +0,0 @@ -using MissingValues.Tests.Helpers; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Core -{ - public class NumberFormatTest - { - private static readonly Quad _decimalSampleValue = Values.CreateFloat(0x400C_81CD_6E63_1F8A, 0x0902_DE00_D1B7_1759); // 12345.6789 - private static readonly NumberFormatInfo CustomInfo = new() - { - PositiveSign = "+", - NegativeSign = "-", - CurrencyPositivePattern = 0, - CurrencyNegativePattern = 2, - CurrencySymbol = "$", - CurrencyDecimalDigits = 2, - CurrencyDecimalSeparator = ".", - CurrencyGroupSeparator = ",", - CurrencyGroupSizes = [3], - NumberGroupSeparator = "_", - NumberGroupSizes = [2], - NumberDecimalDigits = 5, - NumberDecimalSeparator = ".", - NumberNegativePattern = 1, - PositiveInfinitySymbol = "+Inf", - NegativeInfinitySymbol = "-Inf", - NaNSymbol = "NaN", - }; - - private static readonly (IFormattable, string, NumberFormatInfo?, string)[] _formats = - [ - (Int256.MaxValue, "E", NumberFormatInfo.CurrentInfo, "5,789604E+76"), - (Int256.MaxValue, "e25", NumberFormatInfo.CurrentInfo, "5,7896044618658097711785493e+76"), - (Int256.MinValue, "E", NumberFormatInfo.CurrentInfo, "-5,789604E+76"), - (Int256.MinValue, "e25", NumberFormatInfo.CurrentInfo, "-5,7896044618658097711785493e+76"), - (Int512.MaxValue, "E", NumberFormatInfo.CurrentInfo, "6,703904E+153"), - (Int512.MaxValue, "e25", NumberFormatInfo.CurrentInfo, "6,7039039649712985497870125e+153"), - (Int512.MinValue, "E", NumberFormatInfo.CurrentInfo, "-6,703904E+153"), - (Int512.MinValue, "e25", NumberFormatInfo.CurrentInfo, "-6,7039039649712985497870125e+153"), - (Int512.MinValue, "F3", NumberFormatInfo.InvariantInfo, "-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048.000"), - (_decimalSampleValue, "F", NumberFormatInfo.InvariantInfo, "12345.68"), - (_decimalSampleValue, "F", CustomInfo, "12345.67890"), - (Int512.MinValue, "N", NumberFormatInfo.InvariantInfo, "-6,703,903,964,971,298,549,787,012,499,102,923,063,739,682,910,296,196,688,861,780,721,860,882,015,036,773,488,400,937,149,083,451,713,845,015,929,093,243,025,426,876,941,405,973,284,973,216,824,503,042,048.00"), - (_decimalSampleValue, "N3", NumberFormatInfo.InvariantInfo, "12,345.679"), - (_decimalSampleValue, "N", CustomInfo, "1_23_45.67890"), - (Int512.MinValue, "C", CustomInfo, "$-6,703,903,964,971,298,549,787,012,499,102,923,063,739,682,910,296,196,688,861,780,721,860,882,015,036,773,488,400,937,149,083,451,713,845,015,929,093,243,025,426,876,941,405,973,284,973,216,824,503,042,048.00"), - (_decimalSampleValue, "C", CustomInfo, "$12,345.68"), - ]; - private static readonly (string, NumberStyles, NumberFormatInfo?, Int512, bool)[] _parseInt512 = - [ - ("1E200", NumberStyles.Number | NumberStyles.AllowExponent, NumberFormatInfo.CurrentInfo, default, false), - ("2,5E10", NumberStyles.Number | NumberStyles.AllowExponent, NumberFormatInfo.CurrentInfo, 25_000_000_000, true), - ("1E10", NumberStyles.Number | NumberStyles.AllowExponent, NumberFormatInfo.CurrentInfo, 10_000_000_000, true), - ("1,000", NumberStyles.Number, NumberFormatInfo.CurrentInfo, Int512.One, true), - ("1.000,0", NumberStyles.Number, NumberFormatInfo.CurrentInfo, 1_000, true), - ("1.000.000", NumberStyles.Number, NumberFormatInfo.CurrentInfo, 1_000_000, true), - ("1.000.000.000,00", NumberStyles.Number, NumberFormatInfo.CurrentInfo, 1_000_000_000, true), - ("-6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048.000", NumberStyles.Number, NumberFormatInfo.InvariantInfo, Int512.MinValue, true), - ("-6,703,903,964,971,298,549,787,012,499,102,923,063,739,682,910,296,196,688,861,780,721,860,882,015,036,773,488,400,937,149,083,451,713,845,015,929,093,243,025,426,876,941,405,973,284,973,216,824,503,042,048", NumberStyles.Number, NumberFormatInfo.InvariantInfo, Int512.MinValue, true), - ("$-6,703,903,964,971,298,549,787,012,499,102,923,063,739,682,910,296,196,688,861,780,721,860,882,015,036,773,488,400,937,149,083,451,713,845,015,929,093,243,025,426,876,941,405,973,284,973,216,824,503,042,048.00", NumberStyles.Currency, CustomInfo, Int512.MinValue, true), - ]; - private static readonly (string, NumberStyles, NumberFormatInfo?, Quad, bool)[] _parseQuad = - [ - ("2,5E-1", NumberStyles.Float, NumberFormatInfo.CurrentInfo, QuadTest.Quarter, true), - ("0,250", NumberStyles.Float, NumberFormatInfo.CurrentInfo, QuadTest.Quarter, true), - ("$-0.25", NumberStyles.Currency, CustomInfo, QuadTest.NegativeQuarter, true), - ("1,000", NumberStyles.Float, NumberFormatInfo.CurrentInfo, Quad.One, true), - ("1.000,0", NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, QuadTest.Thousand, true), - ("-1.000,0", NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, QuadTest.NegativeThousand, true), - ]; - - public static readonly FormatStringTheoryData FormatsTheoryData = new(_formats); - - public static readonly FormatParsingTheoryData ParseInt512TheoryData = new(_parseInt512); - public static readonly FormatParsingTheoryData ParseQuadTheoryData = new(_parseQuad); - - [Theory] - [MemberData(nameof(FormatsTheoryData))] - public void FormattingTest(IFormattable value, string fmt, NumberFormatInfo? info, string expected) - { - string actual = value.ToString(fmt, info); - actual.Should().Be(expected); - } - [Theory] - [MemberData(nameof(ParseInt512TheoryData))] - public void IntegerParsingTest(string s, NumberStyles style, NumberFormatInfo? info, Int512 expected, bool success) - { - Int512.TryParse(s, style, info, out Int512 actual).Should().Be(success); - actual.Should().Be(expected); - } - [Theory] - [MemberData(nameof(ParseQuadTheoryData))] - public void FloatingPointParsingTest(string s, NumberStyles style, NumberFormatInfo? info, Quad expected, bool success) - { - Quad.TryParse(s, style, info, out Quad actual).Should().Be(success); - actual.Should().Be(expected); - } - } -} diff --git a/src/MissingValues.Tests/Core/OctoTest.GenericMath.cs b/src/MissingValues.Tests/Core/OctoTest.GenericMath.cs deleted file mode 100644 index 8778d68..0000000 --- a/src/MissingValues.Tests/Core/OctoTest.GenericMath.cs +++ /dev/null @@ -1,921 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Float = MissingValues.Octo; - -namespace MissingValues.Tests.Core -{ - public partial class OctoTest - { - #region Generic Math Operators - [Theory] - [MemberData(nameof(UnaryNegationOperationTheoryData))] - public static void op_UnaryNegationTest(Float self, Float result) - { - MathOperatorsHelper.UnaryNegationOperation(self) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(AdditionOperationTheoryData))] - public static void op_AdditionTest(Float left, Float right, Float result) - { - MathOperatorsHelper.AdditionOperation(left, right) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(IncrementOperationTheoryData))] - public static void op_IncrementTest(Float self, Float result) - { - MathOperatorsHelper.IncrementOperation(self) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(SubtractionOperationTheoryData))] - public static void op_SubtractionTest(Float left, Float right, Float result) - { - MathOperatorsHelper.SubtractionOperation(left, right) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(DecrementOperationTheoryData))] - public static void op_DecrementTest(Float self, Float result) - { - MathOperatorsHelper.DecrementOperation(self) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(MultiplicationOperationTheoryData))] - public static void op_MultiplicationTest(Float left, Float right, Float result) - { - MathOperatorsHelper.MultiplicationOperation(left, right) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(DivisionOperationTheoryData))] - public static void op_DivisionTest(Float left, Float right, Float result) - { - MathOperatorsHelper.DivisionOperation(left, right) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - #endregion - - #region IBinaryFloatingPointIEEE - [Fact] - public static void AllBitsSetTest() - { - BinaryNumberHelper.AllBitsSet.Should().Be(BitwiseOperatorsHelper.OnesComplementOperation(Zero)); - } - [Fact] - public static void IsPow2Test() - { - BinaryNumberHelper.IsPow2(Half).Should().BeTrue(); - BinaryNumberHelper.IsPow2(One).Should().BeTrue(); - BinaryNumberHelper.IsPow2(Two).Should().BeTrue(); - BinaryNumberHelper.IsPow2(Three).Should().BeFalse(); - BinaryNumberHelper.IsPow2(NegativeTwo).Should().BeFalse(); - } - #endregion - - #region IFloatingPointIEEE - [Fact] - public static void EpsilonTest() - { - FloatingPointIeee754.Epsilon.Should().Be(Float.Epsilon); - MathOperatorsHelper.AdditionOperation(FloatingPointIeee754.Epsilon, NumberBaseHelper.Zero) - .Should().NotBe(Float.Zero); - } - [Fact] - public static void NaNTest() - { - FloatingPointIeee754.NaN - .Should().Be(Float.NaN) - .And.BeNaN(); - NumberBaseHelper.IsNaN(FloatingPointIeee754.NaN).Should().BeTrue(); - } - [Fact] - public static void NegativeInfinityTest() - { - FloatingPointIeee754.NegativeInfinity.Should().Be(Float.NegativeInfinity); - NumberBaseHelper.IsInfinity(FloatingPointIeee754.NegativeInfinity).Should().BeTrue(); - NumberBaseHelper.IsNegativeInfinity(FloatingPointIeee754.NegativeInfinity).Should().BeTrue(); - NumberBaseHelper.IsPositiveInfinity(FloatingPointIeee754.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void PositiveInfinityTest() - { - FloatingPointIeee754.PositiveInfinity.Should().Be(Float.PositiveInfinity); - NumberBaseHelper.IsInfinity(FloatingPointIeee754.PositiveInfinity).Should().BeTrue(); - NumberBaseHelper.IsNegativeInfinity(FloatingPointIeee754.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsPositiveInfinity(FloatingPointIeee754.PositiveInfinity).Should().BeTrue(); - } - [Fact] - public static void BitDecrementTest() - { - FloatingPointIeee754.BitDecrement(One) - .Should().Be(Values.CreateFloat(0x3FFFEFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); - FloatingPointIeee754.BitDecrement(NegativeOne) - .Should().Be(Values.CreateFloat(0xBFFFF00000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000001)); - FloatingPointIeee754.BitDecrement(Zero) - .Should().Be(-Float.Epsilon); - FloatingPointIeee754.BitDecrement(Float.NegativeInfinity) - .Should().Be(Float.NegativeInfinity); - FloatingPointIeee754.BitDecrement(Float.PositiveInfinity) - .Should().Be(Float.MaxValue); - } - [Fact] - public static void BitIncrementTest() - { - FloatingPointIeee754.BitIncrement(One) - .Should().Be(Values.CreateFloat(0x3FFFF00000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000001)); - FloatingPointIeee754.BitIncrement(NegativeOne) - .Should().Be(Values.CreateFloat(0xBFFFEFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); - FloatingPointIeee754.BitIncrement(NegativeZero) - .Should().Be(Float.Epsilon); - FloatingPointIeee754.BitIncrement(Float.NegativeInfinity) - .Should().Be(Float.MinValue); - FloatingPointIeee754.BitIncrement(Float.PositiveInfinity) - .Should().Be(Float.PositiveInfinity); - } - [Theory] - [MemberData(nameof(FMATheoryData))] - public static void FusedMultiplyAddTest(Float left, Float right, Float addend, Float result) - { - FloatingPointIeee754.FusedMultiplyAdd(left, right, addend) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Fact] - public static void IeeeRemainderTest() - { - FloatingPointIeee754.Ieee754Remainder(Ten, Three).Should().Be(One); - FloatingPointIeee754.Ieee754Remainder(Ten, Two).Should().Be(Zero); - FloatingPointIeee754.Ieee754Remainder(NegativeTen, Three).Should().Be(NegativeOne); - FloatingPointIeee754.Ieee754Remainder(NegativeTen, Two).Should().Be(NegativeZero); - FloatingPointIeee754.Ieee754Remainder(NegativeTen, Zero).Should().Be(Float.NaN); - } - [Fact] - public static void ILogBTest() - { - FloatingPointIeee754.ILogB(Values.CreateFloat(0x4000_9000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)) - .Should().Be(10); - FloatingPointIeee754.ILogB(Values.CreateFloat(0x4003_F000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)) - .Should().Be(64); - FloatingPointIeee754.ILogB(Values.CreateFloat(0x4007_F000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)) - .Should().Be(128); - FloatingPointIeee754.ILogB(Values.CreateFloat(0xC003_F000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)) - .Should().Be(64); - FloatingPointIeee754.ILogB(Zero) - .Should().Be(int.MinValue); - } - [Fact] - public static void ReciprocalEstimateTest() - { - FloatingPointIeee754.ReciprocalEstimate(Two) - .Should().Be(Half); - FloatingPointIeee754.ReciprocalEstimate(Four) - .Should().BeApproximately(Values.CreateFloat(0x3FFF_D000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), Delta); - } - [Fact] - public static void ScaleBTest() - { - FloatingPointIeee754.ScaleB(Two, 3) - .Should().Be(Values.CreateFloat(0x4000_3000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - FloatingPointIeee754.ScaleB(NegativeTwo, 3) - .Should().Be(Values.CreateFloat(0xC000_3000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - FloatingPointIeee754.ScaleB(Zero, 6) - .Should().Be(Zero); - FloatingPointIeee754.ScaleB(Two, 300000) - .Should().Be(Float.PositiveInfinity); - FloatingPointIeee754.ScaleB(Two, -300000) - .Should().Be(Zero); - } - [Fact] - public static void SqrtTest() - { - GenericFloatingPointFunctions.Sqrt(Zero) - .Should().Be(Zero); - GenericFloatingPointFunctions.Sqrt(-Zero) - .Should().Be(-Zero); - GenericFloatingPointFunctions.Sqrt(Float.PositiveInfinity) - .Should().Be(Float.PositiveInfinity); - GenericFloatingPointFunctions.Sqrt(NegativeFour) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Sqrt(Float.NaN) - .Should().Be(Float.NaN); - - GenericFloatingPointFunctions.Sqrt(Hundred) - .Should().BeApproximately(Ten, Delta); - } - #endregion - - #region IFloatingPoint - [Theory] - [MemberData(nameof(RoundAwayFromZeroTheoryData))] - [MemberData(nameof(RoundToEvenTheoryData))] - [MemberData(nameof(RoundToNegativeInfinityTheoryData))] - [MemberData(nameof(RoundToPositiveInfinityTheoryData))] - [MemberData(nameof(RoundToZeroTheoryData))] - public static void RoundTest(Float self, int digits, MidpointRounding midpointRounding, Float result) - { - Float.Round(self, digits, midpointRounding).Should().Be(result); - } - #endregion - - #region IFloatingPointConstants - [Fact] - public static void ConstantPiTest() - { - Assert.Equal(Float.Pi, MathConstantsHelper.Pi()); - } - [Fact] - public static void ConstantTauTest() - { - Assert.Equal(Float.Tau, MathConstantsHelper.Tau()); - } - [Fact] - public static void ConstantETest() - { - Assert.Equal(Float.E, MathConstantsHelper.E()); - } - #endregion - - #region IMinMaxValue - [Fact] - public static void MaxValueTest() - { - MaxValue.Should().Be(MathConstantsHelper.MaxValue()); - } - - [Fact] - public static void MinValueTest() - { - MinValue.Should().Be(MathConstantsHelper.MinValue()); - } - #endregion - - #region ISignedNumber - [Fact] - public static void NegativeOneTest() - { - MathConstantsHelper.NegativeOne().Should().Be(NegativeOne); - MathConstantsHelper.NegativeOne().Should().Be(-One); - } - #endregion - - #region INumber - [Fact] - public static void ClampTest() - { - NumberHelper.Clamp(Float.NegativeInfinity, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(Float.MinValue, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(NegativeOne, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(-GreatestSubnormal, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(-Float.Epsilon, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(NegativeZero, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(Float.NaN, One, Thousand) - .Should().Be(Float.NaN); - NumberHelper.Clamp(Zero, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(Float.Epsilon, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(GreatestSubnormal, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(One, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(Float.MaxValue, One, Thousand) - .Should().Be(Thousand); - NumberHelper.Clamp(Float.PositiveInfinity, One, Thousand) - .Should().Be(Thousand); - } - [Fact] - public static void CopySignTest() - { - NumberHelper.CopySign(One, NegativeOne) - .Should().Be(NegativeOne); - NumberHelper.CopySign(NegativeOne, One) - .Should().Be(One); - NumberHelper.CopySign(Thousand, NegativeOne) - .Should().Be(NegativeThousand); - NumberHelper.CopySign(NegativeHundred, NegativeOne) - .Should().Be(NegativeHundred); - } - [Fact] - public static void MaxTest() - { - NumberHelper.Max(Float.NegativeInfinity, One) - .Should().Be(One); - NumberHelper.Max(Float.MinValue, One) - .Should().Be(One); - NumberHelper.Max(NegativeOne, One) - .Should().Be(One); - NumberHelper.Max(-GreatestSubnormal, One) - .Should().Be(One); - NumberHelper.Max(-Float.Epsilon, One) - .Should().Be(One); - NumberHelper.Max(NegativeZero, One) - .Should().Be(One); - NumberHelper.Max(Float.NaN, One) - .Should().Be(Float.NaN); - NumberHelper.Max(Zero, One) - .Should().Be(One); - NumberHelper.Max(Float.Epsilon, One) - .Should().Be(One); - NumberHelper.Max(GreatestSubnormal, One) - .Should().Be(One); - NumberHelper.Max(One, One) - .Should().Be(One); - NumberHelper.Max(Float.MaxValue, One) - .Should().Be(Float.MaxValue); - NumberHelper.Max(Float.PositiveInfinity, One) - .Should().Be(Float.PositiveInfinity); - } - [Fact] - public static void MaxNumberTest() - { - NumberHelper.MaxNumber(Float.NegativeInfinity, One) - .Should().Be(One); - NumberHelper.MaxNumber(Float.MinValue, One) - .Should().Be(One); - NumberHelper.MaxNumber(NegativeOne, One) - .Should().Be(One); - NumberHelper.MaxNumber(-GreatestSubnormal, One) - .Should().Be(One); - NumberHelper.MaxNumber(-Float.Epsilon, One) - .Should().Be(One); - NumberHelper.MaxNumber(NegativeZero, One) - .Should().Be(One); - NumberHelper.MaxNumber(Float.NaN, One) - .Should().Be(One); - NumberHelper.MaxNumber(Zero, One) - .Should().Be(One); - NumberHelper.MaxNumber(Float.Epsilon, One) - .Should().Be(One); - NumberHelper.MaxNumber(GreatestSubnormal, One) - .Should().Be(One); - NumberHelper.MaxNumber(One, One) - .Should().Be(One); - NumberHelper.MaxNumber(Float.MaxValue, One) - .Should().Be(Float.MaxValue); - NumberHelper.MaxNumber(Float.PositiveInfinity, One) - .Should().Be(Float.PositiveInfinity); - } - [Fact] - public static void MinTest() - { - NumberHelper.Min(Float.NegativeInfinity, One) - .Should().Be(Float.NegativeInfinity); - NumberHelper.Min(Float.MinValue, One) - .Should().Be(Float.MinValue); - NumberHelper.Min(NegativeOne, One) - .Should().Be(NegativeOne); - NumberHelper.Min(-GreatestSubnormal, One) - .Should().Be(-GreatestSubnormal); - NumberHelper.Min(-Float.Epsilon, One) - .Should().Be(-Float.Epsilon); - NumberHelper.Min(NegativeZero, One) - .Should().Be(NegativeZero); - NumberHelper.Min(Float.NaN, One) - .Should().Be(Float.NaN); - NumberHelper.Min(Zero, One) - .Should().Be(Zero); - NumberHelper.Min(Float.Epsilon, One) - .Should().Be(Float.Epsilon); - NumberHelper.Min(GreatestSubnormal, One) - .Should().Be(GreatestSubnormal); - NumberHelper.Min(One, One) - .Should().Be(One); - NumberHelper.Min(Float.MaxValue, One) - .Should().Be(One); - NumberHelper.Min(Float.PositiveInfinity, One) - .Should().Be(One); - } - [Fact] - public static void MinNumberTest() - { - NumberHelper.MinNumber(Float.NegativeInfinity, One) - .Should().Be(Float.NegativeInfinity); - NumberHelper.MinNumber(Float.MinValue, One) - .Should().Be(Float.MinValue); - NumberHelper.MinNumber(NegativeOne, One) - .Should().Be(NegativeOne); - NumberHelper.MinNumber(-GreatestSubnormal, One) - .Should().Be(-GreatestSubnormal); - NumberHelper.MinNumber(-Float.Epsilon, One) - .Should().Be(-Float.Epsilon); - NumberHelper.MinNumber(NegativeZero, One) - .Should().Be(NegativeZero); - NumberHelper.MinNumber(Float.NaN, One) - .Should().Be(One); - NumberHelper.MinNumber(Zero, One) - .Should().Be(Zero); - NumberHelper.MinNumber(Float.Epsilon, One) - .Should().Be(Float.Epsilon); - NumberHelper.MinNumber(GreatestSubnormal, One) - .Should().Be(GreatestSubnormal); - NumberHelper.MinNumber(One, One) - .Should().Be(One); - NumberHelper.MinNumber(Float.MaxValue, One) - .Should().Be(One); - NumberHelper.MinNumber(Float.PositiveInfinity, One) - .Should().Be(One); - } - [Fact] - public static void SignTest() - { - NumberHelper.Sign(One) - .Should().Be(1); - NumberHelper.Sign(NegativeOne) - .Should().Be(-1); - NumberHelper.Sign(Ten) - .Should().Be(1); - NumberHelper.Sign(NegativeTen) - .Should().Be(-1); - NumberHelper.Sign(Zero) - .Should().Be(0); - NumberHelper.Sign(NegativeZero) - .Should().Be(0); - } - #endregion - - #region INumberBase - [Fact] - public static void OneTest() - { - Assert.Equal(One, NumberBaseHelper.One); - } - [Fact] - public static void ZeroTest() - { - Assert.Equal(Zero, NumberBaseHelper.Zero); - } - [Fact] - public static void RadixTest() - { - Assert.Equal(Radix, NumberBaseHelper.Radix); - } - [Fact] - public static void AbsTest() - { - NumberBaseHelper.Abs(One).Should().Be(One); - NumberBaseHelper.Abs(NegativeOne).Should().Be(One); - NumberBaseHelper.Abs(NegativeHalf).Should().Be(Half); - NumberBaseHelper.Abs(NegativeQuarter).Should().Be(Quarter); - NumberBaseHelper.Abs(NegativeZero).Should().Be(Zero); - NumberBaseHelper.Abs(Float.NegativeInfinity).Should().Be(Float.PositiveInfinity); - } - [Fact] - public static void CreateCheckedFromQuadTest() - { - NumberBaseHelper.CreateChecked(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateChecked(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateChecked(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateChecked(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateChecked(Int128MaxValue).Should().Be(Int128.MaxValue); - NumberBaseHelper.CreateChecked(TwoOver255) - .Should().Be(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")); - NumberBaseHelper.CreateChecked(TwoOver511) - .Should() - .Be(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")); - - NumberBaseHelper.CreateChecked(Half).Should().Be((Half)0.5f); - NumberBaseHelper.CreateChecked(Half).Should().Be(0.5f); - NumberBaseHelper.CreateChecked(Half).Should().Be(0.5d); - } - [Fact] - public static void CreateSaturatingFromQuadTest() - { - NumberBaseHelper.CreateSaturating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateSaturating(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateSaturating(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateSaturating(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateSaturating(Int128MaxValue).Should().Be(Int128.MaxValue); - NumberBaseHelper.CreateSaturating(TwoOver255) - .Should().Be(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")); - NumberBaseHelper.CreateSaturating(TwoOver511) - .Should() - .Be(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")); - - NumberBaseHelper.CreateSaturating(Half).Should().Be((Half)0.5f); - NumberBaseHelper.CreateSaturating(Half).Should().Be(0.5f); - NumberBaseHelper.CreateSaturating(Half).Should().Be(0.5d); - } - [Fact] - public static void CreateTruncatingFromQuadTest() - { - NumberBaseHelper.CreateTruncating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateTruncating(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateTruncating(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateTruncating(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateTruncating(Int128MaxValue).Should().Be(Int128.MaxValue); - NumberBaseHelper.CreateTruncating(TwoOver255) - .Should().Be(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")); - NumberBaseHelper.CreateTruncating(TwoOver511) - .Should() - .Be(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")); - - NumberBaseHelper.CreateTruncating(Half).Should().Be((Half)0.5f); - NumberBaseHelper.CreateTruncating(Half).Should().Be(0.5f); - NumberBaseHelper.CreateTruncating(Half).Should().Be(0.5d); - } - [Fact] - public static void CreateCheckedToQuadTest() - { - NumberBaseHelper.CreateChecked(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateChecked(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateChecked(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateChecked(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateChecked(Int128.MaxValue).Should().Be(Int128MaxValue); - NumberBaseHelper.CreateChecked(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")) - .Should().Be(TwoOver255); - NumberBaseHelper.CreateChecked(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")) - .Should().Be(TwoOver511); - - NumberBaseHelper.CreateChecked((Half)0.5f).Should().Be(Half); - NumberBaseHelper.CreateChecked(0.5f).Should().Be(Half); - NumberBaseHelper.CreateChecked(0.5d).Should().Be(Half); - } - [Fact] - public static void CreateSaturatingToQuadTest() - { - NumberBaseHelper.CreateSaturating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateSaturating(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateSaturating(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateSaturating(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateSaturating(Int128.MaxValue).Should().Be(Int128MaxValue); - NumberBaseHelper.CreateSaturating(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")) - .Should().Be(TwoOver255); - NumberBaseHelper.CreateSaturating(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")) - .Should().Be(TwoOver511); - - NumberBaseHelper.CreateSaturating((Half)0.5f).Should().Be(Half); - NumberBaseHelper.CreateSaturating(0.5f).Should().Be(Half); - NumberBaseHelper.CreateSaturating(0.5d).Should().Be(Half); - } - [Fact] - public static void CreateTruncatingToQuadTest() - { - NumberBaseHelper.CreateTruncating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateTruncating(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateTruncating(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateTruncating(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateTruncating(Int128.MaxValue).Should().Be(Int128MaxValue); - NumberBaseHelper.CreateTruncating(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")) - .Should().Be(TwoOver255); - NumberBaseHelper.CreateTruncating(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")) - .Should().Be(TwoOver511); - - NumberBaseHelper.CreateTruncating((Half)0.5f).Should().Be(Half); - NumberBaseHelper.CreateTruncating(0.5f).Should().Be(Half); - NumberBaseHelper.CreateTruncating(0.5d).Should().Be(Half); - } - [Fact] - public static void IsCanonicalTest() - { - NumberBaseHelper.IsCanonical(One).Should().BeTrue(); - } - [Fact] - public static void IsComplexNumberTest() - { - NumberBaseHelper.IsComplexNumber(One).Should().BeFalse(); - } - [Fact] - public static void IsEvenIntegerTest() - { - NumberBaseHelper.IsEvenInteger(Half).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(One).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(Two).Should().BeTrue(); - NumberBaseHelper.IsEvenInteger(Three).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(Four).Should().BeTrue(); - NumberBaseHelper.IsEvenInteger(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(NegativeTwo).Should().BeTrue(); - NumberBaseHelper.IsEvenInteger(NegativeThree).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(NegativeFour).Should().BeTrue(); - } - [Fact] - public static void IsFiniteTest() - { - NumberBaseHelper.IsFinite(One).Should().BeTrue(); - NumberBaseHelper.IsFinite(NegativeOne).Should().BeTrue(); - NumberBaseHelper.IsFinite(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsFinite(Float.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsFinite(Float.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void IsImaginaryNumberTest() - { - NumberBaseHelper.IsImaginaryNumber(One).Should().BeFalse(); - } - [Fact] - public static void IsInfinityTest() - { - NumberBaseHelper.IsInfinity(One).Should().BeFalse(); - NumberBaseHelper.IsInfinity(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsInfinity(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsInfinity(Float.PositiveInfinity).Should().BeTrue(); - NumberBaseHelper.IsInfinity(Float.NegativeInfinity).Should().BeTrue(); - } - [Fact] - public static void IsIntegerTest() - { - NumberBaseHelper.IsInteger(Quarter).Should().BeFalse(); - NumberBaseHelper.IsInteger(Half).Should().BeFalse(); - NumberBaseHelper.IsInteger(Thousand).Should().BeTrue(); - NumberBaseHelper.IsInteger(One).Should().BeTrue(); - NumberBaseHelper.IsInteger(GreaterThanOneSmallest).Should().BeFalse(); - NumberBaseHelper.IsInteger(SmallestSubnormal).Should().BeFalse(); - NumberBaseHelper.IsInteger(NegativeOne).Should().BeTrue(); - NumberBaseHelper.IsInteger(NegativeThousand).Should().BeTrue(); - NumberBaseHelper.IsInteger(NegativeHalf).Should().BeFalse(); - NumberBaseHelper.IsInteger(NegativeQuarter).Should().BeFalse(); - NumberBaseHelper.IsInteger(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsInteger(Float.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsInteger(Float.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void IsNaNTest() - { - NumberBaseHelper.IsNaN(One).Should().BeFalse(); - NumberBaseHelper.IsNaN(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsNaN(Float.NaN).Should().BeTrue(); - NumberBaseHelper.IsNaN(Float.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsNaN(Float.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void IsNegativeTest() - { - NumberBaseHelper.IsNegative(One).Should().BeFalse(); - NumberBaseHelper.IsNegative(GreatestSubnormal).Should().BeFalse(); - NumberBaseHelper.IsNegative(Float.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsNegative(Float.NaN).Should().BeTrue(); - NumberBaseHelper.IsNegative(NegativeOne).Should().BeTrue(); - NumberBaseHelper.IsNegative(Float.NegativeInfinity).Should().BeTrue(); - } - [Fact] - public static void IsNegativeInfinityTest() - { - NumberBaseHelper.IsNegativeInfinity(One).Should().BeFalse(); - NumberBaseHelper.IsNegativeInfinity(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsNegativeInfinity(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsNegativeInfinity(Float.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsNegativeInfinity(Float.NegativeInfinity).Should().BeTrue(); - } - [Fact] - public static void IsNormalTest() - { - NumberBaseHelper.IsNormal(GreatestSubnormal).Should().BeFalse(); - NumberBaseHelper.IsNormal(SmallestSubnormal).Should().BeFalse(); - NumberBaseHelper.IsNormal(MaxValue).Should().BeTrue(); - NumberBaseHelper.IsNormal(MinValue).Should().BeTrue(); - NumberBaseHelper.IsNormal(One).Should().BeTrue(); - } - [Fact] - public static void IsOddIntegerTest() - { - NumberBaseHelper.IsOddInteger(Half).Should().BeFalse(); - NumberBaseHelper.IsOddInteger(One).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(Two).Should().BeFalse(); - NumberBaseHelper.IsOddInteger(Three).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(Four).Should().BeFalse(); - NumberBaseHelper.IsOddInteger(NegativeOne).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(NegativeTwo).Should().BeFalse(); - NumberBaseHelper.IsOddInteger(NegativeThree).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(NegativeFour).Should().BeFalse(); - } - [Fact] - public static void IsPositiveTest() - { - NumberBaseHelper.IsPositive(One).Should().BeTrue(); - NumberBaseHelper.IsPositive(GreatestSubnormal).Should().BeTrue(); - NumberBaseHelper.IsPositive(Float.PositiveInfinity).Should().BeTrue(); - NumberBaseHelper.IsPositive(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsPositive(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsPositive(Float.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void IsPositiveInfinityTest() - { - NumberBaseHelper.IsPositiveInfinity(One).Should().BeFalse(); - NumberBaseHelper.IsPositiveInfinity(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsPositiveInfinity(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsPositiveInfinity(Float.PositiveInfinity).Should().BeTrue(); - NumberBaseHelper.IsPositiveInfinity(Float.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void IsRealNumberTest() - { - NumberBaseHelper.IsRealNumber(GreatestSubnormal).Should().BeTrue(); - NumberBaseHelper.IsRealNumber(MaxValue).Should().BeTrue(); - NumberBaseHelper.IsRealNumber(NegativeThousand).Should().BeTrue(); - NumberBaseHelper.IsRealNumber(Float.PositiveInfinity).Should().BeTrue(); - NumberBaseHelper.IsRealNumber(Float.NegativeInfinity).Should().BeTrue(); - NumberBaseHelper.IsRealNumber(Float.NaN).Should().BeFalse(); - } - [Fact] - public static void IsSubnormalTest() - { - NumberBaseHelper.IsSubnormal(GreatestSubnormal).Should().BeTrue(); - NumberBaseHelper.IsSubnormal(SmallestSubnormal).Should().BeTrue(); - NumberBaseHelper.IsSubnormal(MaxValue).Should().BeFalse(); - NumberBaseHelper.IsSubnormal(MinValue).Should().BeFalse(); - NumberBaseHelper.IsSubnormal(One).Should().BeFalse(); - } - [Fact] - public static void IsZeroTest() - { - NumberBaseHelper.IsZero(One).Should().BeFalse(); - NumberBaseHelper.IsZero(Float.Epsilon).Should().BeFalse(); - NumberBaseHelper.IsZero(Zero).Should().BeTrue(); - NumberBaseHelper.IsZero(NegativeZero).Should().BeTrue(); - } - [Fact] - public static void MaxMagnitudeTest() - { - NumberBaseHelper.MaxMagnitude(Float.NegativeInfinity, One) - .Should().Be(Float.NegativeInfinity); - NumberBaseHelper.MaxMagnitude(Float.MinValue, One) - .Should().Be(Float.MinValue); - NumberBaseHelper.MaxMagnitude(NegativeOne, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(-GreatestSubnormal, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(-Float.Epsilon, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(NegativeZero, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(Float.NaN, One) - .Should().Be(Float.NaN); - NumberBaseHelper.MaxMagnitude(Zero, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(Float.Epsilon, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(GreatestSubnormal, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(One, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(Float.MaxValue, One) - .Should().Be(Float.MaxValue); - NumberBaseHelper.MaxMagnitude(Float.PositiveInfinity, One) - .Should().Be(Float.PositiveInfinity); - } - [Fact] - public static void MaxMagnitudeNumberTest() - { - NumberBaseHelper.MaxMagnitudeNumber(Float.NegativeInfinity, One) - .Should().Be(Float.NegativeInfinity); - NumberBaseHelper.MaxMagnitudeNumber(Float.MinValue, One) - .Should().Be(Float.MinValue); - NumberBaseHelper.MaxMagnitudeNumber(NegativeOne, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(-GreatestSubnormal, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(-Float.Epsilon, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(NegativeZero, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(Float.NaN, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(Zero, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(Float.Epsilon, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(GreatestSubnormal, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(One, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(Float.MaxValue, One) - .Should().Be(Float.MaxValue); - NumberBaseHelper.MaxMagnitudeNumber(Float.PositiveInfinity, One) - .Should().Be(Float.PositiveInfinity); - } - [Fact] - public static void MinMagnitudeTest() - { - NumberBaseHelper.MinMagnitude(Float.NegativeInfinity, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitude(Float.MinValue, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitude(NegativeOne, One) - .Should().Be(NegativeOne); - NumberBaseHelper.MinMagnitude(-GreatestSubnormal, One) - .Should().Be(-GreatestSubnormal); - NumberBaseHelper.MinMagnitude(-Float.Epsilon, One) - .Should().Be(-Float.Epsilon); - NumberBaseHelper.MinMagnitude(NegativeZero, One) - .Should().Be(NegativeZero); - NumberBaseHelper.MinMagnitude(Float.NaN, One) - .Should().Be(Float.NaN); - NumberBaseHelper.MinMagnitude(Zero, One) - .Should().Be(Zero); - NumberBaseHelper.MinMagnitude(Float.Epsilon, One) - .Should().Be(Float.Epsilon); - NumberBaseHelper.MinMagnitude(GreatestSubnormal, One) - .Should().Be(GreatestSubnormal); - NumberBaseHelper.MinMagnitude(One, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitude(Float.MaxValue, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitude(Float.PositiveInfinity, One) - .Should().Be(One); - } - [Fact] - public static void MinMagnitudeNumberTest() - { - NumberBaseHelper.MinMagnitudeNumber(Float.NegativeInfinity, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(Float.MinValue, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(NegativeOne, One) - .Should().Be(NegativeOne); - NumberBaseHelper.MinMagnitudeNumber(-GreatestSubnormal, One) - .Should().Be(-GreatestSubnormal); - NumberBaseHelper.MinMagnitudeNumber(-Float.Epsilon, One) - .Should().Be(-Float.Epsilon); - NumberBaseHelper.MinMagnitudeNumber(NegativeZero, One) - .Should().Be(NegativeZero); - NumberBaseHelper.MinMagnitudeNumber(Float.NaN, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(Zero, One) - .Should().Be(Zero); - NumberBaseHelper.MinMagnitudeNumber(Float.Epsilon, One) - .Should().Be(Float.Epsilon); - NumberBaseHelper.MinMagnitudeNumber(GreatestSubnormal, One) - .Should().Be(GreatestSubnormal); - NumberBaseHelper.MinMagnitudeNumber(One, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(Float.MaxValue, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(Float.PositiveInfinity, One) - .Should().Be(One); - } - [Theory] - [MemberData(nameof(TryParseTheoryData))] - public void ParseTest(string s, bool success, Float output) - { - if (success) - { - NumberBaseHelper.Parse(s, NumberStyles.Float, NumberFormatInfo.CurrentInfo) - .Should().Be(output); - } - else - { - Assert.Throws(() => NumberBaseHelper.Parse(s, NumberStyles.Float, NumberFormatInfo.CurrentInfo)); - } - } - - [Theory] - [MemberData(nameof(TryParseTheoryData))] - public void TryParseTest(string s, bool success, Float output) - { - Float result; - - NumberBaseHelper.TryParse(s, NumberStyles.Float, NumberFormatInfo.CurrentInfo, out result).Should().Be(success); - result.Should().Be(output); - } - - [Theory] - [MemberData(nameof(TryParseTheoryData))] - public void ParseUtf8Test(string s, bool success, Float output) - { - byte[] utf8 = Encoding.UTF8.GetBytes(s); - - if (success) - { - NumberBaseHelper.Parse(utf8, NumberStyles.Float, NumberFormatInfo.CurrentInfo) - .Should().Be(output); - } - else - { - Assert.Throws(() => NumberBaseHelper.Parse(utf8, NumberStyles.Float, NumberFormatInfo.CurrentInfo)); - } - } - - [Theory] - [MemberData(nameof(TryParseTheoryData))] - public void TryParseUtf8Test(string s, bool success, Float output) - { - ReadOnlySpan utf8 = Encoding.UTF8.GetBytes(s); - Float result; - - NumberBaseHelper.TryParse(utf8, NumberStyles.Float, NumberFormatInfo.CurrentInfo, out result).Should().Be(success); - result.Should().Be(output); - } - #endregion - } -} diff --git a/src/MissingValues.Tests/Core/OctoTest.TheoryData.cs b/src/MissingValues.Tests/Core/OctoTest.TheoryData.cs deleted file mode 100644 index 0c7c093..0000000 --- a/src/MissingValues.Tests/Core/OctoTest.TheoryData.cs +++ /dev/null @@ -1,780 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Core -{ - public partial class OctoTest - { -#pragma warning disable S3263 // Static fields should appear in the order they must be initialized - private static (string, bool, Octo)[] _tryParseData => - [ - ("10,0", true, Ten), - ("3", true, Three), - ("-3", true, NegativeThree), - ("2,0", true, Two), - ("-2", true, NegativeTwo), - ("0", true, Zero), - ("-0", true, NegativeZero), - (NumberFormatInfo.CurrentInfo.PositiveInfinitySymbol, true, Octo.PositiveInfinity), - (NumberFormatInfo.CurrentInfo.NegativeInfinitySymbol, true, Octo.NegativeInfinity), - (NumberFormatInfo.CurrentInfo.NaNSymbol, true, Octo.NaN), - ]; - - private static (Octo, Octo)[] _unaryNegationOperationData => - [ - (Zero, NegativeZero), - (One, NegativeOne), - (Two, NegativeTwo), - (Ten, NegativeTen), - (Hundred, NegativeHundred), - (Thousand, NegativeThousand) - ]; - private static (Octo, Octo)[] _incrementOperationData => - [ - (NegativeTwo, NegativeOne), - (NegativeOne, Zero), - (Zero, One), - (One, Two), - ]; - private static (Octo, Octo)[] _decrementOperationData => - [ - (NegativeOne, NegativeTwo), - (Zero, NegativeOne), - (One, Zero), - (Two, One), - ]; - - private static (Octo, Octo, Octo)[] _additionOperationData => - [ - (One, One, Two), - (One, NegativeOne, Zero), - (One, NegativeTwo, NegativeOne), - (One, Four, Five), - (Three, Two, Five), - (SmallestSubnormal, GreatestSubnormal, Values.CreateFloat(0x0000_1000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), - (Octo.PositiveInfinity, Octo.One, Octo.PositiveInfinity), - (Octo.NegativeInfinity, Octo.One, Octo.NegativeInfinity), - (Octo.PositiveInfinity, Octo.PositiveInfinity, Octo.PositiveInfinity), - (Octo.NegativeInfinity, Octo.NegativeInfinity, Octo.NegativeInfinity), - ]; - private static (Octo, Octo, Octo)[] _subtractionOperationData => - [ - (One, One, Zero), - (One, NegativeOne, Two), - (One, Two, NegativeOne), - (SmallestSubnormal, GreatestSubnormal, Values.CreateFloat(0x8000_0FFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)), - (Octo.PositiveInfinity, Octo.PositiveInfinity, Octo.NaN), - (Octo.NegativeInfinity, Octo.NegativeInfinity, Octo.NaN), - ]; - private static (Octo, Octo, Octo)[] _multiplicationOperationData => - [ - (One, One, One), - (One, NegativeOne, NegativeOne), - (Ten, Ten, Hundred), - (NegativeHundred, Ten, NegativeThousand), - (NegativeTen, Hundred, NegativeThousand), - (Zero, NegativeThousand, NegativeZero), - (Zero, Octo.PositiveInfinity, Octo.NaN), - (NegativeZero, Octo.NegativeInfinity, Octo.NaN), - (Octo.PositiveInfinity, Zero, Octo.NaN), - (Octo.NegativeInfinity, NegativeZero, Octo.NaN), - ]; - private static (Octo, Octo, Octo)[] _divisionOperationData => - [ - (One, Two, Half), - (One, Four, Quarter), - (Ten, Five, Two), - (Ten, Ten, One), - (Hundred, Ten, Ten), - (NegativeThousand, Ten, NegativeHundred), - (Zero, Zero, Octo.NaN), - (One, Zero, Octo.PositiveInfinity), - (NegativeOne, Zero, Octo.NegativeInfinity), - (Octo.PositiveInfinity, Octo.PositiveInfinity, Octo.NaN), - (Octo.NegativeInfinity, Octo.NegativeInfinity, Octo.NaN), - ]; - - private static (byte, Octo)[] _castFromByteData => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (byte.MaxValue, ByteMaxValue), - ]; - private static (ushort, Octo)[] _castFromUInt16Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - ]; - private static (uint, Octo)[] _castFromUInt32Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - (uint.MaxValue, UInt32MaxValue), - ]; - private static (ulong, Octo)[] _castFromUInt64Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - (uint.MaxValue, UInt32MaxValue), - (ulong.MaxValue, UInt64MaxValue), - ]; - private static (UInt128, Octo)[] _castFromUInt128Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - (uint.MaxValue, UInt32MaxValue), - (ulong.MaxValue, UInt64MaxValue), - (UInt128.MaxValue, UInt128MaxValue), - ]; - private static (UInt256, Octo)[] _castFromUInt256Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - (uint.MaxValue, UInt32MaxValue), - (ulong.MaxValue, UInt64MaxValue), - (UInt128.MaxValue, UInt128MaxValue), - ]; - private static (UInt512, Octo)[] _castFromUInt512Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - (uint.MaxValue, UInt32MaxValue), - (ulong.MaxValue, UInt64MaxValue), - (UInt128.MaxValue, UInt128MaxValue), - ]; - private static (sbyte, Octo)[] _castFromSByteData => - [ - (sbyte.MinValue, SByteMinValue), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (sbyte.MaxValue, SByteMaxValue), - ]; - private static (short, Octo)[] _castFromInt16Data => - [ - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - ]; - private static (int, Octo)[] _castFromInt32Data => - [ - (int.MinValue, Int32MinValue), - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - (int.MaxValue, Int32MaxValue), - ]; - private static (long, Octo)[] _castFromInt64Data => - [ - (long.MinValue, Int64MinValue), - (int.MinValue, Int32MinValue), - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - (int.MaxValue, Int32MaxValue), - (long.MaxValue, Int64MaxValue), - ]; - private static (Int128, Octo)[] _castFromInt128Data => - [ - (Int128.MinValue, Int128MinValue), - (long.MinValue, Int64MinValue), - (int.MinValue, Int32MinValue), - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - (int.MaxValue, Int32MaxValue), - (long.MaxValue, Int64MaxValue), - (Int128.MaxValue, Int128MaxValue), - ]; - private static (Int256, Octo)[] _castFromInt256Data => - [ - (Int128.MinValue, Int128MinValue), - (long.MinValue, Int64MinValue), - (int.MinValue, Int32MinValue), - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - (int.MaxValue, Int32MaxValue), - (long.MaxValue, Int64MaxValue), - (Int128.MaxValue, Int128MaxValue), - ]; - private static (Int512, Octo)[] _castFromInt512Data => - [ - (Int128.MinValue, Int128MinValue), - (long.MinValue, Int64MinValue), - (int.MinValue, Int32MinValue), - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - (int.MaxValue, Int32MaxValue), - (long.MaxValue, Int64MaxValue), - (Int128.MaxValue, Int128MaxValue), - ]; - private static (Half, Octo)[] _castFromHalfData => - [ - (System.Half.NegativeOne, NegativeOne), - (System.Half.NegativeZero, NegativeZero), - (System.Half.Zero, Zero), - (System.Half.One, One), - ((Half)10, Ten), - ((Half)100, Hundred), - ((Half)1000, Thousand), - ]; - private static (float, Octo)[] _castFromSingleData => - [ - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - ]; - private static (double, Octo)[] _castFromDoubleData => - [ - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - ]; - - private static (Octo, byte)[] _castToByteData => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (ByteMaxValue, byte.MaxValue), - ]; - private static (Octo, ushort)[] _castToUInt16Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - ]; - private static (Octo, uint)[] _castToUInt32Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - (UInt32MaxValue, uint.MaxValue), - ]; - private static (Octo, ulong)[] _castToUInt64Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - (UInt32MaxValue, uint.MaxValue), - (UInt64MaxValue, ulong.MaxValue), - ]; - private static (Octo, UInt128)[] _castToUInt128Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - (UInt32MaxValue, uint.MaxValue), - (UInt64MaxValue, ulong.MaxValue), - (UInt128MaxValue, UInt128.MaxValue), - ]; - private static (Octo, UInt256)[] _castToUInt256Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - (UInt32MaxValue, uint.MaxValue), - (UInt64MaxValue, ulong.MaxValue), - (UInt128MaxValue, UInt128.MaxValue), - ]; - private static (Octo, UInt512)[] _castToUInt512Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - (UInt32MaxValue, uint.MaxValue), - (UInt64MaxValue, ulong.MaxValue), - (UInt128MaxValue, UInt128.MaxValue), - ]; - private static (Octo, sbyte)[] _castToSByteData => - [ - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - ]; - private static (Octo, short)[] _castToInt16Data => - [ - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - ]; - private static (Octo, int)[] _castToInt32Data => - [ - (Int32MinValue, int.MinValue), - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - (Int32MaxValue, int.MaxValue), - ]; - private static (Octo, long)[] _castToInt64Data => - [ - (Int64MinValue, long.MinValue), - (Int32MinValue, int.MinValue), - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - (Int32MaxValue, int.MaxValue), - (Int64MaxValue, long.MaxValue), - ]; - private static (Octo, Int128)[] _castToInt128Data => - [ - (Int128MinValue, Int128.MinValue), - (Int64MinValue, long.MinValue), - (Int32MinValue, int.MinValue), - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - (Int32MaxValue, int.MaxValue), - (Int64MaxValue, long.MaxValue), - (Int128MaxValue, Int128.MaxValue), - ]; - private static (Octo, Int256)[] _castToInt256Data => - [ - (Int128MinValue, Int128.MinValue), - (Int64MinValue, long.MinValue), - (Int32MinValue, int.MinValue), - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - (Int32MaxValue, int.MaxValue), - (Int64MaxValue, long.MaxValue), - (Int128MaxValue, Int128.MaxValue), - ]; - private static (Octo, Int512)[] _castToInt512Data => - [ - (Int128MinValue, Int128.MinValue), - (Int64MinValue, long.MinValue), - (Int32MinValue, int.MinValue), - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - (Int32MaxValue, int.MaxValue), - (Int64MaxValue, long.MaxValue), - (Int128MaxValue, Int128.MaxValue), - ]; - private static (Octo, Half)[] _castToHalfData => - [ - (NegativeHundred, -(Half)100.0f), - (NegativeTen, -(Half)10.0f), - (NegativeTwo, -(Half)2.0f), - (NegativeOne, -(Half)1.0f), - (NegativeZero, -(Half)0.0f), - (Zero, (Half)0.0f), - (One, System.Half.One), - (Two, (Half)2.0f), - (Ten, (Half)10.0f), - (Hundred, (Half)100.0f), - ]; - private static (Octo, float)[] _castToSingleData => - [ - (NegativeThousand, -1000.0f), - (NegativeHundred, -100.0f), - (NegativeTen, -10.0f), - (NegativeTwo, -2.0f), - (NegativeOne, -1.0f), - (NegativeZero, -0.0f), - (Zero, 0.0f), - (Half, 0.5f), - (One, 1.0f), - (Two, 2.0f), - (Ten, 10.0f), - (Hundred, 100.0f), - (Thousand, 1000.0f), - ]; - private static (Octo, double)[] _castToDoubleData => - [ - (NegativeThousand, -1000.0d), - (NegativeHundred, -100.0d), - (NegativeTen, -10.0d), - (NegativeTwo, -2.0d), - (NegativeOne, -1.0d), - (NegativeZero, -0.0d), - (Zero, 0.0d), - (Half, 0.5d), - (One, 1.0d), - (Two, 2.0d), - (Ten, 10.0d), - (Hundred, 100.0d), - (Thousand, 1000.0d), - ]; - private static (Octo, Quad)[] _castToQuadData => - [ - (NegativeThousand, QuadTest.NegativeThousand), - (NegativeHundred, QuadTest.NegativeHundred), - (NegativeTen, QuadTest.NegativeTen), - (NegativeTwo, QuadTest.NegativeTwo), - (NegativeOne, QuadTest.NegativeOne), - (NegativeZero, QuadTest.NegativeZero), - (Zero, QuadTest.Zero), - (Half, QuadTest.Half), - (One, QuadTest.One), - (Two, QuadTest.Two), - (Ten, QuadTest.Ten), - (Hundred, QuadTest.Hundred), - (Thousand, QuadTest.Thousand), - ]; - - private static (Octo, int, MidpointRounding, Octo)[] _roundAwayFromZeroData => - [ - (Values.CreateFloat(0x4000_0C00_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.AwayFromZero, Four), - (Values.CreateFloat(0x4000_0666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.AwayFromZero, Three), - (Values.CreateFloat(0x4000_0400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.AwayFromZero, Three), - (Values.CreateFloat(0x4000_00CC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.AwayFromZero, Two), - (Values.CreateFloat(0xC000_00CC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.AwayFromZero, NegativeTwo), - (Values.CreateFloat(0xC000_0400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.AwayFromZero, NegativeThree), - (Values.CreateFloat(0xC000_0666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.AwayFromZero, NegativeThree), - (Values.CreateFloat(0xC000_0C00_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.AwayFromZero, NegativeFour), - ]; - private static (Octo, int, MidpointRounding, Octo)[] _roundToEvenData => - [ - (Values.CreateFloat(0x4000_0C00_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToEven, Four), - (Values.CreateFloat(0x4000_0666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToEven, Three), - (Values.CreateFloat(0x4000_0400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToEven, Two), - (Values.CreateFloat(0x4000_00CC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToEven, Two), - (Values.CreateFloat(0xC000_00CC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToEven, NegativeTwo), - (Values.CreateFloat(0xC000_0400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToEven, NegativeTwo), - (Values.CreateFloat(0xC000_0666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToEven, NegativeThree), - (Values.CreateFloat(0xC000_0C00_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToEven, NegativeFour), - ]; - private static (Octo, int, MidpointRounding, Octo)[] _roundToNegativeInfinityData => - [ - (Values.CreateFloat(0x4000_0C00_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToNegativeInfinity, Three), - (Values.CreateFloat(0x4000_0666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToNegativeInfinity, Two), - (Values.CreateFloat(0x4000_0400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToNegativeInfinity, Two), - (Values.CreateFloat(0x4000_00CC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToNegativeInfinity, Two), - (Values.CreateFloat(0xC000_00CC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToNegativeInfinity, NegativeThree), - (Values.CreateFloat(0xC000_0400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToNegativeInfinity, NegativeThree), - (Values.CreateFloat(0xC000_0666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToNegativeInfinity, NegativeThree), - (Values.CreateFloat(0xC000_0C00_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToNegativeInfinity, NegativeFour), - ]; - private static (Octo, int, MidpointRounding, Octo)[] _roundToPositiveInfinityData => - [ - (Values.CreateFloat(0x4000_0C00_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToPositiveInfinity, Four), - (Values.CreateFloat(0x4000_0666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToPositiveInfinity, Three), - (Values.CreateFloat(0x4000_0400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToPositiveInfinity, Three), - (Values.CreateFloat(0x4000_00CC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToPositiveInfinity, Three), - (Values.CreateFloat(0xC000_00CC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToPositiveInfinity, NegativeTwo), - (Values.CreateFloat(0xC000_0400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToPositiveInfinity, NegativeTwo), - (Values.CreateFloat(0xC000_0666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToPositiveInfinity, NegativeTwo), - (Values.CreateFloat(0xC000_0C00_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToPositiveInfinity, NegativeThree), - ]; - private static (Octo, int, MidpointRounding, Octo)[] _roundToZeroData => - [ - (Values.CreateFloat(0x4000_0C00_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToZero, Three), - (Values.CreateFloat(0x4000_0666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToZero, Two), - (Values.CreateFloat(0x4000_0400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToZero, Two), - (Values.CreateFloat(0x4000_00CC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToZero, Two), - (Values.CreateFloat(0xC000_00CC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToZero, NegativeTwo), - (Values.CreateFloat(0xC000_0400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToZero, NegativeTwo), - (Values.CreateFloat(0xC000_0666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToZero, NegativeTwo), - (Values.CreateFloat(0xC000_0C00_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToZero, NegativeThree), - ]; - - private static (Octo, Octo, Octo, Octo)[] _fmaData => - [ - (One, One, One, Two), - (Ten, Ten, Zero, Hundred), - (Five, Zero, Five, Five), - (Half, Two, Two, Three), - (Two, Four, Two, Ten), - (Ten, Half, Five, Ten), - (Values.CreateFloat(13835044861142630400, 0, 0, 0), One, Two, Values.CreateFloat(0x3FFF_E800_0000_0000, 0, 0, 0)), - ]; - - - public static TryParseTheoryData TryParseTheoryData = new(_tryParseData); - - public static UnaryTheoryData UnaryNegationOperationTheoryData = new(_unaryNegationOperationData); - public static UnaryTheoryData IncrementOperationTheoryData = new(_incrementOperationData); - public static UnaryTheoryData DecrementOperationTheoryData = new(_decrementOperationData); - - public static OperationTheoryData AdditionOperationTheoryData = new(_additionOperationData); - public static OperationTheoryData SubtractionOperationTheoryData = new(_subtractionOperationData); - public static OperationTheoryData MultiplicationOperationTheoryData = new(_multiplicationOperationData); - public static OperationTheoryData DivisionOperationTheoryData = new(_divisionOperationData); - - public static CastingTheoryData CastFromByteTheoryData = new(_castFromByteData); - public static CastingTheoryData CastFromUInt16TheoryData = new(_castFromUInt16Data); - public static CastingTheoryData CastFromUInt32TheoryData = new(_castFromUInt32Data); - public static CastingTheoryData CastFromUInt64TheoryData = new(_castFromUInt64Data); - public static CastingTheoryData CastFromUInt128TheoryData = new(_castFromUInt128Data); - public static CastingTheoryData CastFromUInt256TheoryData = new(_castFromUInt256Data); - public static CastingTheoryData CastFromUInt512TheoryData = new(_castFromUInt512Data); - public static CastingTheoryData CastFromSByteTheoryData = new(_castFromSByteData); - public static CastingTheoryData CastFromInt16TheoryData = new(_castFromInt16Data); - public static CastingTheoryData CastFromInt32TheoryData = new(_castFromInt32Data); - public static CastingTheoryData CastFromInt64TheoryData = new(_castFromInt64Data); - public static CastingTheoryData CastFromInt128TheoryData = new(_castFromInt128Data); - public static CastingTheoryData CastFromInt256TheoryData = new(_castFromInt256Data); - public static CastingTheoryData CastFromInt512TheoryData = new(_castFromInt512Data); - public static CastingTheoryData CastFromHalfTheoryData = new(_castFromHalfData); - public static CastingTheoryData CastFromSingleTheoryData = new(_castFromSingleData); - public static CastingTheoryData CastFromDoubleTheoryData = new(_castFromDoubleData); - - public static CastingTheoryData CastToByteTheoryData = new(_castToByteData); - public static CastingTheoryData CastToUInt16TheoryData = new(_castToUInt16Data); - public static CastingTheoryData CastToUInt32TheoryData = new(_castToUInt32Data); - public static CastingTheoryData CastToUInt64TheoryData = new(_castToUInt64Data); - public static CastingTheoryData CastToUInt128TheoryData = new(_castToUInt128Data); - public static CastingTheoryData CastToUInt256TheoryData = new(_castToUInt256Data); - public static CastingTheoryData CastToUInt512TheoryData = new(_castToUInt512Data); - public static CastingTheoryData CastToSByteTheoryData = new(_castToSByteData); - public static CastingTheoryData CastToInt16TheoryData = new(_castToInt16Data); - public static CastingTheoryData CastToInt32TheoryData = new(_castToInt32Data); - public static CastingTheoryData CastToInt64TheoryData = new(_castToInt64Data); - public static CastingTheoryData CastToInt128TheoryData = new(_castToInt128Data); - public static CastingTheoryData CastToInt256TheoryData = new(_castToInt256Data); - public static CastingTheoryData CastToInt512TheoryData = new(_castToInt512Data); - public static CastingTheoryData CastToHalfTheoryData = new(_castToHalfData); - public static CastingTheoryData CastToSingleTheoryData = new(_castToSingleData); - public static CastingTheoryData CastToDoubleTheoryData = new(_castToDoubleData); - public static CastingTheoryData CastToQuadTheoryData = new(_castToQuadData); - - public static RoundTheoryData RoundAwayFromZeroTheoryData = new(_roundAwayFromZeroData); - public static RoundTheoryData RoundToEvenTheoryData = new(_roundToEvenData); - public static RoundTheoryData RoundToNegativeInfinityTheoryData = new(_roundToNegativeInfinityData); - public static RoundTheoryData RoundToPositiveInfinityTheoryData = new(_roundToPositiveInfinityData); - public static RoundTheoryData RoundToZeroTheoryData = new(_roundToZeroData); - - public static FusedMultiplyAddTheoryData FMATheoryData = new(_fmaData); -#pragma warning restore S3263 // Static fields should appear in the order they must be initialized - } -} diff --git a/src/MissingValues.Tests/Core/OctoTest.cs b/src/MissingValues.Tests/Core/OctoTest.cs deleted file mode 100644 index 5002b14..0000000 --- a/src/MissingValues.Tests/Core/OctoTest.cs +++ /dev/null @@ -1,355 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Text.Json; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Core -{ - public partial class OctoTest - { - public static readonly Octo NegativeThousand = Values.CreateFloat(0xC000_8F40_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo NegativeHundred = Values.CreateFloat(0xC000_5900_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo NegativeTen = Values.CreateFloat(0xC000_2400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo NegativeFive = Values.CreateFloat(0xC000_1400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo NegativeFour = Values.CreateFloat(0xC000_1000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo NegativeThree = Values.CreateFloat(0xC000_0800_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo NegativeTwo = Values.CreateFloat(0xC000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo NegativeOne = Octo.NegativeOne; - public static readonly Octo NegativeHalf = Values.CreateFloat(0xBFFF_E000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo NegativeQuarter = Values.CreateFloat(0xBFFF_D000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo NegativeZero = Octo.NegativeZero; - public static readonly Octo Zero = Octo.Zero; - public static readonly Octo Quarter = Values.CreateFloat(0x3FFF_D000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Half = Values.CreateFloat(0x3FFF_E000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo One = Octo.One; - public static readonly Octo Two = Values.CreateFloat(0x4000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Three = Values.CreateFloat(0x4000_0800_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Four = Values.CreateFloat(0x4000_1000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Five = Values.CreateFloat(0x4000_1400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Ten = Values.CreateFloat(0x4000_2400_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Hundred = Values.CreateFloat(0x4000_5900_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Thousand = Values.CreateFloat(0x4000_8F40_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - - public static readonly Octo GreaterThanOneSmallest = Values.CreateFloat(0x3FFF_F000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001); - public static readonly Octo LessThanOneLargest = Values.CreateFloat(0x3FFF_EFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF); - - public static readonly Octo SmallestSubnormal = Values.CreateFloat(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001); - public static readonly Octo GreatestSubnormal = Values.CreateFloat(0x0000_0FFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF); - - public static readonly Octo MaxValue = Octo.MaxValue; - public static readonly Octo MinValue = Octo.MinValue; - - public static readonly Octo ByteMaxValue = Values.CreateFloat(0x4000_6FE0_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo UInt16MaxValue = Values.CreateFloat(0x4000_EFFF_E000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo UInt32MaxValue = Values.CreateFloat(0x4001_EFFF_FFFF_E000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo UInt64MaxValue = Values.CreateFloat(0x4003_EFFF_FFFF_FFFF, 0xFFFF_E000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo UInt128MaxValue = Values.CreateFloat(0x4007_EFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_E000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo TwoOver255 = Values.CreateFloat(0x400F_E000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo TwoOver511 = Values.CreateFloat(0x401F_E000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - - public static readonly Octo SByteMaxValue = Values.CreateFloat(0x4000_5FC0_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo SByteMinValue = Values.CreateFloat(0xC000_6000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Int16MaxValue = Values.CreateFloat(0x4000_DFFF_C000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Int16MinValue = Values.CreateFloat(0xC000_E000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Int32MaxValue = Values.CreateFloat(0x4001_DFFF_FFFF_C000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Int32MinValue = Values.CreateFloat(0xC001_E000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Int64MaxValue = Values.CreateFloat(0x4003_DFFF_FFFF_FFFF, 0xFFFF_C000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Int64MinValue = Values.CreateFloat(0xC003_E000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Int128MaxValue = Values.CreateFloat(0x4007_DFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_C000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Octo Int128MinValue = Values.CreateFloat(0xC007_E000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - - public static readonly Octo Delta = Values.CreateFloat(0x400E_B000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - - public static readonly int Radix = 2; - - [Fact] - public void Ctor_Empty() - { - var i = new Octo(); - Assert.Equal(Zero, i); - } - - [Theory] - [MemberData(nameof(CastFromByteTheoryData))] - public void Cast_FromByte(byte from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt16TheoryData))] - public void Cast_FromUInt16(ushort from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt32TheoryData))] - public void Cast_FromUInt32(uint from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt64TheoryData))] - public void Cast_FromUInt64(ulong from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt128TheoryData))] - public void Cast_FromUInt128(UInt128 from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt256TheoryData))] - public void Cast_FromUInt256(UInt256 from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt512TheoryData))] - public void Cast_FromUInt512(UInt512 from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromSByteTheoryData))] - public void Cast_FromSByte(sbyte from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt16TheoryData))] - public void Cast_FromInt16(short from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt32TheoryData))] - public void Cast_FromInt32(int from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt64TheoryData))] - public void Cast_FromInt64(long from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt128TheoryData))] - public void Cast_FromInt128(Int128 from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt256TheoryData))] - public void Cast_FromInt256(Int256 from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt512TheoryData))] - public void Cast_FromInt512(Int512 from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Fact] - public void Cast_FromBigInteger() - { - TwoOver255.Should() - .Be((Octo)BigInteger.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")); - TwoOver511 - .Should() - .Be((Octo)BigInteger.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")); - } - [Theory] - [MemberData(nameof(CastFromHalfTheoryData))] - public void Cast_FromHalf(Half from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromSingleTheoryData))] - public void Cast_FromSingle(float from, Octo to) - { - ((Octo)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromDoubleTheoryData))] - public void Cast_FromDouble(double from, Octo to) - { - ((Octo)from).Should().Be(to); - } - - [Theory] - [MemberData(nameof(CastToByteTheoryData))] - public void Cast_ToByte(Octo from, byte to) - { - ((byte)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt16TheoryData))] - public void Cast_ToUInt16(Octo from, ushort to) - { - ((ushort)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt32TheoryData))] - public void Cast_ToUInt32(Octo from, uint to) - { - ((uint)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt64TheoryData))] - public void Cast_ToUInt64(Octo from, ulong to) - { - ((ulong)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt128TheoryData))] - public void Cast_ToUInt128(Octo from, UInt128 to) - { - ((UInt128)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt256TheoryData))] - public void Cast_ToUInt256(Octo from, UInt256 to) - { - ((UInt256)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt512TheoryData))] - public void Cast_ToUInt512(Octo from, UInt512 to) - { - ((UInt512)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToSByteTheoryData))] - public void Cast_ToSByte(Octo from, sbyte to) - { - ((sbyte)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt16TheoryData))] - public void Cast_ToInt16(Octo from, short to) - { - ((short)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt32TheoryData))] - public void Cast_ToInt32(Octo from, int to) - { - ((int)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt64TheoryData))] - public void Cast_ToInt64(Octo from, long to) - { - ((long)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt128TheoryData))] - public void Cast_ToInt128(Octo from, Int128 to) - { - ((Int128)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt256TheoryData))] - public void Cast_ToInt256(Octo from, Int256 to) - { - ((Int256)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt512TheoryData))] - public void Cast_ToInt512(Octo from, Int512 to) - { - ((Int512)from).Should().Be(to); - } - [Fact] - public void Cast_ToBigInteger() - { - BigInteger.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968") - .Should().Be((BigInteger)TwoOver255); - BigInteger.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048") - .Should().Be((BigInteger)TwoOver511); - } - [Theory] - [MemberData(nameof(CastToHalfTheoryData))] - public void Cast_ToHalf(Octo from, Half to) - { - ((Half)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToSingleTheoryData))] - public void Cast_ToSingle(Octo from, float to) - { - ((float)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToDoubleTheoryData))] - public void Cast_ToDouble(Octo from, double to) - { - ((double)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToQuadTheoryData))] - public void Cast_ToQuad(Octo from, Quad to) - { - ((Quad)from).Should().Be(to); - } - - [Fact] - public void ToGeneralStringTest() - { - Zero.ToString("G70", CultureInfo.InvariantCulture) - .Should().Be("0"); - One.ToString("G70", CultureInfo.InvariantCulture) - .Should().Be("1"); - Two.ToString("G70", CultureInfo.InvariantCulture) - .Should().Be("2"); - Three.ToString("G70", CultureInfo.InvariantCulture) - .Should().Be("3"); - Five.ToString("G70", CultureInfo.InvariantCulture) - .Should().Be("5"); - Ten.ToString("G70", CultureInfo.InvariantCulture) - .Should().Be("10"); - Hundred.ToString("G70", CultureInfo.InvariantCulture) - .Should().Be("100"); - Thousand.ToString("G70", CultureInfo.InvariantCulture) - .Should().Be("1000"); - (new Octo(0x400E_ACFA_698C_9539, 0x0BA8_8C1B_7795_0E32, 0xD6C2_C314_97A4_2D00, 0x0000_0000_0000_0000)) // 1E71 - .ToString("G70", CultureInfo.InvariantCulture) - .Should().Be("1E+71"); - } - - [Theory] - [MemberData(nameof(TryParseTheoryData))] - public void BasicTryParseTest(string s, bool success, Octo expected) - { - Octo.TryParse(s, out Octo actual).Should().Be(success); - actual.Should().Be(expected); - } - - - [Fact] - public void JsonWriteTest() - { - JsonSerializer.Serialize(new Octo[] { MaxValue, One, Half, Quarter, Zero }) - .Should().Be($"[{MaxValue.ToString(null, CultureInfo.InvariantCulture)},1,0.5,0.25,0]"); - } - [Fact] - public void JsonReadTest() - { - string toString = Quarter.ToString(null, CultureInfo.InvariantCulture); - - JsonSerializer.Deserialize(toString) - .Should().Be(Quarter); - JsonSerializer.Deserialize(Encoding.UTF8.GetBytes(toString)) - .Should().Be(Quarter); - } - } -} diff --git a/src/MissingValues.Tests/Core/QuadTest.GenericMath.cs b/src/MissingValues.Tests/Core/QuadTest.GenericMath.cs deleted file mode 100644 index cc86743..0000000 --- a/src/MissingValues.Tests/Core/QuadTest.GenericMath.cs +++ /dev/null @@ -1,1466 +0,0 @@ -using MissingValues.Tests.Helpers; -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Text.Unicode; -using System.Threading.Tasks; - -using Float = MissingValues.Quad; - -namespace MissingValues.Tests.Core -{ - public partial class QuadTest - { - #region Generic Math Operators - [Theory] - [MemberData(nameof(UnaryNegationOperationTheoryData))] - public static void op_UnaryNegationTest(Float self, Float result) - { - MathOperatorsHelper.UnaryNegationOperation(self) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(AdditionOperationTheoryData))] - public static void op_AdditionTest(Float left, Float right, Float result) - { - MathOperatorsHelper.AdditionOperation(left, right) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(IncrementOperationTheoryData))] - public static void op_IncrementTest(Float self, Float result) - { - MathOperatorsHelper.IncrementOperation(self) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(SubtractionOperationTheoryData))] - public static void op_SubtractionTest(Float left, Float right, Float result) - { - MathOperatorsHelper.SubtractionOperation(left, right) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(DecrementOperationTheoryData))] - public static void op_DecrementTest(Float self, Float result) - { - MathOperatorsHelper.DecrementOperation(self) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(MultiplicationOperationTheoryData))] - public static void op_MultiplicationTest(Float left, Float right, Float result) - { - MathOperatorsHelper.MultiplicationOperation(left, right) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Theory] - [MemberData(nameof(DivisionOperationTheoryData))] - public static void op_DivisionTest(Float left, Float right, Float result) - { - MathOperatorsHelper.DivisionOperation(left, right) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Fact] - public static void op_BitwiseAndTest() - { - BitwiseOperatorsHelper.BitwiseAndOperation(Zero, Values.CreateFloat(0x0, 0x1)).Should().Be(Zero); - BitwiseOperatorsHelper.BitwiseAndOperation(Values.CreateFloat(0x0, 0x1), Values.CreateFloat(0x0, 0x1)).Should().Be(Values.CreateFloat(0x0, 0x1)); - BitwiseOperatorsHelper.BitwiseAndOperation(BinaryNumberHelper.AllBitsSet, Values.CreateFloat(0x0, 0x1)).Should().Be(Values.CreateFloat(0x0, 0x1)); - } - [Fact] - public static void op_BitwiseOrTest() - { - BitwiseOperatorsHelper.BitwiseOrOperation(Zero, Values.CreateFloat(0x0, 0x1)) - .Should().Be(Values.CreateFloat(0x0, 0x1)); - BitwiseOperatorsHelper.BitwiseOrOperation(Values.CreateFloat(0x0, 0x1), Values.CreateFloat(0x0, 0x1)) - .Should().Be(Values.CreateFloat(0x0, 0x1)); - BitwiseOperatorsHelper.BitwiseOrOperation(BinaryNumberHelper.AllBitsSet, Values.CreateFloat(0x0, 0x1)) - .Should().Be(BinaryNumberHelper.AllBitsSet); - } - [Fact] - public static void op_ExclusiveOrTest() - { - BitwiseOperatorsHelper.ExclusiveOrOperation(Zero, Values.CreateFloat(0x0, 0x1)) - .Should().Be(Values.CreateFloat(0x0, 0x1)); - BitwiseOperatorsHelper.ExclusiveOrOperation(Values.CreateFloat(0x0, 0x1), Values.CreateFloat(0x0, 0x1)) - .Should().Be(Zero); - BitwiseOperatorsHelper.ExclusiveOrOperation(BinaryNumberHelper.AllBitsSet, Values.CreateFloat(0x0, 0x1)) - .Should().Be(Values.CreateFloat(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)); - } - [Fact] - public static void op_OnesComplementTest() - { - BitwiseOperatorsHelper.OnesComplementOperation(Zero) - .Should().Be(BinaryNumberHelper.AllBitsSet); - BitwiseOperatorsHelper.OnesComplementOperation(Values.CreateFloat(0x0, 0x1)) - .Should().Be(Values.CreateFloat(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)); - BitwiseOperatorsHelper.OnesComplementOperation(BinaryNumberHelper.AllBitsSet) - .Should().Be(Zero); - } - [Theory] - [MemberData(nameof(GreaterThanTheoryData))] - public static void op_GreaterThanTest(Float left, Float right, bool result) - { - ComparisonOperatorsHelper.GreaterThanOperation(left, right) - .Should().Be(result); - } - [Theory] - [MemberData(nameof(GreaterThanTheoryData))] - [MemberData(nameof(EqualToTheoryData))] - public static void op_GreaterThanOrEqualTest(Float left, Float right, bool result) - { - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(left, right) - .Should().Be(result); - } - [Theory] - [MemberData(nameof(LessThanTheoryData))] - public static void op_LessThanTest(Float left, Float right, bool result) - { - ComparisonOperatorsHelper.LessThanOperation(left, right) - .Should().Be(result); - } - [Theory] - [MemberData(nameof(LessThanTheoryData))] - [MemberData(nameof(EqualToTheoryData))] - public static void op_LessThanOrEqualTest(Float left, Float right, bool result) - { - ComparisonOperatorsHelper.LessThanOrEqualOperation(left, right) - .Should().Be(result); - } - [Theory] - [MemberData(nameof(EqualToTheoryData))] - public static void op_EqualToTest(Float left, Float right, bool result) - { - EqualityOperatorsHelper.EqualityOperation(left, right) - .Should().Be(result); - } - [Theory] - [MemberData(nameof(NotEqualToTheoryData))] - public static void op_NotEqualToTest(Float left, Float right, bool result) - { - EqualityOperatorsHelper.InequalityOperation(left, right) - .Should().Be(result); - } - #endregion - - #region Identities - [Fact] - public static void AdditiveIdentityTest() - { - Assert.Equal(Zero, MathConstantsHelper.AdditiveIdentityHelper()); - } - - [Fact] - public static void MultiplicativeIdentityTest() - { - Assert.Equal(One, MathConstantsHelper.MultiplicativeIdentityHelper()); - } - #endregion - - #region IBinaryFloatingPointIEEE - [Fact] - public static void AllBitsSetTest() - { - BinaryNumberHelper.AllBitsSet.Should().Be(BitwiseOperatorsHelper.OnesComplementOperation(Zero)); - } - [Fact] - public static void IsPow2Test() - { - BinaryNumberHelper.IsPow2(Half).Should().BeTrue(); - BinaryNumberHelper.IsPow2(One).Should().BeTrue(); - BinaryNumberHelper.IsPow2(Two).Should().BeTrue(); - BinaryNumberHelper.IsPow2(Three).Should().BeFalse(); - BinaryNumberHelper.IsPow2(NegativeTwo).Should().BeFalse(); - } - #endregion - - #region IFloatingPointIEEE - [Fact] - public static void EpsilonTest() - { - FloatingPointIeee754.Epsilon.Should().Be(Float.Epsilon); - MathOperatorsHelper.AdditionOperation(FloatingPointIeee754.Epsilon, NumberBaseHelper.Zero) - .Should().NotBe(Float.Zero); - } - [Fact] - public static void NaNTest() - { - FloatingPointIeee754.NaN - .Should().Be(Float.NaN) - .And.BeNaN(); - NumberBaseHelper.IsNaN(FloatingPointIeee754.NaN).Should().BeTrue(); - } - [Fact] - public static void NegativeInfinityTest() - { - FloatingPointIeee754.NegativeInfinity.Should().Be(Float.NegativeInfinity); - NumberBaseHelper.IsInfinity(FloatingPointIeee754.NegativeInfinity).Should().BeTrue(); - NumberBaseHelper.IsNegativeInfinity(FloatingPointIeee754.NegativeInfinity).Should().BeTrue(); - NumberBaseHelper.IsPositiveInfinity(FloatingPointIeee754.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void PositiveInfinityTest() - { - FloatingPointIeee754.PositiveInfinity.Should().Be(Float.PositiveInfinity); - NumberBaseHelper.IsInfinity(FloatingPointIeee754.PositiveInfinity).Should().BeTrue(); - NumberBaseHelper.IsNegativeInfinity(FloatingPointIeee754.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsPositiveInfinity(FloatingPointIeee754.PositiveInfinity).Should().BeTrue(); - } - [Fact] - public static void AcosTest() - { - GenericFloatingPointFunctions.Acos(Float.NaN) - .Should() - .BeBitwiseEquivalentTo(Float.NaN) - .And.BeNaN(); - GenericFloatingPointFunctions.Acos(Two) - .Should().BeNaN(); - GenericFloatingPointFunctions.Acos(NegativeTwo) - .Should().BeNaN(); - GenericFloatingPointFunctions.Acos(Half) - .Should().BeApproximately(Float.Pi / 3, Delta); - GenericFloatingPointFunctions.Acos(One) - .Should().BeApproximately(Float.Zero, Delta); - GenericFloatingPointFunctions.Acos(NegativeOne) - .Should().BeApproximately(Float.Pi, Delta); - } - [Fact] - public static void AcoshTest() - { - GenericFloatingPointFunctions.Acosh(Two) - .Should().BeApproximately(Values.CreateFloat(0x3FFF_5124_2719_8043, 0x49BE_684B_D018_8D53), Delta); - GenericFloatingPointFunctions.Acosh(Half) - .Should().BeNaN(); - GenericFloatingPointFunctions.Acosh(Zero) - .Should().BeNaN(); - GenericFloatingPointFunctions.Acosh(NegativeOne) - .Should().BeNaN(); - } - [Fact] - public static void AsinTest() - { - GenericFloatingPointFunctions.Asin(Half) - .Should().BeApproximately(Values.CreateFloat(0x3FFE_0C15_2382_D736, 0x5846_5BB3_2E0F_567B), Delta) - .And.BeApproximately(Float.Pi / Six, Delta); - GenericFloatingPointFunctions.Asin(Two) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Asin(One) - .Should().BeApproximately(Float.Pi / Two, Delta); - GenericFloatingPointFunctions.Asin(NegativeOne) - .Should().BeApproximately(-Float.Pi / Two, Delta); - } - [Fact] - public static void AsinhTest() - { - GenericFloatingPointFunctions.Asinh(Two) - .Should().BeApproximately(Values.CreateFloat(0x3FFF_7192_1831_3D08, 0x72F8_E831_837F_0E95), Delta); - GenericFloatingPointFunctions.Asinh(Zero) - .Should().BeApproximately(Zero, Delta); - GenericFloatingPointFunctions.Asinh(Values.CreateFloat(0xBFFF_8000_0000_0000, 0x0000_0000_0000_0000)) - .Should().BeApproximately(Values.CreateFloat(0x3FFF_31DC_0090_B63D, 0x8682_7E4B_AAAD_1909), Delta); - } - [Fact] - public static void AtanTest() - { - GenericFloatingPointFunctions.Atan(Half) - .Should().BeApproximately(Values.CreateFloat(0x3FFD_DAC6_7056_1BB4, 0xF1DE_7924_87B0_F0F3), Delta); - GenericFloatingPointFunctions.Atan(Zero) - .Should().BeApproximately(Zero, Delta); - GenericFloatingPointFunctions.Atan(Float.PositiveInfinity) - .Should().BeApproximately(Float.Pi / Two, Delta); - GenericFloatingPointFunctions.Atan(Two) - .Should().BeApproximately(Values.CreateFloat(0x3FFF_1B6E_192E_BBE4, 0x3F5A_7D44_566B_01A8), Delta); - } - [Fact] - public static void Atan2Test() - { - FloatingPointIeee754.Atan2(Zero, Two) - .Should().BeApproximately(Zero, Delta); - FloatingPointIeee754.Atan2(Zero, Zero) - .Should().BeApproximately(Zero, Delta); - FloatingPointIeee754.Atan2(Zero, NegativeTwo) - .Should().BeApproximately(Float.Pi, Delta); - FloatingPointIeee754.Atan2(One, Two) - .Should().BeApproximately(Values.CreateFloat(0x3FFD_DAC6_7056_1BB4, 0xF1DE_7924_87B0_F0F3), Delta); - FloatingPointIeee754.Atan2(NegativeOne, Two) - .Should().BeApproximately(Values.CreateFloat(0xBFFD_DAC6_7056_1BB4, 0xF1DE_7924_87B0_F0F3), Delta); - FloatingPointIeee754.Atan2(One, NegativeTwo) - .Should().BeApproximately(Values.CreateFloat(0x4000_56C6_E739_7F5A, 0xE130_A2BB_E272_574C), Delta); - } - [Fact] - public static void AtanhTest() - { - GenericFloatingPointFunctions.Atanh(Two) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Atanh(NegativeFour) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Atanh(Zero) - .Should().BeApproximately(Zero, Delta); - GenericFloatingPointFunctions.Atanh(Half) - .Should().BeApproximately(Values.CreateFloat(0x3FFE_193E_A7AA_D030, 0xA976_BA8D_B53A_D6E3), Delta); - } - [Fact] - public static void BitDecrementTest() - { - FloatingPointIeee754.BitDecrement(One) - .Should().Be(Values.CreateFloat(0x3FFEFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); - FloatingPointIeee754.BitDecrement(NegativeOne) - .Should().Be(Values.CreateFloat(0xBFFF000000000000, 0x0000000000000001)); - FloatingPointIeee754.BitDecrement(Zero) - .Should().Be(-Float.Epsilon); - FloatingPointIeee754.BitDecrement(Float.NegativeInfinity) - .Should().Be(Float.NegativeInfinity); - FloatingPointIeee754.BitDecrement(Float.PositiveInfinity) - .Should().Be(Float.MaxValue); - } - [Fact] - public static void BitIncrementTest() - { - FloatingPointIeee754.BitIncrement(One) - .Should().Be(Values.CreateFloat(0x3FFF000000000000, 0x0000000000000001)); - FloatingPointIeee754.BitIncrement(NegativeOne) - .Should().Be(Values.CreateFloat(0xBFFEFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); - FloatingPointIeee754.BitIncrement(NegativeZero) - .Should().Be(Float.Epsilon); - FloatingPointIeee754.BitIncrement(Float.NegativeInfinity) - .Should().Be(Float.MinValue); - FloatingPointIeee754.BitIncrement(Float.PositiveInfinity) - .Should().Be(Float.PositiveInfinity); - } - [Fact] - public static void CbrtTest() - { - GenericFloatingPointFunctions.Cbrt(Values.CreateFloat(0x4005_0000_0000_0000, 0x0000_0000_0000_0000)) - .Should().Be(Four); - - - GenericFloatingPointFunctions.Cbrt(Zero) - .Should().Be(Zero); - GenericFloatingPointFunctions.Cbrt(-Zero) - .Should().Be(-Zero); - GenericFloatingPointFunctions.Cbrt(Float.PositiveInfinity) - .Should().Be(Float.PositiveInfinity); - GenericFloatingPointFunctions.Cbrt(NegativeFour) - .Should().BeApproximately(Values.CreateFloat(0xBFFF_965F_EA53_D6E3, 0xC82B_0599_9AB4_3DC5), Delta); - GenericFloatingPointFunctions.Cbrt(Float.NaN) - .Should().Be(Float.NaN); - } - [Fact] - public static void CosTest() - { - GenericFloatingPointFunctions.Cos(Zero) - .Should().BeApproximately(One, Delta); - GenericFloatingPointFunctions.Cos(Float.Pi / Two) - .Should().BeApproximately(Zero, Delta); - GenericFloatingPointFunctions.Cos(Float.Pi) - .Should().BeApproximately(NegativeOne, Delta); - GenericFloatingPointFunctions.Cos(Float.Pi * Two) - .Should().BeApproximately(One, Delta); - - GenericFloatingPointFunctions.Cos(Float.NaN) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Cos(Float.PositiveInfinity) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Cos(Float.NegativeInfinity) - .Should().Be(Float.NaN); - } - [Fact] - public static void CoshTest() - { - GenericFloatingPointFunctions.Cosh(Zero) - .Should().Be(One); - GenericFloatingPointFunctions.Cosh(Two) - .Should().BeApproximately(Values.CreateFloat(0x4000_E18F_A0DF_2D9B, 0xC293_27F7_1777_4D0C), Delta); - GenericFloatingPointFunctions.Cosh(Five) - .Should().BeApproximately(Values.CreateFloat(0x4005_28D6_FCBE_FF3A, 0x9C65_3333_916C_7D52), Delta); - GenericFloatingPointFunctions.Cosh(NegativeFive) - .Should().BeApproximately(Values.CreateFloat(0x4005_28D6_FCBE_FF3A, 0x9C65_3333_916C_7D52), Delta); - } - [Fact] - public static void ExpTest() - { - GenericFloatingPointFunctions.Exp(Two) - .Should().BeApproximately(Values.CreateFloat(0x4001_D8E6_4B8D_4DDA, 0xDCC3_3A3B_A206_B68B), Delta); - GenericFloatingPointFunctions.Exp(NegativeHalf) - .Should().BeApproximately(Values.CreateFloat(0x3FFE_368B_2FC6_F960, 0x9FE7_ACEB_46AA_619C), Delta); - GenericFloatingPointFunctions.Exp(Values.CreateFloat(0x400C_7700_0000_0000, 0x0000_0000_0000_0000)) - .Should().Be(Float.PositiveInfinity); - GenericFloatingPointFunctions.Exp(Values.CreateFloat(0xC00C_7700_0000_0000, 0x0000_0000_0000_0000)) - .Should().Be(Zero); - GenericFloatingPointFunctions.Exp(Zero) - .Should().Be(One); - GenericFloatingPointFunctions.Exp(Float.PositiveInfinity) - .Should().Be(Float.PositiveInfinity); - GenericFloatingPointFunctions.Exp(Float.NaN) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Exp(Float.NegativeInfinity) - .Should().Be(Zero); - } - [Fact] - public static void ExpM1Test() - { - GenericFloatingPointFunctions.ExpM1(Two) - .Should().BeApproximately(GenericFloatingPointFunctions.Exp(Two) - One, Delta); - GenericFloatingPointFunctions.ExpM1(NegativeHalf) - .Should().BeApproximately(GenericFloatingPointFunctions.Exp(NegativeHalf) - One, Delta); - } - [Fact] - public static void Exp10Test() - { - GenericFloatingPointFunctions.Exp10(Two) - .Should().Be(Hundred); - GenericFloatingPointFunctions.Exp10(Zero) - .Should().Be(One); - GenericFloatingPointFunctions.Exp10(Float.PositiveInfinity) - .Should().Be(Float.PositiveInfinity); - GenericFloatingPointFunctions.Exp10(Float.NaN) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Exp10(Float.NegativeInfinity) - .Should().Be(Zero); - } - [Fact] - public static void Exp2Test() - { - GenericFloatingPointFunctions.Exp2(Two) - .Should().Be(Four); - GenericFloatingPointFunctions.Exp2(Zero) - .Should().Be(One); - GenericFloatingPointFunctions.Exp2(Float.PositiveInfinity) - .Should().Be(Float.PositiveInfinity); - GenericFloatingPointFunctions.Exp2(Float.NaN) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Exp2(Float.NegativeInfinity) - .Should().Be(Zero); - } - [Theory] - [MemberData(nameof(FMATheoryData))] - public static void FusedMultiplyAddTest(Float left, Float right, Float addend, Float result) - { - FloatingPointIeee754.FusedMultiplyAdd(left, right, addend) - .Should().Be(result) - .And.BeBitwiseEquivalentTo(result); - } - [Fact] - public static void HypotTest() - { - GenericFloatingPointFunctions.Hypot(Hundred, Ten) - .Should().BeApproximately(Values.CreateFloat(0x4005_91FE_B9F2_BF46, 0xC3A7_08A3_1212_49E7), Delta); - GenericFloatingPointFunctions.Hypot(Float.PositiveInfinity, Float.NegativeInfinity) - .Should().Be(Float.PositiveInfinity); - GenericFloatingPointFunctions.Hypot(Float.NaN, Float.NaN) - .Should().Be(Float.NaN); - } - [Fact] - public static void IeeeRemainderTest() - { - FloatingPointIeee754.Ieee754Remainder(Ten, Three).Should().Be(One); - FloatingPointIeee754.Ieee754Remainder(Ten, Two).Should().Be(Zero); - FloatingPointIeee754.Ieee754Remainder(NegativeTen, Three).Should().Be(NegativeOne); - FloatingPointIeee754.Ieee754Remainder(NegativeTen, Two).Should().Be(NegativeZero); - FloatingPointIeee754.Ieee754Remainder(NegativeTen, Zero).Should().Be(Float.NaN); - } - [Fact] - public static void ILogBTest() - { - FloatingPointIeee754.ILogB(Values.CreateFloat(0x4009_0000_0000_0000, 0x0000_0000_0000_0000)) - .Should().Be(10); - FloatingPointIeee754.ILogB(Values.CreateFloat(0x403F_0000_0000_0000, 0x0000_0000_0000_0000)) - .Should().Be(64); - FloatingPointIeee754.ILogB(Values.CreateFloat(0xC03F_0000_0000_0000, 0x0000_0000_0000_0000)) - .Should().Be(64); - FloatingPointIeee754.ILogB(Zero) - .Should().Be(int.MinValue); - } - [Fact] - public static void LogTest() - { - GenericFloatingPointFunctions.Log(Hundred) - .Should().BeApproximately(Values.CreateFloat(0x4001_26BB_1BBB_5551, 0x582D_D4AD_AC57_05A6), Delta); - GenericFloatingPointFunctions.Log(One) - .Should().Be(Zero); - GenericFloatingPointFunctions.Log(Zero) - .Should().Be(Float.NegativeInfinity); - GenericFloatingPointFunctions.Log(NegativeFive) - .Should().Be(Float.NaN); - } - [Fact] - public static void LogP1Test() - { - GenericFloatingPointFunctions.LogP1(One) - .Should().Be(GenericFloatingPointFunctions.Log(Two)) - .And.BeApproximately(Values.CreateFloat(0x3FFE_62E4_2FEF_A39E, 0xF357_93C7_6730_07E6), Delta); - GenericFloatingPointFunctions.LogP1(Zero) - .Should().Be(Zero); - GenericFloatingPointFunctions.LogP1(NegativeOne) - .Should().Be(Float.NegativeInfinity); - GenericFloatingPointFunctions.LogP1(NegativeFive) - .Should().Be(Float.NaN); - } - [Fact] - public static void Log2Test() - { - GenericFloatingPointFunctions.Log2(Four) - .Should().BeApproximately(Two, Delta); - GenericFloatingPointFunctions.Log2(One) - .Should().Be(Zero); - GenericFloatingPointFunctions.Log2(Zero) - .Should().Be(Float.NegativeInfinity); - GenericFloatingPointFunctions.Log2(NegativeFive) - .Should().Be(Float.NaN); - } - [Fact] - public static void Log10Test() - { - GenericFloatingPointFunctions.Log10(Thousand) - .Should().BeApproximately(Three, Delta); - GenericFloatingPointFunctions.Log10(One) - .Should().Be(Zero); - GenericFloatingPointFunctions.Log10(Zero) - .Should().Be(Float.NegativeInfinity); - GenericFloatingPointFunctions.Log10(NegativeFive) - .Should().Be(Float.NaN); - } - [Fact] - public static void PowTest() - { - GenericFloatingPointFunctions.Pow(Three, Ten) - .Should() - .BeApproximately(Values.CreateFloat(0x400E_CD52_0000_0000, 0x0000_0000_0000_0000), Delta); - GenericFloatingPointFunctions.Pow(Two, NegativeFour) - .Should() - .BeApproximately(Values.CreateFloat(0x3FFB_0000_0000_0000, 0x0000_0000_0000_0000), Delta); - - // Special Cases - Float anything = 8, oddInt = 7, nonInt = 7.5d, greaterThanOne = GreaterThanOneSmallest, lessThanOne = LessThanOneLargest; - - GenericFloatingPointFunctions.Pow(anything, Zero) - .Should() - .Be(One); - - GenericFloatingPointFunctions.Pow(anything, One) - .Should() - .Be(anything); - - GenericFloatingPointFunctions.Pow(anything, Float.NaN) - .Should() - .Be(Float.NaN); - - GenericFloatingPointFunctions.Pow(One, Float.NaN) - .Should() - .Be(One); - - GenericFloatingPointFunctions.Pow(Float.NaN, anything) - .Should() - .Be(Float.NaN); - - GenericFloatingPointFunctions.Pow(greaterThanOne, Float.PositiveInfinity) - .Should() - .Be(Float.PositiveInfinity); - - GenericFloatingPointFunctions.Pow(greaterThanOne, Float.NegativeInfinity) - .Should() - .Be(Zero); - - GenericFloatingPointFunctions.Pow(lessThanOne, Float.PositiveInfinity) - .Should() - .Be(Zero); - - GenericFloatingPointFunctions.Pow(lessThanOne, Float.NegativeInfinity) - .Should() - .Be(Float.PositiveInfinity); - - GenericFloatingPointFunctions.Pow(One, Float.PositiveInfinity) - .Should() - .Be(One); - - GenericFloatingPointFunctions.Pow(One, Float.NegativeInfinity) - .Should() - .Be(One); - - GenericFloatingPointFunctions.Pow(NegativeOne, Float.PositiveInfinity) - .Should() - .Be(One); - - GenericFloatingPointFunctions.Pow(NegativeOne, Float.NegativeInfinity) - .Should() - .Be(One); - - GenericFloatingPointFunctions.Pow(Zero, anything) - .Should() - .Be(Zero); - - GenericFloatingPointFunctions.Pow(NegativeZero, anything) - .Should() - .Be(Zero); - - GenericFloatingPointFunctions.Pow(Zero, -anything) - .Should() - .Be(Float.PositiveInfinity); - - GenericFloatingPointFunctions.Pow(NegativeZero, -anything) - .Should() - .Be(Float.PositiveInfinity); - - GenericFloatingPointFunctions.Pow(NegativeZero, oddInt) - .Should() - .Be(-(GenericFloatingPointFunctions.Pow(Zero, oddInt))); - - GenericFloatingPointFunctions.Pow(Float.PositiveInfinity, anything) - .Should() - .Be(Float.PositiveInfinity); - - GenericFloatingPointFunctions.Pow(Float.PositiveInfinity, -anything) - .Should() - .Be(Zero); - - GenericFloatingPointFunctions.Pow(Float.NegativeInfinity, anything) - .Should() - .Be(GenericFloatingPointFunctions.Pow(NegativeZero, -anything)); - - GenericFloatingPointFunctions.Pow(-anything, oddInt) - .Should() - .Be(GenericFloatingPointFunctions.Pow(NegativeOne, oddInt) * GenericFloatingPointFunctions.Pow(+anything, oddInt)); - - GenericFloatingPointFunctions.Pow(-anything, nonInt) - .Should() - .Be(Float.NaN); - } - [Fact] - public static void ReciprocalEstimateTest() - { - FloatingPointIeee754.ReciprocalEstimate(Two) - .Should().Be(Half); - FloatingPointIeee754.ReciprocalEstimate(Three) - .Should().BeApproximately(Values.CreateFloat(0x3FFD_5555_5555_5555, 0x5555_165E_5289_24A5), Delta); - FloatingPointIeee754.ReciprocalEstimate(Four) - .Should().BeApproximately(Values.CreateFloat(0x3FFD_0000_0000_0000, 0x0000_0000_0000_0000), Delta); - } - [Fact] - public static void RootNTest() - { - GenericFloatingPointFunctions.RootN(Values.CreateFloat(0x4005_4400_0000_0000, 0x0000_0000_0000_0000), 4) - .Should().Be(Three); - GenericFloatingPointFunctions.RootN(Values.CreateFloat(0x4005_0000_0000_0000, 0x0000_0000_0000_0000), 3) - .Should().Be(Four) - .And.Be(GenericFloatingPointFunctions.Cbrt(Values.CreateFloat(0x4005_0000_0000_0000, 0x0000_0000_0000_0000))); - GenericFloatingPointFunctions.RootN(Hundred, 2) - .Should().Be(Ten) - .And.Be(GenericFloatingPointFunctions.Sqrt(Hundred)); - - GenericFloatingPointFunctions.RootN(Zero, 2) - .Should().Be(Zero); - GenericFloatingPointFunctions.RootN(NegativeZero, 2) - .Should().Be(NegativeZero); - GenericFloatingPointFunctions.RootN(Float.PositiveInfinity, 2) - .Should().Be(Float.PositiveInfinity); - GenericFloatingPointFunctions.RootN(NegativeFour, 2) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.RootN(Float.NaN, 2) - .Should().Be(Float.NaN); - } - [Fact] - public static void ScaleBTest() - { - FloatingPointIeee754.ScaleB(Two, 3) - .Should().Be(Values.CreateFloat(0x4003_0000_0000_0000, 0x0000_0000_0000_0000)); - FloatingPointIeee754.ScaleB(NegativeTwo, 3) - .Should().Be(Values.CreateFloat(0xC003_0000_0000_0000, 0x0000_0000_0000_0000)); - FloatingPointIeee754.ScaleB(Zero, 6) - .Should().Be(Zero); - FloatingPointIeee754.ScaleB(Two, 30000) - .Should().Be(Float.PositiveInfinity); - FloatingPointIeee754.ScaleB(Two, -30000) - .Should().Be(Zero); - } - [Fact] - public static void SinTest() - { - GenericFloatingPointFunctions.Sin(Float.NaN) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Sin(Float.PositiveInfinity) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Sin(Float.NegativeInfinity) - .Should().Be(Float.NaN); - } - [Fact] - public static void SinCosTest() - { - Float sin, cos; - - (sin, cos) = GenericFloatingPointFunctions.SinCos(Zero); - sin.Should().BeApproximately(Zero, Delta); - cos.Should().BeApproximately(One, Delta); - - (sin, cos) = GenericFloatingPointFunctions.SinCos(Float.Pi); - sin.Should().BeApproximately(Zero, Delta); - cos.Should().BeApproximately(NegativeOne, Delta); - - (sin, cos) = GenericFloatingPointFunctions.SinCos(Float.Pi / Two); - sin.Should().BeApproximately(One, Delta); - cos.Should().BeApproximately(Zero, Delta); - - (sin, cos) = GenericFloatingPointFunctions.SinCos(Float.Pi * Two); - sin.Should().BeApproximately(Zero, Delta); - cos.Should().BeApproximately(One, Delta); - } - [Fact] - public static void SinhTest() - { - GenericFloatingPointFunctions.Sinh(Two) - .Should().BeApproximately(Values.CreateFloat(0x4000_D03C_F63B_6E19, 0xF6F3_4C80_2C96_2009), Delta); - GenericFloatingPointFunctions.Sinh(Zero) - .Should().Be(Zero); - } - [Fact] - public static void SqrtTest() - { - GenericFloatingPointFunctions.Sqrt(Ten) - .Should().BeApproximately(Values.CreateFloat(0x4000_94C5_83AD_A5B5, 0x2920_4A2B_C830_CD9C), Delta); - GenericFloatingPointFunctions.Sqrt(Hundred) - .Should().BeApproximately(Ten, Delta); - - GenericFloatingPointFunctions.Sqrt(Zero) - .Should().Be(Zero); - GenericFloatingPointFunctions.Sqrt(-Zero) - .Should().Be(-Zero); - GenericFloatingPointFunctions.Sqrt(Float.PositiveInfinity) - .Should().Be(Float.PositiveInfinity); - GenericFloatingPointFunctions.Sqrt(NegativeFour) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Sqrt(Float.NaN) - .Should().Be(Float.NaN); - } - [Fact] - public static void TanTest() - { - GenericFloatingPointFunctions.Tan(Float.NaN) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Tan(Float.PositiveInfinity) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Tan(Float.NegativeInfinity) - .Should().Be(Float.NaN); - } - [Fact] - public static void TanhTest() - { - GenericFloatingPointFunctions.Tanh(Two) - .Should().BeApproximately(Values.CreateFloat(0x3FFE_ED95_05E1_BC3D, 0x3D33_C432_FC3E_8256), Delta); - GenericFloatingPointFunctions.Tanh(Float.NaN) - .Should().Be(Float.NaN); - GenericFloatingPointFunctions.Tanh(Zero) - .Should().Be(Zero); - } - #endregion - - #region IFloatingPoint - [Theory] - [MemberData(nameof(RoundAwayFromZeroTheoryData))] - [MemberData(nameof(RoundToEvenTheoryData))] - [MemberData(nameof(RoundToNegativeInfinityTheoryData))] - [MemberData(nameof(RoundToPositiveInfinityTheoryData))] - [MemberData(nameof(RoundToZeroTheoryData))] - public static void RoundTest(Float self, int digits, MidpointRounding midpointRounding, Float result) - { - Float.Round(self, digits, midpointRounding).Should().Be(result); - } - #endregion - - #region IFloatingPointConstants - [Fact] - public static void ConstantPiTest() - { - Assert.Equal(Float.Pi, MathConstantsHelper.Pi()); - } - [Fact] - public static void ConstantTauTest() - { - Assert.Equal(Float.Tau, MathConstantsHelper.Tau()); - } - [Fact] - public static void ConstantETest() - { - Assert.Equal(Float.E, MathConstantsHelper.E()); - } - #endregion - - #region IMinMaxValue - [Fact] - public static void MaxValueTest() - { - MaxValue.Should().Be(MathConstantsHelper.MaxValue()); - } - - [Fact] - public static void MinValueTest() - { - MinValue.Should().Be(MathConstantsHelper.MinValue()); - } - #endregion - - #region ISignedNumber - [Fact] - public static void NegativeOneTest() - { - MathConstantsHelper.NegativeOne().Should().Be(NegativeOne); - MathConstantsHelper.NegativeOne().Should().Be(-One); - } - #endregion - - #region INumber - [Fact] - public static void ClampTest() - { - NumberHelper.Clamp(Float.NegativeInfinity, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(Float.MinValue, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(NegativeOne, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(-GreatestSubnormal, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(-Float.Epsilon, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(NegativeZero, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(Float.NaN, One, Thousand) - .Should().Be(Float.NaN); - NumberHelper.Clamp(Zero, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(Float.Epsilon, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(GreatestSubnormal, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(One, One, Thousand) - .Should().Be(One); - NumberHelper.Clamp(Float.MaxValue, One, Thousand) - .Should().Be(Thousand); - NumberHelper.Clamp(Float.PositiveInfinity, One, Thousand) - .Should().Be(Thousand); - } - [Fact] - public static void CopySignTest() - { - NumberHelper.CopySign(One, NegativeOne) - .Should().Be(NegativeOne); - NumberHelper.CopySign(NegativeOne, One) - .Should().Be(One); - NumberHelper.CopySign(Thousand, NegativeOne) - .Should().Be(NegativeThousand); - NumberHelper.CopySign(NegativeHundred, NegativeOne) - .Should().Be(NegativeHundred); - } - [Fact] - public static void MaxTest() - { - NumberHelper.Max(Float.NegativeInfinity, One) - .Should().Be(One); - NumberHelper.Max(Float.MinValue, One) - .Should().Be(One); - NumberHelper.Max(NegativeOne, One) - .Should().Be(One); - NumberHelper.Max(-GreatestSubnormal, One) - .Should().Be(One); - NumberHelper.Max(-Float.Epsilon, One) - .Should().Be(One); - NumberHelper.Max(NegativeZero, One) - .Should().Be(One); - NumberHelper.Max(Float.NaN, One) - .Should().Be(Float.NaN); - NumberHelper.Max(Zero, One) - .Should().Be(One); - NumberHelper.Max(Float.Epsilon, One) - .Should().Be(One); - NumberHelper.Max(GreatestSubnormal, One) - .Should().Be(One); - NumberHelper.Max(One, One) - .Should().Be(One); - NumberHelper.Max(Float.MaxValue, One) - .Should().Be(Float.MaxValue); - NumberHelper.Max(Float.PositiveInfinity, One) - .Should().Be(Float.PositiveInfinity); - } - [Fact] - public static void MaxNumberTest() - { - NumberHelper.MaxNumber(Float.NegativeInfinity, One) - .Should().Be(One); - NumberHelper.MaxNumber(Float.MinValue, One) - .Should().Be(One); - NumberHelper.MaxNumber(NegativeOne, One) - .Should().Be(One); - NumberHelper.MaxNumber(-GreatestSubnormal, One) - .Should().Be(One); - NumberHelper.MaxNumber(-Float.Epsilon, One) - .Should().Be(One); - NumberHelper.MaxNumber(NegativeZero, One) - .Should().Be(One); - NumberHelper.MaxNumber(Float.NaN, One) - .Should().Be(One); - NumberHelper.MaxNumber(Zero, One) - .Should().Be(One); - NumberHelper.MaxNumber(Float.Epsilon, One) - .Should().Be(One); - NumberHelper.MaxNumber(GreatestSubnormal, One) - .Should().Be(One); - NumberHelper.MaxNumber(One, One) - .Should().Be(One); - NumberHelper.MaxNumber(Float.MaxValue, One) - .Should().Be(Float.MaxValue); - NumberHelper.MaxNumber(Float.PositiveInfinity, One) - .Should().Be(Float.PositiveInfinity); - } - [Fact] - public static void MinTest() - { - NumberHelper.Min(Float.NegativeInfinity, One) - .Should().Be(Float.NegativeInfinity); - NumberHelper.Min(Float.MinValue, One) - .Should().Be(Float.MinValue); - NumberHelper.Min(NegativeOne, One) - .Should().Be(NegativeOne); - NumberHelper.Min(-GreatestSubnormal, One) - .Should().Be(-GreatestSubnormal); - NumberHelper.Min(-Float.Epsilon, One) - .Should().Be(-Float.Epsilon); - NumberHelper.Min(NegativeZero, One) - .Should().Be(NegativeZero); - NumberHelper.Min(Float.NaN, One) - .Should().Be(Float.NaN); - NumberHelper.Min(Zero, One) - .Should().Be(Zero); - NumberHelper.Min(Float.Epsilon, One) - .Should().Be(Float.Epsilon); - NumberHelper.Min(GreatestSubnormal, One) - .Should().Be(GreatestSubnormal); - NumberHelper.Min(One, One) - .Should().Be(One); - NumberHelper.Min(Float.MaxValue, One) - .Should().Be(One); - NumberHelper.Min(Float.PositiveInfinity, One) - .Should().Be(One); - } - [Fact] - public static void MinNumberTest() - { - NumberHelper.MinNumber(Float.NegativeInfinity, One) - .Should().Be(Float.NegativeInfinity); - NumberHelper.MinNumber(Float.MinValue, One) - .Should().Be(Float.MinValue); - NumberHelper.MinNumber(NegativeOne, One) - .Should().Be(NegativeOne); - NumberHelper.MinNumber(-GreatestSubnormal, One) - .Should().Be(-GreatestSubnormal); - NumberHelper.MinNumber(-Float.Epsilon, One) - .Should().Be(-Float.Epsilon); - NumberHelper.MinNumber(NegativeZero, One) - .Should().Be(NegativeZero); - NumberHelper.MinNumber(Float.NaN, One) - .Should().Be(One); - NumberHelper.MinNumber(Zero, One) - .Should().Be(Zero); - NumberHelper.MinNumber(Float.Epsilon, One) - .Should().Be(Float.Epsilon); - NumberHelper.MinNumber(GreatestSubnormal, One) - .Should().Be(GreatestSubnormal); - NumberHelper.MinNumber(One, One) - .Should().Be(One); - NumberHelper.MinNumber(Float.MaxValue, One) - .Should().Be(One); - NumberHelper.MinNumber(Float.PositiveInfinity, One) - .Should().Be(One); - } - [Fact] - public static void SignTest() - { - NumberHelper.Sign(One) - .Should().Be(1); - NumberHelper.Sign(NegativeOne) - .Should().Be(-1); - NumberHelper.Sign(Ten) - .Should().Be(1); - NumberHelper.Sign(NegativeTen) - .Should().Be(-1); - NumberHelper.Sign(Zero) - .Should().Be(0); - NumberHelper.Sign(NegativeZero) - .Should().Be(0); - } - #endregion - - #region INumberBase - [Fact] - public static void OneTest() - { - Assert.Equal(One, NumberBaseHelper.One); - } - [Fact] - public static void ZeroTest() - { - Assert.Equal(Zero, NumberBaseHelper.Zero); - } - [Fact] - public static void RadixTest() - { - Assert.Equal(Radix, NumberBaseHelper.Radix); - } - [Fact] - public static void AbsTest() - { - NumberBaseHelper.Abs(One).Should().Be(One); - NumberBaseHelper.Abs(NegativeOne).Should().Be(One); - NumberBaseHelper.Abs(NegativeHalf).Should().Be(Half); - NumberBaseHelper.Abs(NegativeQuarter).Should().Be(Quarter); - NumberBaseHelper.Abs(NegativeZero).Should().Be(Zero); - NumberBaseHelper.Abs(Float.NegativeInfinity).Should().Be(Float.PositiveInfinity); - } - [Fact] - public static void CreateCheckedFromQuadTest() - { - NumberBaseHelper.CreateChecked(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateChecked(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateChecked(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateChecked(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateChecked(TwoOver127).Should().Be(UInt128.Parse("170141183460469231731687303715884105728")); - NumberBaseHelper.CreateChecked(TwoOver255) - .Should().Be(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")); - NumberBaseHelper.CreateChecked(TwoOver511) - .Should().Be(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")); - - NumberBaseHelper.CreateChecked(Half).Should().Be((Half)0.5f); - NumberBaseHelper.CreateChecked(Half).Should().Be(0.5f); - NumberBaseHelper.CreateChecked(Half).Should().Be(0.5d); - } - [Fact] - public static void CreateSaturatingFromQuadTest() - { - NumberBaseHelper.CreateSaturating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateSaturating(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateSaturating(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateSaturating(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateSaturating(TwoOver127).Should().Be(UInt128.Parse("170141183460469231731687303715884105728")); - NumberBaseHelper.CreateSaturating(TwoOver255) - .Should().Be(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")); - NumberBaseHelper.CreateSaturating(TwoOver511) - .Should().Be(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")); - - NumberBaseHelper.CreateSaturating(Half).Should().Be((Half)0.5f); - NumberBaseHelper.CreateSaturating(Half).Should().Be(0.5f); - NumberBaseHelper.CreateSaturating(Half).Should().Be(0.5d); - } - [Fact] - public static void CreateTruncatingFromQuadTest() - { - NumberBaseHelper.CreateTruncating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateTruncating(Int16MaxValue).Should().Be(short.MaxValue); - NumberBaseHelper.CreateTruncating(Int32MaxValue).Should().Be(int.MaxValue); - NumberBaseHelper.CreateTruncating(Int64MaxValue).Should().Be(long.MaxValue); - NumberBaseHelper.CreateTruncating(TwoOver127).Should().Be(UInt128.Parse("170141183460469231731687303715884105728")); - NumberBaseHelper.CreateTruncating(TwoOver255) - .Should().Be(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")); - NumberBaseHelper.CreateTruncating(TwoOver511) - .Should().Be(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")); - - NumberBaseHelper.CreateTruncating(Half).Should().Be((Half)0.5f); - NumberBaseHelper.CreateTruncating(Half).Should().Be(0.5f); - NumberBaseHelper.CreateTruncating(Half).Should().Be(0.5d); - } - [Fact] - public static void CreateCheckedToQuadTest() - { - NumberBaseHelper.CreateChecked(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateChecked(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateChecked(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateChecked(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateChecked(UInt128.Parse("170141183460469231731687303715884105728")) - .Should().Be(TwoOver127); - NumberBaseHelper.CreateChecked(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")) - .Should().Be(TwoOver255); - NumberBaseHelper.CreateChecked(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")) - .Should().Be(TwoOver511); - - NumberBaseHelper.CreateChecked((Half)0.5f).Should().Be(Half); - NumberBaseHelper.CreateChecked(0.5f).Should().Be(Half); - NumberBaseHelper.CreateChecked(0.5d).Should().Be(Half); - } - [Fact] - public static void CreateSaturatingToQuadTest() - { - NumberBaseHelper.CreateSaturating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateSaturating(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateSaturating(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateSaturating(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateSaturating(UInt128.Parse("170141183460469231731687303715884105728")) - .Should().Be(TwoOver127); - NumberBaseHelper.CreateSaturating(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")) - .Should().Be(TwoOver255); - NumberBaseHelper.CreateSaturating(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")) - .Should().Be(TwoOver511); - - NumberBaseHelper.CreateSaturating((Half)0.5f).Should().Be(Half); - NumberBaseHelper.CreateSaturating(0.5f).Should().Be(Half); - NumberBaseHelper.CreateSaturating(0.5d).Should().Be(Half); - } - [Fact] - public static void CreateTruncatingToQuadTest() - { - NumberBaseHelper.CreateTruncating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateTruncating(short.MaxValue).Should().Be(Int16MaxValue); - NumberBaseHelper.CreateTruncating(int.MaxValue).Should().Be(Int32MaxValue); - NumberBaseHelper.CreateTruncating(long.MaxValue).Should().Be(Int64MaxValue); - NumberBaseHelper.CreateTruncating(UInt128.Parse("170141183460469231731687303715884105728")) - .Should().Be(TwoOver127); - NumberBaseHelper.CreateTruncating(UInt256.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")) - .Should().Be(TwoOver255); - NumberBaseHelper.CreateTruncating(UInt512.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")) - .Should().Be(TwoOver511); - - NumberBaseHelper.CreateTruncating((Half)0.5f).Should().Be(Half); - NumberBaseHelper.CreateTruncating(0.5f).Should().Be(Half); - NumberBaseHelper.CreateTruncating(0.5d).Should().Be(Half); - } - [Fact] - public static void IsCanonicalTest() - { - NumberBaseHelper.IsCanonical(One).Should().BeTrue(); - } - [Fact] - public static void IsComplexNumberTest() - { - NumberBaseHelper.IsComplexNumber(One).Should().BeFalse(); - } - [Fact] - public static void IsEvenIntegerTest() - { - NumberBaseHelper.IsEvenInteger(Half).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(One).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(Two).Should().BeTrue(); - NumberBaseHelper.IsEvenInteger(Three).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(Four).Should().BeTrue(); - NumberBaseHelper.IsEvenInteger(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(NegativeTwo).Should().BeTrue(); - NumberBaseHelper.IsEvenInteger(NegativeThree).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(NegativeFour).Should().BeTrue(); - } - [Fact] - public static void IsFiniteTest() - { - NumberBaseHelper.IsFinite(One).Should().BeTrue(); - NumberBaseHelper.IsFinite(NegativeOne).Should().BeTrue(); - NumberBaseHelper.IsFinite(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsFinite(Float.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsFinite(Float.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void IsImaginaryNumberTest() - { - NumberBaseHelper.IsImaginaryNumber(One).Should().BeFalse(); - } - [Fact] - public static void IsInfinityTest() - { - NumberBaseHelper.IsInfinity(One).Should().BeFalse(); - NumberBaseHelper.IsInfinity(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsInfinity(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsInfinity(Float.PositiveInfinity).Should().BeTrue(); - NumberBaseHelper.IsInfinity(Float.NegativeInfinity).Should().BeTrue(); - } - [Fact] - public static void IsIntegerTest() - { - NumberBaseHelper.IsInteger(Quarter).Should().BeFalse(); - NumberBaseHelper.IsInteger(Half).Should().BeFalse(); - NumberBaseHelper.IsInteger(Thousand).Should().BeTrue(); - NumberBaseHelper.IsInteger(One).Should().BeTrue(); - NumberBaseHelper.IsInteger(GreaterThanOneSmallest).Should().BeFalse(); - NumberBaseHelper.IsInteger(SmallestSubnormal).Should().BeFalse(); - NumberBaseHelper.IsInteger(NegativeOne).Should().BeTrue(); - NumberBaseHelper.IsInteger(NegativeThousand).Should().BeTrue(); - NumberBaseHelper.IsInteger(NegativeHalf).Should().BeFalse(); - NumberBaseHelper.IsInteger(NegativeQuarter).Should().BeFalse(); - NumberBaseHelper.IsInteger(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsInteger(Float.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsInteger(Float.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void IsNaNTest() - { - NumberBaseHelper.IsNaN(One).Should().BeFalse(); - NumberBaseHelper.IsNaN(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsNaN(Float.NaN).Should().BeTrue(); - NumberBaseHelper.IsNaN(Float.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsNaN(Float.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void IsNegativeTest() - { - NumberBaseHelper.IsNegative(One).Should().BeFalse(); - NumberBaseHelper.IsNegative(GreatestSubnormal).Should().BeFalse(); - NumberBaseHelper.IsNegative(Float.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsNegative(Float.NaN).Should().BeTrue(); - NumberBaseHelper.IsNegative(NegativeOne).Should().BeTrue(); - NumberBaseHelper.IsNegative(Float.NegativeInfinity).Should().BeTrue(); - } - [Fact] - public static void IsNegativeInfinityTest() - { - NumberBaseHelper.IsNegativeInfinity(One).Should().BeFalse(); - NumberBaseHelper.IsNegativeInfinity(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsNegativeInfinity(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsNegativeInfinity(Float.PositiveInfinity).Should().BeFalse(); - NumberBaseHelper.IsNegativeInfinity(Float.NegativeInfinity).Should().BeTrue(); - } - [Fact] - public static void IsNormalTest() - { - NumberBaseHelper.IsNormal(GreatestSubnormal).Should().BeFalse(); - NumberBaseHelper.IsNormal(SmallestSubnormal).Should().BeFalse(); - NumberBaseHelper.IsNormal(MaxValue).Should().BeTrue(); - NumberBaseHelper.IsNormal(MinValue).Should().BeTrue(); - NumberBaseHelper.IsNormal(One).Should().BeTrue(); - } - [Fact] - public static void IsOddIntegerTest() - { - NumberBaseHelper.IsOddInteger(Half).Should().BeFalse(); - NumberBaseHelper.IsOddInteger(One).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(Two).Should().BeFalse(); - NumberBaseHelper.IsOddInteger(Three).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(Four).Should().BeFalse(); - NumberBaseHelper.IsOddInteger(NegativeOne).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(NegativeTwo).Should().BeFalse(); - NumberBaseHelper.IsOddInteger(NegativeThree).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(NegativeFour).Should().BeFalse(); - } - [Fact] - public static void IsPositiveTest() - { - NumberBaseHelper.IsPositive(One).Should().BeTrue(); - NumberBaseHelper.IsPositive(GreatestSubnormal).Should().BeTrue(); - NumberBaseHelper.IsPositive(Float.PositiveInfinity).Should().BeTrue(); - NumberBaseHelper.IsPositive(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsPositive(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsPositive(Float.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void IsPositiveInfinityTest() - { - NumberBaseHelper.IsPositiveInfinity(One).Should().BeFalse(); - NumberBaseHelper.IsPositiveInfinity(NegativeOne).Should().BeFalse(); - NumberBaseHelper.IsPositiveInfinity(Float.NaN).Should().BeFalse(); - NumberBaseHelper.IsPositiveInfinity(Float.PositiveInfinity).Should().BeTrue(); - NumberBaseHelper.IsPositiveInfinity(Float.NegativeInfinity).Should().BeFalse(); - } - [Fact] - public static void IsRealNumberTest() - { - NumberBaseHelper.IsRealNumber(GreatestSubnormal).Should().BeTrue(); - NumberBaseHelper.IsRealNumber(MaxValue).Should().BeTrue(); - NumberBaseHelper.IsRealNumber(NegativeThousand).Should().BeTrue(); - NumberBaseHelper.IsRealNumber(Float.PositiveInfinity).Should().BeTrue(); - NumberBaseHelper.IsRealNumber(Float.NegativeInfinity).Should().BeTrue(); - NumberBaseHelper.IsRealNumber(Float.NaN).Should().BeFalse(); - } - [Fact] - public static void IsSubnormalTest() - { - NumberBaseHelper.IsSubnormal(GreatestSubnormal).Should().BeTrue(); - NumberBaseHelper.IsSubnormal(SmallestSubnormal).Should().BeTrue(); - NumberBaseHelper.IsSubnormal(MaxValue).Should().BeFalse(); - NumberBaseHelper.IsSubnormal(MinValue).Should().BeFalse(); - NumberBaseHelper.IsSubnormal(One).Should().BeFalse(); - } - [Fact] - public static void IsZeroTest() - { - NumberBaseHelper.IsZero(One).Should().BeFalse(); - NumberBaseHelper.IsZero(Float.Epsilon).Should().BeFalse(); - NumberBaseHelper.IsZero(Zero).Should().BeTrue(); - NumberBaseHelper.IsZero(NegativeZero).Should().BeTrue(); - } - [Fact] - public static void MaxMagnitudeTest() - { - NumberBaseHelper.MaxMagnitude(Float.NegativeInfinity, One) - .Should().Be(Float.NegativeInfinity); - NumberBaseHelper.MaxMagnitude(Float.MinValue, One) - .Should().Be(Float.MinValue); - NumberBaseHelper.MaxMagnitude(NegativeOne, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(-GreatestSubnormal, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(-Float.Epsilon, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(NegativeZero, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(Float.NaN, One) - .Should().Be(Float.NaN); - NumberBaseHelper.MaxMagnitude(Zero, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(Float.Epsilon, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(GreatestSubnormal, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(One, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitude(Float.MaxValue, One) - .Should().Be(Float.MaxValue); - NumberBaseHelper.MaxMagnitude(Float.PositiveInfinity, One) - .Should().Be(Float.PositiveInfinity); - } - [Fact] - public static void MaxMagnitudeNumberTest() - { - NumberBaseHelper.MaxMagnitudeNumber(Float.NegativeInfinity, One) - .Should().Be(Float.NegativeInfinity); - NumberBaseHelper.MaxMagnitudeNumber(Float.MinValue, One) - .Should().Be(Float.MinValue); - NumberBaseHelper.MaxMagnitudeNumber(NegativeOne, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(-GreatestSubnormal, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(-Float.Epsilon, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(NegativeZero, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(Float.NaN, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(Zero, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(Float.Epsilon, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(GreatestSubnormal, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(One, One) - .Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(Float.MaxValue, One) - .Should().Be(Float.MaxValue); - NumberBaseHelper.MaxMagnitudeNumber(Float.PositiveInfinity, One) - .Should().Be(Float.PositiveInfinity); - } - [Fact] - public static void MinMagnitudeTest() - { - NumberBaseHelper.MinMagnitude(Float.NegativeInfinity, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitude(Float.MinValue, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitude(NegativeOne, One) - .Should().Be(NegativeOne); - NumberBaseHelper.MinMagnitude(-GreatestSubnormal, One) - .Should().Be(-GreatestSubnormal); - NumberBaseHelper.MinMagnitude(-Float.Epsilon, One) - .Should().Be(-Float.Epsilon); - NumberBaseHelper.MinMagnitude(NegativeZero, One) - .Should().Be(NegativeZero); - NumberBaseHelper.MinMagnitude(Float.NaN, One) - .Should().Be(Float.NaN); - NumberBaseHelper.MinMagnitude(Zero, One) - .Should().Be(Zero); - NumberBaseHelper.MinMagnitude(Float.Epsilon, One) - .Should().Be(Float.Epsilon); - NumberBaseHelper.MinMagnitude(GreatestSubnormal, One) - .Should().Be(GreatestSubnormal); - NumberBaseHelper.MinMagnitude(One, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitude(Float.MaxValue, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitude(Float.PositiveInfinity, One) - .Should().Be(One); - } - [Fact] - public static void MinMagnitudeNumberTest() - { - NumberBaseHelper.MinMagnitudeNumber(Float.NegativeInfinity, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(Float.MinValue, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(NegativeOne, One) - .Should().Be(NegativeOne); - NumberBaseHelper.MinMagnitudeNumber(-GreatestSubnormal, One) - .Should().Be(-GreatestSubnormal); - NumberBaseHelper.MinMagnitudeNumber(-Float.Epsilon, One) - .Should().Be(-Float.Epsilon); - NumberBaseHelper.MinMagnitudeNumber(NegativeZero, One) - .Should().Be(NegativeZero); - NumberBaseHelper.MinMagnitudeNumber(Float.NaN, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(Zero, One) - .Should().Be(Zero); - NumberBaseHelper.MinMagnitudeNumber(Float.Epsilon, One) - .Should().Be(Float.Epsilon); - NumberBaseHelper.MinMagnitudeNumber(GreatestSubnormal, One) - .Should().Be(GreatestSubnormal); - NumberBaseHelper.MinMagnitudeNumber(One, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(Float.MaxValue, One) - .Should().Be(One); - NumberBaseHelper.MinMagnitudeNumber(Float.PositiveInfinity, One) - .Should().Be(One); - } - - [Theory] - [MemberData(nameof(TryParseTheoryData))] - public void ParseTest(string s, bool success, Float output) - { - if (success) - { - NumberBaseHelper.Parse(s, NumberStyles.Float, NumberFormatInfo.CurrentInfo) - .Should().Be(output); - } - else - { - Assert.Throws(() => NumberBaseHelper.Parse(s, NumberStyles.Float, NumberFormatInfo.CurrentInfo)); - } - } - - [Theory] - [MemberData(nameof(TryParseTheoryData))] - public void TryParseTest(string s, bool success, Float output) - { - Float result; - - NumberBaseHelper.TryParse(s, NumberStyles.Float, NumberFormatInfo.CurrentInfo, out result).Should().Be(success); - result.Should().Be(output); - } - - [Theory] - [MemberData(nameof(TryParseTheoryData))] - public void ParseUtf8Test(string s, bool success, Float output) - { - byte[] utf8 = Encoding.UTF8.GetBytes(s); - - if (success) - { - NumberBaseHelper.Parse(utf8, NumberStyles.Float, NumberFormatInfo.CurrentInfo) - .Should().Be(output); - } - else - { - Assert.Throws(() => NumberBaseHelper.Parse(utf8, NumberStyles.Float, NumberFormatInfo.CurrentInfo)); - } - } - - [Theory] - [MemberData(nameof(TryParseTheoryData))] - public void TryParseUtf8Test(string s, bool success, Float output) - { - ReadOnlySpan utf8 = Encoding.UTF8.GetBytes(s); - Float result; - - NumberBaseHelper.TryParse(utf8, NumberStyles.Float, NumberFormatInfo.CurrentInfo, out result).Should().Be(success); - result.Should().Be(output); - } - #endregion - } -} diff --git a/src/MissingValues.Tests/Core/QuadTest.TheoryData.cs b/src/MissingValues.Tests/Core/QuadTest.TheoryData.cs deleted file mode 100644 index 8037eb2..0000000 --- a/src/MissingValues.Tests/Core/QuadTest.TheoryData.cs +++ /dev/null @@ -1,798 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.Contracts; -using System.Globalization; -using System.Xml; - -namespace MissingValues.Tests.Core -{ - public partial class QuadTest - { -#pragma warning disable S3263 // Static fields should appear in the order they must be initialized - private static (string, bool, Quad)[] _tryParseData => - [ - ("2,0", true, Two), - ("-2", true, NegativeTwo), - ("0", true, Zero), - (NumberFormatInfo.CurrentInfo.PositiveInfinitySymbol, true, Quad.PositiveInfinity), - (NumberFormatInfo.CurrentInfo.NegativeInfinitySymbol, true, Quad.NegativeInfinity), - (NumberFormatInfo.CurrentInfo.NaNSymbol, true, Quad.NaN), - ("256,4995", true, Values.CreateFloat(0x4007_007F_DF3B_645A, 0x1CAC_0831_26E9_78D5)), - ("471581881", true, Values.CreateFloat(0x401B_C1BC_4B90_0000, 0x0000_0000_0000_0000)), - ("1,93561113", true, Values.CreateFloat(0x3FFF_EF84_3605_1FA4, 0x8B0F_3D34_BECE_8762)), - ("9715574,2", true, Values.CreateFloat(0x4016_287E_EC66_6666, 0x6666_6666_6666_6666)), - ("0,51438427732005011792", true, Values.CreateFloat(0x3FFE_075D_6041_5519, 0x72D0_0AD3_7DB4_57E9)), - ("0,04201133209656899095", true, Values.CreateFloat(0x3FFA_5828_262D_512C, 0x8840_B3B3_D424_5947)), - ("7,7E777", true, Values.CreateFloat(0x4A17_0F28_5D1D_4C84, 0xA11F_6899_101B_A9A4)), - ("-7,7E-777", true, Values.CreateFloat(0xB5EC_BFCE_3AF6_4E08, 0x42C8_5750_BEBD_A572)), - ("1A", false, default), - ]; - - private static (Quad, Quad)[] _unaryNegationOperationData => - [ - (Zero, NegativeZero), - (One, NegativeOne), - (Two, NegativeTwo), - (Ten, NegativeTen), - (Hundred, NegativeHundred), - (Thousand, NegativeThousand) - ]; - private static (Quad, Quad)[] _incrementOperationData => - [ - (NegativeTwo, NegativeOne), - (NegativeOne, Zero), - (Zero, One), - (One, Two), - ]; - private static (Quad, Quad)[] _decrementOperationData => - [ - (NegativeOne, NegativeTwo), - (Zero, NegativeOne), - (One, Zero), - (Two, One), - ]; - - private static (Quad, Quad, Quad)[] _additionOperationData => - [ - (One, One, Two), - (One, NegativeOne, Zero), - (One, NegativeTwo, NegativeOne), - (One, Four, Five), - (Three, Two, Five), - (SmallestSubnormal, GreatestSubnormal, Values.CreateFloat(0x0001_0000_0000_0000, 0x0000_0000_0000_0000)), - (Quad.PositiveInfinity, Quad.One, Quad.PositiveInfinity), - (Quad.NegativeInfinity, Quad.One, Quad.NegativeInfinity), - (Quad.PositiveInfinity, Quad.PositiveInfinity, Quad.PositiveInfinity), - (Quad.NegativeInfinity, Quad.NegativeInfinity, Quad.NegativeInfinity), - ]; - private static (Quad, Quad, Quad)[] _subtractionOperationData => - [ - (One, One, Zero), - (One, NegativeOne, Two), - (One, Two, NegativeOne), - (SmallestSubnormal, GreatestSubnormal, Values.CreateFloat(0x8000_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)), - (Quad.PositiveInfinity, Quad.PositiveInfinity, Quad.NaN), - (Quad.NegativeInfinity, Quad.NegativeInfinity, Quad.NaN), - ]; - private static (Quad, Quad, Quad)[] _multiplicationOperationData => - [ - (One, One, One), - (One, NegativeOne, NegativeOne), - (Ten, Ten, Hundred), - (NegativeHundred, Ten, NegativeThousand), - (NegativeTen, Hundred, NegativeThousand), - (Zero, NegativeThousand, NegativeZero), - (Zero, Quad.PositiveInfinity, Quad.NaN), - (NegativeZero, Quad.NegativeInfinity, Quad.NaN), - (Quad.PositiveInfinity, Zero, Quad.NaN), - (Quad.NegativeInfinity, NegativeZero, Quad.NaN), - ]; - private static (Quad, Quad, Quad)[] _divisionOperationData => - [ - (Ten, Ten, One), - (Hundred, Ten, Ten), - (NegativeThousand, Ten, NegativeHundred), - (Zero, Zero, Quad.NaN), - (One, Zero, Quad.PositiveInfinity), - (NegativeOne, Zero, Quad.NegativeInfinity), - (Quad.PositiveInfinity, Quad.PositiveInfinity, Quad.NaN), - (Quad.NegativeInfinity, Quad.NegativeInfinity, Quad.NaN), - ]; - - private static (byte, Quad)[] _castFromByteData => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (byte.MaxValue, ByteMaxValue), - ]; - private static (ushort, Quad)[] _castFromUInt16Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - ]; - private static (uint, Quad)[] _castFromUInt32Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - (uint.MaxValue, UInt32MaxValue), - ]; - private static (ulong, Quad)[] _castFromUInt64Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - (uint.MaxValue, UInt32MaxValue), - (ulong.MaxValue, UInt64MaxValue), - ]; - private static (UInt128, Quad)[] _castFromUInt128Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - (uint.MaxValue, UInt32MaxValue), - (ulong.MaxValue, UInt64MaxValue), - ]; - private static (UInt256, Quad)[] _castFromUInt256Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - (uint.MaxValue, UInt32MaxValue), - (ulong.MaxValue, UInt64MaxValue), - ]; - private static (UInt512, Quad)[] _castFromUInt512Data => - [ - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (byte.MaxValue, ByteMaxValue), - (ushort.MaxValue, UInt16MaxValue), - (uint.MaxValue, UInt32MaxValue), - (ulong.MaxValue, UInt64MaxValue), - ]; - private static (sbyte, Quad)[] _castFromSByteData => - [ - (sbyte.MinValue, SByteMinValue), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (sbyte.MaxValue, SByteMaxValue), - ]; - private static (short, Quad)[] _castFromInt16Data => - [ - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - ]; - private static (int, Quad)[] _castFromInt32Data => - [ - (int.MinValue, Int32MinValue), - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - (int.MaxValue, Int32MaxValue), - ]; - private static (long, Quad)[] _castFromInt64Data => - [ - (long.MinValue, Int64MinValue), - (int.MinValue, Int32MinValue), - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - (int.MaxValue, Int32MaxValue), - (long.MaxValue, Int64MaxValue), - ]; - private static (Int128, Quad)[] _castFromInt128Data => - [ - (long.MinValue, Int64MinValue), - (int.MinValue, Int32MinValue), - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - (int.MaxValue, Int32MaxValue), - (long.MaxValue, Int64MaxValue), - ]; - private static (Int256, Quad)[] _castFromInt256Data => - [ - (long.MinValue, Int64MinValue), - (int.MinValue, Int32MinValue), - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - (int.MaxValue, Int32MaxValue), - (long.MaxValue, Int64MaxValue), - ]; - private static (Int512, Quad)[] _castFromInt512Data => - [ - (long.MinValue, Int64MinValue), - (int.MinValue, Int32MinValue), - (short.MinValue, Int16MinValue), - (sbyte.MinValue, SByteMinValue), - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - (sbyte.MaxValue, SByteMaxValue), - (short.MaxValue, Int16MaxValue), - (int.MaxValue, Int32MaxValue), - (long.MaxValue, Int64MaxValue), - ]; - private static (Half, Quad)[] _castFromHalfData => - [ - (System.Half.NegativeOne, NegativeOne), - (System.Half.NegativeZero, NegativeZero), - (System.Half.Zero, Zero), - (System.Half.One, One), - ((Half)10, Ten), - ((Half)100, Hundred), - ((Half)1000, Thousand), - ]; - private static (float, Quad)[] _castFromSingleData => - [ - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - ]; - private static (double, Quad)[] _castFromDoubleData => - [ - (-1000, NegativeThousand), - (-100, NegativeHundred), - (-10, NegativeTen), - (-2, NegativeTwo), - (-1, NegativeOne), - (0, Zero), - (1, One), - (2, Two), - (10, Ten), - (100, Hundred), - (1000, Thousand), - ]; - - private static (Quad, byte)[] _castToByteData => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (ByteMaxValue, byte.MaxValue), - ]; - private static (Quad, ushort)[] _castToUInt16Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - ]; - private static (Quad, uint)[] _castToUInt32Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - (UInt32MaxValue, uint.MaxValue), - ]; - private static (Quad, ulong)[] _castToUInt64Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - (UInt32MaxValue, uint.MaxValue), - (UInt64MaxValue, ulong.MaxValue), - ]; - private static (Quad, UInt128)[] _castToUInt128Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - (UInt32MaxValue, uint.MaxValue), - (UInt64MaxValue, ulong.MaxValue), - ]; - private static (Quad, UInt256)[] _castToUInt256Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - (UInt32MaxValue, uint.MaxValue), - (UInt64MaxValue, ulong.MaxValue), - ]; - private static (Quad, UInt512)[] _castToUInt512Data => - [ - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (Thousand, 1000), - (ByteMaxValue, byte.MaxValue), - (UInt16MaxValue, ushort.MaxValue), - (UInt32MaxValue, uint.MaxValue), - (UInt64MaxValue, ulong.MaxValue), - ]; - private static (Quad, sbyte)[] _castToSByteData => - [ - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - ]; - private static (Quad, short)[] _castToInt16Data => - [ - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - ]; - private static (Quad, int)[] _castToInt32Data => - [ - (Int32MinValue, int.MinValue), - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - (Int32MaxValue, int.MaxValue), - ]; - private static (Quad, long)[] _castToInt64Data => - [ - (Int64MinValue, long.MinValue), - (Int32MinValue, int.MinValue), - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - (Int32MaxValue, int.MaxValue), - (Int64MaxValue, long.MaxValue), - ]; - private static (Quad, Int128)[] _castToInt128Data => - [ - (Int64MinValue, long.MinValue), - (Int32MinValue, int.MinValue), - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - (Int32MaxValue, int.MaxValue), - (Int64MaxValue, long.MaxValue), - ]; - private static (Quad, Int256)[] _castToInt256Data => - [ - (Int64MinValue, long.MinValue), - (Int32MinValue, int.MinValue), - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - (Int32MaxValue, int.MaxValue), - (Int64MaxValue, long.MaxValue), - ]; - private static (Quad, Int512)[] _castToInt512Data => - [ - (Int64MinValue, long.MinValue), - (Int32MinValue, int.MinValue), - (Int16MinValue, short.MinValue), - (SByteMinValue, sbyte.MinValue), - (NegativeHundred, -100), - (NegativeTen, -10), - (NegativeTwo, -2), - (NegativeOne, -1), - (Half, 0), - (One, 1), - (Two, 2), - (Ten, 10), - (Hundred, 100), - (SByteMaxValue, sbyte.MaxValue), - (Int16MaxValue, short.MaxValue), - (Int32MaxValue, int.MaxValue), - (Int64MaxValue, long.MaxValue), - ]; - private static (Quad, Half)[] _castToHalfData => - [ - (NegativeHundred, -(Half)100.0f), - (NegativeTen, -(Half)10.0f), - (NegativeTwo, -(Half)2.0f), - (NegativeOne, -(Half)1.0f), - (NegativeZero, -(Half)0.0f), - (Zero, (Half)0.0f), - (One, System.Half.One), - (Two, (Half)2.0f), - (Ten, (Half)10.0f), - (Hundred, (Half)100.0f), - ]; - private static (Quad, float)[] _castToSingleData => - [ - (NegativeThousand, -1000.0f), - (NegativeHundred, -100.0f), - (NegativeTen, -10.0f), - (NegativeTwo, -2.0f), - (NegativeOne, -1.0f), - (NegativeZero, -0.0f), - (Zero, 0.0f), - (Half, 0.5f), - (One, 1.0f), - (Two, 2.0f), - (Ten, 10.0f), - (Hundred, 100.0f), - (Thousand, 1000.0f), - ]; - private static (Quad, double)[] _castToDoubleData => - [ - (NegativeThousand, -1000.0d), - (NegativeHundred, -100.0d), - (NegativeTen, -10.0d), - (NegativeTwo, -2.0d), - (NegativeOne, -1.0d), - (NegativeZero, -0.0d), - (Zero, 0.0d), - (Half, 0.5d), - (One, 1.0d), - (Two, 2.0d), - (Ten, 10.0d), - (Hundred, 100.0d), - (Thousand, 1000.0d), - ]; - private static (Quad, Octo)[] _castToOctoData => - [ - (NegativeThousand, OctoTest.NegativeThousand), - (NegativeHundred, OctoTest.NegativeHundred), - (NegativeTen, OctoTest.NegativeTen), - (NegativeTwo, OctoTest.NegativeTwo), - (NegativeOne, OctoTest.NegativeOne), - (NegativeZero, OctoTest.NegativeZero), - (Zero, OctoTest.Zero), - (Half, OctoTest.Half), - (One, OctoTest.One), - (Two, OctoTest.Two), - (Ten, OctoTest.Ten), - (Hundred, OctoTest.Hundred), - (Thousand, OctoTest.Thousand), - ]; - - private static (Quad, int, MidpointRounding, Quad)[] _roundAwayFromZeroData => - [ - (Values.CreateFloat(0x4000_C000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.AwayFromZero, Four), - (Values.CreateFloat(0x4000_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.AwayFromZero, Three), - (Values.CreateFloat(0x4000_4000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.AwayFromZero, Three), - (Values.CreateFloat(0x4000_0CCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.AwayFromZero, Two), - (Values.CreateFloat(0xC000_0CCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.AwayFromZero, NegativeTwo), - (Values.CreateFloat(0xC000_4000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.AwayFromZero, NegativeThree), - (Values.CreateFloat(0xC000_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.AwayFromZero, NegativeThree), - (Values.CreateFloat(0xC000_C000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.AwayFromZero, NegativeFour), - ]; - private static (Quad, int, MidpointRounding, Quad)[] _roundToEvenData => - [ - (Values.CreateFloat(0x4000_C000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToEven, Four), - (Values.CreateFloat(0x4000_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToEven, Three), - (Values.CreateFloat(0x4000_4000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToEven, Two), - (Values.CreateFloat(0x4000_0CCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToEven, Two), - (Values.CreateFloat(0xC000_0CCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToEven, NegativeTwo), - (Values.CreateFloat(0xC000_4000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToEven, NegativeTwo), - (Values.CreateFloat(0xC000_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToEven, NegativeThree), - (Values.CreateFloat(0xC000_C000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToEven, NegativeFour), - ]; - private static (Quad, int, MidpointRounding, Quad)[] _roundToNegativeInfinityData => - [ - (Values.CreateFloat(0x4000_C000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToNegativeInfinity, Three), - (Values.CreateFloat(0x4000_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToNegativeInfinity, Two), - (Values.CreateFloat(0x4000_4000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToNegativeInfinity, Two), - (Values.CreateFloat(0x4000_0CCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToNegativeInfinity, Two), - (Values.CreateFloat(0xC000_0CCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToNegativeInfinity, NegativeThree), - (Values.CreateFloat(0xC000_4000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToNegativeInfinity, NegativeThree), - (Values.CreateFloat(0xC000_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToNegativeInfinity, NegativeThree), - (Values.CreateFloat(0xC000_C000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToNegativeInfinity, NegativeFour), - ]; - private static (Quad, int, MidpointRounding, Quad)[] _roundToPositiveInfinityData => - [ - (Values.CreateFloat(0x4000_C000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToPositiveInfinity, Four), - (Values.CreateFloat(0x4000_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToPositiveInfinity, Three), - (Values.CreateFloat(0x4000_4000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToPositiveInfinity, Three), - (Values.CreateFloat(0x4000_0CCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToPositiveInfinity, Three), - (Values.CreateFloat(0xC000_0CCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToPositiveInfinity, NegativeTwo), - (Values.CreateFloat(0xC000_4000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToPositiveInfinity, NegativeTwo), - (Values.CreateFloat(0xC000_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToPositiveInfinity, NegativeTwo), - (Values.CreateFloat(0xC000_C000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToPositiveInfinity, NegativeThree), - ]; - private static (Quad, int, MidpointRounding, Quad)[] _roundToZeroData => - [ - (Values.CreateFloat(0x4000_C000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToZero, Three), - (Values.CreateFloat(0x4000_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToZero, Two), - (Values.CreateFloat(0x4000_4000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToZero, Two), - (Values.CreateFloat(0x4000_0CCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToZero, Two), - (Values.CreateFloat(0xC000_0CCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCD), 0, MidpointRounding.ToZero, NegativeTwo), - (Values.CreateFloat(0xC000_4000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToZero, NegativeTwo), - (Values.CreateFloat(0xC000_6666_6666_6666, 0x6666_6666_6666_6666), 0, MidpointRounding.ToZero, NegativeTwo), - (Values.CreateFloat(0xC000_C000_0000_0000, 0x0000_0000_0000_0000), 0, MidpointRounding.ToZero, NegativeThree), - ]; - - private static (Quad, Quad, bool)[] _greaterThanData => - [ - (Two, One, true), - (Thousand, NegativeThousand, true), - (NegativeQuarter, NegativeHalf, true), - (Quarter, Half, false), - (Ten, Hundred, false), - (GreaterThanOneSmallest, One, true), - ]; - private static (Quad, Quad, bool)[] _lessThanData => - [ - (Zero, One, true), - (Zero, Quarter, true), - (NegativeThousand, Thousand, true), - (NegativeOne, NegativeThree, false), - (Hundred, Two, false), - (LessThanOneLargest, One, true), - ]; - private static (Quad, Quad, bool)[] _equalToData => - [ - (One, One, true), - (Two, Two, true), - (Quad.NaN, Quad.NaN, false), - (GreatestSubnormal, GreatestSubnormal, true), - ]; - private static (Quad, Quad, bool)[] _notEqualToData => - [ - (One, One, false), - (Quad.NaN, Quad.NaN, true), - (NegativeTwo, Two, true), - (SmallestSubnormal, GreatestSubnormal, true) - ]; - - private static (Quad, Quad, Quad, Quad)[] _fmaData => - [ - (One, One, One, Two), - (Ten, Ten, Zero, Hundred), - (Five, Zero, Five, Five), - (Values.CreateFloat(0xBFFF_4000_0000_0000, 0), One, Two, Values.CreateFloat(0x3FFE_8000_0000_0000, 0)) - ]; - - - public static TryParseTheoryData TryParseTheoryData = new(_tryParseData); - - public static UnaryTheoryData UnaryNegationOperationTheoryData = new(_unaryNegationOperationData); - public static UnaryTheoryData IncrementOperationTheoryData = new(_incrementOperationData); - public static UnaryTheoryData DecrementOperationTheoryData = new(_decrementOperationData); - - public static OperationTheoryData AdditionOperationTheoryData = new(_additionOperationData); - public static OperationTheoryData SubtractionOperationTheoryData = new(_subtractionOperationData); - public static OperationTheoryData MultiplicationOperationTheoryData = new(_multiplicationOperationData); - public static OperationTheoryData DivisionOperationTheoryData = new(_divisionOperationData); - - public static CastingTheoryData CastFromByteTheoryData = new(_castFromByteData); - public static CastingTheoryData CastFromUInt16TheoryData = new(_castFromUInt16Data); - public static CastingTheoryData CastFromUInt32TheoryData = new(_castFromUInt32Data); - public static CastingTheoryData CastFromUInt64TheoryData = new(_castFromUInt64Data); - public static CastingTheoryData CastFromUInt128TheoryData = new(_castFromUInt128Data); - public static CastingTheoryData CastFromUInt256TheoryData = new(_castFromUInt256Data); - public static CastingTheoryData CastFromUInt512TheoryData = new(_castFromUInt512Data); - public static CastingTheoryData CastFromSByteTheoryData = new(_castFromSByteData); - public static CastingTheoryData CastFromInt16TheoryData = new(_castFromInt16Data); - public static CastingTheoryData CastFromInt32TheoryData = new(_castFromInt32Data); - public static CastingTheoryData CastFromInt64TheoryData = new(_castFromInt64Data); - public static CastingTheoryData CastFromInt128TheoryData = new(_castFromInt128Data); - public static CastingTheoryData CastFromInt256TheoryData = new(_castFromInt256Data); - public static CastingTheoryData CastFromInt512TheoryData = new(_castFromInt512Data); - public static CastingTheoryData CastFromHalfTheoryData = new(_castFromHalfData); - public static CastingTheoryData CastFromSingleTheoryData = new(_castFromSingleData); - public static CastingTheoryData CastFromDoubleTheoryData = new(_castFromDoubleData); - - public static CastingTheoryData CastToByteTheoryData = new(_castToByteData); - public static CastingTheoryData CastToUInt16TheoryData = new(_castToUInt16Data); - public static CastingTheoryData CastToUInt32TheoryData = new(_castToUInt32Data); - public static CastingTheoryData CastToUInt64TheoryData = new(_castToUInt64Data); - public static CastingTheoryData CastToUInt128TheoryData = new(_castToUInt128Data); - public static CastingTheoryData CastToUInt256TheoryData = new(_castToUInt256Data); - public static CastingTheoryData CastToUInt512TheoryData = new(_castToUInt512Data); - public static CastingTheoryData CastToSByteTheoryData = new(_castToSByteData); - public static CastingTheoryData CastToInt16TheoryData = new(_castToInt16Data); - public static CastingTheoryData CastToInt32TheoryData = new(_castToInt32Data); - public static CastingTheoryData CastToInt64TheoryData = new(_castToInt64Data); - public static CastingTheoryData CastToInt128TheoryData = new(_castToInt128Data); - public static CastingTheoryData CastToInt256TheoryData = new(_castToInt256Data); - public static CastingTheoryData CastToInt512TheoryData = new(_castToInt512Data); - public static CastingTheoryData CastToHalfTheoryData = new(_castToHalfData); - public static CastingTheoryData CastToSingleTheoryData = new(_castToSingleData); - public static CastingTheoryData CastToDoubleTheoryData = new(_castToDoubleData); - public static CastingTheoryData CastToOctoTheoryData = new(_castToOctoData); - - public static RoundTheoryData RoundAwayFromZeroTheoryData = new(_roundAwayFromZeroData); - public static RoundTheoryData RoundToEvenTheoryData = new(_roundToEvenData); - public static RoundTheoryData RoundToNegativeInfinityTheoryData = new(_roundToNegativeInfinityData); - public static RoundTheoryData RoundToPositiveInfinityTheoryData = new(_roundToPositiveInfinityData); - public static RoundTheoryData RoundToZeroTheoryData = new(_roundToZeroData); - - public static ComparisonOperatorsTheoryData GreaterThanTheoryData = new(_greaterThanData); - public static ComparisonOperatorsTheoryData LessThanTheoryData = new(_lessThanData); - public static ComparisonOperatorsTheoryData EqualToTheoryData = new(_equalToData); - public static ComparisonOperatorsTheoryData NotEqualToTheoryData = new(_notEqualToData); - - public static FusedMultiplyAddTheoryData FMATheoryData = new(_fmaData); -#pragma warning restore S3263 // Static fields should appear in the order they must be initialized - } -} diff --git a/src/MissingValues.Tests/Core/QuadTest.cs b/src/MissingValues.Tests/Core/QuadTest.cs deleted file mode 100644 index 8abefb7..0000000 --- a/src/MissingValues.Tests/Core/QuadTest.cs +++ /dev/null @@ -1,466 +0,0 @@ -using MissingValues.Internals; -using System; -using System.Collections.Generic; -using System.Diagnostics.Contracts; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Text.Json; -using System.Text.Unicode; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Core -{ - public partial class QuadTest - { - public static readonly Quad NegativeThousand = Values.CreateFloat(0xC008_F400_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad NegativeHundred = Values.CreateFloat(0xC005_9000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad NegativeTen = Values.CreateFloat(0xC002_4000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad NegativeSix = Values.CreateFloat(0xC001_8000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad NegativeFive = Values.CreateFloat(0xC001_4000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad NegativeFour = Values.CreateFloat(0xC001_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad NegativeThree = Values.CreateFloat(0xC000_8000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad NegativeTwo = Values.CreateFloat(0xC000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad NegativeOne = Quad.NegativeOne; - public static readonly Quad NegativeHalf = Values.CreateFloat(0xBFFE_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad NegativeQuarter = Values.CreateFloat(0xBFFD_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad NegativeZero = Quad.NegativeZero; - public static readonly Quad Zero = Quad.Zero; - public static readonly Quad Quarter = Values.CreateFloat(0x3FFD_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Half = Values.CreateFloat(0x3FFE_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad One = Quad.One; - public static readonly Quad Two = Values.CreateFloat(0x4000_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Three = Values.CreateFloat(0x4000_8000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Four = Values.CreateFloat(0x4001_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Five = Values.CreateFloat(0x4001_4000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Six = Values.CreateFloat(0x4001_8000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Ten = Values.CreateFloat(0x4002_4000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Hundred = Values.CreateFloat(0x4005_9000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Thousand = Values.CreateFloat(0x4008_F400_0000_0000, 0x0000_0000_0000_0000); - - public static readonly Quad GreaterThanOneSmallest = Values.CreateFloat(0x3FFF_0000_0000_0000, 0x0000_0000_0000_0001); - public static readonly Quad LessThanOneLargest = Values.CreateFloat(0x3FFE_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF); - - public static readonly Quad SmallestSubnormal = Values.CreateFloat(0x0000_0000_0000_0000, 0x0000_0000_0000_0001); - public static readonly Quad GreatestSubnormal = Values.CreateFloat(0x0000_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF); - - public static readonly Quad MaxValue = Quad.MaxValue; - public static readonly Quad MinValue = Quad.MinValue; - - public static readonly Quad ByteMaxValue = Values.CreateFloat(0x4006_FE00_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad UInt16MaxValue = Values.CreateFloat(0x400E_FFFE_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad UInt32MaxValue = Values.CreateFloat(0x401E_FFFF_FFFE_0000, 0x0000_0000_0000_0000); - public static readonly Quad UInt64MaxValue = Values.CreateFloat(0x403E_FFFF_FFFF_FFFF, 0xFFFE_0000_0000_0000); - public static readonly Quad TwoOver127 = Values.CreateFloat(0x407E_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad TwoOver255 = Values.CreateFloat(0x40FE_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad TwoOver511 = Values.CreateFloat(0x41FE_0000_0000_0000, 0x0000_0000_0000_0000); - - public static readonly Quad SByteMaxValue = Values.CreateFloat(0x4005_FC00_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad SByteMinValue = Values.CreateFloat(0xC006_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Int16MaxValue = Values.CreateFloat(0x400D_FFFC_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Int16MinValue = Values.CreateFloat(0xC00E_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Int32MaxValue = Values.CreateFloat(0x401D_FFFF_FFFC_0000, 0x0000_0000_0000_0000); - public static readonly Quad Int32MinValue = Values.CreateFloat(0xC01E_0000_0000_0000, 0x0000_0000_0000_0000); - public static readonly Quad Int64MaxValue = Values.CreateFloat(0x403D_FFFF_FFFF_FFFF, 0xFFFC_0000_0000_0000); - public static readonly Quad Int64MinValue = Values.CreateFloat(0xC03E_0000_0000_0000, 0x0000_0000_0000_0000); - - public static readonly Quad Delta = Values.CreateFloat(0x406F_0000_0000_0000, 0x0000_0000_0000_0000); - - public static readonly int Radix = 2; - - - [Fact] - public void Ctor_Empty() - { - var i = new Quad(); - Assert.Equal(Zero, i); - } - - [Theory] - [MemberData(nameof(CastFromByteTheoryData))] - public void Cast_FromByte(byte from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt16TheoryData))] - public void Cast_FromUInt16(ushort from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt32TheoryData))] - public void Cast_FromUInt32(uint from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt64TheoryData))] - public void Cast_FromUInt64(ulong from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt128TheoryData))] - public void Cast_FromUInt128(UInt128 from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt256TheoryData))] - public void Cast_FromUInt256(UInt256 from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromUInt512TheoryData))] - public void Cast_FromUInt512(UInt512 from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromSByteTheoryData))] - public void Cast_FromSByte(sbyte from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt16TheoryData))] - public void Cast_FromInt16(short from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt32TheoryData))] - public void Cast_FromInt32(int from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt64TheoryData))] - public void Cast_FromInt64(long from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt128TheoryData))] - public void Cast_FromInt128(Int128 from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt256TheoryData))] - public void Cast_FromInt256(Int256 from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromInt512TheoryData))] - public void Cast_FromInt512(Int512 from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Fact] - public void Cast_FromBigInteger() - { - TwoOver127.Should() - .Be((Quad)BigInteger.Parse("170141183460469231731687303715884105728")); - TwoOver255.Should() - .Be((Quad)BigInteger.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968")); - TwoOver511 - .Should() - .Be((Quad)BigInteger.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048")); - } - [Theory] - [MemberData(nameof(CastFromHalfTheoryData))] - public void Cast_FromHalf(Half from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromSingleTheoryData))] - public void Cast_FromSingle(float from, Quad to) - { - ((Quad)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastFromDoubleTheoryData))] - public void Cast_FromDouble(double from, Quad to) - { - ((Quad)from).Should().Be(to); - } - - [Theory] - [MemberData(nameof(CastToByteTheoryData))] - public void Cast_ToByte(Quad from, byte to) - { - ((byte)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt16TheoryData))] - public void Cast_ToUInt16(Quad from, ushort to) - { - ((ushort)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt32TheoryData))] - public void Cast_ToUInt32(Quad from, uint to) - { - ((uint)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt64TheoryData))] - public void Cast_ToUInt64(Quad from, ulong to) - { - ((ulong)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt128TheoryData))] - public void Cast_ToUInt128(Quad from, UInt128 to) - { - ((UInt128)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt256TheoryData))] - public void Cast_ToUInt256(Quad from, UInt256 to) - { - ((UInt256)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToUInt512TheoryData))] - public void Cast_ToUInt512(Quad from, UInt512 to) - { - ((UInt512)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToSByteTheoryData))] - public void Cast_ToSByte(Quad from, sbyte to) - { - ((sbyte)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt16TheoryData))] - public void Cast_ToInt16(Quad from, short to) - { - ((short)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt32TheoryData))] - public void Cast_ToInt32(Quad from, int to) - { - ((int)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt64TheoryData))] - public void Cast_ToInt64(Quad from, long to) - { - ((long)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt128TheoryData))] - public void Cast_ToInt128(Quad from, Int128 to) - { - ((Int128)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt256TheoryData))] - public void Cast_ToInt256(Quad from, Int256 to) - { - ((Int256)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToInt512TheoryData))] - public void Cast_ToInt512(Quad from, Int512 to) - { - ((Int512)from).Should().Be(to); - } - [Fact] - public void Cast_ToBigInteger() - { - BigInteger.Parse("170141183460469231731687303715884105728") - .Should().Be((BigInteger)TwoOver127); - BigInteger.Parse("57896044618658097711785492504343953926634992332820282019728792003956564819968") - .Should().Be((BigInteger)TwoOver255); - BigInteger.Parse("6703903964971298549787012499102923063739682910296196688861780721860882015036773488400937149083451713845015929093243025426876941405973284973216824503042048") - .Should().Be((BigInteger)TwoOver511); - } - [Theory] - [MemberData(nameof(CastToHalfTheoryData))] - public void Cast_ToHalf(Quad from, Half to) - { - ((Half)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToSingleTheoryData))] - public void Cast_ToSingle(Quad from, float to) - { - ((float)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToDoubleTheoryData))] - public void Cast_ToDouble(Quad from, double to) - { - ((double)from).Should().Be(to); - } - [Theory] - [MemberData(nameof(CastToOctoTheoryData))] - public void Cast_ToOcto(Quad from, Octo to) - { - ((Octo)from).Should().Be(to); - } - - [Fact] - public void ToGeneralStringTest() - { - NegativeQuarter.ToString("G33", CultureInfo.InvariantCulture) - .Should().Be("-0.25"); - Half.ToString("G33", CultureInfo.InvariantCulture) - .Should().Be("0.5"); - NegativeHalf.ToString("G33", CultureInfo.InvariantCulture) - .Should().Be("-0.5"); - One.ToString("G33", CultureInfo.InvariantCulture) - .Should().Be("1"); - Thousand.ToString("G33", CultureInfo.InvariantCulture) - .Should().Be("1000"); - NegativeThousand.ToString("G33", CultureInfo.InvariantCulture) - .Should().Be("-1000"); - } - - [Fact] - public void ToScientificStringTest() - { - NegativeQuarter.ToString("E33", CultureInfo.InvariantCulture) - .Should().Be("-2.5E-1"); - Half.ToString("E33", CultureInfo.InvariantCulture) - .Should().Be("5E-1"); - NegativeHalf.ToString("E33", CultureInfo.InvariantCulture) - .Should().Be("-5E-1"); - One.ToString("E33", CultureInfo.InvariantCulture) - .Should().Be("1E+0"); - Thousand.ToString("E33", CultureInfo.InvariantCulture) - .Should().Be("1E+3"); - NegativeThousand.ToString("E33", CultureInfo.InvariantCulture) - .Should().Be("-1E+3"); - } - - [Fact] - public void ToGeneralFormatStringTest() - { - $"{NegativeQuarter:G33}" - .Should().Be("-0,25"); - $"{Half:G33}" - .Should().Be("0,5"); - $"{NegativeHalf:G33}" - .Should().Be("-0,5"); - $"{One:G33}" - .Should().Be("1"); - $"{Thousand:G33}" - .Should().Be("1000"); - $"{NegativeThousand:G33}" - .Should().Be("-1000"); - } - - [Fact] - public void ToScientificFormatStringTest() - { - $"{NegativeQuarter:E33}" - .Should().Be("-2,5E-1"); - $"{Half:E33}" - .Should().Be("5E-1"); - $"{NegativeHalf:E33}" - .Should().Be("-5E-1"); - $"{One:E33}" - .Should().Be("1E+0"); - $"{Thousand:E33}" - .Should().Be("1E+3"); - $"{NegativeThousand:E33}" - .Should().Be("-1E+3"); - } - - [Fact] - public void ToGeneralFormatUtf8StringTest() - { - int bytesWritten; - Span utf8 = stackalloc byte[10]; - - Utf8.TryWrite(utf8, $"{NegativeQuarter:G33}", out bytesWritten); - Assert.Equal("-0,25"u8, utf8[..bytesWritten]); - utf8.Clear(); - - Utf8.TryWrite(utf8, $"{Half:G33}", out bytesWritten); - Assert.Equal("0,5"u8, utf8[..bytesWritten]); - utf8.Clear(); - - Utf8.TryWrite(utf8, $"{NegativeHalf:G33}", out bytesWritten); - Assert.Equal("-0,5"u8, utf8[..bytesWritten]); - utf8.Clear(); - - Utf8.TryWrite(utf8, $"{One:G33}", out bytesWritten); - Assert.Equal("1"u8, utf8[..bytesWritten]); - utf8.Clear(); - - Utf8.TryWrite(utf8, $"{Thousand:G33}", out bytesWritten); - Assert.Equal("1000"u8, utf8[..bytesWritten]); - utf8.Clear(); - - Utf8.TryWrite(utf8, $"{NegativeThousand:G33}", out bytesWritten); - Assert.Equal("-1000"u8, utf8[..bytesWritten]); - } - - [Fact] - public void ToScientificFormatUtf8StringTest() - { - int bytesWritten; - Span utf8 = stackalloc byte[10]; - - Utf8.TryWrite(utf8, $"{NegativeQuarter:E33}", out bytesWritten); - Assert.Equal("-2,5E-1"u8, utf8[..bytesWritten]); - utf8.Clear(); - - Utf8.TryWrite(utf8, $"{Half:E33}", out bytesWritten); - Assert.Equal("5E-1"u8, utf8[..bytesWritten]); - utf8.Clear(); - - Utf8.TryWrite(utf8, $"{NegativeHalf:E33}", out bytesWritten); - Assert.Equal("-5E-1"u8, utf8[..bytesWritten]); - utf8.Clear(); - - Utf8.TryWrite(utf8, $"{One:E33}", out bytesWritten); - Assert.Equal("1E+0"u8, utf8[..bytesWritten]); - utf8.Clear(); - - Utf8.TryWrite(utf8, $"{Thousand:E33}", out bytesWritten); - Assert.Equal("1E+3"u8, utf8[..bytesWritten]); - utf8.Clear(); - - Utf8.TryWrite(utf8, $"{NegativeThousand:E33}", out bytesWritten); - Assert.Equal("-1E+3"u8, utf8[..bytesWritten]); - } - - [Theory] - [MemberData(nameof(TryParseTheoryData))] - public void BasicTryParseTest(string s, bool success, Quad expected) - { - Quad.TryParse(s, out Quad actual).Should().Be(success); - actual.Should().Be(expected); - } - - [Fact] - public void JsonWriteTest() - { - JsonSerializer.Serialize(new Quad[] { MaxValue, One, Half, Quarter, Zero }) - .Should().Be($"[{MaxValue.ToString(null, CultureInfo.InvariantCulture)},1,0.5,0.25,0]"); - } - [Fact] - public void JsonReadTest() - { - string toString = Quarter.ToString(null, CultureInfo.InvariantCulture); - - JsonSerializer.Deserialize(toString) - .Should().Be(Quarter); - JsonSerializer.Deserialize(Encoding.UTF8.GetBytes(toString)) - .Should().Be(Quarter); - } - } -} diff --git a/src/MissingValues.Tests/Core/UInt256Test.GenericMath.cs b/src/MissingValues.Tests/Core/UInt256Test.GenericMath.cs deleted file mode 100644 index 3a88fc2..0000000 --- a/src/MissingValues.Tests/Core/UInt256Test.GenericMath.cs +++ /dev/null @@ -1,1180 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -using UInt = MissingValues.UInt256; - -namespace MissingValues.Tests.Core -{ - public partial class UInt256Test - { - #region Readonly Variables - private const string MaxValueBin = - "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111"; - private ReadOnlySpan MaxValueBinUtf8 => - "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8; - private const double MaxValueAsDouble = 115792089237316195423570985008687907853269984665640564039457584007913129639935.0; - - private static readonly UInt ByteMaxValue = new(0, new(0x0000_0000_0000_0000, 0x0000_0000_0000_00FF)); - private static readonly UInt UInt16MaxValue = new(0, new(0x0000_0000_0000_0000, 0x0000_0000_0000_FFFF)); - private static readonly UInt UInt32MaxValue = new(0, new(0x0000_0000_0000_0000, 0x0000_0000_FFFF_FFFF)); - private static readonly UInt UInt64MaxValue = new(0, new(0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF)); - private static readonly UInt UInt128MaxValue = new(0, new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - - private static readonly UInt Zero = new(new (0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new (0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - private static readonly UInt One = new(new (0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new (0x0000_0000_0000_0000, 0x0000_0000_0000_0001)); - private static readonly UInt Two = new(new (0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new (0x0000_0000_0000_0000, 0x0000_0000_0000_0002)); - - private static readonly UInt MaxValue = new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - private static readonly UInt MaxValueMinusOne = new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)); - private static readonly UInt MaxValueMinusTwo = new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFD)); - - private static readonly UInt E40 = new(0x0000_0000_0000_0000, 0x0000_0000_0000_001D, 0x6329_F1C3_5CA4_BFAB, 0xB9F5_6100_0000_0000); - #endregion - - #region Generic Math Operators - [Fact] - public static void op_AdditionTest() - { - Assert.Equal(One, MathOperatorsHelper.AdditionOperation(Zero, One)); - Assert.Equal(Two, MathOperatorsHelper.AdditionOperation(One, One)); - Assert.Equal(Zero, MathOperatorsHelper.AdditionOperation(MaxValue, One)); - } - [Fact] - public static void op_CheckedAdditionTest() - { - Assert.Equal(One, MathOperatorsHelper.CheckedAdditionOperation(Zero, One)); - Assert.Equal(Two, MathOperatorsHelper.CheckedAdditionOperation(One, One)); - - Assert.Throws(() => MathOperatorsHelper.CheckedAdditionOperation(MaxValue, 1)); - } - [Fact] - public static void op_IncrementTest() - { - MathOperatorsHelper.IncrementOperation(Zero).Should().Be(One); - MathOperatorsHelper.IncrementOperation(One).Should().Be(Two); - MathOperatorsHelper.IncrementOperation(MaxValueMinusTwo).Should().Be(MaxValueMinusOne); - MathOperatorsHelper.IncrementOperation(MaxValueMinusOne).Should().Be(MaxValue); - MathOperatorsHelper.IncrementOperation(MaxValue).Should().Be(Zero); - } - [Fact] - public static void op_CheckedIncrementTest() - { - MathOperatorsHelper.CheckedIncrementOperation(Zero).Should().Be(One); - MathOperatorsHelper.CheckedIncrementOperation(One).Should().Be(Two); - MathOperatorsHelper.CheckedIncrementOperation(MaxValueMinusTwo).Should().Be(MaxValueMinusOne); - MathOperatorsHelper.CheckedIncrementOperation(MaxValueMinusOne).Should().Be(MaxValue); - - Assert.Throws(() => MathOperatorsHelper.CheckedIncrementOperation(MaxValue)); - } - [Fact] - public static void op_SubtractionTest() - { - Assert.Equal(One, MathOperatorsHelper.SubtractionOperation(Two, One)); - Assert.Equal(MaxValueMinusOne, MathOperatorsHelper.SubtractionOperation(MaxValue, 1)); - } - [Fact] - public static void op_CheckedSubtractionTest() - { - Assert.Equal(One, MathOperatorsHelper.CheckedSubtractionOperation(Two, One)); - Assert.Equal(MaxValueMinusOne, MathOperatorsHelper.CheckedSubtractionOperation(MaxValue, 1)); - - Assert.Throws(() => MathOperatorsHelper.CheckedSubtractionOperation(Zero, 1)); - } - [Fact] - public static void op_DecrementTest() - { - MathOperatorsHelper.DecrementOperation(Two).Should().Be(One); - MathOperatorsHelper.DecrementOperation(One).Should().Be(Zero); - MathOperatorsHelper.DecrementOperation(MaxValueMinusOne).Should().Be(MaxValueMinusTwo); - MathOperatorsHelper.DecrementOperation(MaxValue).Should().Be(MaxValueMinusOne); - MathOperatorsHelper.DecrementOperation(Zero).Should().Be(MaxValue); - } - [Fact] - public static void op_CheckedDecrementTest() - { - MathOperatorsHelper.CheckedDecrementOperation(Two).Should().Be(One); - MathOperatorsHelper.CheckedDecrementOperation(One).Should().Be(Zero); - MathOperatorsHelper.CheckedDecrementOperation(MaxValueMinusOne).Should().Be(MaxValueMinusTwo); - MathOperatorsHelper.CheckedDecrementOperation(MaxValue).Should().Be(MaxValueMinusOne); - - Assert.Throws(() => MathOperatorsHelper.CheckedDecrementOperation(Zero)); - } - [Fact] - public static void op_MultiplyTest() - { - Assert.Equal(One, MathOperatorsHelper.MultiplicationOperation(One, One)); - Assert.Equal(Two, MathOperatorsHelper.MultiplicationOperation(Two, One)); - } - [Fact] - public static void op_CheckedMultiplyTest() - { - Assert.Equal(One, MathOperatorsHelper.CheckedMultiplicationOperation(One, One)); - Assert.Equal(Two, MathOperatorsHelper.CheckedMultiplicationOperation(Two, One)); - - Assert.Throws(() => MathOperatorsHelper.CheckedMultiplicationOperation(MaxValue, Two)); - } - [Fact] - public static void op_DivisionTest() - { - Assert.Equal(new UInt(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), MathOperatorsHelper.DivisionOperation(MaxValue, Two)); - Assert.Equal(new UInt(0, 0, 0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), MathOperatorsHelper.DivisionOperation(UInt128.MaxValue, Two)); - Assert.Equal(new UInt(0x0000_0000_0000_0001, 0xD83C_94FB_6D2A_C34A, 0x5663_D3C7_A0D8_65CA, 0x3C4C_A40E_0EA7_CFE9), MathOperatorsHelper.DivisionOperation(MaxValue, 0x8AC7_2304_89E8_0000)); - - Assert.Equal(new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0003, 0x671F_73B5_4F1C_8956, 0x5B9E_F4D6_3241_2884), MathOperatorsHelper.DivisionOperation(MaxValue, new UInt128(0x4B3B_4CA8_5A86_C47A, 0x098A_2240_0000_0000))); - Assert.Equal(One, MathOperatorsHelper.DivisionOperation(MaxValue, MaxValue)); - Assert.Equal(new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x08B6_1313_BBAB_CE2C, 0x6232_3AC4_B3B3_DA01), MathOperatorsHelper.DivisionOperation(MaxValue, E40)); - - Assert.Throws(() => MathOperatorsHelper.DivisionOperation(One, Zero)); - } - [Fact] - public static void op_CheckedDivisionTest() - { - Assert.Equal(new UInt(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), MathOperatorsHelper.CheckedDivisionOperation(MaxValue, Two)); - Assert.Equal(new UInt(0x0000_0000_0000_0001, 0xD83C_94FB_6D2A_C34A, 0x5663_D3C7_A0D8_65CA, 0x3C4C_A40E_0EA7_CFE9), MathOperatorsHelper.CheckedDivisionOperation(MaxValue, 0x8AC7_2304_89E8_0000)); - Assert.Equal(new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0003, 0x671F_73B5_4F1C_8956, 0x5B9E_F4D6_3241_2884), MathOperatorsHelper.CheckedDivisionOperation(MaxValue, new UInt128(0x4B3B_4CA8_5A86_C47A, 0x098A_2240_0000_0000))); - Assert.Equal(One, MathOperatorsHelper.CheckedDivisionOperation(MaxValue, MaxValue)); - Assert.Equal(new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x08B6_1313_BBAB_CE2C, 0x6232_3AC4_B3B3_DA01), MathOperatorsHelper.CheckedDivisionOperation(MaxValue, E40)); - - Assert.Throws(() => MathOperatorsHelper.CheckedDivisionOperation(One, Zero)); - } - [Fact] - public static void op_ModulusTest() - { - MathOperatorsHelper.ModulusOperation(Two, Two).Should().Be(Zero); - MathOperatorsHelper.ModulusOperation(One, Two).Should().NotBe(Zero); - MathOperatorsHelper.ModulusOperation(MaxValue, new(10U)).Should().Be(5U); - MathOperatorsHelper.ModulusOperation(MaxValue, new(10_000_000_000_000_000_000U)).Should().Be(7584007913129639935U); - MathOperatorsHelper.ModulusOperation(MaxValue, E40) - .Should().Be(new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0009, 0x9C10_2376_5631_2693, 0x7E70_9EFF_FFFF_FFFF)); - - Assert.Throws(() => MathOperatorsHelper.ModulusOperation(One, Zero)); - } - - [Fact] - public static void op_BitwiseAndTest() - { - BitwiseOperatorsHelper.BitwiseAndOperation(Zero, 1U).Should().Be(Zero); - BitwiseOperatorsHelper.BitwiseAndOperation(One, 1U).Should().Be(One); - BitwiseOperatorsHelper.BitwiseAndOperation(MaxValue, 1U).Should().Be(One); - } - [Fact] - public static void op_BitwiseOrTest() - { - BitwiseOperatorsHelper.BitwiseOrOperation(Zero, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.BitwiseOrOperation(One, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.BitwiseOrOperation(MaxValue, 1U) - .Should().Be(MaxValue); - } - [Fact] - public static void op_ExclusiveOrTest() - { - BitwiseOperatorsHelper.ExclusiveOrOperation(Zero, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.ExclusiveOrOperation(One, 1U) - .Should().Be(Zero); - BitwiseOperatorsHelper.ExclusiveOrOperation(MaxValue, 1U) - .Should().Be(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE))); - } - [Fact] - public static void op_OnesComplementTest() - { - BitwiseOperatorsHelper.OnesComplementOperation(Zero) - .Should().Be(MaxValue); - BitwiseOperatorsHelper.OnesComplementOperation(One) - .Should().Be(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE))); - BitwiseOperatorsHelper.OnesComplementOperation(MaxValue) - .Should().Be(Zero); - } - - [Fact] - public static void op_LeftShiftTest() - { - ShiftOperatorsHelper.LeftShiftOperation(Zero, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.LeftShiftOperation(One, 1) - .Should().Be(Two); - ShiftOperatorsHelper.LeftShiftOperation(MaxValue, 1) - .Should().Be(MaxValueMinusOne); - - UInt actual = new(0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F); - - ShiftOperatorsHelper.LeftShiftOperation(actual, 0) - .Should().Be(actual); - ShiftOperatorsHelper.LeftShiftOperation(actual, 64) - .Should().Be(new(0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, 0)); - ShiftOperatorsHelper.LeftShiftOperation(actual, 128) - .Should().Be(new(0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, 0, 0)); - ShiftOperatorsHelper.LeftShiftOperation(actual, 192) - .Should().Be(new(0xF5C2_8F5C_28F5_C28F, 0, 0, 0)); - } - [Fact] - public static void op_RightShiftTest() - { - ShiftOperatorsHelper.RightShiftOperation(Zero, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.RightShiftOperation(One, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.RightShiftOperation(MaxValue, 1) - .Should().Be(new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF))); - - UInt actual = new(0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F); - - ShiftOperatorsHelper.RightShiftOperation(actual, 0) - .Should().Be(actual); - ShiftOperatorsHelper.RightShiftOperation(actual, 64) - .Should().Be(new(0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28)); - ShiftOperatorsHelper.RightShiftOperation(actual, 128) - .Should().Be(new(0, 0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2)); - ShiftOperatorsHelper.RightShiftOperation(actual, 192) - .Should().Be(new(0, 0, 0, 0x028F_5C28_F5C2_8F5C)); - } - [Fact] - public static void op_UnsignedRightShiftTest() - { - ShiftOperatorsHelper.UnsignedRightShiftOperation(Zero, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.UnsignedRightShiftOperation(One, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.UnsignedRightShiftOperation(MaxValue, 1) - .Should().Be(new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF))); - - UInt actual = new(0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F); - - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 0) - .Should().Be(actual); - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 64) - .Should().Be(new(0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28)); - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 128) - .Should().Be(new(0, 0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2)); - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 192) - .Should().Be(new(0, 0, 0, 0x028F_5C28_F5C2_8F5C)); - } - - [Fact] - public static void op_EqualityTest() - { - EqualityOperatorsHelper.EqualityOperation(Zero, 1U).Should().BeFalse(); - EqualityOperatorsHelper.EqualityOperation(One, 1U).Should().BeTrue(); - EqualityOperatorsHelper.EqualityOperation(MaxValue, 1U).Should().BeFalse(); - } - [Fact] - public static void op_InequalityTest() - { - EqualityOperatorsHelper.InequalityOperation(Zero, 1U).Should().BeTrue(); - EqualityOperatorsHelper.InequalityOperation(One, 1U).Should().BeFalse(); - EqualityOperatorsHelper.InequalityOperation(MaxValue, 1U).Should().BeTrue(); - } - - [Fact] - public static void op_GreaterThanTest() - { - ComparisonOperatorsHelper.GreaterThanOperation(Zero, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOperation(One, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOperation(MaxValue, 1U).Should().BeTrue(); - } - [Fact] - public static void op_GreaterThanOrEqualTest() - { - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(Zero, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(One, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(MaxValue, 1U).Should().BeTrue(); - } - [Fact] - public static void op_LessThanTest() - { - ComparisonOperatorsHelper.LessThanOperation(Zero, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOperation(One, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.LessThanOperation(MaxValue, 1U).Should().BeFalse(); - } - [Fact] - public static void op_LessThanOrEqualTest() - { - ComparisonOperatorsHelper.LessThanOrEqualOperation(Zero, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(One, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(MaxValue, 1U).Should().BeFalse(); - } - #endregion - - #region Identities - [Fact] - public static void AdditiveIdentityTest() - { - Assert.Equal(Zero, MathConstantsHelper.AdditiveIdentityHelper()); - } - - [Fact] - public static void MultiplicativeIdentityTest() - { - Assert.Equal(One, MathConstantsHelper.MultiplicativeIdentityHelper()); - } - #endregion - - #region IBinaryInteger - [Fact] - public static void DivRemTest() - { - Assert.Equal((Zero, Zero), BinaryIntegerHelper.DivRem(Zero, Two)); - Assert.Equal((Zero, One), BinaryIntegerHelper.DivRem(One, Two)); - Assert.Equal( - (new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x08B6_1313_BBAB_CE2C, 0x6232_3AC4_B3B3_DA01), - new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0009, 0x9C10_2376_5631_2693, 0x7E70_9EFF_FFFF_FFFF)), - BinaryIntegerHelper.DivRem(MaxValue, E40)); - Assert.Equal((new UInt(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), One), BinaryIntegerHelper.DivRem(MaxValue, 2)); - } - - [Fact] - public static void LeadingZeroCountTest() - { - Assert.Equal(256U, BinaryIntegerHelper.LeadingZeroCount(Zero)); - Assert.Equal(255U, BinaryIntegerHelper.LeadingZeroCount(One)); - Assert.Equal(192U, BinaryIntegerHelper.LeadingZeroCount(ulong.MaxValue)); - Assert.Equal(128U, BinaryIntegerHelper.LeadingZeroCount(UInt128.MaxValue)); - Assert.Equal(64U, BinaryIntegerHelper.LeadingZeroCount(MaxValue >>> 64)); - Assert.Equal(0U, BinaryIntegerHelper.LeadingZeroCount(MaxValue)); - } - - [Fact] - public static void PopCountTest() - { - Assert.Equal(0U, BinaryIntegerHelper.PopCount(Zero)); - Assert.Equal(1U, BinaryIntegerHelper.PopCount(One)); - Assert.Equal(256U, BinaryIntegerHelper.PopCount(MaxValue)); - } - - [Fact] - public static void RotateLeftTest() - { - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), BinaryIntegerHelper.RotateLeft(Zero, 1)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0002)), BinaryIntegerHelper.RotateLeft(One, 1)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), BinaryIntegerHelper.RotateLeft(MaxValue, 1)); - } - - [Fact] - public static void RotateRightTest() - { - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), BinaryIntegerHelper.RotateRight(Zero, 1)); - Assert.Equal(new(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), BinaryIntegerHelper.RotateRight(One, 1)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), BinaryIntegerHelper.RotateRight(MaxValue, 1)); - } - - [Fact] - public static void TrailingZeroCountTest() - { - Assert.Equal(256U, BinaryIntegerHelper.TrailingZeroCount(Zero)); - Assert.Equal(0U, BinaryIntegerHelper.TrailingZeroCount(One)); - Assert.Equal(1U, BinaryIntegerHelper.TrailingZeroCount(Two)); - Assert.Equal(64U, BinaryIntegerHelper.TrailingZeroCount(new UInt(0,0,1,0))); - Assert.Equal(128U, BinaryIntegerHelper.TrailingZeroCount(new UInt(0,1,0,0))); - Assert.Equal(192U, BinaryIntegerHelper.TrailingZeroCount(new UInt(1,0,0,0))); - Assert.Equal(0U, BinaryIntegerHelper.TrailingZeroCount(MaxValue)); - } - - [Fact] - public static void TryReadBigEndianInt128Test() - { - UInt result; - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: false, out result)); - Assert.Equal(new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0001), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: false, out result)); - Assert.Equal(new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0080), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new UInt128(0x0100_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new UInt128(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), result); - - Assert.False(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.False(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: false, out result)); - Assert.Equal(new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.False(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - } - - [Fact] - public static void TryReadBigEndianUInt128Test() - { - UInt result; - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F)), result); - - Assert.True(BinaryIntegerHelper.TryReadBigEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - } - - [Fact] - public static void TryReadLittleEndianInt128Test() - { - UInt result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - } - - [Fact] - public static void TryReadLittleEndianInt192Test() - { - UInt result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0100_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x7FFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - } - - [Fact] - public static void TryReadLittleEndianInt256Test() - { - UInt result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - } - - [Fact] - public static void TryReadLittleEndianUInt128Test() - { - UInt result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(0, new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - } - - [Fact] - public static void TryReadLittleEndianUInt192Test() - { - UInt result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0100_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x8000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0, new UInt128(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x7FFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - } - - [Fact] - public static void TryReadLittleEndianUInt256Test() - { - UInt result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0001)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new(0x0000_0000_0000_0000, 0x0000_0000_0000_0080)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: true, out result)); - Assert.Equal(new(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)), result); - } - - [Fact] - public static void GetByteCountTest() - { - Assert.Equal(32, BinaryIntegerHelper.GetByteCount(Zero)); - Assert.Equal(32, BinaryIntegerHelper.GetByteCount(One)); - Assert.Equal(32, BinaryIntegerHelper.GetByteCount(MaxValue)); - } - - [Fact] - public static void GetShortestBitLengthTest() - { - Assert.Equal(0x00, BinaryIntegerHelper.GetShortestBitLength(Zero)); - Assert.Equal(0x01, BinaryIntegerHelper.GetShortestBitLength(One)); - Assert.Equal(0x100, BinaryIntegerHelper.GetShortestBitLength(MaxValue)); - } - - [Fact] - public static void TryWriteBigEndianTest() - { - Span destination = stackalloc byte[32]; - int bytesWritten = 0; - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(Zero, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(One, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(MaxValue, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - - Assert.False(BinaryIntegerHelper.TryWriteBigEndian(default, Span.Empty, out bytesWritten)); - Assert.Equal(0, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - } - - [Fact] - public static void TryWriteLittleEndianTest() - { - Span destination = stackalloc byte[32]; - int bytesWritten = 0; - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(Zero, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(One, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(MaxValue, destination, out bytesWritten)); - Assert.Equal(32, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - - Assert.False(BinaryIntegerHelper.TryWriteLittleEndian(default, Span.Empty, out bytesWritten)); - Assert.Equal(0, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - } - #endregion - - #region IBinaryNumber - [Fact] - public static void AllBitsSetTest() - { - Assert.Equal(BinaryNumberHelper.AllBitsSet, ~Zero); - } - [Fact] - public static void IsPow2Test() - { - Assert.True(BinaryNumberHelper.IsPow2(new(0x100))); - Assert.True(BinaryNumberHelper.IsPow2(new(0x1_0000))); - Assert.True(BinaryNumberHelper.IsPow2(new(0x1_0000_0000))); - Assert.True(BinaryNumberHelper.IsPow2(new(0, new(0x1, 0x0000_0000_0000_0000)))); - Assert.True(BinaryNumberHelper.IsPow2(new(0x1, new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)))); - } - [Fact] - public static void Log2Test() - { - Assert.Equal(8U, BinaryNumberHelper.Log2(new(0x100))); - Assert.Equal(16U, BinaryNumberHelper.Log2(new(0x1_0000))); - Assert.Equal(32U, BinaryNumberHelper.Log2(new(0x1_0000_0000))); - Assert.Equal(64U, BinaryNumberHelper.Log2(new(0, new(0x1, 0x0000_0000_0000_0000)))); - Assert.Equal(128U, BinaryNumberHelper.Log2(new(0x1, new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000)))); - } - #endregion - - #region IMinMaxValue - [Fact] - public static void MaxValueTest() - { - MaxValue.Should().Be(MathConstantsHelper.MaxValue()); - } - - [Fact] - public static void MinValueTest() - { - Zero.Should().Be(MathConstantsHelper.MinValue()); - } - #endregion - - #region INumber - [Fact] - public static void ClampTest() - { - NumberHelper.Clamp(MaxValueMinusOne, UInt128MaxValue, MaxValue).Should().Be(MaxValueMinusOne); - NumberHelper.Clamp(Zero, Two, MaxValue).Should().Be(Two); - NumberHelper.Clamp(MaxValue, Zero, One).Should().Be(One); - - Assert.Throws(() => NumberHelper.Clamp(Zero, MaxValue, Zero)); - } - [Fact] - public static void CopySignTest() - { - NumberHelper.CopySign(MaxValue, One).Should().Be(MaxValue); - } - [Fact] - public static void MaxTest() - { - NumberHelper.Max(MaxValue, Two).Should().Be(MaxValue); - NumberHelper.Max(One, Zero).Should().Be(One); - NumberHelper.Max(Two, Zero).Should().Be(Two); - NumberHelper.Max(Two, One).Should().Be(Two); - } - [Fact] - public static void MaxNumberTest() - { - NumberHelper.MaxNumber(MaxValue, Zero).Should().Be(MaxValue); - NumberHelper.MaxNumber(One, Zero).Should().Be(One); - NumberHelper.MaxNumber(Two, Zero).Should().Be(Two); - } - [Fact] - public static void MinTest() - { - NumberHelper.Min(MaxValue, Zero).Should().Be(Zero); - NumberHelper.Min(One, Zero).Should().Be(Zero); - NumberHelper.Min(Two, Zero).Should().Be(Zero); - } - [Fact] - public static void MinNumberTest() - { - NumberHelper.MinNumber(MaxValue, Zero).Should().Be(Zero); - NumberHelper.MinNumber(One,Zero).Should().Be(Zero); - NumberHelper.MinNumber(Two, Zero).Should().Be(Zero); - } - [Fact] - public static void SignTest() - { - NumberHelper.Sign(MaxValue).Should().Be(1); - NumberHelper.Sign(UInt.Zero).Should().Be(0); - } - #endregion - - #region INumberBase - [Fact] - public static void AbsTest() - { - NumberBaseHelper.Abs(One).Should().Be(One); - } - [Fact] - public static void CreateCheckedToUInt256Test() - { - NumberBaseHelper.CreateChecked(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateChecked(ushort.MaxValue).Should().Be(UInt16MaxValue); - NumberBaseHelper.CreateChecked(uint.MaxValue).Should().Be(UInt32MaxValue); - NumberBaseHelper.CreateChecked(ulong.MaxValue).Should().Be(UInt64MaxValue); - NumberBaseHelper.CreateChecked(UInt128.MaxValue).Should().Be(UInt128MaxValue); - NumberBaseHelper - .CreateChecked(BigInteger.Parse( - "115792089237316195423570985008687907853269984665640564039457584007913129639935")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateChecked(MaxValueAsDouble).Should().Be(MaxValue); - - NumberBaseHelper.CreateChecked(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateChecked(ushort.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateChecked(uint.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateChecked(ulong.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateChecked(UInt128.MinValue).Should().Be(Zero); - } - [Fact] - public static void CreateSaturatingToUInt256Test() - { - NumberBaseHelper.CreateSaturating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateSaturating(ushort.MaxValue).Should().Be(UInt16MaxValue); - NumberBaseHelper.CreateSaturating(uint.MaxValue).Should().Be(UInt32MaxValue); - NumberBaseHelper.CreateSaturating(ulong.MaxValue).Should().Be(UInt64MaxValue); - NumberBaseHelper.CreateSaturating(UInt128.MaxValue).Should().Be(UInt128MaxValue); - NumberBaseHelper - .CreateSaturating(BigInteger.Parse( - "115792089237316195423570985008687907853269984665640564039457584007913129639935")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateSaturating(MaxValueAsDouble).Should().Be(MaxValue); - - NumberBaseHelper.CreateSaturating(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateSaturating(ushort.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateSaturating(uint.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateSaturating(ulong.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateSaturating(UInt128.MinValue).Should().Be(Zero); - } - [Fact] - public static void CreateTruncatingToUInt256Test() - { - NumberBaseHelper.CreateTruncating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateTruncating(ushort.MaxValue).Should().Be(UInt16MaxValue); - NumberBaseHelper.CreateTruncating(uint.MaxValue).Should().Be(UInt32MaxValue); - NumberBaseHelper.CreateTruncating(ulong.MaxValue).Should().Be(UInt64MaxValue); - NumberBaseHelper.CreateTruncating(UInt128.MaxValue).Should().Be(UInt128MaxValue); - NumberBaseHelper - .CreateTruncating(BigInteger.Parse( - "115792089237316195423570985008687907853269984665640564039457584007913129639935")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateTruncating(MaxValueAsDouble).Should().Be(MaxValue); - - NumberBaseHelper.CreateTruncating(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(ushort.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(uint.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(ulong.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(UInt128.MinValue).Should().Be(Zero); - } - - [Fact] - public static void CreateCheckedFromUInt256Test() - { - NumberBaseHelper.CreateChecked(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateChecked(UInt16MaxValue).Should().Be(ushort.MaxValue); - NumberBaseHelper.CreateChecked(UInt32MaxValue).Should().Be(uint.MaxValue); - NumberBaseHelper.CreateChecked(UInt64MaxValue).Should().Be(ulong.MaxValue); - NumberBaseHelper.CreateChecked(UInt128MaxValue).Should().Be(UInt128.MaxValue); - NumberBaseHelper.CreateChecked(MaxValue).Should() - .Be(BigInteger.Parse( - "115792089237316195423570985008687907853269984665640564039457584007913129639935")); - NumberBaseHelper.CreateChecked(MaxValue).Should().Be(MaxValueAsDouble); - - NumberBaseHelper.CreateChecked(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateChecked(Zero).Should().Be(ushort.MinValue); - NumberBaseHelper.CreateChecked(Zero).Should().Be(uint.MinValue); - NumberBaseHelper.CreateChecked(Zero).Should().Be(ulong.MinValue); - NumberBaseHelper.CreateChecked(Zero).Should().Be(UInt128.MinValue); - } - [Fact] - public static void CreateSaturatingFromUInt256Test() - { - NumberBaseHelper.CreateSaturating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateSaturating(UInt16MaxValue).Should().Be(ushort.MaxValue); - NumberBaseHelper.CreateSaturating(UInt32MaxValue).Should().Be(uint.MaxValue); - NumberBaseHelper.CreateSaturating(UInt64MaxValue).Should().Be(ulong.MaxValue); - NumberBaseHelper.CreateSaturating(UInt128MaxValue).Should().Be(UInt128.MaxValue); - NumberBaseHelper.CreateSaturating(MaxValue).Should() - .Be(BigInteger.Parse( - "115792089237316195423570985008687907853269984665640564039457584007913129639935")); - NumberBaseHelper.CreateSaturating(MaxValue).Should().Be(MaxValueAsDouble); - - NumberBaseHelper.CreateSaturating(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateSaturating(Zero).Should().Be(ushort.MinValue); - NumberBaseHelper.CreateSaturating(Zero).Should().Be(uint.MinValue); - NumberBaseHelper.CreateSaturating(Zero).Should().Be(ulong.MinValue); - NumberBaseHelper.CreateSaturating(Zero).Should().Be(UInt128.MinValue); - } - [Fact] - public static void CreateTruncatingFromUInt256Test() - { - NumberBaseHelper.CreateTruncating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateTruncating(UInt16MaxValue).Should().Be(ushort.MaxValue); - NumberBaseHelper.CreateTruncating(UInt32MaxValue).Should().Be(uint.MaxValue); - NumberBaseHelper.CreateTruncating(UInt64MaxValue).Should().Be(ulong.MaxValue); - NumberBaseHelper.CreateTruncating(UInt128MaxValue).Should().Be(UInt128.MaxValue); - NumberBaseHelper.CreateTruncating(MaxValue).Should() - .Be(BigInteger.Parse( - "115792089237316195423570985008687907853269984665640564039457584007913129639935")); - NumberBaseHelper.CreateTruncating(MaxValue).Should().Be(MaxValueAsDouble); - - NumberBaseHelper.CreateTruncating(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateTruncating(Zero).Should().Be(ushort.MinValue); - NumberBaseHelper.CreateTruncating(Zero).Should().Be(uint.MinValue); - NumberBaseHelper.CreateTruncating(Zero).Should().Be(ulong.MinValue); - NumberBaseHelper.CreateTruncating(Zero).Should().Be(UInt128.MinValue); - } - - [Fact] - public static void IsCanonicalTest() - { - NumberBaseHelper.IsCanonical(default(UInt)).Should().BeTrue(); - } - - [Fact] - public static void IsComplexNumberTest() - { - NumberBaseHelper.IsComplexNumber(default(UInt)).Should().BeFalse(); - } - - [Fact] - public static void IsEvenIntegerTest() - { - NumberBaseHelper.IsEvenInteger(One).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(Two).Should().BeTrue(); - } - - [Fact] - public static void IsFiniteTest() - { - NumberBaseHelper.IsFinite(default(UInt)).Should().BeTrue(); - } - - [Fact] - public static void IsImaginaryNumberTest() - { - NumberBaseHelper.IsImaginaryNumber(default(UInt)).Should().BeFalse(); - } - - [Fact] - public static void IsInfinityTest() - { - NumberBaseHelper.IsInfinity(default(UInt)).Should().BeFalse(); - } - - [Fact] - public static void IsIntegerTest() - { - NumberBaseHelper.IsInteger(default(UInt)).Should().BeTrue(); - } - - [Fact] - public static void IsNaNTest() - { - NumberBaseHelper.IsNaN(default(UInt)).Should().BeFalse(); - } - - [Fact] - public static void IsNegativeTest() - { - NumberBaseHelper.IsNegative(One).Should().BeFalse(); - } - - [Fact] - public static void IsNegativeInfinityTest() - { - NumberBaseHelper.IsNegativeInfinity(One).Should().BeFalse(); - } - - [Fact] - public static void IsNormalTest() - { - NumberBaseHelper.IsNormal(Zero).Should().BeFalse(); - NumberBaseHelper.IsNormal(One).Should().BeTrue(); - } - - [Fact] - public static void IsOddIntegerTest() - { - NumberBaseHelper.IsOddInteger(One).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(Two).Should().BeFalse(); - } - - [Fact] - public static void IsPositiveTest() - { - NumberBaseHelper.IsPositive(One).Should().BeTrue(); - } - - [Fact] - public static void IsPositiveInfinityTest() - { - NumberBaseHelper.IsPositiveInfinity(One).Should().BeFalse(); - } - - [Fact] - public static void IsRealNumberTest() - { - NumberBaseHelper.IsRealNumber(default).Should().BeTrue(); - } - - [Fact] - public static void IsSubnormalTest() - { - NumberBaseHelper.IsSubnormal(default).Should().BeFalse(); - } - - [Fact] - public static void IsZeroTest() - { - NumberBaseHelper.IsZero(default).Should().BeTrue(); - NumberBaseHelper.IsZero(Zero).Should().BeTrue(); - NumberBaseHelper.IsZero(One).Should().BeFalse(); - } - - [Fact] - public static void MaxMagnitudeTest() - { - NumberBaseHelper.MaxMagnitude(MaxValue, Zero).Should().Be(MaxValue); - NumberBaseHelper.MaxMagnitude(One, Zero).Should().Be(One); - NumberBaseHelper.MaxMagnitude(Two, Zero).Should().Be(Two); - } - - [Fact] - public static void MaxMagnitudeNumberTest() - { - NumberBaseHelper.MaxMagnitudeNumber(MaxValue, Zero).Should().Be(MaxValue); - NumberBaseHelper.MaxMagnitudeNumber(One, Zero).Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(Two, Zero).Should().Be(Two); - } - - [Fact] - public static void MinMagnitudeTest() - { - NumberBaseHelper.MinMagnitude(MaxValue, MaxValueMinusOne).Should().Be(MaxValueMinusOne); - NumberBaseHelper.MinMagnitude(One, Zero).Should().Be(Zero); - NumberBaseHelper.MinMagnitude(Two, Zero).Should().Be(Zero); - } - - [Fact] - public static void MinMagnitudeNumberTest() - { - NumberBaseHelper.MinMagnitudeNumber(MaxValue, MaxValueMinusOne).Should().Be(MaxValueMinusOne); - NumberBaseHelper.MinMagnitudeNumber(One, Zero).Should().Be(Zero); - NumberBaseHelper.MinMagnitudeNumber(Two, Zero).Should().Be(Zero); - } - - [Fact] - public void ParseTest() - { - NumberBaseHelper.Parse("115792089237316195423570985008687907853269984665640564039457584007913129639935", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - - NumberBaseHelper.Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(new(0x0000_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)) - .And.BeRankedEquallyTo(new(0x0000_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - NumberBaseHelper.Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(new(0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)) - .And.BeRankedEquallyTo(new(0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - NumberBaseHelper.Parse("FFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF)) - .And.BeRankedEquallyTo(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF)); - NumberBaseHelper.Parse("123456790ABCDEF123456790ABCDEFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0123_4567_90AB_CDEF, 0x1234_5679_0ABC_DEFF)) - .And.BeRankedEquallyTo(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0123_4567_90AB_CDEF, 0x1234_5679_0ABC_DEFF)); - - NumberBaseHelper.Parse(MaxValueBin, System.Globalization.NumberStyles.BinaryNumber, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.Parse("00010001010101111001001000001000100100100011011100110001011000011000", System.Globalization.NumberStyles.BinaryNumber, CultureInfo.CurrentCulture) - .Should().Be(new(0x0, 0x0, 0x1, 0x1579_2089_2373_1618)) - .And.BeRankedEquallyTo(new(0x0, 0x0, 0x1, 0x1579_2089_2373_1618)); - - Assert.Throws(() => NumberBaseHelper.Parse("115792089237316195423570985008687907853269984665640564039457584007913129639936", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - } - - [Fact] - public void TryParseTest() - { - NumberBaseHelper.TryParse("115792089237316195423570985008687907853269984665640564039457584007913129639935", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out UInt parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.TryParse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.TryParse(MaxValueBin, System.Globalization.NumberStyles.BinaryNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - - NumberBaseHelper.TryParse("115792089237316195423570985008687907853269984665640564039457584007913129639936", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - } - - [Fact] - public void ParseUtf8Test() - { - NumberBaseHelper.Parse("115792089237316195423570985008687907853269984665640564039457584007913129639935"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - - NumberBaseHelper.Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(new(0x0000_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)) - .And.BeRankedEquallyTo(new(0x0000_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - NumberBaseHelper.Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(new(0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)) - .And.BeRankedEquallyTo(new(0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); - NumberBaseHelper.Parse("FFFFFFFFFFFFFFFF"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF)) - .And.BeRankedEquallyTo(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF)); - NumberBaseHelper.Parse("123456790ABCDEF123456790ABCDEFF"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0123_4567_90AB_CDEF, 0x1234_5679_0ABC_DEFF)) - .And.BeRankedEquallyTo(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0123_4567_90AB_CDEF, 0x1234_5679_0ABC_DEFF)); - - NumberBaseHelper.Parse(MaxValueBinUtf8, System.Globalization.NumberStyles.BinaryNumber, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.Parse("00010001010101111001001000001000100100100011011100110001011000011000"u8, System.Globalization.NumberStyles.BinaryNumber, CultureInfo.CurrentCulture) - .Should().Be(new(0x0, 0x0, 0x1, 0x1579_2089_2373_1618)) - .And.BeRankedEquallyTo(new(0x0, 0x0, 0x1, 0x1579_2089_2373_1618)); - - Assert.Throws(() => NumberBaseHelper.Parse("115792089237316195423570985008687907853269984665640564039457584007913129639936"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - } - - [Fact] - public void TryParseUtf8Test() - { - NumberBaseHelper.TryParse("115792089237316195423570985008687907853269984665640564039457584007913129639935"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out UInt parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.TryParse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.TryParse(MaxValueBinUtf8, System.Globalization.NumberStyles.BinaryNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - - NumberBaseHelper.TryParse("115792089237316195423570985008687907853269984665640564039457584007913129639936"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - } - #endregion - - #region IPowerFunctions - [Fact] - public void PowTest() - { - GenericFloatingPointFunctions.Pow(Zero, (uint)int.MaxValue).Should().Be(Zero); - GenericFloatingPointFunctions.Pow(One, (uint)int.MaxValue).Should().Be(One); - GenericFloatingPointFunctions.Pow(MaxValue, Zero).Should().Be(One); - GenericFloatingPointFunctions.Pow(MaxValue, One).Should().Be(MaxValue); - GenericFloatingPointFunctions.Pow(Two, Two).Should().Be(4); - GenericFloatingPointFunctions.Pow(Two, 4U).Should().Be(16); - GenericFloatingPointFunctions.Pow(16U, Two).Should().Be(256); - GenericFloatingPointFunctions.Pow(Two, 255U) - .Should().Be(new UInt(0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - - Assert.Throws(() => GenericFloatingPointFunctions.Pow(Two, 256U)); - Assert.Throws(() => GenericFloatingPointFunctions.Pow(Two + Two, 255U)); - } - #endregion - } -} diff --git a/src/MissingValues.Tests/Core/UInt256Test.cs b/src/MissingValues.Tests/Core/UInt256Test.cs deleted file mode 100644 index a234c97..0000000 --- a/src/MissingValues.Tests/Core/UInt256Test.cs +++ /dev/null @@ -1,236 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Text.Json; -using System.Text.Unicode; -using System.Threading.Tasks; - -using UInt = MissingValues.UInt256; - -namespace MissingValues.Tests.Core -{ - public partial class UInt256Test - { - [Fact] - public void Cast_ToByte() - { - byte.MinValue.Should().Be((byte)Zero); - byte.MaxValue.Should().Be((byte)ByteMaxValue); - } - - [Fact] - public void Cast_ToUInt16() - { - ushort.MinValue.Should().Be((ushort)Zero); - ushort.MaxValue.Should().Be((ushort)UInt16MaxValue); - } - - [Fact] - public void Cast_ToUInt32() - { - uint.MinValue.Should().Be((uint)Zero); - uint.MaxValue.Should().Be((uint)UInt32MaxValue); - } - - [Fact] - public void Cast_ToUInt64() - { - ulong.MinValue.Should().Be((ulong)Zero); - ulong.MaxValue.Should().Be((ulong)UInt64MaxValue); - } - - [Fact] - public void Cast_ToUInt128() - { - UInt128.MinValue.Should().Be((UInt128)Zero); - UInt128.MaxValue.Should().Be((UInt128)UInt128MaxValue); - } - - [Fact] - public void Cast_ToBigInteger() - { - BigInteger.One.Should().Be((BigInteger)One); - BigInteger.Parse("115792089237316195423570985008687907853269984665640564039457584007913129639935") - .Should().Be((BigInteger)MaxValue); - } - - [Fact] - public void Cast_ToDouble() - { - // Test a UInt256Converter value where _upper is 0 - UInt value1 = new UInt(UInt128.Zero, UInt128.MaxValue); - double exp1 = System.Math.Round((double)UInt128.MaxValue, 5); - double act1 = System.Math.Round((double)value1, 5); - double diff1 = System.Math.Abs(exp1 * 0.00000000001); - Assert.True(System.Math.Abs(exp1 - act1) <= diff1); - - - // Test a UInt256Converter value where _upper is not 0 - UInt value2 = new UInt(UInt128.MaxValue, UInt128.MaxValue); - double exp2 = System.Math.Round(((double)UInt128.MaxValue) * System.Math.Pow(2.0, 128), 5); - double act2 = System.Math.Round((double)value2, 5); - double diff2 = System.Math.Abs(exp2 * 0.00000000001); - Assert.True(System.Math.Abs(exp2 - act2) <= diff2); - } - - [Fact] - public void BigMulTest() - { - UInt upper = UInt.BigMul(MaxValue, Two, out UInt lower); - - upper - .Should() - .Be(new(0x1)); - lower - .Should() - .Be(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)); - } - - [Fact] - public void Internal_DivRemTest() - { - const long Left = 101_000_000_000; - const long Right = 10_000_000_000; - const long Quotient = 10; - const long Remainder = 1_000_000_000; - - UInt a = Left; - UInt b = Right; - - UInt.DivRem(in a, in b, out UInt quotient, out UInt remainder); - - quotient.Should().Be(Quotient); - remainder.Should().Be(Remainder); - - UInt.DivRem(in a, in b, out a, out remainder); - - a.Should().Be(Quotient); - remainder.Should().Be(Remainder); - - UInt.DivRem(Left, in b, out quotient, out b); - - quotient.Should().Be(Quotient); - b.Should().Be(Remainder); - } - - [Fact] - public void BasicParseTest() - { - UInt.Parse("115792089237316195423570985008687907853269984665640564039457584007913129639935") - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - } - - [Fact] - public void BasicTryParseTest() - { - UInt.TryParse("115792089237316195423570985008687907853269984665640564039457584007913129639935", out UInt parsedValue).Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - } - - [Fact] - public void ToDecStringTest() - { - Zero.ToString("D", CultureInfo.CurrentCulture) - .Should().Be("0"); - One.ToString("D", CultureInfo.CurrentCulture) - .Should().Be("1"); - MaxValue.ToString("D", CultureInfo.CurrentCulture) - .Should().Be("115792089237316195423570985008687907853269984665640564039457584007913129639935"); - } - [Fact] - public void ToHexStringTest() - { - One.ToString("X", CultureInfo.CurrentCulture) - .Should().Be("1"); - ((UInt)byte.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("FF"); - ((UInt)ushort.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("FFFF"); - ((UInt)uint.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("FFFFFFFF"); - ((UInt)ulong.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("FFFFFFFFFFFFFFFF"); - ((UInt)UInt128.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - - Zero.ToString("X64", CultureInfo.CurrentCulture) - .Should().Be("0000000000000000000000000000000000000000000000000000000000000000"); - MaxValue.ToString("x64", CultureInfo.CurrentCulture) - .Should().Be("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - MaxValue.ToString("X64", CultureInfo.CurrentCulture) - .Should().Be("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - } - [Fact] - public void ToBinStringTest() - { - One.ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1"); - ((UInt)byte.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("11111111"); - ((UInt)ushort.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1111111111111111"); - ((UInt)uint.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("11111111111111111111111111111111"); - ((UInt)ulong.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1111111111111111111111111111111111111111111111111111111111111111"); - ((UInt)UInt128.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); - - Zero.ToString("B256", CultureInfo.CurrentCulture) - .Should().Be("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); - MaxValue.ToString("B256", CultureInfo.CurrentCulture) - .Should().Be("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); - } - - [Fact] - public void ToDecFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString()!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:D}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - [Fact] - public void ToHexFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString("X64", CultureInfo.CurrentCulture)!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:X64}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - [Fact] - public void ToBinFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString("B256", CultureInfo.CurrentCulture)!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:B256}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - - [Fact] - public void JsonWriteTest() - { - JsonSerializer.Serialize(new object[] { MaxValue, Zero, One }) - .Should().Be("[115792089237316195423570985008687907853269984665640564039457584007913129639935,0,1]"); - } - [Fact] - public void JsonReadTest() - { - JsonSerializer.Deserialize("115792089237316195423570985008687907853269984665640564039457584007913129639935") - .Should().Be(MaxValue); - JsonSerializer.Deserialize("115792089237316195423570985008687907853269984665640564039457584007913129639935"u8) - .Should().Be(MaxValue); - } - } -} diff --git a/src/MissingValues.Tests/Core/UInt512Test.GenericMath.cs b/src/MissingValues.Tests/Core/UInt512Test.GenericMath.cs deleted file mode 100644 index d22d1e5..0000000 --- a/src/MissingValues.Tests/Core/UInt512Test.GenericMath.cs +++ /dev/null @@ -1,1172 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -using UInt = MissingValues.UInt512; - -namespace MissingValues.Tests.Core -{ - public partial class UInt512Test - { - #region Readonly Variables - private const string MaxValueBin = - "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111" - + "11111111111111111111111111111111"; - private ReadOnlySpan MaxValueBinUtf8 => - "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8 - + "11111111111111111111111111111111"u8; - private const double MaxValueAsDouble = 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095.0; - - private static readonly UInt ByteMaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_00FF); - private static readonly UInt UInt16MaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_FFFF); - private static readonly UInt UInt32MaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_FFFF_FFFF); - private static readonly UInt UInt64MaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF); - private static readonly UInt UInt128MaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF); - private static readonly UInt UInt256MaxValue = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF); - - private static readonly UInt Zero = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000); - private static readonly UInt One = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001); - private static readonly UInt Two = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0002); - - private static readonly UInt MaxValue = new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF); - private static readonly UInt MaxValueMinusOne = new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE); - private static readonly UInt MaxValueMinusTwo = new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFD); - private static readonly UInt HalfMaxValue = new( - 0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF); - - private static readonly UInt E40 = new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_001D, 0x6329_F1C3_5CA4_BFAB, 0xB9F5_6100_0000_0000); - #endregion - - #region Generic Math Operators - [Fact] - public static void op_AdditionTest() - { - Assert.Equal(One, MathOperatorsHelper.AdditionOperation(Zero, One)); - Assert.Equal(Two, MathOperatorsHelper.AdditionOperation(One, One)); - Assert.Equal(Zero, MathOperatorsHelper.AdditionOperation(MaxValue, One)); - } - [Fact] - public static void op_CheckedAdditionTest() - { - Assert.Equal(One, MathOperatorsHelper.CheckedAdditionOperation(Zero, One)); - Assert.Equal(Two, MathOperatorsHelper.CheckedAdditionOperation(One, One)); - - Assert.Throws(() => MathOperatorsHelper.CheckedAdditionOperation(MaxValue, 1)); - } - [Fact] - public static void op_IncrementTest() - { - MathOperatorsHelper.IncrementOperation(Zero).Should().Be(One); - MathOperatorsHelper.IncrementOperation(One).Should().Be(Two); - MathOperatorsHelper.IncrementOperation(MaxValueMinusTwo).Should().Be(MaxValueMinusOne); - MathOperatorsHelper.IncrementOperation(MaxValueMinusOne).Should().Be(MaxValue); - MathOperatorsHelper.IncrementOperation(MaxValue).Should().Be(Zero); - } - [Fact] - public static void op_CheckedIncrementTest() - { - MathOperatorsHelper.CheckedIncrementOperation(Zero).Should().Be(One); - MathOperatorsHelper.CheckedIncrementOperation(One).Should().Be(Two); - MathOperatorsHelper.CheckedIncrementOperation(MaxValueMinusTwo).Should().Be(MaxValueMinusOne); - MathOperatorsHelper.CheckedIncrementOperation(MaxValueMinusOne).Should().Be(MaxValue); - - Assert.Throws(() => MathOperatorsHelper.CheckedIncrementOperation(MaxValue)); - } - [Fact] - public static void op_SubtractionTest() - { - Assert.Equal(One, MathOperatorsHelper.SubtractionOperation(Two, One)); - Assert.Equal(MaxValueMinusOne, MathOperatorsHelper.SubtractionOperation(MaxValue, 1)); - } - [Fact] - public static void op_CheckedSubtractionTest() - { - Assert.Equal(One, MathOperatorsHelper.CheckedSubtractionOperation(Two, One)); - Assert.Equal(MaxValueMinusOne, MathOperatorsHelper.CheckedSubtractionOperation(MaxValue, 1)); - - Assert.Throws(() => MathOperatorsHelper.CheckedSubtractionOperation(Zero, 1)); - } - [Fact] - public static void op_DecrementTest() - { - MathOperatorsHelper.DecrementOperation(Two).Should().Be(One); - MathOperatorsHelper.DecrementOperation(One).Should().Be(Zero); - MathOperatorsHelper.DecrementOperation(MaxValueMinusOne).Should().Be(MaxValueMinusTwo); - MathOperatorsHelper.DecrementOperation(MaxValue).Should().Be(MaxValueMinusOne); - MathOperatorsHelper.DecrementOperation(Zero).Should().Be(MaxValue); - } - [Fact] - public static void op_CheckedDecrementTest() - { - MathOperatorsHelper.CheckedDecrementOperation(Two).Should().Be(One); - MathOperatorsHelper.CheckedDecrementOperation(One).Should().Be(Zero); - MathOperatorsHelper.CheckedDecrementOperation(MaxValueMinusOne).Should().Be(MaxValueMinusTwo); - MathOperatorsHelper.CheckedDecrementOperation(MaxValue).Should().Be(MaxValueMinusOne); - - Assert.Throws(() => MathOperatorsHelper.CheckedDecrementOperation(Zero)); - } - [Fact] - public static void op_MultiplyTest() - { - Assert.Equal(One, MathOperatorsHelper.MultiplicationOperation(One, One)); - Assert.Equal(Two, MathOperatorsHelper.MultiplicationOperation(Two, One)); - Assert.Equal(MaxValueMinusOne, MathOperatorsHelper.MultiplicationOperation(Two, HalfMaxValue)); - } - [Fact] - public static void op_CheckedMultiplyTest() - { - Assert.Equal(One, MathOperatorsHelper.CheckedMultiplicationOperation(One, One)); - Assert.Equal(Two, MathOperatorsHelper.CheckedMultiplicationOperation(Two, One)); - - Assert.Throws(() => MathOperatorsHelper.CheckedMultiplicationOperation(MaxValue, Two)); - } - [Fact] - public static void op_DivisionTest() - { - Assert.Equal( - HalfMaxValue, - MathOperatorsHelper.DivisionOperation(MaxValue, Two)); - Assert.Equal( - new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), - MathOperatorsHelper.DivisionOperation( - UInt256.MaxValue, - Two)); - Assert.Equal( - new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), - MathOperatorsHelper.DivisionOperation( - UInt128.MaxValue, - Two)); - - Assert.Equal( - new(0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, - 0x5C28_F5C2_8F5C_28F5, 0xC28F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28), - MaxValue / 100); - Assert.Equal( - new(0x0006_8DB8_BAC7_10CB, 0x295E_9E1B_089A_0275, 0x2546_0AA6_4C2F_837B, 0x4A23_39C0_EBED_FA43, - 0xFE5C_91D1_4E3B_CD35, 0xA858_793D_D97F_62B6, 0xAE7D_566C_F41F_212D, 0x7731_8FC5_0481_6F00), - (MaxValue / 100) / 100); - Assert.Equal( - new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x08B6_1313_BBAB_CE2C, 0x6232_3AC4_B3B3_DA01, - 0x53B6_2BE7_BC1A_0042, 0xB443_E18A_C4E7_0AFD, 0xB897_7684_D802_7110, 0x5B47_424E_B16F_CC18), - MathOperatorsHelper.DivisionOperation(MaxValue, E40)); - Assert.Equal( - new UInt( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x1DA4_8CE4_68E7_C702, 0x6520_247D_3556_476D, 0x1469_CAF6_DB22_4CF9, 0x7D7D_B189_5F2A_4679 - ), - MathOperatorsHelper.DivisionOperation(new UInt( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x08B6_1313_BBAB_CE2C, 0x6232_3AC4_B3B3_DA01, - 0x53B6_2BE7_BC1A_0042, 0xB443_E18A_C4E7_0AFD, 0xB897_7684_D802_7110, 0x5B47_424E_B16F_CC18 - ), - new UInt( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x4B3B_4CA8_5A86_C47A, 0x098A_2240_0000_0000 - ))); - Assert.Equal(One, MathOperatorsHelper.DivisionOperation(MaxValue, MaxValue)); - - Assert.Throws(() => MathOperatorsHelper.DivisionOperation(One, Zero)); - } - [Fact] - public static void op_CheckedDivisionTest() - { - Assert.Equal( - HalfMaxValue, - MathOperatorsHelper.CheckedDivisionOperation(MaxValue, Two)); - Assert.Equal(One, MathOperatorsHelper.CheckedDivisionOperation(MaxValue, MaxValue)); - Assert.Equal( - new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x08B6_1313_BBAB_CE2C, 0x6232_3AC4_B3B3_DA01, - 0x53B6_2BE7_BC1A_0042, 0xB443_E18A_C4E7_0AFD, 0xB897_7684_D802_7110, 0x5B47_424E_B16F_CC18), - MathOperatorsHelper.CheckedDivisionOperation(MaxValue, E40)); - - Assert.Throws(() => MathOperatorsHelper.CheckedDivisionOperation(One, Zero)); - } - [Fact] - public static void op_ModulusTest() - { - MathOperatorsHelper.ModulusOperation(Two, Two).Should().Be(Zero); - MathOperatorsHelper.ModulusOperation(One, Two).Should().NotBe(Zero); - MathOperatorsHelper.ModulusOperation(MaxValue, new(10U)).Should().Be(5U); - MathOperatorsHelper.ModulusOperation(MaxValue, E40) - .Should().Be( - new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0011, 0xC828_0B1A_5E03_5840, 0xF8B2_E7FF_FFFF_FFFF)); - - Assert.Throws(() => MathOperatorsHelper.ModulusOperation(One, Zero)); - } - - [Fact] - public static void op_BitwiseAndTest() - { - BitwiseOperatorsHelper.BitwiseAndOperation(Zero, 1U).Should().Be(Zero); - BitwiseOperatorsHelper.BitwiseAndOperation(One, 1U).Should().Be(One); - BitwiseOperatorsHelper.BitwiseAndOperation(MaxValue, 1U).Should().Be(One); - } - [Fact] - public static void op_BitwiseOrTest() - { - BitwiseOperatorsHelper.BitwiseOrOperation(Zero, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.BitwiseOrOperation(One, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.BitwiseOrOperation(MaxValue, 1U) - .Should().Be(MaxValue); - } - [Fact] - public static void op_ExclusiveOrTest() - { - BitwiseOperatorsHelper.ExclusiveOrOperation(Zero, 1U) - .Should().Be(One); - BitwiseOperatorsHelper.ExclusiveOrOperation(One, 1U) - .Should().Be(Zero); - BitwiseOperatorsHelper.ExclusiveOrOperation(MaxValue, 1U) - .Should().Be(MaxValueMinusOne); - } - [Fact] - public static void op_OnesComplementTest() - { - BitwiseOperatorsHelper.OnesComplementOperation(Zero) - .Should().Be(MaxValue); - BitwiseOperatorsHelper.OnesComplementOperation(One) - .Should().Be(MaxValueMinusOne); - BitwiseOperatorsHelper.OnesComplementOperation(MaxValue) - .Should().Be(Zero); - } - - [Fact] - public static void op_LeftShiftTest() - { - ShiftOperatorsHelper.LeftShiftOperation(Zero, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.LeftShiftOperation(One, 1) - .Should().Be(Two); - ShiftOperatorsHelper.LeftShiftOperation(MaxValue, 1) - .Should().Be(MaxValueMinusOne); - - UInt actual = new( - 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, - 0x5C28_F5C2_8F5C_28F5, 0xC28F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28); - - ShiftOperatorsHelper.LeftShiftOperation(actual, 0) - .Should().Be(actual); - ShiftOperatorsHelper.LeftShiftOperation(actual, 64) - .Should().Be(new( - 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, 0x5C28_F5C2_8F5C_28F5, - 0xC28F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0)); - ShiftOperatorsHelper.LeftShiftOperation(actual, 64 * 2) - .Should().Be(new( - 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, 0x5C28_F5C2_8F5C_28F5, 0xC28F_5C28_F5C2_8F5C, - 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0, 0)); - ShiftOperatorsHelper.LeftShiftOperation(actual, 64 * 3) - .Should().Be(new( - 0xF5C2_8F5C_28F5_C28F, 0x5C28_F5C2_8F5C_28F5, 0xC28F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, - 0x8F5C_28F5_C28F_5C28, 0, 0, 0)); - ShiftOperatorsHelper.LeftShiftOperation(actual, 64 * 4) - .Should().Be(new( - 0x5C28_F5C2_8F5C_28F5, 0xC28F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, - 0, 0, 0, 0 )); - ShiftOperatorsHelper.LeftShiftOperation(actual, 64 * 5) - .Should().Be(new( - 0xC28F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0, - 0, 0, 0, 0)); - ShiftOperatorsHelper.LeftShiftOperation(actual, 64 * 6) - .Should().Be(new( - 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0, 0, - 0, 0, 0, 0)); - ShiftOperatorsHelper.LeftShiftOperation(actual, 64 * 7) - .Should().Be(new( - 0x8F5C_28F5_C28F_5C28, 0, 0, 0, - 0, 0, 0, 0)); - } - [Fact] - public static void op_RightShiftTest() - { - ShiftOperatorsHelper.RightShiftOperation(Zero, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.RightShiftOperation(One, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.RightShiftOperation(MaxValue, 1) - .Should().Be(HalfMaxValue); - - UInt actual = new( - 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, - 0x5C28_F5C2_8F5C_28F5, 0xC28F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28); - - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 0) - .Should().Be(actual); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 1) - .Should().Be(new( - 0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, - 0xF5C2_8F5C_28F5_C28F, 0x5C28_F5C2_8F5C_28F5, 0xC28F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 2) - .Should().Be(new( - 0, 0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, - 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, 0x5C28_F5C2_8F5C_28F5, 0xC28F_5C28_F5C2_8F5C)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 3) - .Should().Be(new( - 0, 0, 0, 0x028F_5C28_F5C2_8F5C, - 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, 0x5C28_F5C2_8F5C_28F5)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 4) - .Should().Be(new( - 0, 0, 0, 0, - 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 5) - .Should().Be(new( - 0, 0, 0, 0, - 0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 6) - .Should().Be(new( - 0, 0, 0, 0, - 0, 0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2)); - ShiftOperatorsHelper.RightShiftOperation(actual, 64 * 7) - .Should().Be(new( - 0, 0, 0, 0, - 0, 0, 0, 0x028F_5C28_F5C2_8F5C)); - } - [Fact] - public static void op_UnsignedRightShiftTest() - { - ShiftOperatorsHelper.UnsignedRightShiftOperation(Zero, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.UnsignedRightShiftOperation(One, 1) - .Should().Be(Zero); - ShiftOperatorsHelper.UnsignedRightShiftOperation(MaxValue, 1) - .Should().Be(HalfMaxValue); - - UInt actual = new( - 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, - 0x5C28_F5C2_8F5C_28F5, 0xC28F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28); - - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 64 * 0) - .Should().Be(actual); - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 64 * 1) - .Should().Be(new( - 0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, - 0xF5C2_8F5C_28F5_C28F, 0x5C28_F5C2_8F5C_28F5, 0xC28F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2)); - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 64 * 2) - .Should().Be(new( - 0, 0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, - 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, 0x5C28_F5C2_8F5C_28F5, 0xC28F_5C28_F5C2_8F5C)); - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 64 * 3) - .Should().Be(new( - 0, 0, 0, 0x028F_5C28_F5C2_8F5C, - 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F, 0x5C28_F5C2_8F5C_28F5)); - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 64 * 4) - .Should().Be(new( - 0, 0, 0, 0, - 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28, 0xF5C2_8F5C_28F5_C28F)); - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 64 * 5) - .Should().Be(new( - 0, 0, 0, 0, - 0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2, 0x8F5C_28F5_C28F_5C28)); - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 64 * 6) - .Should().Be(new( - 0, 0, 0, 0, - 0, 0, 0x028F_5C28_F5C2_8F5C, 0x28F5_C28F_5C28_F5C2)); - ShiftOperatorsHelper.UnsignedRightShiftOperation(actual, 64 * 7) - .Should().Be(new( - 0, 0, 0, 0, - 0, 0, 0, 0x028F_5C28_F5C2_8F5C)); - } - - [Fact] - public static void op_EqualityTest() - { - EqualityOperatorsHelper.EqualityOperation(Zero, 1U).Should().BeFalse(); - EqualityOperatorsHelper.EqualityOperation(One, 1U).Should().BeTrue(); - EqualityOperatorsHelper.EqualityOperation(MaxValue, 1U).Should().BeFalse(); - } - [Fact] - public static void op_InequalityTest() - { - EqualityOperatorsHelper.InequalityOperation(Zero, 1U).Should().BeTrue(); - EqualityOperatorsHelper.InequalityOperation(One, 1U).Should().BeFalse(); - EqualityOperatorsHelper.InequalityOperation(MaxValue, 1U).Should().BeTrue(); - } - - [Fact] - public static void op_GreaterThanTest() - { - ComparisonOperatorsHelper.GreaterThanOperation(Zero, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOperation(One, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOperation(MaxValue, 1U).Should().BeTrue(); - - ComparisonOperatorsHelper.GreaterThanOperation( - new(0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1), new(0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1)) - .Should().BeTrue(); - ComparisonOperatorsHelper.GreaterThanOperation( - new(0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1), new(0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0)) - .Should().BeTrue(); - ComparisonOperatorsHelper.GreaterThanOperation( - new(0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1), new(0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x1, 0x1)) - .Should().BeTrue(); - } - [Fact] - public static void op_GreaterThanOrEqualTest() - { - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(Zero, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(One, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.GreaterThanOrEqualOperation(MaxValue, 1U).Should().BeTrue(); - } - [Fact] - public static void op_LessThanTest() - { - ComparisonOperatorsHelper.LessThanOperation(Zero, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOperation(One, 1U).Should().BeFalse(); - ComparisonOperatorsHelper.LessThanOperation(MaxValue, 1U).Should().BeFalse(); - } - [Fact] - public static void op_LessThanOrEqualTest() - { - ComparisonOperatorsHelper.LessThanOrEqualOperation(Zero, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(One, 1U).Should().BeTrue(); - ComparisonOperatorsHelper.LessThanOrEqualOperation(MaxValue, 1U).Should().BeFalse(); - } - #endregion - - #region Identities - [Fact] - public static void AdditiveIdentityTest() - { - Assert.Equal(Zero, MathConstantsHelper.AdditiveIdentityHelper()); - } - - [Fact] - public static void MultiplicativeIdentityTest() - { - Assert.Equal(One, MathConstantsHelper.MultiplicativeIdentityHelper()); - } - #endregion - - #region IBinaryInteger - [Fact] - public static void DivRemTest() - { - Assert.Equal((Zero, Zero), BinaryIntegerHelper.DivRem(Zero, Two)); - Assert.Equal((Zero, One), BinaryIntegerHelper.DivRem(One, Two)); - Assert.Equal((HalfMaxValue, One), BinaryIntegerHelper.DivRem(MaxValue, 2)); - Assert.Equal(( - new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x08B6_1313_BBAB_CE2C, 0x6232_3AC4_B3B3_DA01, - 0x53B6_2BE7_BC1A_0042, 0xB443_E18A_C4E7_0AFD, 0xB897_7684_D802_7110, 0x5B47_424E_B16F_CC18), - new UInt(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0011, 0xC828_0B1A_5E03_5840, 0xF8B2_E7FF_FFFF_FFFF)), - BinaryIntegerHelper.DivRem(MaxValue, E40)); - } - - [Fact] - public static void LeadingZeroCountTest() - { - Assert.Equal(512U, BinaryIntegerHelper.LeadingZeroCount(Zero)); - Assert.Equal(511U, BinaryIntegerHelper.LeadingZeroCount(One)); - Assert.Equal(448U, BinaryIntegerHelper.LeadingZeroCount(ulong.MaxValue)); - Assert.Equal(384U, BinaryIntegerHelper.LeadingZeroCount(UInt128.MaxValue)); - Assert.Equal(256U, BinaryIntegerHelper.LeadingZeroCount(UInt256.MaxValue)); - Assert.Equal(192U, BinaryIntegerHelper.LeadingZeroCount(MaxValue >>> 192)); - Assert.Equal(128U, BinaryIntegerHelper.LeadingZeroCount(MaxValue >>> 128)); - Assert.Equal(64U, BinaryIntegerHelper.LeadingZeroCount(MaxValue >>> 64)); - Assert.Equal(0U, BinaryIntegerHelper.LeadingZeroCount(MaxValue)); - } - - [Fact] - public static void PopCountTest() - { - Assert.Equal(0U, BinaryIntegerHelper.PopCount(Zero)); - Assert.Equal(1U, BinaryIntegerHelper.PopCount(One)); - Assert.Equal(512U, BinaryIntegerHelper.PopCount(MaxValue)); - } - - [Fact] - public static void RotateLeftTest() - { - Assert.Equal(Zero, BinaryIntegerHelper.RotateLeft(Zero, 1)); - Assert.Equal(Two, BinaryIntegerHelper.RotateLeft(One, 1)); - Assert.Equal(MaxValue, BinaryIntegerHelper.RotateLeft(MaxValue, 1)); - } - - [Fact] - public static void RotateRightTest() - { - Assert.Equal(new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), BinaryIntegerHelper.RotateRight(Zero, 1)); - Assert.Equal(new( - 0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), BinaryIntegerHelper.RotateRight(One, 1)); - Assert.Equal(new( - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, - 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), BinaryIntegerHelper.RotateRight(MaxValue, 1)); - } - - [Fact] - public static void TrailingZeroCountTest() - { - Assert.Equal(512U, BinaryIntegerHelper.TrailingZeroCount(Zero)); - Assert.Equal(0U, BinaryIntegerHelper.TrailingZeroCount(One)); - Assert.Equal(64U, BinaryIntegerHelper.TrailingZeroCount(new UInt(0, 0, 0, 0, 0, 0, 1, 0))); - Assert.Equal(128U, BinaryIntegerHelper.TrailingZeroCount(new UInt(0, 0, 0, 0, 0, 1, 0, 0))); - Assert.Equal(192U, BinaryIntegerHelper.TrailingZeroCount(new UInt(0, 0, 0, 0, 1, 0, 0, 0))); - Assert.Equal(256U, BinaryIntegerHelper.TrailingZeroCount(new UInt(0, 0, 0, 1, 0, 0, 0, 0))); - Assert.Equal(320U, BinaryIntegerHelper.TrailingZeroCount(new UInt(0, 0, 1, 0, 0, 0, 0, 0))); - Assert.Equal(384U, BinaryIntegerHelper.TrailingZeroCount(new UInt(0, 1, 0, 0, 0, 0, 0, 0))); - Assert.Equal(448U, BinaryIntegerHelper.TrailingZeroCount(new UInt(1, 0, 0, 0, 0, 0, 0, 0))); - Assert.Equal(0U, BinaryIntegerHelper.TrailingZeroCount(MaxValue)); - } - [Fact] - public static void TryReadLittleEndianInt256Test() - { - UInt result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: false, out result)); - Assert.Equal(new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: false, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: false, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0080), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: false, out result)); - Assert.Equal(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), result); - - Assert.False(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: false, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - } - - [Fact] - public static void TryReadLittleEndianUInt256Test() - { - UInt result; - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, isUnsigned: true, out result)); - Assert.Equal(new(0x0100_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 }, isUnsigned: true, out result)); - Assert.Equal(new(0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FF7F), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, isUnsigned: true, out result)); - Assert.Equal(new(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0080), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }, isUnsigned: true, out result)); - Assert.Equal(new(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), result); - - Assert.True(BinaryIntegerHelper.TryReadLittleEndian(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, isUnsigned: true, out result)); - Assert.Equal(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), result); - } - - [Fact] - public static void GetByteCountTest() - { - Assert.Equal(64, BinaryIntegerHelper.GetByteCount(Zero)); - Assert.Equal(64, BinaryIntegerHelper.GetByteCount(One)); - Assert.Equal(64, BinaryIntegerHelper.GetByteCount(MaxValue)); - } - - [Fact] - public static void GetShortestBitLengthTest() - { - Assert.Equal(0x00, BinaryIntegerHelper.GetShortestBitLength(Zero)); - Assert.Equal(0x01, BinaryIntegerHelper.GetShortestBitLength(One)); - Assert.Equal(0x200, BinaryIntegerHelper.GetShortestBitLength(MaxValue)); - } - - [Fact] - public static void TryWriteBigEndianTest() - { - Span destination = stackalloc byte[64]; - int bytesWritten = 0; - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(Zero, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(One, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteBigEndian(MaxValue, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - - Assert.False(BinaryIntegerHelper.TryWriteBigEndian(default, Span.Empty, out bytesWritten)); - Assert.Equal(0, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - } - - [Fact] - public static void TryWriteLittleEndianTest() - { - Span destination = stackalloc byte[64]; - int bytesWritten = 0; - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(Zero, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(One, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, destination.ToArray()); - - Assert.True(BinaryIntegerHelper.TryWriteLittleEndian(MaxValue, destination, out bytesWritten)); - Assert.Equal(64, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - - Assert.False(BinaryIntegerHelper.TryWriteLittleEndian(default, Span.Empty, out bytesWritten)); - Assert.Equal(0, bytesWritten); - Assert.Equal(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }, destination.ToArray()); - } - #endregion - - #region IBinaryNumber - [Fact] - public static void AllBitsSetTest() - { - Assert.Equal(BinaryNumberHelper.AllBitsSet, ~Zero); - } - [Fact] - public static void IsPow2Test() - { - Assert.True(BinaryNumberHelper.IsPow2(new(0x100))); - Assert.True(BinaryNumberHelper.IsPow2(new(0x1_0000))); - Assert.True(BinaryNumberHelper.IsPow2(new(0x1_0000_0000))); - Assert.True(BinaryNumberHelper.IsPow2(new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000))); - Assert.True(BinaryNumberHelper.IsPow2(new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000))); - } - [Fact] - public static void Log2Test() - { - Assert.Equal(8U, BinaryNumberHelper.Log2(new(0x100))); - Assert.Equal(16U, BinaryNumberHelper.Log2(new(0x1_0000))); - Assert.Equal(32U, BinaryNumberHelper.Log2(new(0x1_0000_0000))); - Assert.Equal(64U, BinaryNumberHelper.Log2(new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000))); - Assert.Equal(128U, BinaryNumberHelper.Log2(new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000))); - Assert.Equal(256U, BinaryNumberHelper.Log2(new( - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000))); - } - #endregion - - #region IMinMaxValue - [Fact] - public static void MaxValueTest() - { - MaxValue.Should().Be(MathConstantsHelper.MaxValue()); - } - - [Fact] - public static void MinValueTest() - { - Zero.Should().Be(MathConstantsHelper.MinValue()); - } - #endregion - - #region INumber - [Fact] - public static void ClampTest() - { - NumberHelper.Clamp(MaxValueMinusOne, UInt128MaxValue, MaxValue).Should().Be(MaxValueMinusOne); - NumberHelper.Clamp(Zero, Two, MaxValue).Should().Be(Two); - NumberHelper.Clamp(MaxValue, Zero, One).Should().Be(One); - - Assert.Throws(() => NumberHelper.Clamp(Zero, MaxValue, Zero)); - } - [Fact] - public static void CopySignTest() - { - NumberHelper.CopySign(MaxValue, One).Should().Be(MaxValue); - } - [Fact] - public static void MaxTest() - { - NumberHelper.Max(MaxValue, Two).Should().Be(MaxValue); - NumberHelper.Max(One, Zero).Should().Be(One); - NumberHelper.Max(Two, Zero).Should().Be(Two); - NumberHelper.Max(Two, One).Should().Be(Two); - } - [Fact] - public static void MaxNumberTest() - { - NumberHelper.MaxNumber(MaxValue, Zero).Should().Be(MaxValue); - NumberHelper.MaxNumber(One, Zero).Should().Be(One); - NumberHelper.MaxNumber(Two, Zero).Should().Be(Two); - } - [Fact] - public static void MinTest() - { - NumberHelper.Min(MaxValue, Zero).Should().Be(Zero); - NumberHelper.Min(One, Zero).Should().Be(Zero); - NumberHelper.Min(Two, Zero).Should().Be(Zero); - } - [Fact] - public static void MinNumberTest() - { - NumberHelper.MinNumber(MaxValue, Zero).Should().Be(Zero); - NumberHelper.MinNumber(One,Zero).Should().Be(Zero); - NumberHelper.MinNumber(Two, Zero).Should().Be(Zero); - } - [Fact] - public static void SignTest() - { - NumberHelper.Sign(MaxValue).Should().Be(1); - NumberHelper.Sign(UInt.Zero).Should().Be(0); - } - #endregion - - #region INumberBase - [Fact] - public static void AbsTest() - { - NumberBaseHelper.Abs(One).Should().Be(One); - } - [Fact] - public static void CreateCheckedToUInt512Test() - { - NumberBaseHelper.CreateChecked(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateChecked(ushort.MaxValue).Should().Be(UInt16MaxValue); - NumberBaseHelper.CreateChecked(uint.MaxValue).Should().Be(UInt32MaxValue); - NumberBaseHelper.CreateChecked(ulong.MaxValue).Should().Be(UInt64MaxValue); - NumberBaseHelper.CreateChecked(UInt128.MaxValue).Should().Be(UInt128MaxValue); - NumberBaseHelper.CreateChecked(UInt256.MaxValue).Should().Be(UInt256MaxValue); - NumberBaseHelper - .CreateChecked(BigInteger.Parse( - "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateChecked(MaxValueAsDouble).Should().Be(MaxValue); - - NumberBaseHelper.CreateChecked(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateChecked(ushort.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateChecked(uint.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateChecked(ulong.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateChecked(UInt128.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateChecked(UInt256.MinValue).Should().Be(Zero); - } - [Fact] - public static void CreateSaturatingToUInt512Test() - { - NumberBaseHelper.CreateSaturating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateSaturating(ushort.MaxValue).Should().Be(UInt16MaxValue); - NumberBaseHelper.CreateSaturating(uint.MaxValue).Should().Be(UInt32MaxValue); - NumberBaseHelper.CreateSaturating(ulong.MaxValue).Should().Be(UInt64MaxValue); - NumberBaseHelper.CreateSaturating(UInt128.MaxValue).Should().Be(UInt128MaxValue); - NumberBaseHelper.CreateSaturating(UInt256.MaxValue).Should().Be(UInt256MaxValue); - NumberBaseHelper - .CreateSaturating(BigInteger.Parse( - "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateSaturating(MaxValueAsDouble).Should().Be(MaxValue); - - NumberBaseHelper.CreateSaturating(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateSaturating(ushort.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateSaturating(uint.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateSaturating(ulong.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateSaturating(UInt128.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateSaturating(UInt256.MinValue).Should().Be(Zero); - } - [Fact] - public static void CreateTruncatingToUInt512Test() - { - NumberBaseHelper.CreateTruncating(byte.MaxValue).Should().Be(ByteMaxValue); - NumberBaseHelper.CreateTruncating(ushort.MaxValue).Should().Be(UInt16MaxValue); - NumberBaseHelper.CreateTruncating(uint.MaxValue).Should().Be(UInt32MaxValue); - NumberBaseHelper.CreateTruncating(ulong.MaxValue).Should().Be(UInt64MaxValue); - NumberBaseHelper.CreateTruncating(UInt128.MaxValue).Should().Be(UInt128MaxValue); - NumberBaseHelper.CreateTruncating(UInt256.MaxValue).Should().Be(UInt256MaxValue); - NumberBaseHelper - .CreateTruncating(BigInteger.Parse( - "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095")) - .Should().Be(MaxValue); - NumberBaseHelper.CreateTruncating(MaxValueAsDouble).Should().Be(MaxValue); - - NumberBaseHelper.CreateTruncating(byte.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(ushort.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(uint.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(ulong.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(UInt128.MinValue).Should().Be(Zero); - NumberBaseHelper.CreateTruncating(UInt256.MinValue).Should().Be(Zero); - } - - [Fact] - public static void CreateCheckedFromUInt512Test() - { - NumberBaseHelper.CreateChecked(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateChecked(UInt16MaxValue).Should().Be(ushort.MaxValue); - NumberBaseHelper.CreateChecked(UInt32MaxValue).Should().Be(uint.MaxValue); - NumberBaseHelper.CreateChecked(UInt64MaxValue).Should().Be(ulong.MaxValue); - NumberBaseHelper.CreateChecked(UInt128MaxValue).Should().Be(UInt128.MaxValue); - NumberBaseHelper.CreateChecked(UInt256MaxValue).Should().Be(UInt256.MaxValue); - NumberBaseHelper.CreateChecked(MaxValue).Should() - .Be(BigInteger.Parse( - "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095")); - NumberBaseHelper.CreateChecked(MaxValue).Should().Be(MaxValueAsDouble); - - NumberBaseHelper.CreateChecked(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateChecked(Zero).Should().Be(ushort.MinValue); - NumberBaseHelper.CreateChecked(Zero).Should().Be(uint.MinValue); - NumberBaseHelper.CreateChecked(Zero).Should().Be(ulong.MinValue); - NumberBaseHelper.CreateChecked(Zero).Should().Be(UInt128.MinValue); - NumberBaseHelper.CreateChecked(Zero).Should().Be(UInt256.MinValue); - } - [Fact] - public static void CreateSaturatingFromUInt512Test() - { - NumberBaseHelper.CreateSaturating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateSaturating(UInt16MaxValue).Should().Be(ushort.MaxValue); - NumberBaseHelper.CreateSaturating(UInt32MaxValue).Should().Be(uint.MaxValue); - NumberBaseHelper.CreateSaturating(UInt64MaxValue).Should().Be(ulong.MaxValue); - NumberBaseHelper.CreateSaturating(UInt128MaxValue).Should().Be(UInt128.MaxValue); - NumberBaseHelper.CreateSaturating(UInt256MaxValue).Should().Be(UInt256.MaxValue); - NumberBaseHelper.CreateSaturating(MaxValue).Should() - .Be(BigInteger.Parse( - "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095")); - NumberBaseHelper.CreateSaturating(MaxValue).Should().Be(MaxValueAsDouble); - - NumberBaseHelper.CreateSaturating(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateSaturating(Zero).Should().Be(ushort.MinValue); - NumberBaseHelper.CreateSaturating(Zero).Should().Be(uint.MinValue); - NumberBaseHelper.CreateSaturating(Zero).Should().Be(ulong.MinValue); - NumberBaseHelper.CreateSaturating(Zero).Should().Be(UInt128.MinValue); - NumberBaseHelper.CreateSaturating(Zero).Should().Be(UInt256.MinValue); - } - [Fact] - public static void CreateTruncatingFromUInt512Test() - { - NumberBaseHelper.CreateTruncating(ByteMaxValue).Should().Be(byte.MaxValue); - NumberBaseHelper.CreateTruncating(UInt16MaxValue).Should().Be(ushort.MaxValue); - NumberBaseHelper.CreateTruncating(UInt32MaxValue).Should().Be(uint.MaxValue); - NumberBaseHelper.CreateTruncating(UInt64MaxValue).Should().Be(ulong.MaxValue); - NumberBaseHelper.CreateTruncating(UInt128MaxValue).Should().Be(UInt128.MaxValue); - NumberBaseHelper.CreateTruncating(UInt256MaxValue).Should().Be(UInt256.MaxValue); - NumberBaseHelper.CreateTruncating(MaxValue).Should() - .Be(BigInteger.Parse( - "13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095")); - NumberBaseHelper.CreateTruncating(MaxValue).Should().Be(MaxValueAsDouble); - - NumberBaseHelper.CreateTruncating(Zero).Should().Be(byte.MinValue); - NumberBaseHelper.CreateTruncating(Zero).Should().Be(ushort.MinValue); - NumberBaseHelper.CreateTruncating(Zero).Should().Be(uint.MinValue); - NumberBaseHelper.CreateTruncating(Zero).Should().Be(ulong.MinValue); - NumberBaseHelper.CreateTruncating(Zero).Should().Be(UInt128.MinValue); - NumberBaseHelper.CreateTruncating(Zero).Should().Be(UInt256.MinValue); - } - - [Fact] - public static void IsCanonicalTest() - { - NumberBaseHelper.IsCanonical(default(UInt)).Should().BeTrue(); - } - - [Fact] - public static void IsComplexNumberTest() - { - NumberBaseHelper.IsComplexNumber(default(UInt)).Should().BeFalse(); - } - - [Fact] - public static void IsEvenIntegerTest() - { - NumberBaseHelper.IsEvenInteger(One).Should().BeFalse(); - NumberBaseHelper.IsEvenInteger(Two).Should().BeTrue(); - } - - [Fact] - public static void IsFiniteTest() - { - NumberBaseHelper.IsFinite(default(UInt)).Should().BeTrue(); - } - - [Fact] - public static void IsImaginaryNumberTest() - { - NumberBaseHelper.IsImaginaryNumber(default(UInt)).Should().BeFalse(); - } - - [Fact] - public static void IsInfinityTest() - { - NumberBaseHelper.IsInfinity(default(UInt)).Should().BeFalse(); - } - - [Fact] - public static void IsIntegerTest() - { - NumberBaseHelper.IsInteger(default(UInt)).Should().BeTrue(); - } - - [Fact] - public static void IsNaNTest() - { - NumberBaseHelper.IsNaN(default(UInt)).Should().BeFalse(); - } - - [Fact] - public static void IsNegativeTest() - { - NumberBaseHelper.IsNegative(One).Should().BeFalse(); - } - - [Fact] - public static void IsNegativeInfinityTest() - { - NumberBaseHelper.IsNegativeInfinity(One).Should().BeFalse(); - } - - [Fact] - public static void IsNormalTest() - { - NumberBaseHelper.IsNormal(Zero).Should().BeFalse(); - NumberBaseHelper.IsNormal(One).Should().BeTrue(); - } - - [Fact] - public static void IsOddIntegerTest() - { - NumberBaseHelper.IsOddInteger(One).Should().BeTrue(); - NumberBaseHelper.IsOddInteger(Two).Should().BeFalse(); - } - - [Fact] - public static void IsPositiveTest() - { - NumberBaseHelper.IsPositive(One).Should().BeTrue(); - } - - [Fact] - public static void IsPositiveInfinityTest() - { - NumberBaseHelper.IsPositiveInfinity(One).Should().BeFalse(); - } - - [Fact] - public static void IsRealNumberTest() - { - NumberBaseHelper.IsRealNumber(default).Should().BeTrue(); - } - - [Fact] - public static void IsSubnormalTest() - { - NumberBaseHelper.IsSubnormal(default).Should().BeFalse(); - } - - [Fact] - public static void IsZeroTest() - { - NumberBaseHelper.IsZero(default).Should().BeTrue(); - NumberBaseHelper.IsZero(Zero).Should().BeTrue(); - NumberBaseHelper.IsZero(One).Should().BeFalse(); - } - - [Fact] - public static void MaxMagnitudeTest() - { - NumberBaseHelper.MaxMagnitude(MaxValue, Zero).Should().Be(MaxValue); - NumberBaseHelper.MaxMagnitude(One, Zero).Should().Be(One); - NumberBaseHelper.MaxMagnitude(Two, Zero).Should().Be(Two); - } - - [Fact] - public static void MaxMagnitudeNumberTest() - { - NumberBaseHelper.MaxMagnitudeNumber(MaxValue, Zero).Should().Be(MaxValue); - NumberBaseHelper.MaxMagnitudeNumber(One, Zero).Should().Be(One); - NumberBaseHelper.MaxMagnitudeNumber(Two, Zero).Should().Be(Two); - } - - [Fact] - public static void MinMagnitudeTest() - { - NumberBaseHelper.MinMagnitude(MaxValue, MaxValueMinusOne).Should().Be(MaxValueMinusOne); - NumberBaseHelper.MinMagnitude(One, Zero).Should().Be(Zero); - NumberBaseHelper.MinMagnitude(Two, Zero).Should().Be(Zero); - } - - [Fact] - public static void MinMagnitudeNumberTest() - { - NumberBaseHelper.MinMagnitudeNumber(MaxValue, MaxValueMinusOne).Should().Be(MaxValueMinusOne); - NumberBaseHelper.MinMagnitudeNumber(One, Zero).Should().Be(Zero); - NumberBaseHelper.MinMagnitudeNumber(Two, Zero).Should().Be(Zero); - } - - [Fact] - public void ParseTest() - { - NumberBaseHelper.Parse("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.Parse(MaxValueBin, System.Globalization.NumberStyles.BinaryNumber, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - - Assert.Throws(() => NumberBaseHelper.Parse("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - } - - [Fact] - public void TryParseTest() - { - NumberBaseHelper.TryParse("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out UInt parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.TryParse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.TryParse(MaxValueBin, System.Globalization.NumberStyles.BinaryNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - - NumberBaseHelper.TryParse("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096", System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - } - - [Fact] - public void ParseUtf8Test() - { - NumberBaseHelper.Parse("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.Parse(MaxValueBinUtf8, System.Globalization.NumberStyles.BinaryNumber, CultureInfo.CurrentCulture) - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - - Assert.Throws(() => NumberBaseHelper.Parse("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture)); - } - - [Fact] - public void TryParseUtf8Test() - { - NumberBaseHelper.TryParse("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out UInt parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.TryParse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8, System.Globalization.NumberStyles.HexNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - NumberBaseHelper.TryParse(MaxValueBinUtf8, System.Globalization.NumberStyles.BinaryNumber, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - - NumberBaseHelper.TryParse("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096"u8, System.Globalization.NumberStyles.Integer, CultureInfo.CurrentCulture, out parsedValue) - .Should().BeFalse(); - parsedValue.Should().Be(default); - } - #endregion - - #region IPowerFunctions - [Fact] - public void PowTest() - { - GenericFloatingPointFunctions.Pow(Zero, (uint)int.MaxValue).Should().Be(Zero); - GenericFloatingPointFunctions.Pow(One, (uint)int.MaxValue).Should().Be(One); - GenericFloatingPointFunctions.Pow(MaxValue, Zero).Should().Be(One); - GenericFloatingPointFunctions.Pow(MaxValue, One).Should().Be(MaxValue); - GenericFloatingPointFunctions.Pow(Two, Two).Should().Be(4); - GenericFloatingPointFunctions.Pow(Two, 4U).Should().Be(16); - GenericFloatingPointFunctions.Pow(16U, Two).Should().Be(256); - GenericFloatingPointFunctions.Pow(Two, 511U) - .Should().Be(new UInt( - 0x8000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, - 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); - - Assert.Throws(() => GenericFloatingPointFunctions.Pow(Two, 512U)); - Assert.Throws(() => GenericFloatingPointFunctions.Pow(Two + Two, 511U)); - } - #endregion - } -} diff --git a/src/MissingValues.Tests/Core/UInt512Test.cs b/src/MissingValues.Tests/Core/UInt512Test.cs deleted file mode 100644 index f1f8110..0000000 --- a/src/MissingValues.Tests/Core/UInt512Test.cs +++ /dev/null @@ -1,259 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Text.Json; -using System.Text.Unicode; -using System.Threading.Tasks; - -using UInt = MissingValues.UInt512; - -namespace MissingValues.Tests.Core -{ - public partial class UInt512Test - { - [Fact] - public void Cast_ToByte() - { - byte.MinValue.Should().Be((byte)Zero); - byte.MaxValue.Should().Be((byte)ByteMaxValue); - } - - [Fact] - public void Cast_ToUInt16() - { - ushort.MinValue.Should().Be((ushort)Zero); - ushort.MaxValue.Should().Be((ushort)UInt16MaxValue); - } - - [Fact] - public void Cast_ToUInt32() - { - uint.MinValue.Should().Be((uint)Zero); - uint.MaxValue.Should().Be((uint)UInt32MaxValue); - } - - [Fact] - public void Cast_ToUInt64() - { - ulong.MinValue.Should().Be((ulong)Zero); - ulong.MaxValue.Should().Be((ulong)UInt64MaxValue); - } - - [Fact] - public void Cast_ToUInt128() - { - UInt128.MinValue.Should().Be((UInt128)Zero); - UInt128.MaxValue.Should().Be((UInt128)UInt128MaxValue); - } - - [Fact] - public void Cast_ToUInt256() - { - UInt256.MinValue.Should().Be((UInt256)Zero); - UInt256.MaxValue.Should().Be((UInt256)UInt256MaxValue); - } - - [Fact] - public void Cast_ToBigInteger() - { - BigInteger.One.Should().Be((BigInteger)One); - BigInteger.Parse("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095") - .Should().Be((BigInteger)MaxValue); - } - - [Fact] - public void Cast_ToDouble() - { - // Test a UInt256Converter value where _upper is 0 - UInt value1 = new UInt(UInt256.MaxValue); - double exp1 = System.Math.Round((double)UInt256.MaxValue, 5); - double act1 = System.Math.Round((double)value1, 5); - double diff1 = System.Math.Abs(exp1 * 0.00000000001); - Assert.True(System.Math.Abs(exp1 - act1) <= diff1); - - - // Test a UInt256Converter value where _upper is not 0 - UInt value2 = new UInt(UInt256.MaxValue, UInt256.MaxValue); - double exp2 = System.Math.Round(((double)UInt256.MaxValue) * System.Math.Pow(2.0, 256), 5); - double act2 = System.Math.Round((double)value2, 5); - double diff2 = System.Math.Abs(exp2 * 0.00000000001); - Assert.True(System.Math.Abs(exp2 - act2) <= diff2); - } - - [Fact] - public void BigMulTest() - { - UInt upper = UInt.BigMul(MaxValue, Two, out UInt lower); - - upper - .Should() - .Be(new(0x1)); - lower - .Should() - .Be(new(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFE)); - } - - [Fact] - public void Internal_DivRemTest() - { - const long Left = 101_000_000_000; - const long Right = 10_000_000_000; - const long Quotient = 10; - const long Remainder = 1_000_000_000; - - UInt a = Left; - UInt b = Right; - - UInt.DivRem(in a, in b, out UInt quotient, out UInt remainder); - - quotient.Should().Be(Quotient); - remainder.Should().Be(Remainder); - - UInt.DivRem(in a, in b, out a, out remainder); - - a.Should().Be(Quotient); - remainder.Should().Be(Remainder); - - UInt.DivRem(Left, in b, out quotient, out b); - - quotient.Should().Be(Quotient); - b.Should().Be(Remainder); - } - - [Fact] - public void BasicParseTest() - { - UInt.Parse("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095") - .Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - } - - [Fact] - public void BasicTryParseTest() - { - UInt.TryParse("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095", out UInt parsedValue).Should().BeTrue(); - parsedValue.Should().Be(MaxValue) - .And.BeRankedEquallyTo(MaxValue); - } - - [Fact] - public void ToDecStringTest() - { - Zero.ToString("D", CultureInfo.CurrentCulture) - .Should().Be("0"); - MaxValue.ToString("D", CultureInfo.CurrentCulture) - .Should().Be("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095"); - } - [Fact] - public void ToHexStringTest() - { - One.ToString("X", CultureInfo.CurrentCulture) - .Should().Be("1"); - ((UInt)byte.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("FF"); - ((UInt)ushort.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("FFFF"); - ((UInt)uint.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("FFFFFFFF"); - ((UInt)ulong.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("FFFFFFFFFFFFFFFF"); - ((UInt)UInt128.MaxValue).ToString("X", CultureInfo.CurrentCulture) - .Should().Be("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - - Zero.ToString("X128", CultureInfo.CurrentCulture) - .Should().Be("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); - MaxValue.ToString("x128", CultureInfo.CurrentCulture) - .Should().Be("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - MaxValue.ToString("X128", CultureInfo.CurrentCulture) - .Should().Be("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); - } - [Fact] - public void ToBinStringTest() - { - One.ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1"); - ((UInt)byte.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("11111111"); - ((UInt)ushort.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1111111111111111"); - ((UInt)uint.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("11111111111111111111111111111111"); - ((UInt)ulong.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("1111111111111111111111111111111111111111111111111111111111111111"); - ((UInt)UInt128.MaxValue).ToString("B", CultureInfo.CurrentCulture) - .Should().Be("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); - - Zero.ToString("B512", CultureInfo.CurrentCulture) - .Should() - .Be("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); - MaxValue.ToString("B512", CultureInfo.CurrentCulture) - .Should() - .Be("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"); - } - - [Fact] - public void ToDecFormatStringTest() - { - MaxValue.ToString().Should().Be($"{MaxValue:D}"); - } - [Fact] - public void ToHexFormatStringTest() - { - MaxValue.ToString("X128", CultureInfo.CurrentCulture).Should().Be($"{MaxValue:X128}"); - } - [Fact] - public void ToBinFormatStringTest() - { - MaxValue.ToString("B512", CultureInfo.CurrentCulture).Should().Be($"{MaxValue:B512}"); - } - - [Fact] - public void ToDecFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString()!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:D}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - [Fact] - public void ToHexFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString("X128", CultureInfo.CurrentCulture)!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:X128}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - [Fact] - public void ToBinFormatUtf8StringTest() - { - ReadOnlySpan toString = Encoding.UTF8.GetBytes(MaxValue.ToString("B512", CultureInfo.CurrentCulture)!); - - Span format = stackalloc byte[toString.Length]; - bool success = Utf8.TryWrite(format, CultureInfo.CurrentCulture, $"{MaxValue:B512}", out _); - Assert.Equal(toString, format); - success.Should().BeTrue(); - } - - [Fact] - public void JsonWriteTest() - { - JsonSerializer.Serialize(new object[] { MaxValue, Zero, One }) - .Should().Be("[13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095,0,1]"); - } - [Fact] - public void JsonReadTest() - { - JsonSerializer.Deserialize("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095") - .Should().Be(MaxValue); - JsonSerializer.Deserialize("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095"u8) - .Should().Be(MaxValue); - } - } -} diff --git a/src/MissingValues.Tests/Data/CalculatorDataSources.cs b/src/MissingValues.Tests/Data/CalculatorDataSources.cs new file mode 100644 index 0000000..895e89a --- /dev/null +++ b/src/MissingValues.Tests/Data/CalculatorDataSources.cs @@ -0,0 +1,475 @@ +using MissingValues.Internals; + +namespace MissingValues.Tests.Data; + +public class CalculatorDataSources +{ + public static IEnumerable> Log10TestData() + { + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x0000000000000001), 0); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x000000000000000A), 1); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x0000000000000064), 2); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x00000000000003E8), 3); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x0000000000002710), 4); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x00000000000186A0), 5); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x00000000000F4240), 6); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x0000000000989680), 7); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x0000000005F5E100), 8); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x000000003B9ACA00), 9); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x00000002540BE400), 10); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x000000174876E800), 11); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x000000E8D4A51000), 12); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x000009184E72A000), 13); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x00005AF3107A4000), 14); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x00038D7EA4C68000), 15); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x002386F26FC10000), 16); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x016345785D8A0000), 17); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x0DE0B6B3A7640000), 18); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000000, 0x8AC7230489E80000), 19); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000005, 0x6BC75E2D63100000), 20); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000000036, 0x35C9ADC5DEA00000), 21); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x000000000000021E, 0x19E0C9BAB2400000), 22); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x000000000000152D, 0x02C7E14AF6800000), 23); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x000000000000D3C2, 0x1BCECCEDA1000000), 24); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000000084595, 0x161401484A000000), 25); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x000000000052B7D2, 0xDCC80CD2E4000000), 26); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x00000000033B2E3C, 0x9FD0803CE8000000), 27); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x00000000204FCE5E, 0x3E25026110000000), 28); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x00000001431E0FAE, 0x6D7217CAA0000000), 29); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000000C9F2C9CD0, 0x4674EDEA40000000), 30); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000007E37BE2022, 0xC0914B2680000000), 31); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x000004EE2D6D415B, 0x85ACEF8100000000), 32); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0000314DC6448D93, 0x38C15B0A00000000), 33); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0001ED09BEAD87C0, 0x378D8E6400000000), 34); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0013426172C74D82, 0x2B878FE800000000), 35); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x00C097CE7BC90715, 0xB34B9F1000000000), 36); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x0785EE10D5DA46D9, 0x00F436A000000000), 37); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000000, 0x4B3B4CA85A86C47A, 0x098A224000000000), 38); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000002, 0xF050FE938943ACC4, 0x5F65568000000000), 39); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x000000000000001D, 0x6329F1C35CA4BFAB, 0xB9F5610000000000), 40); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000125, 0xDFA371A19E6F7CB5, 0x4395CA0000000000), 41); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000000B7A, 0xBC627050305ADF14, 0xA3D9E40000000000), 42); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x00000000000072CB, 0x5BD86321E38CB6CE, 0x6682E80000000000), 43); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000000047BF1, 0x9673DF52E37F2410, 0x011D100000000000), 44); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x00000000002CD76F, 0xE086B93CE2F768A0, 0x0B22A00000000000), 45); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x0000000001C06A5E, 0xC5433C60DDAA1640, 0x6F5A400000000000), 46); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x00000000118427B3, 0xB4A05BC8A8A4DE84, 0x5986800000000000), 47); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x00000000AF298D05, 0x0E4395D69670B12B, 0x7F41000000000000), 48); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x00000006D79F8232, 0x8EA3DA61E066EBB2, 0xF88A000000000000), 49); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x000000446C3B15F9, 0x926687D2C40534FD, 0xB564000000000000), 50); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x000002AC3A4EDBBF, 0xB8014E3BA83411E9, 0x15E8000000000000), 51); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x00001ABA4714957D, 0x300D0E549208B31A, 0xDB10000000000000), 52); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x00010B46C6CDD6E3, 0xE0828F4DB456FF0C, 0x8EA0000000000000), 53); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x000A70C3C40A64E6, 0xC51999090B65F67D, 0x9240000000000000), 54); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x006867A5A867F103, 0xB2FFFA5A71FBA0E7, 0xB680000000000000), 55); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x04140C78940F6A24, 0xFDFFC78873D4490D, 0x2100000000000000), 56); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, + 0x28C87CB5C89A2571, 0xEBFDCB54864ADA83, 0x4A00000000000000), 57); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000001, + 0x97D4DF19D6057673, 0x37E9F14D3EEC8920, 0xE400000000000000), 58); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000000000000000F, + 0xEE50B7025C36A080, 0x2F236D04753D5B48, 0xE800000000000000), 59); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000000000000009F, + 0x4F2726179A224501, 0xD762422C946590D9, 0x1000000000000000), 60); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000639, + 0x17877CEC0556B212, 0x69D695BDCBF7A87A, 0xA000000000000000), 61); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000003E3A, + 0xEB4AE1383562F4B8, 0x2261D969F7AC94CA, 0x4000000000000000), 62); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000026E4D, + 0x30ECCC3215DD8F31, 0x57D27E23ACBDCFE6, 0x8000000000000000), 63); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000184F03, + 0xE93FF9F4DAA797ED, 0x6E38ED64BF6A1F01, 0x0000000000000000), 64); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000F31627, + 0x1C7FC3908A8BEF46, 0x4E3945EF7A25360A, 0x0000000000000000), 65); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00000000097EDD87, + 0x1CFDA3A5697758BF, 0x0E3CBB5AC5741C64, 0x0000000000000000), 66); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000000005EF4A747, + 0x21E864761EA97776, 0x8E5F518BB6891BE8, 0x0000000000000000), 67); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00000003B58E88C7, + 0x5313EC9D329EAAA1, 0x8FB92F75215B1710, 0x0000000000000000), 68); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00000025179157C9, + 0x3EC73E23FA32AA4F, 0x9D3BDA934D8EE6A0, 0x0000000000000000), 69); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00000172EBAD6DDC, + 0x73C86D67C5FAA71C, 0x245689C107950240, 0x0000000000000000), 70); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00000E7D34C64A9C, + 0x85D4460DBBCA8719, 0x6B61618A4BD21680, 0x0000000000000000), 71); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000090E40FBEEA1D, + 0x3A4ABC8955E946FE, 0x31CDCF66F634E100, 0x0000000000000000), 72); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0005A8E89D752524, + 0x46EB5D5D5B1CC5ED, 0xF20A1A059E10CA00, 0x0000000000000000), 73); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x003899162693736A, + 0xC531A5A58F1FBB4B, 0x746504382CA7E400, 0x0000000000000000), 74); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0235FADD81C2822B, + 0xB3F07877973D50F2, 0x8BF22A31BE8EE800, 0x0000000000000000), 75); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x161BCCA7119915B5, + 0x0764B4ABE8652979, 0x7775A5F171951000, 0x0000000000000000), 76); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0xDD15FE86AFFAD912, + 0x49EF0EB713F39EBE, 0xAA987B6E6FD2A000, 0x0000000000000000), 77); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000008, 0xA2DBF142DFCC7AB6, + 0xE3569326C7843372, 0xA9F4D2505E3A4000, 0x0000000000000000), 78); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000056, 0x5C976C9CBDFCCB24, + 0xE161BF83CB2A027A, 0xA3903723AE468000, 0x0000000000000000), 79); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000000000000035F, 0x9DEA3E1F6BDFEF70, + 0xCDD17B25EFA418CA, 0x63A22764CEC10000, 0x0000000000000000), 80); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00000000000021BC, 0x2B266D3A36BF5A68, + 0x0A2ECF7B5C68F7E7, 0xE45589F0138A0000, 0x0000000000000000), 81); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000015159, 0xAF80444623798810, + 0x65D41AD19C19AF0E, 0xEB576360C3640000, 0x0000000000000000), 82); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00000000000D2D80, 0xDB02AABD62BF50A3, + 0xFA490C301900D695, 0x3169E1C7A1E80000, 0x0000000000000000), 83); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000000000083C708, 0x8E1AAB65DB792667, + 0xC6DA79E0FA0861D3, 0xEE22D1CC53100000, 0x0000000000000000), 84); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000000000525C655, 0x8D0AB1FA92BB800D, + 0xC488C2C9C453D247, 0x4D5C31FB3EA00000, 0x0000000000000000), 85); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000000003379BF57, 0x826AF3C9BB530089, + 0xAD579BE1AB4636C9, 0x0599F3D072400000, 0x0000000000000000), 86); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000202C1796B, 0x182D85E1513E0560, + 0xC56C16D0B0BE23DA, 0x3803862476800000, 0x0000000000000000), 87); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000000141B8EBE2E, 0xF1C73ACD2C6C35C7, + 0xB638E426E76D6686, 0x30233D6CA1000000, 0x0000000000000000), 88); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000000C913936DD5, 0x71C84C03BC3A19CD, + 0x1E38E9850A46013D, 0xE160663E4A000000, 0x0000000000000000), 89); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x000007DAC3C24A56, 0x71D2F8255A450203, + 0x2E391F3266BC0C6A, 0xCDC3FE6EE4000000, 0x0000000000000000), 90); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00004E8BA596E760, 0x723DB17586B2141F, + 0xCE3B37F803587C2C, 0x09A7F054E8000000, 0x0000000000000000), 91); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0003117477E509C4, 0x7668EE9742F4C93E, + 0x0E502FB02174D9B8, 0x608F635110000000, 0x0000000000000000), 92); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x001EAE8CAEF261AC, 0xA01951E89D8FDC6C, + 0x8F21DCE14E908133, 0xC599E12AA0000000, 0x0000000000000000), 93); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0132D17ED577D0BE, 0x40FD3316279E9C3D, + 0x9752A0CD11A50C05, 0xB802CBAA40000000, 0x0000000000000000), 94); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0BFC2EF456AE276E, 0x89E3FEDD8C321A67, + 0xE93A4802B0727839, 0x301BF4A680000000, 0x0000000000000000), 95); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x77D9D58B62CD8A51, 0x62E7F4A779F5080F, + 0x1C46D01AE478B23B, 0xE1178E8100000000, 0x0000000000000000), 96); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000000004, 0xAE825771DC07672D, 0xDD0F8E8AC3925097, + 0x1AC4210CECB6F656, 0xCAEB910A00000000, 0x0000000000000000), 97); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x000000000000002E, 0xD1176A72984A07CA, 0xA29B916BA3B725E7, + 0x0BA94A813F259F63, 0xED33AA6400000000, 0x0000000000000000), 98); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x00000000000001D4, 0x2AEA2879F2E44DEA, 0x5A13AE3465277B06, + 0x749CE90C777839E7, 0x4404A7E800000000, 0x0000000000000000), 99); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000001249, 0xAD2594C37CEB0B27, 0x84C4CE0BF38ACE40, + 0x8E211A7CAAB24308, 0xA82E8F1000000000, 0x0000000000000000), 100); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x000000000000B6E0, 0xC377CFA2E12E6F8B, 0x2FB00C77836C0E85, + 0x8D4B08DEAAF69E56, 0x91D196A000000000, 0x0000000000000000), 101); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x00000000000724C7, 0xA2AE1C5CCBD05B6F, 0xDCE07CAB22389137, + 0x84EE58B2ADA22F61, 0xB22FE24000000000, 0x0000000000000000), 102); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000000476FCC, 0x5ACD1B9FF623925E, 0xA0C4DEAF5635AC2B, + 0x314F76FAC855D9D0, 0xF5DED68000000000, 0x0000000000000000), 103); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000002CA5DFB, 0x8C03143F9D63B7B2, 0x47B0B2D95E18B9AF, + 0xED1AA5CBD35A8229, 0x9AB4610000000000, 0x0000000000000000), 104); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x000000001BE7ABD3, 0x781ECA7C25E52CF6, 0xCCE6FC7DACF740DF, + 0x430A79F6418915A0, 0x0B0BCA0000000000, 0x0000000000000000), 105); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x00000001170CB642, 0xB133E8D97AF3C1A4, 0x0105DCE8C1A888B8, + 0x9E68C39E8F5AD840, 0x6E75E40000000000, 0x0000000000000000), 106); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000000AE67F1E9A, 0xEC07187ECD859068, 0x0A3AA11790955736, + 0x3017A431998C7284, 0x509AE80000000000, 0x0000000000000000), 107); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000006D00F7320D, 0x3846F4F40737A410, 0x664A4AEBA5D5681D, + 0xE0EC69EFFF7C792B, 0x260D100000000000, 0x0000000000000000), 108); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0000044209A7F484, 0x32C59188482C68A3, 0xFEE6ED347A56112A, + 0xC93C235FFADCBBAF, 0x7C82A00000000000, 0x0000000000000000), 109); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x00002A94608F8D29, 0xFBB7AF52D1BC1667, 0xF505440CC75CABAB, + 0xDC5961BFCC9F54DA, 0xDD1A400000000000, 0x0000000000000000), 110); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0001A9CBC59B83A3, 0xD52CD93C3158E00F, 0x9234A87FC99EB4B6, + 0x9B7DD17DFE39508C, 0xA306800000000000, 0x0000000000000000), 111); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x0010A1F5B8132466, 0x53C07C59ED78C09B, 0xB60E94FDE0330F22, + 0x12EA2EEBEE3D257E, 0x5E41000000000000, 0x0000000000000000), 112); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x00A6539930BF6BFF, 0x4584DB8346B78615, 0x1C91D1EAC1FE9754, + 0xBD25D5374E6376EF, 0xAE8A000000000000, 0x0000000000000000), 113); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x067F43FBE77A37F8, 0xB7309320C32B3CD3, 0x1DB2332B93F1E94F, + 0x637A54290FE2A55C, 0xD164000000000000, 0x0000000000000000), 114); + yield return () => ( + new(0x0000000000000000, 0x0000000000000000, 0x40F8A7D70AC62FB7, 0x27E5BF479FB0603F, 0x28F5FFB3C7731D19, + 0xE2C7499A9EDA75A0, 0x2DE8000000000000, 0x0000000000000000), 115); + yield return () => ( + new(0x0000000000000000, 0x0000000000000002, 0x89B68E666BBDDD27, 0x8EF978CC3CE3C277, 0x999BFD05CA7F2302, + 0xDBC8E00A34889841, 0xCB10000000000000, 0x0000000000000000), 116); + yield return () => ( + new(0x0000000000000000, 0x0000000000000019, 0x61219000356AA38B, 0x95BEB7FA60E598AC, 0x0017E239E8F75E1C, + 0x95D8C0660D55F291, 0xEEA0000000000000, 0x0000000000000000), 117); + yield return () => ( + new(0x0000000000000000, 0x00000000000000FD, 0xCB4FA002162A6373, 0xD9732FC7C8F7F6B8, 0x00EED64319A9AD1D, + 0xDA7783FC855B79B3, 0x5240000000000000, 0x0000000000000000), 118); + yield return () => ( + new(0x0000000000000000, 0x00000000000009E9, 0xF11C4014DDA7E286, 0x7E7FDDCDD9AFA330, 0x09545E9F00A0C32A, + 0x88AB27DD3592C101, 0x3680000000000000, 0x0000000000000000), 119); + yield return () => ( + new(0x0000000000000000, 0x0000000000006323, 0x6B1A80D0A88ED940, 0xF0FEAA0A80DC5FE0, 0x5D4BB23606479FA9, + 0x56AF8EA417BB8A0C, 0x2100000000000000, 0x0000000000000000), 120); + yield return () => ( + new(0x0000000000000000, 0x000000000003DF62, 0x2F09082695947C89, 0x69F2A469089BBEC3, 0xA4F4F61C3ECC3C9D, + 0x62DB9268ED536479, 0x4A00000000000000, 0x0000000000000000), 121); + yield return () => ( + new(0x0000000000000000, 0x000000000026B9D5, 0xD65A5181D7CCDD5E, 0x237A6C1A561573A4, 0x71919D1A73FA5E25, + 0xDC93B8194541ECBC, 0xE400000000000000, 0x0000000000000000), 122); + yield return () => ( + new(0x0000000000000000, 0x000000000183425A, 0x5F872F126E00A5AD, 0x62C839075CD6846C, 0x6FB0230887C7AD7A, + 0x9DC530FCB4933F60, 0xE800000000000000, 0x0000000000000000), 123); + yield return () => ( + new(0x0000000000000000, 0x000000000F209787, 0xBB47D6B84C0678C5, 0xDBD23A49A0612C3C, 0x5CE15E554DCCC6CA, + 0x29B3E9DF0DC079C9, 0x1000000000000000, 0x0000000000000000), 124); + yield return () => ( + new(0x0000000000000000, 0x000000009745EB4D, 0x50CE6332F840B7BA, 0x963646E043CBBA5B, 0xA0CDAF5509FFC3E5, + 0xA10722B68984C1DA, 0xA000000000000000, 0x0000000000000000), 125); + yield return () => ( + new(0x0000000000000000, 0x00000005E8BB3105, 0x280FDFFDB2872D49, 0xDE1EC4C2A5F54794, 0x4808D95263FDA6F8, + 0x4A475B215F2F928A, 0x4000000000000000, 0x0000000000000000), 126); + yield return () => ( + new(0x0000000000000000, 0x0000003B174FEA33, 0x909EBFE8F947C4E2, 0xAD33AF9A7B94CBCA, 0xD0587D37E7E885B2, + 0xE6C98F4DB7DBB966, 0x8000000000000000, 0x0000000000000000), 127); + yield return () => ( + new(0x0000000000000000, 0x0000024EE91F2603, 0xA6337F19BCCDB0DA, 0xC404DC08D3CFF5EC, 0x2374E42F0F1538FD, + 0x03DF99092E953E01, 0x0000000000000000, 0x0000000000000000), 128); + yield return () => ( + new(0x0000000000000000, 0x000017151B377C24, 0x7E02F7016008E88B, 0xA8309858461F9B39, 0x6290E9D696D439E2, + 0x26BBFA5BD1D46C0A, 0x0000000000000000, 0x0000000000000000), 129); + yield return () => ( + new(0x0000000000000000, 0x0000E6D3102AD96C, 0xEC1DA60DC0591574, 0x91E5F372BD3C103D, 0xD9A92261E44A42D5, + 0x8357C796324C3864, 0x0000000000000000, 0x0000000000000000), 130); + yield return () => ( + new(0x0000000000000000, 0x0009043EA1AC7E41, 0x39287C89837AD68D, 0xB2FB827B6458A26A, 0x809B57D2EAE69C57, + 0x216DCBDDF6FA33E8, 0x0000000000000000, 0x0000000000000000), 131); + yield return () => ( + new(0x0000000000000000, 0x005A2A7250BCEE8C, 0x3B94DD5F22CC6188, 0xFDD318D1EB765829, 0x06116E3D2D021B67, + 0x4E49F6ABA5C60710, 0x0000000000000000, 0x0000000000000000), 132); + yield return () => ( + new(0x0000000000000000, 0x0385A8772761517A, 0x53D0A5B75BFBCF59, 0xEA3EF833329F719A, 0x3CAE4E63C2151209, + 0x0EE3A2B479BC46A0, 0x0000000000000000, 0x0000000000000000), 133); + yield return () => ( + new(0x0000000000000000, 0x233894A789CD2EC7, 0x4626792997D61983, 0x2675B1FFFA3A7006, 0x5ECF0FE594D2B45A, + 0x94E45B0CC15AC240, 0x0000000000000000, 0x0000000000000000), 134); + yield return () => ( + new(0x0000000000000001, 0x6035CE8B6203D3C8, 0xBD80BB9FEE5CFF1F, 0x8098F3FFC648603F, 0xB4169EF7D03B0B89, + 0xD0EB8E7F8D8B9680, 0x0000000000000000, 0x0000000000000000), 135); + yield return () => ( + new(0x000000000000000D, 0xC21A1171D42645D7, 0x6707543F4FA1F73B, 0x05F987FDBED3C27D, 0x08E235AE224E7362, + 0x293390FB8773E100, 0x0000000000000000, 0x0000000000000000), 136); + yield return () => ( + new(0x0000000000000089, 0x9504AE72497EBA6A, 0x06494A791C53A84E, 0x3BBF4FE9744598E2, 0x58D618CD571081D5, + 0x9C03A9D34A86CA00, 0x0000000000000000, 0x0000000000000000), 137); + yield return () => ( + new(0x000000000000055F, 0xD22ED076DEF34824, 0x3EDCE8BB1B44930E, 0x55791F1E8AB7F8D7, 0x785CF80566A51258, + 0x1824A240E943E400, 0x0000000000000000, 0x0000000000000000), 138); + yield return () => ( + new(0x00000000000035BE, 0x35D424A4B580D16A, 0x74A1174F10ADBE8F, 0x56BB37316B2FB86A, 0xB3A1B0360272B770, + 0xF16E56891CA6E800, 0x0000000000000000, 0x0000000000000000), 139); + yield return () => ( + new(0x000000000002196E, 0x1A496E6F17082E28, 0x8E4AE916A6C97199, 0x635027EE2FDD342B, 0x0450E21C187B2A69, + 0x6E4F615B1E851000, 0x0000000000000000, 0x0000000000000000), 140); + yield return () => ( + new(0x000000000014FE4D, 0x06DE5056E651CD95, 0x8EED1AE283DE6FFD, 0xE1218F4DDEA409AE, 0x2B28D518F4CFA81E, + 0x4F19CD8F3132A000, 0x0000000000000000, 0x0000000000000000), 141); + yield return () => ( + new(0x0000000000D1EF02, 0x44AF2364FF3207D7, 0x95430CD926B05FEA, 0xCB4F990AB26860CD, 0xAF9852F9901C912F, + 0x17020797EBFA4000, 0x0000000000000000, 0x0000000000000000), 142); + yield return () => ( + new(0x0000000008335616, 0xAED761F1F7F44E6B, 0xD49E807B82E3BF2B, 0xF11BFA6AF813C808, 0xDBF33DBFA11DABD6, + 0xE6144BEF37C68000, 0x0000000000000000, 0x0000000000000000), 143); + yield return () => ( + new(0x0000000052015CE2, 0xD469D373AF8B1036, 0x4E3104D31CE577B7, 0x6B17C82DB0C5D058, 0x9780697C4B28B664, + 0xFCCAF7582DC10000, 0x0000000000000000, 0x0000000000000000), 144); + yield return () => ( + new(0x00000003340DA0DC, 0x4C224284DB6EA21F, 0x0DEA303F20F6AD2A, 0x2EEDD1C8E7BA2375, 0xEB041EDAEF971FF1, + 0xDFEDA971C98A0000, 0x0000000000000000, 0x0000000000000000), 145); + yield return () => ( + new(0x000000200888489A, 0xF956993092525536, 0x8B25E27749A2C3A5, 0xD54A31D90D45629B, 0x2E29348D5BE73F72, + 0xBF489E71DF640000, 0x0000000000000000, 0x0000000000000000), 146); + yield return () => ( + new(0x000001405552D60D, 0xBD61FBE5B7375421, 0x6F7AD8A8E05BA47A, 0x54E5F27A84B5DA0F, 0xCD9C0D8597087A7B, + 0x78D63072B9E80000, 0x0000000000000000, 0x0000000000000000), 147); + yield return () => ( + new(0x00000C83553C5C89, 0x65D3D6F92829494E, 0x5ACC7698C3946CC7, 0x50FB78C92F1A849E, 0x08188737E654C8D2, + 0xB85DE47B43100000, 0x0000000000000000, 0x0000000000000000), 148); + yield return () => ( + new(0x00007D21545B9D5D, 0xFA4665BB919CDD0F, 0x8BFCA1F7A3CC3FC9, 0x29D2B7DBD7092E2C, 0x50F5482EFF4FD83B, + 0x33AAECD09EA00000, 0x0000000000000000, 0x0000000000000000), 149); + yield return () => ( + new(0x0004E34D4B9425AB, 0xC6BFF953B020A29B, 0x77DE53AC65FA7DDB, 0xA23B2E96665BCDBB, 0x2994D1D5F91E7250, + 0x04AD402632400000, 0x0000000000000000, 0x0000000000000000), 150); + yield return () => ( + new(0x0030E104F3C978B5, 0xC37FBD44E1465A12, 0xAEAF44BBFBC8EA94, 0x564FD1DFFF96094F, 0x9FD0325BBB307720, + 0x2EC4817DF6800000, 0x0000000000000000, 0x0000000000000000), 151); + yield return () => ( + new(0x01E8CA3185DEB719, 0xA2FD64B0CCBF84BA, 0xD2D8AF57D5D929CB, 0x5F1E32BFFBDC5D1C, 0x3E21F7954FE4A741, + 0xD3AD0EEBA1000000, 0x0000000000000000, 0x0000000000000000), 152); + yield return () => ( + new(0x1317E5EF3AB32700, 0x5DE5EEE7FF7B2F4C, 0x3C76D96E5A7BA1F1, 0xB72DFB7FD69BA31A, 0x6D53ABD51EEE8892, + 0x44C295344A000000, 0x0000000000000000, 0x0000000000000000), 153); + yield return () => ( + new(0xBEEEFB584AFF8603, 0xAAFB550FFACFD8FA, 0x5CA47E4F88D45371, 0x27CBD2FE62145F08, 0x4544B653355155B6, + 0xAF99D40AE4000000, 0x0000000000000000, 0x0000000000000000), 154); + } +} diff --git a/src/MissingValues.Tests/Data/Int256DataSources.cs b/src/MissingValues.Tests/Data/Int256DataSources.cs new file mode 100644 index 0000000..034c625 --- /dev/null +++ b/src/MissingValues.Tests/Data/Int256DataSources.cs @@ -0,0 +1,1645 @@ +using System.Globalization; +using System.Runtime.CompilerServices; +using MissingValues.Tests.Data.Sources; + +namespace MissingValues.Tests.Data; + +public class Int256DataSources + : IMathOperatorsDataSource, + IShiftOperatorsDataSource, + IBitwiseOperatorsDataSource, + IEqualityOperatorsDataSource, + IComparisonOperatorsDataSource, + INumberBaseDataSource, + INumberDataSource, + IBinaryNumberDataSource, + IBinaryIntegerDataSource +{ + public static IEnumerable> op_AdditionTestData() + { + yield return () => (Int256.Zero, Int256.Zero, Int256.Zero); + yield return () => (Int256.One, Int256.Zero, Int256.One); + yield return () => (Int256.One, Int256.One, new Int256(0, 0, 0, 2)); + yield return () => (new Int256(0, 0, 1, ulong.MaxValue), new Int256(0, 0, 1, 1), new Int256(0, 0, 3, 0)); + yield return () => (new Int256(0, 1, ulong.MaxValue, ulong.MaxValue), new Int256(0, 1, 1, 1), new Int256(0, 3, 1, 0)); + yield return () => (new Int256(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new Int256(1, 1, 1, 1), new Int256(3, 1, 1, 0)); + yield return () => (Int256.MaxValue, Int256.One, Int256.MinValue); + yield return () => (Int256.NegativeOne, Int256.One, Int256.Zero); + } + + public static IEnumerable> op_CheckedAdditionTestData() + { + yield return () => (Int256.Zero, Int256.Zero, Int256.Zero, false); + yield return () => (Int256.One, Int256.Zero, Int256.One, false); + yield return () => (Int256.One, Int256.One, new Int256(0, 0, 0, 2), false); + yield return () => (new Int256(0, 0, 1, ulong.MaxValue), new Int256(0, 0, 1, 1), new Int256(0, 0, 3, 0), false); + yield return () => (new Int256(0, 1, ulong.MaxValue, ulong.MaxValue), new Int256(0, 1, 1, 1), new Int256(0, 3, 1, 0), false); + yield return () => (new Int256(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new Int256(1, 1, 1, 1), new Int256(3, 1, 1, 0), false); + yield return () => (Int256.MaxValue, Int256.One, Int256.MinValue, true); + yield return () => (Int256.NegativeOne, Int256.One, Int256.Zero, false); + yield return () => (Int256.MinValue, Int256.NegativeOne, Int256.MaxValue, true); + } + + public static IEnumerable> op_CheckedDecrementTestData() + { + yield return () => (Int256.Zero, Int256.NegativeOne, false); + yield return () => (Int256.One, Int256.Zero, false); + yield return () => (new Int256(0, 0, 0, 2), new Int256(0, 0, 0, 1), false); + yield return () => (new Int256(0, 0, 1, 0), new Int256(0, 0, 0, ulong.MaxValue), false); + yield return () => (new Int256(0, 1, 0, 0), new Int256(0, 0, ulong.MaxValue, ulong.MaxValue), false); + yield return () => (new Int256(1, 0, 0, 0), new Int256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), false); + yield return () => (Int256.MinValue, Int256.MaxValue, true); + } + + public static IEnumerable> op_CheckedIncrementTestData() + { + yield return () => (Int256.Zero, Int256.One, false); + yield return () => (Int256.One, new Int256(0, 0, 0, 2), false); + yield return () => (Int256.MaxValue, Int256.Zero, true); + yield return () => (Int256.NegativeOne, Int256.Zero, false); + yield return () => (new Int256(0, 0, 0, ulong.MaxValue), new Int256(0, 0, 1, 0), false); + yield return () => (new Int256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new Int256(1, 0, 0, 0), false); + yield return () => (new Int256(unchecked((ulong)-123456789), 987654321, 555555555, 999999999), new Int256(unchecked((ulong)-123456789), 987654321, 555555555, 1000000000), false); + } + + public static IEnumerable> op_CheckedMultiplyTestData() + { + yield return () => (Int256.Zero, Int256.Zero, Int256.Zero, false); + yield return () => (Int256.One, Int256.One, Int256.One, false); + yield return () => (Int256.One, Int256.NegativeOne, Int256.NegativeOne, false); + yield return () => (Int256.NegativeOne, Int256.NegativeOne, Int256.One, false); + yield return () => (new Int256(0, 0, 0, 2), new Int256(0, 0, 0, 3), new Int256(0, 0, 0, 6), false); + yield return () => (Int256.MaxValue, Int256.One, Int256.MaxValue, false); + yield return () => (Int256.MaxValue, new Int256(0, 0, 0, 2), default, true); + yield return () => (Int256.MinValue, Int256.NegativeOne, default, true); + yield return () => (new Int256(0, 0, 0, ulong.MaxValue), new Int256(0, 0, 0, ulong.MaxValue), new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFE, 0x0000_0000_0000_0001), false); + yield return () => (new Int256(ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new Int256(2, 0, 0, 0), new Int256(0xFFFF_FFFF_FFFF_FFFE, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), false); + yield return () => (new Int256(long.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new Int256(2, 0, 0, 0), default, true); + } + + public static IEnumerable> op_CheckedSubtractionTestData() + { + yield return () => (Int256.Zero, Int256.Zero, Int256.Zero, false); + yield return () => (Int256.One, Int256.Zero, Int256.One, false); + yield return () => (Int256.One, Int256.One, Int256.Zero, false); + yield return () => (new Int256(0, 0, 0, 2), Int256.One, Int256.One, false); + yield return () => (new Int256(0, 0, 1, 0), new Int256(0, 0, 0, 1), new Int256(0, 0, 0, ulong.MaxValue), false); + yield return () => (new Int256(0, 1, 0, 0), new Int256(0, 0, ulong.MaxValue, ulong.MaxValue), new Int256(0, 0, 0, 1), false); + yield return () => (Int256.MinValue, Int256.One, Int256.MaxValue, true); + yield return () => (Int256.MaxValue, Int256.NegativeOne, Int256.MinValue, true); + } + + public static IEnumerable> op_DecrementTestData() + { + yield return () => (Int256.Zero, Int256.NegativeOne); + yield return () => (Int256.One, Int256.Zero); + yield return () => (new Int256(0, 0, 0, 2), new Int256(0, 0, 0, 1)); + yield return () => (new Int256(0, 0, 1, 0), new Int256(0, 0, 0, ulong.MaxValue)); + yield return () => (new Int256(0, 1, 0, 0), new Int256(0, 0, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new Int256(1, 0, 0, 0), new Int256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + yield return () => (Int256.MinValue, Int256.MaxValue); + } + + public static IEnumerable> op_DivisionTestData() + { + yield return () => (Int256.Zero, Int256.One, Int256.Zero); + yield return () => (Int256.One, Int256.One, Int256.One); + yield return () => (Int256.One, Int256.NegativeOne, Int256.NegativeOne); + yield return () => (Int256.NegativeOne, Int256.One, Int256.NegativeOne); + yield return () => (new Int256(0, 0, 0, 4), new Int256(0, 0, 0, 2), new Int256(0, 0, 0, 2)); + yield return () => (Int256.MaxValue, Int256.One, Int256.MaxValue); + yield return () => (Int256.MinValue, Int256.One, Int256.MinValue); + yield return () => (Int256.Zero, Int256.MaxValue, Int256.Zero); + yield return () => (Int256.MaxValue, Int256.MaxValue, Int256.One); + yield return () => (Int256.MinValue, Int256.MinValue, Int256.One); + yield return () => (new Int256(0, 0, 1, 0), new Int256(0, 1, 0, 0), Int256.Zero); + yield return () => (new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000), new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000)); + yield return () => (new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x0000_0000_0000_0000), new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x0000_0000_0000_0000)); + yield return () => (new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000), new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x0000_0000_0000_0000)); + yield return () => (new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x0000_0000_0000_0000), new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000)); + yield return () => (new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x0000_0000_0000_0000), new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000)); + yield return () => (new Int256(0x7FFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new Int256(0, 0, 0, 10), new Int256(0x0CCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC)); + yield return () => (new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x8000_0000_0000_0000, 0x0000_0000_0000_0000), new Int256(0, 0, 0, 10), new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0CCC_CCCC_CCCC_CCCC, 0xCCCC_CCCC_CCCC_CCCC)); + yield return () => (new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0x8000_0000_0000_0000, 0x0000_0000_0000_0000), new Int256(0, 0, 0, 10), new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xF333_3333_3333_3333, 0x3333_3333_3333_3334)); + } + + public static IEnumerable> op_IncrementTestData() + { + yield return () => (Int256.Zero, Int256.One); + yield return () => (Int256.One, new Int256(0, 0, 0, 2)); + yield return () => (Int256.MaxValue, Int256.MinValue); + yield return () => (Int256.NegativeOne, Int256.Zero); + yield return () => (new Int256(0, 0, 0, ulong.MaxValue), new Int256(0, 0, 1, 0)); + yield return () => (new Int256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new Int256(1, 0, 0, 0)); + yield return () => (new Int256(123456789, 987654321, 555555555, 999999999), new Int256(123456789, 987654321, 555555555, 1000000000)); + yield return () => (new Int256(0x8000000000000000, 0, 0, 0),new Int256(0x8000000000000000, 0, 0, 1)); + } + + public static IEnumerable> op_ModulusTestData() + { + yield return () => (Int256.Zero, Int256.One, Int256.Zero); + yield return () => (Int256.One, Int256.One, Int256.Zero); + yield return () => (new Int256(0, 0, 0, 123456789), Int256.One, Int256.Zero); + yield return () => (Int256.MaxValue, Int256.MaxValue, Int256.Zero); + yield return () => (new Int256(0, 0, 1, 0), new Int256(0, 1, 0, 0), new Int256(0, 0, 1, 0)); + yield return () => (new Int256(0, 0, 0, 10), new Int256(0, 0, 0, 3), new Int256(0, 0, 0, 1)); + yield return () => (new Int256(0, 0, 0, 15), new Int256(0, 0, 0, 5), Int256.Zero); + yield return () => (Int256.NegativeOne, new Int256(0, 0, 0, 2), Int256.NegativeOne); + yield return () => (new Int256(0, 0, 0, 7), Int256.NegativeOne, Int256.Zero); + yield return () => (Int256.MaxValue, new Int256(0, 0, 0, 123456789), new Int256(0, 0, 0, 77645365)); + yield return () => (new Int256(0x0000_0000_0000_0040, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new Int256(0x0000_0000_0000_000F, 0xEE50_B702_5C36_A080, 0x2F23_6D04_753D_5B48, 0xE800_0000_0000_0000), new Int256(0x0000_0000_0000_0000, 0x46BD_23F6_8F25_7DFF, 0x4372_4BEE_2B0A_92DC, 0x6000_0000_0000_0000)); + } + + public static IEnumerable> op_MultiplyTestData() + { + yield return () => (Int256.Zero, Int256.Zero, Int256.Zero); + yield return () => (Int256.Zero, Int256.One, Int256.Zero); + yield return () => (Int256.One, Int256.One, Int256.One); + yield return () => (Int256.One, Int256.NegativeOne, Int256.NegativeOne); + yield return () => (Int256.NegativeOne, Int256.NegativeOne, Int256.One); + yield return () => (new Int256(0, 0, 0, 2), new Int256(0, 0, 0, 3), new Int256(0, 0, 0, 6)); + yield return () => (new Int256(0, 0, 0, ulong.MaxValue), new Int256(0, 0, 0, 2), new Int256(0, 0, 1, ulong.MaxValue - 1)); + yield return () => (new Int256(0, 0, 0, ulong.MaxValue), new Int256(0, 0, 0, ulong.MaxValue), new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFE, 0x0000_0000_0000_0001)); + yield return () => (new Int256(0, 0, 1, 0), new Int256(0, 0, 1, 0), new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000)); + } + + public static IEnumerable> op_SubtractionTestData() + { + yield return () => (Int256.Zero, Int256.Zero, Int256.Zero); + yield return () => (Int256.One, Int256.Zero, Int256.One); + yield return () => (Int256.One, Int256.One, Int256.Zero); + yield return () => (Int256.Zero, Int256.One, Int256.NegativeOne); + yield return () => (Int256.MaxValue,Int256.One, new Int256(ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue - 1)); + yield return () => (Int256.MinValue,Int256.One,Int256.MaxValue); + yield return () => (Int256.MinValue,Int256.NegativeOne, new Int256(unchecked((ulong)-1), ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new Int256(1, 2, 3, 4),new Int256(0, 1, 2, 3),new Int256(1, 1, 1, 1)); + yield return () => (new Int256(0, 0, 0, 0),new Int256(0, 0, 0, 1),new Int256(unchecked((ulong)-1), ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + } + + public static IEnumerable> op_ShiftLeftTestData() + { + yield return () => (Int256.Zero, 100, Int256.Zero); + yield return () => (Int256.One, 0, Int256.One); + yield return () => (Int256.One, 1, new Int256(0, 0, 0, 2)); + yield return () => (Int256.One, 2, new Int256(0, 0, 0, 4)); + yield return () => (Int256.One, 64, new Int256(0, 0, 1, 0)); + yield return () => (Int256.One, 128, new Int256(0, 1, 0, 0)); + yield return () => (Int256.One, 192, new Int256(1, 0, 0, 0)); + yield return () => (new Int256(0, 0, 0, 0xFFFF_FFFF_FFFF_FFFF), 32, new Int256(0, 0, 0xFFFF_FFFF, 0xFFFF_FFFF_0000_0000)); + yield return () => (new Int256(0, 0, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), 96, new Int256(0xFFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_0000_0000, 0)); + yield return () => (Int256.One, 256, Int256.One); + } + + public static IEnumerable> op_ShiftRightTestData() + { + yield return () => (Int256.Zero, 100, Int256.Zero); + yield return () => (Int256.One, 0, Int256.One); + yield return () => (new Int256(1, 0, 0, 0), 64, new Int256(0, 1, 0, 0)); + yield return () => (new Int256(1, 0, 0, 0), 128, new Int256(0, 0, 1, 0)); + yield return () => (new Int256(1, 0, 0, 0), 192, new Int256(0, 0, 0, 1)); + yield return () => (new Int256(0b1000000000000000000000000000000000000000000000000000000000000000, 0, 0, 0), 031, new Int256(0b1111111111111111111111111111111100000000000000000000000000000000, 0, 0, 0)); + yield return () => (new Int256(0b1000000000000000000000000000000000000000000000000000000000000000, 0, 0, 0), 127, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0)); + yield return () => (new Int256(0b1000000000000000000000000000000000000000000000000000000000000000, 0, 0, 0), 255, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => (Int256.One, 256, Int256.One); + } + + public static IEnumerable> op_UnsignedShiftRightTestData() + { + yield return () => (Int256.Zero, 100, Int256.Zero); + yield return () => (Int256.One, 0, Int256.One); + yield return () => (new Int256(1, 0, 0, 0), 64, new Int256(0, 1, 0, 0)); + yield return () => (new Int256(1, 0, 0, 0), 128, new Int256(0, 0, 1, 0)); + yield return () => (new Int256(1, 0, 0, 0), 192, new Int256(0, 0, 0, 1)); + yield return () => (new Int256(0xFFFF_FFFF_FFFF_FFFF, 0, 0, 0), 64, new Int256(0, 0xFFFF_FFFF_FFFF_FFFF, 0, 0)); + yield return () => (new Int256(0xFFFF_FFFF_FFFF_FFFF, 0, 0, 0), 128, new Int256(0, 0, 0xFFFF_FFFF_FFFF_FFFF, 0)); + yield return () => (new Int256(0xFFFF_FFFF_FFFF_FFFF, 0, 0, 0), 192, new Int256(0, 0, 0, 0xFFFF_FFFF_FFFF_FFFF)); + yield return () => (Int256.One, 256, Int256.One); + } + + public static IEnumerable> op_BitwiseAndTestData() + { + yield return () => (Int256.Zero, Int256.Zero, Int256.Zero); + yield return () => (Int256.Zero, Int256.MaxValue, Int256.Zero); + yield return () => (new Int256(1, 2, 3, 4), new Int256(1, 2, 3, 4), new Int256(1, 2, 3, 4)); + yield return () => (new Int256(1, 2, 3, 4), Int256.MaxValue, new Int256(1, 2, 3, 4)); + yield return () => (new Int256(0xFFFFFFFF00000000, 0xAAAAAAAA55555555, 0x123456789ABCDEF0, 0x0F0F0F0F0F0F0F0F), new Int256(0x00000000FFFFFFFF, 0x55555555AAAAAAAA, 0x0F0F0F0F0F0F0F0F, 0xF0F0F0F0F0F0F0F0), new Int256(0x0000000000000000, 0x0000000000000000, 0x020406080A0C0E00, 0x0000000000000000)); + } + + public static IEnumerable> op_BitwiseOrTestData() + { + yield return () => (Int256.Zero, Int256.Zero, Int256.Zero); + yield return () => (Int256.Zero, Int256.MaxValue, Int256.MaxValue); + yield return () => (new Int256(1, 2, 3, 4), new Int256(1, 2, 3, 4), new Int256(1, 2, 3, 4)); + yield return () => (new Int256(1, 2, 3, 4), Int256.MaxValue, new Int256(long.MaxValue | 1, ulong.MaxValue | 2, ulong.MaxValue | 3, ulong.MaxValue | 4)); + yield return () => (new Int256(0x00000000FFFFFFFF, 0xAAAAAAAA00000000, 0x00000000AAAAAAAA, 0x1234567890ABCDEF), new Int256(0xFFFFFFFF00000000, 0x0000000055555555, 0x5555555500000000, 0xFEDCBA9876543210), new Int256(0xFFFFFFFFFFFFFFFF, 0xAAAAAAAA55555555, 0x55555555AAAAAAAA, 0x1234567890ABCDEF | 0xFEDCBA9876543210)); + } + + public static IEnumerable> op_BitwiseXorTestData() + { + yield return () => (Int256.Zero, Int256.Zero, Int256.Zero); + yield return () => (Int256.Zero, Int256.MaxValue, Int256.MaxValue); + yield return () => (new Int256(1, 2, 3, 4), new Int256(1, 2, 3, 4), Int256.Zero); + yield return () => (new Int256(0x0000000000000000, 0xFFFFFFFFFFFFFFFF, 0x1234567890ABCDEF, 0xFEDCBA9876543210), new Int256(ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new Int256(ulong.MaxValue, 0x0, 0xEDCBA9876F543210, 0x0123456789ABCDEF)); + yield return () => (new Int256(0x1234567890ABCDEF, 0xAAAAAAAA00000000, 0x00000000AAAAAAAA, 0xFFFFFFFFFFFFFFFF), new Int256(0xFFFFFFFFFFFFFFFF, 0x00000000AAAAAAAA, 0xAAAAAAAA00000000, 0x0000000000000000), new Int256(0xEDCBA9876F543210, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xFFFFFFFFFFFFFFFF)); + } + + public static IEnumerable> op_OnesComplementTestData() + { + yield return () => (Int256.Zero, new Int256(ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new Int256(ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), Int256.Zero); + yield return () => (new Int256(0xAAAAAAAAAAAAAAAA, 0x5555555555555555, 0xAAAAAAAAAAAAAAAA, 0x5555555555555555), new Int256(0x5555555555555555, 0xAAAAAAAAAAAAAAAA, 0x5555555555555555, 0xAAAAAAAAAAAAAAAA)); + yield return () => (new Int256(0x0123456789ABCDEF, 0xFEDCBA9876543210, 0x0F0F0F0F0F0F0F0F, 0xF0F0F0F0F0F0F0F0), new Int256(~(ulong)0x0123456789ABCDEF, ~0xFEDCBA9876543210, ~(ulong)0x0F0F0F0F0F0F0F0F, ~0xF0F0F0F0F0F0F0F0)); + } + + public static IEnumerable> op_EqualityTestData() + { + yield return () => (Int256.Zero, Int256.Zero, true); + yield return () => (new Int256(1, 2, 3, 4), new Int256(1, 2, 3, 4), true); + yield return () => (new Int256(1, 2, 3, 4), new Int256(1, 2, 3, 5), false); + yield return () => (new Int256(1, 2, 3, 4), new Int256(1, 2, 4, 4), false); + yield return () => (new Int256(1, 2, 3, 4), new Int256(1, 3, 3, 4), false); + yield return () => (new Int256(1, 2, 3, 4), new Int256(2, 2, 3, 4), false); + } + + public static IEnumerable> op_InequalityTestData() + { + yield return () => (Int256.Zero, Int256.Zero, false); + yield return () => (new Int256(1, 2, 3, 4), new Int256(1, 2, 3, 4), false); + yield return () => (new Int256(1, 2, 3, 4), new Int256(1, 2, 3, 5), true); + yield return () => (new Int256(1, 2, 3, 4), new Int256(1, 2, 4, 4), true); + yield return () => (new Int256(1, 2, 3, 4), new Int256(1, 3, 3, 4), true); + yield return () => (new Int256(1, 2, 3, 4), new Int256(2, 2, 3, 4), true); + } + + public static IEnumerable> op_GreaterThanOrEqualTestData() + { + yield return () => (Int256.Zero, Int256.Zero, true); + yield return () => (Int256.NegativeOne, Int256.One, false); + yield return () => (Int256.One, Int256.NegativeOne, true); + yield return () => (Int256.Zero, Int256.MinValue, true); + yield return () => (Int256.Zero, Int256.NegativeOne, true); + yield return () => (Int256.Zero, Int256.One, false); + yield return () => (Int256.Zero, Int256.MaxValue, false); + } + + public static IEnumerable> op_GreaterThanTestData() + { + yield return () => (Int256.Zero, Int256.Zero, false); + yield return () => (Int256.NegativeOne, Int256.One, false); + yield return () => (Int256.One, Int256.NegativeOne, true); + yield return () => (Int256.Zero, Int256.MinValue, true); + yield return () => (Int256.Zero, Int256.NegativeOne, true); + yield return () => (Int256.Zero, Int256.One, false); + yield return () => (Int256.Zero, Int256.MaxValue, false); + } + + public static IEnumerable> op_LessThanOrEqualTestData() + { + yield return () => (Int256.Zero, Int256.Zero, true); + yield return () => (Int256.NegativeOne, Int256.One, true); + yield return () => (Int256.One, Int256.NegativeOne, false); + yield return () => (Int256.Zero, Int256.MinValue, false); + yield return () => (Int256.Zero, Int256.NegativeOne, false); + yield return () => (Int256.Zero, Int256.One, true); + yield return () => (Int256.Zero, Int256.MaxValue, true); + } + + public static IEnumerable> op_LessThanTestData() + { + yield return () => (Int256.Zero, Int256.Zero, false); + yield return () => (Int256.NegativeOne, Int256.One, true); + yield return () => (Int256.One, Int256.NegativeOne, false); + yield return () => (Int256.Zero, Int256.MinValue, false); + yield return () => (Int256.Zero, Int256.NegativeOne, false); + yield return () => (Int256.Zero, Int256.One, true); + yield return () => (Int256.Zero, Int256.MaxValue, true); + } + + public static IEnumerable> AbsTestData() + { + yield return () => (Int256.Zero, Int256.Zero); + yield return () => (Int256.One, Int256.One); + yield return () => (Int256.NegativeOne, Int256.One); + yield return () => (Int256.MinValue + Int256.One, Int256.MaxValue); + } + + public static IEnumerable> IsCanonicalTestData() + { + yield return () => (Int256.Zero, true); + } + + public static IEnumerable> IsComplexNumberTestData() + { + yield return () => (Int256.Zero, false); + } + + public static IEnumerable> IsEvenIntegerTestData() + { + yield return () => (Int256.Zero, true); + yield return () => (Int256.One, false); + yield return () => (Int256.NegativeOne, false); + yield return () => (new Int256(0, 0, 0, 2), true); + yield return () => (new Int256(0, 0, 0, 3), false); + yield return () => (new Int256(0, 0, 0, 4), true); + yield return () => (new Int256(0, 0, 0, 6), true); + yield return () => (new Int256(0, 0, 0, 8), true); + yield return () => (new Int256(0, 0, 0, 16), true); + yield return () => (-new Int256(0, 0, 0, 2), true); + yield return () => (-new Int256(0, 0, 0, 3), false); + yield return () => (-new Int256(0, 0, 0, 4), true); + yield return () => (-new Int256(0, 0, 0, 6), true); + yield return () => (-new Int256(0, 0, 0, 8), true); + yield return () => (-new Int256(0, 0, 0, 16), true); + } + + public static IEnumerable> IsFiniteTestData() + { + yield return () => (Int256.Zero, true); + } + + public static IEnumerable> IsImaginaryNumberTestData() + { + yield return () => (Int256.Zero, false); + } + + public static IEnumerable> IsInfinityTestData() + { + yield return () => (Int256.Zero, false); + } + + public static IEnumerable> IsIntegerTestData() + { + yield return () => (Int256.Zero, true); + } + + public static IEnumerable> IsNaNTestData() + { + yield return () => (Int256.Zero, false); + } + + public static IEnumerable> IsNegativeTestData() + { + yield return () => (Int256.Zero, false); + yield return () => (Int256.One, false); + yield return () => (Int256.MaxValue, false); + yield return () => (Int256.NegativeOne, true); + yield return () => (-Int256.One, true); + yield return () => (-Int256.MaxValue, true); + yield return () => (Int256.MinValue, true); + } + + public static IEnumerable> IsNegativeInfinityTestData() + { + yield return () => (Int256.Zero, false); + } + + public static IEnumerable> IsNormalTestData() + { + yield return () => (Int256.Zero, false); + yield return () => (Int256.One, true); + yield return () => (Int256.NegativeOne, true); + } + + public static IEnumerable> IsOddIntegerTestData() + { + yield return () => (Int256.Zero, false); + yield return () => (Int256.One, true); + yield return () => (Int256.NegativeOne, true); + yield return () => (new Int256(0, 0, 0, 2), false); + yield return () => (new Int256(0, 0, 0, 3), true); + yield return () => (new Int256(0, 0, 0, 4), false); + yield return () => (new Int256(0, 0, 0, 6), false); + yield return () => (new Int256(0, 0, 0, 8), false); + yield return () => (new Int256(0, 0, 0, 16), false); + yield return () => (-new Int256(0, 0, 0, 2), false); + yield return () => (-new Int256(0, 0, 0, 3), true); + yield return () => (-new Int256(0, 0, 0, 4), false); + yield return () => (-new Int256(0, 0, 0, 6), false); + yield return () => (-new Int256(0, 0, 0, 8), false); + yield return () => (-new Int256(0, 0, 0, 16), false); + } + + public static IEnumerable> IsPositiveTestData() + { + yield return () => (Int256.Zero, true); + yield return () => (Int256.One, true); + yield return () => (Int256.MaxValue, true); + yield return () => (Int256.NegativeOne, false); + yield return () => (-Int256.One, false); + yield return () => (-Int256.MaxValue, false); + yield return () => (Int256.MinValue, false); + } + + public static IEnumerable> IsPositiveInfinityTestData() + { + yield return () => (Int256.Zero, false); + } + + public static IEnumerable> IsRealNumberTestData() + { + yield return () => (Int256.Zero, true); + } + + public static IEnumerable> IsSubnormalTestData() + { + yield return () => (Int256.Zero, false); + } + + public static IEnumerable> IsZeroTestData() + { + yield return () => (Int256.Zero, true); + yield return () => (Int256.One, false); + yield return () => (Int256.NegativeOne, false); + yield return () => (Int256.MaxValue, false); + yield return () => (Int256.MinValue, false); + } + + public static IEnumerable> MaxMagnitudeTestData() + { + yield return () => (Int256.MaxValue, 5, Int256.MaxValue); + yield return () => (Int256.One, 5, 5); + yield return () => (Int256.One, Int256.NegativeOne, Int256.One); + yield return () => (Int256.One, -2, -2); + yield return () => (Int256.NegativeOne, Int256.MaxValue, Int256.MaxValue); + yield return () => (Int256.MinValue, -2, Int256.MinValue); + yield return () => (Int256.MaxValue, Int256.MinValue, Int256.MinValue); + } + + public static IEnumerable> MaxMagnitudeNumberTestData() + { + yield return () => (Int256.MaxValue, 5, Int256.MaxValue); + yield return () => (Int256.One, 5, 5); + yield return () => (Int256.One, Int256.NegativeOne, Int256.One); + yield return () => (Int256.One, -2, -2); + yield return () => (Int256.NegativeOne, Int256.MaxValue, Int256.MaxValue); + yield return () => (Int256.MinValue, -2, Int256.MinValue); + yield return () => (Int256.MaxValue, Int256.MinValue, Int256.MinValue); + } + + public static IEnumerable> MinMagnitudeTestData() + { + yield return () => (Int256.MaxValue, 5, 5); + yield return () => (Int256.One, 5, Int256.One); + yield return () => (Int256.One, Int256.NegativeOne, Int256.NegativeOne); + yield return () => (Int256.One, -2, Int256.One); + yield return () => (Int256.NegativeOne, Int256.MaxValue, Int256.NegativeOne); + yield return () => (Int256.MinValue, -2, -2); + yield return () => (Int256.MaxValue, Int256.MinValue, Int256.MaxValue); + } + + public static IEnumerable> MinMagnitudeNumberTestData() + { + yield return () => (Int256.MaxValue, 5, 5); + yield return () => (Int256.One, 5, Int256.One); + yield return () => (Int256.One, Int256.NegativeOne, Int256.NegativeOne); + yield return () => (Int256.One, -2, Int256.One); + yield return () => (Int256.NegativeOne, Int256.MaxValue, Int256.NegativeOne); + yield return () => (Int256.MinValue, -2, -2); + yield return () => (Int256.MaxValue, Int256.MinValue, Int256.MaxValue); + } + + public static IEnumerable> MultiplyAddEstimateTestData() + { + yield return () => (Int256.One, Int256.One, Int256.One, 2); + yield return () => (Int256.One, Int256.Zero, Int256.One, Int256.One); + yield return () => (Int256.MaxValue, Int256.NegativeOne, Int256.NegativeOne, Int256.MinValue); + yield return () => (200, 100, 500, 20500); + yield return () => (new Int256(0, 0, ulong.MaxValue, ulong.MaxValue), new Int256(0, 0, ulong.MaxValue, ulong.MaxValue), new Int256(0, 0, ulong.MaxValue, ulong.MaxValue), Int256.Parse("115792089237316195423570985008687907852929702298719625575994209400481361428480")); + } + + public static IEnumerable> ParseTestData() + { + yield return () => ("-57896044618658097711785492504343953926634992332820282019728792003956564819968", NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.MinValue); + yield return () => ("-170141183460469231731687303715884105728", NumberStyles.Integer, CultureInfo.InvariantCulture, Int128.MinValue); + yield return () => ("-9223372036854775808", NumberStyles.Integer, CultureInfo.InvariantCulture, long.MinValue); + yield return () => ("-1", NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.NegativeOne); + yield return () => ("0", NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.Zero); + yield return () => ("1", NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.One); + yield return () => ("9223372036854775808", NumberStyles.Integer, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => ("170141183460469231731687303715884105728", NumberStyles.Integer, CultureInfo.InvariantCulture, new Int256(0, 0, 0x8000_0000_0000_0000, 0)); + yield return () => ("57896044618658097711785492504343953926634992332820282019728792003956564819967", NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.MaxValue); + + yield return () => ("123456789ABCDEF0", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFF)); + yield return () => ("FFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + + yield return () => ("1010101010101010", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + } + + public static IEnumerable> ParseSpanTestData() + { + yield return () => ("-57896044618658097711785492504343953926634992332820282019728792003956564819968".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.MinValue); + yield return () => ("-170141183460469231731687303715884105728".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int128.MinValue); + yield return () => ("-9223372036854775808".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, long.MinValue); + yield return () => ("-1".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.NegativeOne); + yield return () => ("0".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.Zero); + yield return () => ("1".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.One); + yield return () => ("9223372036854775808".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => ("170141183460469231731687303715884105728".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new Int256(0, 0, 0x8000_0000_0000_0000, 0)); + yield return () => ("57896044618658097711785492504343953926634992332820282019728792003956564819967".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.MaxValue); + + yield return () => ("123456789ABCDEF0".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFF)); + yield return () => ("FFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + + yield return () => ("1010101010101010".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + } + + public static IEnumerable> ParseUtf8TestData() + { + yield return () => ("-57896044618658097711785492504343953926634992332820282019728792003956564819968"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.MinValue); + yield return () => ("-170141183460469231731687303715884105728"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int128.MinValue); + yield return () => ("-9223372036854775808"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, long.MinValue); + yield return () => ("-1"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.NegativeOne); + yield return () => ("0"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.Zero); + yield return () => ("1"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.One); + yield return () => ("9223372036854775808"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => ("170141183460469231731687303715884105728"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new Int256(0, 0, 0x8000_0000_0000_0000, 0)); + yield return () => ("57896044618658097711785492504343953926634992332820282019728792003956564819967"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, Int256.MaxValue); + + yield return () => ("123456789ABCDEF0"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFF)); + yield return () => ("FFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new Int256(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + + yield return () => ("1010101010101010"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + } + + public static IEnumerable> TryParseTestData() + { + yield return () => ("-57896044618658097711785492504343953926634992332820282019728792003956564819969", NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("-57896044618658097711785492504343953926634992332820282019728792003956564819968", NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.MinValue); + yield return () => ("-170141183460469231731687303715884105728", NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int128.MinValue); + yield return () => ("-9223372036854775808", NumberStyles.Integer, CultureInfo.InvariantCulture, true, long.MinValue); + yield return () => ("-1", NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.NegativeOne); + yield return () => ("0", NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.Zero); + yield return () => ("1", NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.One); + yield return () => ("9223372036854775808", NumberStyles.Integer, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => ("170141183460469231731687303715884105728", NumberStyles.Integer, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0x8000_0000_0000_0000, 0)); + yield return () => ("57896044618658097711785492504343953926634992332820282019728792003956564819967", NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.MaxValue); + yield return () => ("57896044618658097711785492504343953926634992332820282019728792003956564819968", NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + + yield return () => ("123456789ABCDEF0", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFF)); + yield return () => ("FFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, false, default); + + yield return () => ("1010101010101010", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> TryParseSpanTestData() + { + yield return () => ("-57896044618658097711785492504343953926634992332820282019728792003956564819969".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("-57896044618658097711785492504343953926634992332820282019728792003956564819968".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.MinValue); + yield return () => ("-170141183460469231731687303715884105728".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int128.MinValue); + yield return () => ("-9223372036854775808".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, long.MinValue); + yield return () => ("-1".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.NegativeOne); + yield return () => ("0".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.Zero); + yield return () => ("1".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.One); + yield return () => ("9223372036854775808".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => ("170141183460469231731687303715884105728".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0x8000_0000_0000_0000, 0)); + yield return () => ("57896044618658097711785492504343953926634992332820282019728792003956564819967".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.MaxValue); + yield return () => ("57896044618658097711785492504343953926634992332820282019728792003956564819968".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + + yield return () => ("123456789ABCDEF0".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFF)); + yield return () => ("FFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, false, default); + + yield return () => ("1010101010101010".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> TryParseUtf8TestData() + { + yield return () => ("-57896044618658097711785492504343953926634992332820282019728792003956564819969"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("-57896044618658097711785492504343953926634992332820282019728792003956564819968"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.MinValue); + yield return () => ("-170141183460469231731687303715884105728"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int128.MinValue); + yield return () => ("-9223372036854775808"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, long.MinValue); + yield return () => ("-1"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.NegativeOne); + yield return () => ("0"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.Zero); + yield return () => ("1"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.One); + yield return () => ("9223372036854775808"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => ("170141183460469231731687303715884105728"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0x8000_0000_0000_0000, 0)); + yield return () => ("57896044618658097711785492504343953926634992332820282019728792003956564819967"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, Int256.MaxValue); + yield return () => ("57896044618658097711785492504343953926634992332820282019728792003956564819968"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + + yield return () => ("123456789ABCDEF0"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFF)); + yield return () => ("FFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, true, new Int256(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, false, default); + + yield return () => ("1010101010101010"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, true, new Int256(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> ClampTestData() + { + yield return () => ( + new Int256(0, 0, 0, 1), + new Int256(0, 0, 0, 2), + new Int256(0, 0, 0, 4), + new Int256(0, 0, 0, 2) + ); + yield return () => ( + new Int256(0, 0, 0, 1), + new Int256(0, 0, 0, 1), + new Int256(0, 0, 0, 4), + new Int256(0, 0, 0, 1) + ); + yield return () => ( + new Int256(0, 1, 0, 0), + new Int256(0, 0, 0, 1), + new Int256(1, 0, 0, 0), + new Int256(0, 1, 0, 0) + ); + } + + public static IEnumerable> CopySignTestData() + { + yield return () => (Int256.One, Int256.One, Int256.One); + yield return () => (Int256.One, Int256.NegativeOne, Int256.NegativeOne); + yield return () => (Int256.NegativeOne, Int256.NegativeOne, Int256.NegativeOne); + yield return () => (Int256.NegativeOne, Int256.One, Int256.One); + } + + public static IEnumerable> MaxTestData() + { + yield return () => (Int256.One, Int256.One, Int256.One); + yield return () => (Int256.One, Int256.NegativeOne, Int256.One); + yield return () => (Int256.MinValue, Int256.NegativeOne, Int256.NegativeOne); + yield return () => (Int256.Zero, Int256.One, Int256.One); + yield return () => (Int256.One, Int256.MaxValue, Int256.MaxValue); + } + + public static IEnumerable> MaxNumberTestData() + { + return MaxTestData(); + } + + public static IEnumerable> MinTestData() + { + yield return () => (Int256.One, Int256.One, Int256.One); + yield return () => (Int256.One, Int256.NegativeOne, Int256.NegativeOne); + yield return () => (Int256.MinValue, Int256.NegativeOne, Int256.MinValue); + yield return () => (Int256.Zero, Int256.One, Int256.Zero); + yield return () => (Int256.One, Int256.MaxValue, Int256.One); + } + + public static IEnumerable> MinNumberTestData() + { + return MinTestData(); + } + + public static IEnumerable> SignTestData() + { + yield return () => (Int256.Zero, 0); + yield return () => (Int256.MaxValue, 1); + yield return () => (Int256.One, 1); + yield return () => (Int256.MinValue, -1); + yield return () => (Int256.NegativeOne, -1); + } + + public static IEnumerable> IsPow2TestData() + { + yield return () => (Int256.Zero, false); + yield return () => (Int256.One, true); + yield return () => (new Int256(0, 0, 0, 3), false); + yield return () => (new Int256(0, 0, 0, 4), true); + yield return () => (new Int256(0, 0, 0, 6), false); + yield return () => (new Int256(0, 0, 0, 8), true); + yield return () => (new Int256(1UL << 62, 0, 0, 0), true); + yield return () => (Int256.NegativeOne, false); + yield return () => (-new Int256(0, 0, 0, 3), false); + yield return () => (-new Int256(0, 0, 0, 4), false); + yield return () => (-new Int256(0, 0, 0, 6), false); + yield return () => (-new Int256(0, 0, 0, 8), false); + } + + public static IEnumerable> Log2TestData() + { + yield return () => (new Int256(0, 0, 0, 1), new Int256(0, 0, 0, 0)); + yield return () => (new Int256(0, 0, 0, 2), new Int256(0, 0, 0, 1)); + yield return () => (new Int256(0, 0, 0, 4), new Int256(0, 0, 0, 2)); + yield return () => (new Int256(0, 0, 0, 8), new Int256(0, 0, 0, 3)); + yield return () => (new Int256(0, 0, 0, 1UL << 63), new Int256(0, 0, 0, 63)); + yield return () => (new Int256(0, 0, 1UL << 5, 0), new Int256(0, 0, 0, 69)); + yield return () => (new Int256(0, 1UL << 42, 0, 0), new Int256(0, 0, 0, 170)); + yield return () => (new Int256(1UL << 13, 0, 0, 0), new Int256(0, 0, 0, 205)); + yield return () => (new Int256(0, 0, 0, 0), new Int256(0, 0, 0, 0)); + } + + public static IEnumerable> DivRemTestData() + { + yield return () => (new Int256(0, 0, 0, 0xFFFF_FFFF_FFFF_FFFF), new Int256(0, 0, 0, 10), (new Int256(0, 0, 0, 0xFFFF_FFFF_FFFF_FFFF / 10), new Int256(0, 0, 0, 0xFFFF_FFFF_FFFF_FFFF % 10))); + yield return () => (new Int256(0, 0, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new Int256(0, 0, 0, 10), (new Int256(0, new UInt128(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF) / 10), new Int256(0, new UInt128(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF) % 10))); + yield return () => (new Int256(0, 0, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new Int256(0, 0, 1, 0), (new Int256(0, new UInt128(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF) / new UInt128(1, 0)), new Int256(0, new UInt128(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF) % new UInt128(1, 0)))); + yield return () => (new Int256(0, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new Int256(0, 0, 0, 10), (new Int256(0x0000_0000_0000_0000, 0x1999_9999_9999_9999, 0x9999_9999_9999_9999, 0x9999_9999_9999_9999), new Int256(0, 0, 0, 5))); + yield return () => (new Int256(0, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new Int256(0, 0, 1, 0), (new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF))); + yield return () => (new Int256(0, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new Int256(0, 1, 0, 0), (new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF), new Int256(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF))); + } + + public static IEnumerable> LeadingZeroCountTestData() + { + yield return () => (new Int256(0, 0, 0, 0), new Int256(0, 0, 0, 256)); + yield return () => (new Int256(0, 0, 0, 1), new Int256(0, 0, 0, 255)); + yield return () => (new Int256(0, 0, 1, 0), new Int256(0, 0, 0, 191)); + yield return () => (new Int256(0, 1, 0, 0), new Int256(0, 0, 0, 127)); + yield return () => (new Int256(1, 0, 0, 0), new Int256(0, 0, 0, 63)); + yield return () => (new Int256(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new Int256(0, 0, 0, 63)); + yield return () => (new Int256(0, 0, 0, 1UL << 63), new Int256(0, 0, 0, 192)); + yield return () => (new Int256(0, 0, 1UL << 63, 0), new Int256(0, 0, 0, 128)); + yield return () => (new Int256(0, 1UL << 63, 0, 0), new Int256(0, 0, 0, 64)); + yield return () => (new Int256(1UL << 63, 0, 0, 0), new Int256(0, 0, 0, 0)); + yield return () => (new Int256(1UL << 62, 0, 0, 0), new Int256(0, 0, 0, 1)); + } + + public static IEnumerable> PopCountTestData() + { + yield return () => (new Int256(0, 0, 0, 0), new Int256(0, 0, 0, 0)); + yield return () => (new Int256(0, 0, 0, 1), new Int256(0, 0, 0, 1)); + yield return () => (Int256.MaxValue, new Int256(0, 0, 0, 255)); + yield return () => (new Int256(ulong.MaxValue, 0, 0, 0), new Int256(0, 0, 0, 64)); + yield return () => (new Int256(0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA), new Int256(0, 0, 0, 128)); + yield return () => (new Int256(1UL << 63, 1UL << 62, 1UL << 61, 1UL << 60), new Int256(0, 0, 0, 4)); + } + + public static IEnumerable> ReadBigEndianTestData() + { + yield return () => ([], true, Int256.Zero); + yield return () => ([0x01], true, Int256.One); + yield return () => + { + byte[] array = new byte[32]; + Array.Fill(array, byte.MaxValue); + return (array, false, new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); + }; + yield return () => + { + byte[] array = new byte[35]; + for (int i = 0; i < 35; i++) + array[i] = byte.MaxValue; + return (array, false, new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); + }; + yield return () => ([0x12, 0x34], true, new Int256(0, 0, 0, 0x1234)); + yield return () => + { + byte[] array = new byte[32]; + array[0] = 0x80; + return (array, false, new Int256(1UL << 63, 0, 0, 0)); + }; + } + + public static IEnumerable> ReadLittleEndianTestData() + { + yield return () => ([], true, Int256.Zero); + yield return () => ([0x01], true, Int256.One); + yield return () => + { + byte[] array = new byte[32]; + Array.Fill(array, byte.MaxValue); + return (array, false, new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); + }; + yield return () => + { + byte[] array = new byte[35]; + for (int i = 0; i < 35; i++) + array[i] = byte.MaxValue; + return (array, false, new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); + }; + yield return () => ([0x34, 0x12], true, new Int256(0, 0, 0, 0x1234)); + yield return () => + { + byte[] array = new byte[32]; + array[31] = 0x80; + return (array, false, new Int256(1UL << 63, 0, 0, 0)); + }; + } + + public static IEnumerable> RotateLeftTestData() + { + yield return () => (new Int256(1, 2, 3, 4), 0, new Int256(1, 2, 3, 4)); + yield return () => (new Int256(1, 2, 3, 4), 256, new Int256(1, 2, 3, 4)); + yield return () => (new Int256(0, 0, 0x8000_0000_0000_0000, 0), 64, new Int256(0, 0x8000_0000_0000_0000, 0, 0)); + yield return () => (new Int256(0x8000_0000_0000_0000, 0, 0, 0), 64, new Int256(0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => (new Int256(0, 0, 0x8000_0000_0000_0000, 0), 128, new Int256(0x8000_0000_0000_0000, 0, 0, 0)); + yield return () => (new Int256(0x8000_0000_0000_0000, 0, 0, 0), 128, new Int256(0, 0, 0x8000_0000_0000_0000, 0)); + } + + public static IEnumerable> RotateRightTestData() + { + yield return () => (new Int256(1, 2, 3, 4), 0, new Int256(1, 2, 3, 4)); + yield return () => (new Int256(1, 2, 3, 4), 256, new Int256(1, 2, 3, 4)); + yield return () => (new Int256(0, 0, 0x8000_0000_0000_0000, 0), 64, new Int256(0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => (new Int256(0, 0, 0, 0x8000_0000_0000_0000), 64, new Int256(0x8000_0000_0000_0000, 0, 0, 0)); + yield return () => (new Int256(0, 0, 0x8000_0000_0000_0000, 0), 128, new Int256(0x8000_0000_0000_0000, 0, 0, 0)); + yield return () => (new Int256(0x8000_0000_0000_0000, 0, 0, 0), 128, new Int256(0, 0, 0x8000_0000_0000_0000, 0)); + } + + public static IEnumerable> TrailingZeroCountTestData() + { + yield return () => (new Int256(0, 0, 0, 0), new Int256(0, 0, 0, 256)); + yield return () => (new Int256(0, 0, 0, 1), new Int256(0, 0, 0, 0)); + yield return () => (new Int256(0, 0, 8, 0), new Int256(0, 0, 0, 67)); + yield return () => (new Int256(0, 0x10, 0, 0), new Int256(0, 0, 0, 132)); + yield return () => (new Int256(0x200, 0, 0, 0), new Int256(0, 0, 0, 201)); + } + + public static IEnumerable> GetByteCountTestData() + { + yield return () => (new Int256(0, 0, 0, 0), Unsafe.SizeOf()); + } + + public static IEnumerable> GetShortestBitLengthTestData() + { + yield return () => (new Int256(0, 0, 0, 0), 0); + yield return () => (new Int256(0, 0, 0, 1), 1); + yield return () => (new Int256(1, 0, 0, 0), 193); + yield return () => (Int256.MaxValue, 255); + yield return () => (Int256.MinValue, 256); + } + + public static IEnumerable> WriteBigEndianTestData() + { + yield return () => (new Int256(0, 0, 0, 0), new byte[32], Unsafe.SizeOf()); + yield return () => + { + var buffer = new byte[32]; + + for (int i = 0; i < 31; i++) + buffer[i] = 0; + + buffer[31] = 1; + + return (new Int256(0, 0, 0, 1), buffer, Unsafe.SizeOf()); + }; + yield return () => + { + var buffer = new byte[32]; + + for (int i = 0; i < 32; i++) + buffer[i] = 0xFF; + + return (new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), buffer, Unsafe.SizeOf()); + }; + } + + public static IEnumerable> WriteLittleEndianTestData() + { + yield return () => (new Int256(0, 0, 0, 0), new byte[32], Unsafe.SizeOf()); + yield return () => + { + var buffer = new byte[32]; + + buffer[0] = 1; + for (int i = 1; i < 32; i++) + buffer[i] = 0; + + return (new Int256(0, 0, 0, 1), buffer, Unsafe.SizeOf()); + }; + yield return () => + { + var buffer = new byte[32]; + + for (int i = 0; i < 32; i++) + buffer[i] = 0xFF; + + return (new Int256(0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), buffer, Unsafe.SizeOf()); + }; + } + + public static IEnumerable> ConvertToCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt512TestData() + { + yield return () => (Int256.Parse("-465182250000"), Int512.Parse("-465182250000")); + } + + public static IEnumerable> ConvertToSaturatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedDoubleTestData() + { + yield return () => (Int256.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + yield return () => (Int256.Parse("-781377183594418599030564404241984000000000000000000"), + -781377183594418599030564404241984000000000000000000.0d); + } + + public static IEnumerable> ConvertToSaturatingDoubleTestData() + { + yield return () => (Int256.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + yield return () => (Int256.Parse("-781377183594418599030564404241984000000000000000000"), + -781377183594418599030564404241984000000000000000000.0d); + } + + public static IEnumerable> ConvertToTruncatingDoubleTestData() + { + yield return () => (Int256.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + yield return () => (Int256.Parse("-781377183594418599030564404241984000000000000000000"), + -781377183594418599030564404241984000000000000000000.0d); + } + + public static IEnumerable> ConvertToCheckedQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingOctoTestData() + { + throw new NotImplementedException(); + } +} diff --git a/src/MissingValues.Tests/Data/Int512DataSources.cs b/src/MissingValues.Tests/Data/Int512DataSources.cs new file mode 100644 index 0000000..82182c8 --- /dev/null +++ b/src/MissingValues.Tests/Data/Int512DataSources.cs @@ -0,0 +1,1158 @@ +using System.Globalization; +using MissingValues.Tests.Data.Sources; + +namespace MissingValues.Tests.Data; + +public class Int512DataSources + : IMathOperatorsDataSource, + IShiftOperatorsDataSource, + IBitwiseOperatorsDataSource, + IEqualityOperatorsDataSource, + IComparisonOperatorsDataSource, + INumberBaseDataSource, + INumberDataSource, + IBinaryNumberDataSource, + IBinaryIntegerDataSource +{ + public static IEnumerable> op_AdditionTestData() + { + yield return () => (Int512.Zero, Int512.Zero, Int512.Zero); + yield return () => (Int512.One, Int512.Zero, Int512.One); + yield return () => (Int512.One, Int512.One, new Int512(0, 0, 0, 0, 0, 0, 0, 2)); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 1, ulong.MaxValue), + new Int512(0, 0, 0, 0, 0, 0, 1, 1), + new Int512(0, 0, 0, 0, 0, 0, 3, 0)); + yield return () => ( + new Int512(0, 0, 0, 1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), + new Int512(0, 0, 0, 1, 1, 1, 1, 1), + new Int512(0, 0, 0, 3, 1, 1, 1, 0)); + yield return () => ( + new Int512(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), + new Int512(1, 1, 1, 1, 1, 1, 1, 1), + new Int512(3, 1, 1, 1, 1, 1, 1, 0)); + yield return () => (Int512.MaxValue, Int512.One, Int512.MinValue); + yield return () => (Int512.NegativeOne, Int512.One, Int512.Zero); + } + + public static IEnumerable> op_CheckedAdditionTestData() + { + yield return () => (Int512.Zero, Int512.Zero, Int512.Zero, false); + yield return () => (Int512.One, Int512.Zero, Int512.One, false); + yield return () => (Int512.One, Int512.One, new Int512(0, 0, 0, 0, 0, 0, 0, 2), false); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 1, ulong.MaxValue), + new Int512(0, 0, 0, 0, 0, 0, 1, 1), + new Int512(0, 0, 0, 0, 0, 0, 3, 0), + false); + yield return () => ( + new Int512(0, 0, 0, 1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), + new Int512(0, 0, 0, 1, 1, 1, 1, 1), + new Int512(0, 0, 0, 3, 1, 1, 1, 0), + false); + yield return () => ( + new Int512(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), + new Int512(1, 1, 1, 1, 1, 1, 1, 1), + new Int512(3, 1, 1, 1, 1, 1, 1, 0), + false); + yield return () => (Int512.MaxValue, Int512.One, Int512.MinValue, true); + yield return () => (Int512.NegativeOne, Int512.One, Int512.Zero, false); + yield return () => (Int512.MinValue, Int512.NegativeOne, Int512.MaxValue, true); + } + + public static IEnumerable> op_CheckedDecrementTestData() + { + yield return () => (Int512.Zero, Int512.NegativeOne, false); + yield return () => (Int512.One, Int512.Zero, false); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 0, 2), + new Int512(0, 0, 0, 0, 0, 0, 0, 1), + false); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 1, 0), + new Int512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), + false); + yield return () => ( + new Int512(0, 0, 0, 0, 1, 0, 0, 0), + new Int512(0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), + false); + yield return () => ( + new Int512(0, 0, 0, 1, 0, 0, 0, 0), + new Int512(0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), + false); + yield return () => ( + new Int512(1, 0, 0, 0, 0, 0, 0, 0), + new Int512(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), + false); + yield return () => (Int512.MinValue, Int512.MaxValue, true); + } + + public static IEnumerable> op_CheckedIncrementTestData() + { + yield return () => (Int512.Zero, Int512.One, false); + yield return () => (Int512.One, new Int512(0, 0, 0, 0, 0, 0, 0, 2), false); + yield return () => (Int512.MaxValue, Int512.Zero, true); + yield return () => (Int512.NegativeOne, Int512.Zero, false); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), + new Int512(0, 0, 0, 0, 0, 0, 1, 0), + false); + yield return () => ( + new Int512(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), + new Int512(1, 0, 0, 0, 0, 0, 0, 0), + false); + yield return () => ( + new Int512(0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), + new Int512(0, 0, 0, 1, 0, 0, 0, 0), + false); + yield return () => ( + new Int512(unchecked((ulong)-123456789), 987654321, 555555555, 444444444, 333333333, 222222222, 111111111, 999999999), + new Int512(unchecked((ulong)-123456789), 987654321, 555555555, 444444444, 333333333, 222222222, 111111111, 1000000000), + false); + } + + public static IEnumerable> op_CheckedMultiplyTestData() + { + yield return () => (Int512.Zero, Int512.Zero, Int512.Zero, false); + yield return () => (Int512.Zero, Int512.One, Int512.Zero, false); + yield return () => (Int512.One, Int512.One, Int512.One, false); + yield return () => (Int512.One, Int512.NegativeOne, Int512.NegativeOne, false); + yield return () => (Int512.NegativeOne, Int512.NegativeOne, Int512.One, false); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 0, 2), new Int512(0, 0, 0, 0, 0, 0, 0, 3), new Int512(0, 0, 0, 0, 0, 0, 0, 6), false); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), new Int256(0, 0, 0, 2), new Int256(0, 0, 1, ulong.MaxValue - 1), false); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), + new Int512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), + new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFE, 0x0000_0000_0000_0001), + false + ); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 1, 0), + new Int512(0, 0, 0, 0, 0, 0, 1, 0), + new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), + false + ); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 1, 0, 0), + new Int512(0, 0, 0, 0, 0, 1, 0, 0), + new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), + false + ); + yield return () => ( + Int512.MaxValue, + new Int512(0, 0, 0, 0, 0, 0, 0, 1), + default, + true + ); + } + + public static IEnumerable> op_CheckedSubtractionTestData() + { + yield return () => (Int512.Zero, Int512.Zero, Int512.Zero, false); + yield return () => (Int512.One, Int512.Zero, Int512.One, false); + yield return () => (Int512.One, Int512.One, Int512.Zero, false); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 0, 2), + Int512.One, + Int512.One, + false); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 1, 0), + new Int512(0, 0, 0, 0, 0, 0, 0, 1), + new Int512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), + false); + yield return () => ( + new Int512(0, 0, 0, 1, 0, 0, 0, 0), + new Int512(0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), + new Int512(0, 0, 0, 0, 0, 0, 0, 1), + false); + yield return () => (Int512.MinValue, Int512.One, Int512.MaxValue, true); + yield return () => (Int512.MaxValue, Int512.NegativeOne, Int512.MinValue, true); + } + + public static IEnumerable> op_DecrementTestData() + { + yield return () => (Int512.Zero, Int512.NegativeOne); + yield return () => (Int512.One, Int512.Zero); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 0, 2), new Int512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 1, 0), new Int512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue)); + yield return () => (new Int512(0, 0, 0, 0, 0, 1, 0, 0), new Int512(0, 0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new Int512(0, 0, 0, 0, 1, 0, 0, 0), new Int512(0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new Int512(1, 0, 0, 0, 0, 0, 0, 0), new Int512(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + yield return () => (Int512.MinValue, Int512.MaxValue); + } + + public static IEnumerable> op_DivisionTestData() + { + yield return () => (Int512.Zero, Int512.One, Int512.Zero); + yield return () => (Int512.One, Int512.One, Int512.One); + yield return () => (Int512.One, Int512.NegativeOne, Int512.NegativeOne); + yield return () => (Int512.NegativeOne, Int512.One, Int512.NegativeOne); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 0, 4), new Int512(0, 0, 0, 0, 0, 0, 0, 2), new Int512(0, 0, 0, 0, 0, 0, 0, 2)); + yield return () => (Int512.MaxValue, Int512.One, Int512.MaxValue); + yield return () => (Int512.MinValue, Int512.One, Int512.MinValue); + yield return () => (Int512.Zero, Int512.MaxValue, Int256.Zero); + yield return () => (Int512.MaxValue, Int512.MaxValue, Int512.One); + yield return () => (Int512.MinValue, Int512.MinValue, Int512.One); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 1, 0), new Int512(0, 0, 0, 0, 0, 1, 0, 0), Int512.Zero); + yield return () => ( + new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), + new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000), + new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000) + ); + } + + public static IEnumerable> op_IncrementTestData() + { + yield return () => (Int512.Zero, Int512.One); + yield return () => (Int512.One, new Int512(0, 0, 0, 0, 0, 0, 0, 2)); + yield return () => (Int512.MaxValue, Int512.MinValue); + yield return () => (Int512.NegativeOne, Int512.Zero); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), new Int512(0, 0, 0, 0, 0, 0, 1, 0)); + yield return () => (new Int512(0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new Int512(0, 0, 0, 0, 1, 0, 0, 0)); + yield return () => ( + new Int512(unchecked((ulong)-123456789), 987654321, 555555555, 444444444, 333333333, 222222222, 111111111, 999999999), + new Int512(unchecked((ulong)-123456789), 987654321, 555555555, 444444444, 333333333, 222222222, 111111111, 1000000000)); + yield return () => (new Int512(0, 0, 0, 0, 0x8000000000000000, 0, 0, 0),new Int512(0, 0, 0, 0, 0x8000000000000000, 0, 0, 1)); + } + + public static IEnumerable> op_ModulusTestData() + { + yield return () => (Int512.Zero, Int512.One, Int512.Zero); + yield return () => (Int512.One, Int512.One, Int512.Zero); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 0, 123456789), Int512.One, Int512.Zero); + yield return () => (Int512.MaxValue, Int512.MaxValue, Int512.Zero); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 1, 0), new Int512(0, 0, 0, 0, 0, 1, 0, 0), new Int512(0, 0, 0, 0, 0, 0, 1, 0)); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 0, 10), new Int512(0, 0, 0, 0, 0, 0, 0, 3), new Int512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 0, 15), new Int512(0, 0, 0, 0, 0, 0, 0, 5), Int512.Zero); + yield return () => (Int512.NegativeOne, new Int512(0, 0, 0, 0, 0, 0, 0, 2), Int512.NegativeOne); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 0, 7), Int512.NegativeOne, Int512.Zero); + yield return () => (Int512.MaxValue, new Int512(0, 0, 0, 0, 0, 0, 0, 123456789), new Int512(0, 0, 0, 0, 0, 0, 0, 77645365)); + yield return () => (new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0040, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000), new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_000F, 0xEE50_B702_5C36_A080, 0x2F23_6D04_753D_5B48, 0xE800_0000_0000_0000), new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x46BD_23F6_8F25_7DFF, 0x4372_4BEE_2B0A_92DC, 0x6000_0000_0000_0000)); + } + + public static IEnumerable> op_MultiplyTestData() + { + yield return () => (Int512.Zero, Int512.Zero, Int512.Zero); + yield return () => (Int512.Zero, Int512.One, Int512.Zero); + yield return () => (Int512.One, Int512.One, Int512.One); + yield return () => (Int512.One, Int512.NegativeOne, Int512.NegativeOne); + yield return () => (Int512.NegativeOne, Int512.NegativeOne, Int512.One); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 0, 2), new Int512(0, 0, 0, 0, 0, 0, 0, 3), new Int512(0, 0, 0, 0, 0, 0, 0, 6)); + yield return () => (new Int512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), new Int256(0, 0, 0, 2), new Int256(0, 0, 1, ulong.MaxValue - 1)); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), + new Int512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), + new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFE, 0x0000_0000_0000_0001) + ); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 1, 0), + new Int512(0, 0, 0, 0, 0, 0, 1, 0), + new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000) + ); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 1, 0, 0), + new Int512(0, 0, 0, 0, 0, 1, 0, 0), + new Int512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000) + ); + } + + public static IEnumerable> op_SubtractionTestData() + { + yield return () => (Int512.Zero, Int512.Zero, Int512.Zero); + yield return () => (Int512.One, Int512.Zero, Int512.One); + yield return () => (Int512.One, Int512.One, Int512.Zero); + yield return () => (Int512.Zero, Int512.One, Int512.NegativeOne); + yield return () => ( + Int512.MaxValue, + Int512.One, + new Int512(long.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue - 1)); + yield return () => (Int512.MinValue, Int512.One, Int512.MaxValue); + yield return () => ( + Int512.MinValue, + Int512.NegativeOne, + new Int512(unchecked((ulong)long.MinValue), 0, 0, 0, 0, 0, 0, 1)); + yield return () => ( + new Int512(1, 2, 3, 4, 5, 6, 7, 8), + new Int512(0, 1, 2, 3, 4, 5, 6, 7), + new Int512(1, 1, 1, 1, 1, 1, 1, 1)); + yield return () => ( + new Int512(0, 0, 0, 0, 0, 0, 0, 0), + new Int512(0, 0, 0, 0, 0, 0, 0, 1), + new Int512(unchecked((ulong)-1), ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + } + + public static IEnumerable> op_ShiftLeftTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_ShiftRightTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_UnsignedShiftRightTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_BitwiseAndTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_BitwiseOrTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_BitwiseXorTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_OnesComplementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_EqualityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_InequalityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_GreaterThanOrEqualTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_GreaterThanTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_LessThanOrEqualTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_LessThanTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> AbsTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsCanonicalTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsComplexNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsEvenIntegerTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsFiniteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsImaginaryNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsInfinityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsIntegerTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNaNTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNegativeTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNegativeInfinityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNormalTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsOddIntegerTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsPositiveTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsPositiveInfinityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsRealNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsSubnormalTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsZeroTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxMagnitudeTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxMagnitudeNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinMagnitudeTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinMagnitudeNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MultiplyAddEstimateTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ParseTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ParseSpanTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ParseUtf8TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryParseTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryParseSpanTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryParseUtf8TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ClampTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> CopySignTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> SignTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsPow2TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> Log2TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> DivRemTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> LeadingZeroCountTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> PopCountTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ReadBigEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ReadLittleEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> RotateLeftTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> RotateRightTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TrailingZeroCountTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> GetByteCountTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> GetShortestBitLengthTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> WriteBigEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> WriteLittleEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedDoubleTestData() + { + yield return () => (Int512.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + yield return () => (Int512.Parse("-781377183594418599030564404241984000000000000000000"), + -781377183594418599030564404241984000000000000000000.0d); + yield return () => (Int512.Parse("-693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455"), + -693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455.0d); + } + + public static IEnumerable> ConvertToSaturatingDoubleTestData() + { + yield return () => (Int512.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + yield return () => (Int512.Parse("-781377183594418599030564404241984000000000000000000"), + -781377183594418599030564404241984000000000000000000.0d); + yield return () => (Int512.Parse("693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455"), + 693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455.0d); + yield return () => (Int512.Parse("-693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455"), + -693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455.0d); + } + + public static IEnumerable> ConvertToTruncatingDoubleTestData() + { + yield return () => (Int512.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + yield return () => (Int512.Parse("-781377183594418599030564404241984000000000000000000"), + -781377183594418599030564404241984000000000000000000.0d); + yield return () => (Int512.Parse("693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455"), + 693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455.0d); + yield return () => (Int512.Parse("-693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455"), + -693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455.0d); + } + + public static IEnumerable> ConvertToCheckedQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingOctoTestData() + { + throw new NotImplementedException(); + } +} diff --git a/src/MissingValues.Tests/Data/OctoDataSources.cs b/src/MissingValues.Tests/Data/OctoDataSources.cs new file mode 100644 index 0000000..b2565ad --- /dev/null +++ b/src/MissingValues.Tests/Data/OctoDataSources.cs @@ -0,0 +1,970 @@ +using System.Globalization; +using MissingValues.Tests.Data.Sources; + +namespace MissingValues.Tests.Data; + +public class OctoDataSources + : IMathOperatorsDataSource, + IBitwiseOperatorsDataSource, + IEqualityOperatorsDataSource, + IComparisonOperatorsDataSource, + INumberBaseDataSource, + INumberDataSource, + IBinaryNumberDataSource, + IFloatingPointDataSource, + IFloatingPointIeee754DataSource +{ + public static IEnumerable> op_AdditionTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_CheckedAdditionTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_CheckedDecrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_CheckedIncrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_CheckedMultiplyTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_CheckedSubtractionTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_DecrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_DivisionTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_IncrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_ModulusTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_MultiplyTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_SubtractionTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_BitwiseAndTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_BitwiseOrTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_BitwiseXorTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_OnesComplementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_EqualityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_InequalityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_GreaterThanOrEqualTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_GreaterThanTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_LessThanOrEqualTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_LessThanTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> AbsTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsCanonicalTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsComplexNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsEvenIntegerTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsFiniteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsImaginaryNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsInfinityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsIntegerTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNaNTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNegativeTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNegativeInfinityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNormalTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsOddIntegerTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsPositiveTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsPositiveInfinityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsRealNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsSubnormalTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsZeroTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxMagnitudeTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxMagnitudeNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinMagnitudeTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinMagnitudeNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MultiplyAddEstimateTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ParseTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ParseSpanTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ParseUtf8TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryParseTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryParseSpanTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryParseUtf8TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ClampTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> CopySignTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> SignTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsPow2TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> Log2TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> CeilingTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> FloorTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> RoundTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TruncateTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> GetExponentByteCountTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> GetExponentShortestBitLengthTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> GetSignificandBitLengthTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> GetSignificandByteCountTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryWriteExponentBigEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryWriteExponentLittleEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryWriteSignificandBigEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryWriteSignificandLittleEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> Atan2TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> Atan2PiTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> BitDecrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> BitIncrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> FusedMultiplyAddTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> Ieee754RemainderTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ILogBTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> LerpTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ReciprocalEstimateTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ReciprocalSqrtEstimateTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ScaleBTestData() + { + throw new NotImplementedException(); + } + public static IEnumerable> ConvertToCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingQuadTestData() + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/QuadDataSources.cs b/src/MissingValues.Tests/Data/QuadDataSources.cs new file mode 100644 index 0000000..4858328 --- /dev/null +++ b/src/MissingValues.Tests/Data/QuadDataSources.cs @@ -0,0 +1,1053 @@ +using System.Globalization; +using System.Text; +using MissingValues.Tests.Data.Sources; + +namespace MissingValues.Tests.Data; + +public class QuadDataSources + : IMathOperatorsDataSource, + IBitwiseOperatorsDataSource, + IEqualityOperatorsDataSource, + IComparisonOperatorsDataSource, + INumberBaseDataSource, + INumberDataSource, + IBinaryNumberDataSource, + IFloatingPointDataSource, + IFloatingPointIeee754DataSource +{ + public static IEnumerable> op_AdditionTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_CheckedAdditionTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_CheckedDecrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_CheckedIncrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_CheckedMultiplyTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_CheckedSubtractionTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_DecrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_DivisionTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_IncrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_ModulusTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_MultiplyTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_SubtractionTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_BitwiseAndTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_BitwiseOrTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_BitwiseXorTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_OnesComplementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_EqualityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_InequalityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_GreaterThanOrEqualTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_GreaterThanTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_LessThanOrEqualTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> op_LessThanTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> AbsTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsCanonicalTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsComplexNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsEvenIntegerTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsFiniteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsImaginaryNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsInfinityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsIntegerTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNaNTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNegativeTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNegativeInfinityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsNormalTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsOddIntegerTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsPositiveTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsPositiveInfinityTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsRealNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsSubnormalTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsZeroTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxMagnitudeTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxMagnitudeNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinMagnitudeTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinMagnitudeNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MultiplyAddEstimateTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ParseTestData() + { + yield return () => ("2.0", NumberStyles.Float, CultureInfo.InvariantCulture, Quad.Two); + yield return () => ("-2", NumberStyles.Float, CultureInfo.InvariantCulture, -Quad.Two); + yield return () => ("0", NumberStyles.Float, CultureInfo.InvariantCulture, Quad.Zero); + yield return () => (NumberFormatInfo.InvariantInfo.PositiveInfinitySymbol, NumberStyles.Float, CultureInfo.InvariantCulture, Quad.PositiveInfinity); + yield return () => (NumberFormatInfo.InvariantInfo.NegativeInfinitySymbol, NumberStyles.Float, CultureInfo.InvariantCulture, Quad.NegativeInfinity); + yield return () => (NumberFormatInfo.InvariantInfo.NaNSymbol, NumberStyles.Float, CultureInfo.InvariantCulture, Quad.NaN); + yield return () => ("256.4995", NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x4007_007F_DF3B_645A, 0x1CAC_0831_26E9_78D5)); + yield return () => ("471581881", NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x401B_C1BC_4B90_0000, 0x0000_0000_0000_0000)); + yield return () => ("1.93561113", NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x3FFF_EF84_3605_1FA4, 0x8B0F_3D34_BECE_8762)); + yield return () => ("9715574.2", NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x4016_287E_EC66_6666, 0x6666_6666_6666_6666)); + yield return () => ("0.51438427732005011792", NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x3FFE_075D_6041_5519, 0x72D0_0AD3_7DB4_57E9)); + yield return () => ("0.04201133209656899095", NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x3FFA_5828_262D_512C, 0x8840_B3B3_D424_5947)); + yield return () => ("7.7E777", NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x4A17_0F28_5D1D_4C84, 0xA11F_6899_101B_A9A4)); + yield return () => ("-7.7E-777", NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0xB5EC_BFCE_3AF6_4E08, 0x42C8_5750_BEBD_A572)); + } + + public static IEnumerable> ParseSpanTestData() + { + yield return () => ("2.0".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Quad.Two); + yield return () => ("-2".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, -Quad.Two); + yield return () => ("0".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Quad.Zero); + yield return () => (NumberFormatInfo.InvariantInfo.PositiveInfinitySymbol.ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Quad.PositiveInfinity); + yield return () => (NumberFormatInfo.InvariantInfo.NegativeInfinitySymbol.ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Quad.NegativeInfinity); + yield return () => (NumberFormatInfo.InvariantInfo.NaNSymbol.ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Quad.NaN); + yield return () => ("256.4995".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x4007_007F_DF3B_645A, 0x1CAC_0831_26E9_78D5)); + yield return () => ("471581881".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x401B_C1BC_4B90_0000, 0x0000_0000_0000_0000)); + yield return () => ("1.93561113".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x3FFF_EF84_3605_1FA4, 0x8B0F_3D34_BECE_8762)); + yield return () => ("9715574.2".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x4016_287E_EC66_6666, 0x6666_6666_6666_6666)); + yield return () => ("0.51438427732005011792".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x3FFE_075D_6041_5519, 0x72D0_0AD3_7DB4_57E9)); + yield return () => ("0.04201133209656899095".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x3FFA_5828_262D_512C, 0x8840_B3B3_D424_5947)); + yield return () => ("7.7E777".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x4A17_0F28_5D1D_4C84, 0xA11F_6899_101B_A9A4)); + yield return () => ("-7.7E-777".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0xB5EC_BFCE_3AF6_4E08, 0x42C8_5750_BEBD_A572)); + } + + public static IEnumerable> ParseUtf8TestData() + { + yield return () => ("2.0"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Quad.Two); + yield return () => ("-2"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, -Quad.Two); + yield return () => ("0"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Quad.Zero); + yield return () => (Encoding.UTF8.GetBytes(NumberFormatInfo.InvariantInfo.PositiveInfinitySymbol), NumberStyles.Float, CultureInfo.InvariantCulture, Quad.PositiveInfinity); + yield return () => (Encoding.UTF8.GetBytes(NumberFormatInfo.InvariantInfo.NegativeInfinitySymbol), NumberStyles.Float, CultureInfo.InvariantCulture, Quad.NegativeInfinity); + yield return () => (Encoding.UTF8.GetBytes(NumberFormatInfo.InvariantInfo.NaNSymbol), NumberStyles.Float, CultureInfo.InvariantCulture, Quad.NaN); + yield return () => ("256.4995"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x4007_007F_DF3B_645A, 0x1CAC_0831_26E9_78D5)); + yield return () => ("471581881"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x401B_C1BC_4B90_0000, 0x0000_0000_0000_0000)); + yield return () => ("1.93561113"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x3FFF_EF84_3605_1FA4, 0x8B0F_3D34_BECE_8762)); + yield return () => ("9715574.2"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x4016_287E_EC66_6666, 0x6666_6666_6666_6666)); + yield return () => ("0.51438427732005011792"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x3FFE_075D_6041_5519, 0x72D0_0AD3_7DB4_57E9)); + yield return () => ("0.04201133209656899095"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x3FFA_5828_262D_512C, 0x8840_B3B3_D424_5947)); + yield return () => ("7.7E777"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0x4A17_0F28_5D1D_4C84, 0xA11F_6899_101B_A9A4)); + yield return () => ("-7.7E-777"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, Values.CreateFloat(0xB5EC_BFCE_3AF6_4E08, 0x42C8_5750_BEBD_A572)); + } + + public static IEnumerable> TryParseTestData() + { + yield return () => ("2.0", NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.Two); + yield return () => ("-2", NumberStyles.Float, CultureInfo.InvariantCulture, true, -Quad.Two); + yield return () => ("0", NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.Zero); + yield return () => (NumberFormatInfo.InvariantInfo.PositiveInfinitySymbol, NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.PositiveInfinity); + yield return () => (NumberFormatInfo.InvariantInfo.NegativeInfinitySymbol, NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.NegativeInfinity); + yield return () => (NumberFormatInfo.InvariantInfo.NaNSymbol, NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.NaN); + yield return () => ("256.4995", NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x4007_007F_DF3B_645A, 0x1CAC_0831_26E9_78D5)); + yield return () => ("471581881", NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x401B_C1BC_4B90_0000, 0x0000_0000_0000_0000)); + yield return () => ("1.93561113", NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x3FFF_EF84_3605_1FA4, 0x8B0F_3D34_BECE_8762)); + yield return () => ("9715574.2", NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x4016_287E_EC66_6666, 0x6666_6666_6666_6666)); + yield return () => ("0.51438427732005011792", NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x3FFE_075D_6041_5519, 0x72D0_0AD3_7DB4_57E9)); + yield return () => ("0.04201133209656899095", NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x3FFA_5828_262D_512C, 0x8840_B3B3_D424_5947)); + yield return () => ("7.7E777", NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x4A17_0F28_5D1D_4C84, 0xA11F_6899_101B_A9A4)); + yield return () => ("-7.7E-777", NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0xB5EC_BFCE_3AF6_4E08, 0x42C8_5750_BEBD_A572)); + yield return () => ("1A", NumberStyles.Float, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> TryParseSpanTestData() + { + yield return () => ("2.0".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.Two); + yield return () => ("-2".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, -Quad.Two); + yield return () => ("0".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.Zero); + yield return () => (NumberFormatInfo.InvariantInfo.PositiveInfinitySymbol.ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.PositiveInfinity); + yield return () => (NumberFormatInfo.InvariantInfo.NegativeInfinitySymbol.ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.NegativeInfinity); + yield return () => (NumberFormatInfo.InvariantInfo.NaNSymbol.ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.NaN); + yield return () => ("256.4995".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x4007_007F_DF3B_645A, 0x1CAC_0831_26E9_78D5)); + yield return () => ("471581881".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x401B_C1BC_4B90_0000, 0x0000_0000_0000_0000)); + yield return () => ("1.93561113".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x3FFF_EF84_3605_1FA4, 0x8B0F_3D34_BECE_8762)); + yield return () => ("9715574.2".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x4016_287E_EC66_6666, 0x6666_6666_6666_6666)); + yield return () => ("0.51438427732005011792".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x3FFE_075D_6041_5519, 0x72D0_0AD3_7DB4_57E9)); + yield return () => ("0.04201133209656899095".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x3FFA_5828_262D_512C, 0x8840_B3B3_D424_5947)); + yield return () => ("7.7E777".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x4A17_0F28_5D1D_4C84, 0xA11F_6899_101B_A9A4)); + yield return () => ("-7.7E-777".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0xB5EC_BFCE_3AF6_4E08, 0x42C8_5750_BEBD_A572)); + yield return () => ("1A".ToCharArray(), NumberStyles.Float, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> TryParseUtf8TestData() + { + yield return () => ("2.0"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.Two); + yield return () => ("-2"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, -Quad.Two); + yield return () => ("0"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.Zero); + yield return () => (Encoding.UTF8.GetBytes(NumberFormatInfo.InvariantInfo.PositiveInfinitySymbol), NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.PositiveInfinity); + yield return () => (Encoding.UTF8.GetBytes(NumberFormatInfo.InvariantInfo.NegativeInfinitySymbol), NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.NegativeInfinity); + yield return () => (Encoding.UTF8.GetBytes(NumberFormatInfo.InvariantInfo.NaNSymbol), NumberStyles.Float, CultureInfo.InvariantCulture, true, Quad.NaN); + yield return () => ("256.4995"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x4007_007F_DF3B_645A, 0x1CAC_0831_26E9_78D5)); + yield return () => ("471581881"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x401B_C1BC_4B90_0000, 0x0000_0000_0000_0000)); + yield return () => ("1.93561113"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x3FFF_EF84_3605_1FA4, 0x8B0F_3D34_BECE_8762)); + yield return () => ("9715574.2"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x4016_287E_EC66_6666, 0x6666_6666_6666_6666)); + yield return () => ("0.51438427732005011792"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x3FFE_075D_6041_5519, 0x72D0_0AD3_7DB4_57E9)); + yield return () => ("0.04201133209656899095"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x3FFA_5828_262D_512C, 0x8840_B3B3_D424_5947)); + yield return () => ("7.7E777"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0x4A17_0F28_5D1D_4C84, 0xA11F_6899_101B_A9A4)); + yield return () => ("-7.7E-777"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, true, Values.CreateFloat(0xB5EC_BFCE_3AF6_4E08, 0x42C8_5750_BEBD_A572)); + yield return () => ("1A"u8.ToArray(), NumberStyles.Float, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> ClampTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> CopySignTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MaxNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> MinNumberTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> SignTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> IsPow2TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> Log2TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> CeilingTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> FloorTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> RoundTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TruncateTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> GetExponentByteCountTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> GetExponentShortestBitLengthTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> GetSignificandBitLengthTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> GetSignificandByteCountTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryWriteExponentBigEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryWriteExponentLittleEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryWriteSignificandBigEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> TryWriteSignificandLittleEndianTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> Atan2TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> Atan2PiTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> BitDecrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> BitIncrementTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> FusedMultiplyAddTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> Ieee754RemainderTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ILogBTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> LerpTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ReciprocalEstimateTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ReciprocalSqrtEstimateTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ScaleBTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingOctoTestData() + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/Sources/IBinaryIntegerDataSource.cs b/src/MissingValues.Tests/Data/Sources/IBinaryIntegerDataSource.cs new file mode 100644 index 0000000..b0bda8f --- /dev/null +++ b/src/MissingValues.Tests/Data/Sources/IBinaryIntegerDataSource.cs @@ -0,0 +1,20 @@ +using System.Numerics; + +namespace MissingValues.Tests.Data.Sources; + +public interface IBinaryIntegerDataSource + where T : IBinaryInteger +{ + static abstract IEnumerable> DivRemTestData(); + static abstract IEnumerable> LeadingZeroCountTestData(); + static abstract IEnumerable> PopCountTestData(); + static abstract IEnumerable> ReadBigEndianTestData(); + static abstract IEnumerable> ReadLittleEndianTestData(); + static abstract IEnumerable> RotateLeftTestData(); + static abstract IEnumerable> RotateRightTestData(); + static abstract IEnumerable> TrailingZeroCountTestData(); + static abstract IEnumerable> GetByteCountTestData(); + static abstract IEnumerable> GetShortestBitLengthTestData(); + static abstract IEnumerable> WriteBigEndianTestData(); + static abstract IEnumerable> WriteLittleEndianTestData(); +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/Sources/IBinaryNumberDataSource.cs b/src/MissingValues.Tests/Data/Sources/IBinaryNumberDataSource.cs new file mode 100644 index 0000000..329de97 --- /dev/null +++ b/src/MissingValues.Tests/Data/Sources/IBinaryNumberDataSource.cs @@ -0,0 +1,10 @@ +using System.Numerics; + +namespace MissingValues.Tests.Data.Sources; + +public interface IBinaryNumberDataSource + where T : IBinaryNumber +{ + static abstract IEnumerable> IsPow2TestData(); + static abstract IEnumerable> Log2TestData(); +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/Sources/IBitwiseOperatorsDataSource.cs b/src/MissingValues.Tests/Data/Sources/IBitwiseOperatorsDataSource.cs new file mode 100644 index 0000000..36742e8 --- /dev/null +++ b/src/MissingValues.Tests/Data/Sources/IBitwiseOperatorsDataSource.cs @@ -0,0 +1,12 @@ +using System.Numerics; + +namespace MissingValues.Tests.Data.Sources; + +public interface IBitwiseOperatorsDataSource + where T : IBitwiseOperators +{ + static abstract IEnumerable> op_BitwiseAndTestData(); + static abstract IEnumerable> op_BitwiseOrTestData(); + static abstract IEnumerable> op_BitwiseXorTestData(); + static abstract IEnumerable> op_OnesComplementTestData(); +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/Sources/IComparisonOperatorsDataSource.cs b/src/MissingValues.Tests/Data/Sources/IComparisonOperatorsDataSource.cs new file mode 100644 index 0000000..b9f9b99 --- /dev/null +++ b/src/MissingValues.Tests/Data/Sources/IComparisonOperatorsDataSource.cs @@ -0,0 +1,12 @@ +using System.Numerics; + +namespace MissingValues.Tests.Data.Sources; + +public interface IComparisonOperatorsDataSource + where T : IComparisonOperators +{ + static abstract IEnumerable> op_GreaterThanOrEqualTestData(); + static abstract IEnumerable> op_GreaterThanTestData(); + static abstract IEnumerable> op_LessThanOrEqualTestData(); + static abstract IEnumerable> op_LessThanTestData(); +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/Sources/IEqualityOperatorsDataSource.cs b/src/MissingValues.Tests/Data/Sources/IEqualityOperatorsDataSource.cs new file mode 100644 index 0000000..70b6f26 --- /dev/null +++ b/src/MissingValues.Tests/Data/Sources/IEqualityOperatorsDataSource.cs @@ -0,0 +1,10 @@ +using System.Numerics; + +namespace MissingValues.Tests.Data.Sources; + +public interface IEqualityOperatorsDataSource + where T : IEqualityOperators +{ + static abstract IEnumerable> op_EqualityTestData(); + static abstract IEnumerable> op_InequalityTestData(); +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/Sources/IFloatingPointDataSource.cs b/src/MissingValues.Tests/Data/Sources/IFloatingPointDataSource.cs new file mode 100644 index 0000000..06ec3b1 --- /dev/null +++ b/src/MissingValues.Tests/Data/Sources/IFloatingPointDataSource.cs @@ -0,0 +1,20 @@ +using System.Numerics; + +namespace MissingValues.Tests.Data.Sources; + +public interface IFloatingPointDataSource + where T : IFloatingPoint +{ + static abstract IEnumerable> CeilingTestData(); + static abstract IEnumerable> FloorTestData(); + static abstract IEnumerable> RoundTestData(); + static abstract IEnumerable> TruncateTestData(); + static abstract IEnumerable> GetExponentByteCountTestData(); + static abstract IEnumerable> GetExponentShortestBitLengthTestData(); + static abstract IEnumerable> GetSignificandBitLengthTestData(); + static abstract IEnumerable> GetSignificandByteCountTestData(); + static abstract IEnumerable> TryWriteExponentBigEndianTestData(); + static abstract IEnumerable> TryWriteExponentLittleEndianTestData(); + static abstract IEnumerable> TryWriteSignificandBigEndianTestData(); + static abstract IEnumerable> TryWriteSignificandLittleEndianTestData(); +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/Sources/IFloatingPointIeee754DataSource.cs b/src/MissingValues.Tests/Data/Sources/IFloatingPointIeee754DataSource.cs new file mode 100644 index 0000000..c2fe941 --- /dev/null +++ b/src/MissingValues.Tests/Data/Sources/IFloatingPointIeee754DataSource.cs @@ -0,0 +1,19 @@ +using System.Numerics; + +namespace MissingValues.Tests.Data.Sources; + +public interface IFloatingPointIeee754DataSource + where T : IFloatingPointIeee754 +{ + static abstract IEnumerable> Atan2TestData(); + static abstract IEnumerable> Atan2PiTestData(); + static abstract IEnumerable> BitDecrementTestData(); + static abstract IEnumerable> BitIncrementTestData(); + static abstract IEnumerable> FusedMultiplyAddTestData(); + static abstract IEnumerable> Ieee754RemainderTestData(); + static abstract IEnumerable> ILogBTestData(); + static abstract IEnumerable> LerpTestData(); + static abstract IEnumerable> ReciprocalEstimateTestData(); + static abstract IEnumerable> ReciprocalSqrtEstimateTestData(); + static abstract IEnumerable> ScaleBTestData(); +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/Sources/IMathOperators.cs b/src/MissingValues.Tests/Data/Sources/IMathOperators.cs new file mode 100644 index 0000000..512debc --- /dev/null +++ b/src/MissingValues.Tests/Data/Sources/IMathOperators.cs @@ -0,0 +1,28 @@ +using System.Numerics; + +namespace MissingValues.Tests.Data.Sources; + +public interface IMathOperatorsDataSource + where T + : + IAdditionOperators, + IIncrementOperators, + ISubtractionOperators, + IDecrementOperators, + IMultiplyOperators, + IDivisionOperators, + IModulusOperators +{ + static abstract IEnumerable> op_AdditionTestData(); + static abstract IEnumerable> op_CheckedAdditionTestData(); + static abstract IEnumerable> op_CheckedDecrementTestData(); + static abstract IEnumerable> op_CheckedIncrementTestData(); + static abstract IEnumerable> op_CheckedMultiplyTestData(); + static abstract IEnumerable> op_CheckedSubtractionTestData(); + static abstract IEnumerable> op_DecrementTestData(); + static abstract IEnumerable> op_DivisionTestData(); + static abstract IEnumerable> op_IncrementTestData(); + static abstract IEnumerable> op_ModulusTestData(); + static abstract IEnumerable> op_MultiplyTestData(); + static abstract IEnumerable> op_SubtractionTestData(); +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/Sources/INumberBaseDataSource.cs b/src/MissingValues.Tests/Data/Sources/INumberBaseDataSource.cs new file mode 100644 index 0000000..5ec0253 --- /dev/null +++ b/src/MissingValues.Tests/Data/Sources/INumberBaseDataSource.cs @@ -0,0 +1,38 @@ +using System.Globalization; +using System.Numerics; + +namespace MissingValues.Tests.Data.Sources; + +public interface INumberBaseDataSource + where T : INumberBase +{ + static abstract IEnumerable> AbsTestData(); + static abstract IEnumerable> IsCanonicalTestData(); + static abstract IEnumerable> IsComplexNumberTestData(); + static abstract IEnumerable> IsEvenIntegerTestData(); + static abstract IEnumerable> IsFiniteTestData(); + static abstract IEnumerable> IsImaginaryNumberTestData(); + static abstract IEnumerable> IsInfinityTestData(); + static abstract IEnumerable> IsIntegerTestData(); + static abstract IEnumerable> IsNaNTestData(); + static abstract IEnumerable> IsNegativeTestData(); + static abstract IEnumerable> IsNegativeInfinityTestData(); + static abstract IEnumerable> IsNormalTestData(); + static abstract IEnumerable> IsOddIntegerTestData(); + static abstract IEnumerable> IsPositiveTestData(); + static abstract IEnumerable> IsPositiveInfinityTestData(); + static abstract IEnumerable> IsRealNumberTestData(); + static abstract IEnumerable> IsSubnormalTestData(); + static abstract IEnumerable> IsZeroTestData(); + static abstract IEnumerable> MaxMagnitudeTestData(); + static abstract IEnumerable> MaxMagnitudeNumberTestData(); + static abstract IEnumerable> MinMagnitudeTestData(); + static abstract IEnumerable> MinMagnitudeNumberTestData(); + static abstract IEnumerable> MultiplyAddEstimateTestData(); + static abstract IEnumerable> ParseTestData(); + static abstract IEnumerable> ParseSpanTestData(); + static abstract IEnumerable> ParseUtf8TestData(); + static abstract IEnumerable> TryParseTestData(); + static abstract IEnumerable> TryParseSpanTestData(); + static abstract IEnumerable> TryParseUtf8TestData(); +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/Sources/INumberDataSource.cs b/src/MissingValues.Tests/Data/Sources/INumberDataSource.cs new file mode 100644 index 0000000..f06a3e5 --- /dev/null +++ b/src/MissingValues.Tests/Data/Sources/INumberDataSource.cs @@ -0,0 +1,15 @@ +using System.Numerics; + +namespace MissingValues.Tests.Data.Sources; + +public interface INumberDataSource + where T : INumber +{ + static abstract IEnumerable> ClampTestData(); + static abstract IEnumerable> CopySignTestData(); + static abstract IEnumerable> MaxTestData(); + static abstract IEnumerable> MaxNumberTestData(); + static abstract IEnumerable> MinTestData(); + static abstract IEnumerable> MinNumberTestData(); + static abstract IEnumerable> SignTestData(); +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/Sources/IShiftOperatorsDataSource.cs b/src/MissingValues.Tests/Data/Sources/IShiftOperatorsDataSource.cs new file mode 100644 index 0000000..6f40c21 --- /dev/null +++ b/src/MissingValues.Tests/Data/Sources/IShiftOperatorsDataSource.cs @@ -0,0 +1,11 @@ +using System.Numerics; + +namespace MissingValues.Tests.Data.Sources; + +public interface IShiftOperatorsDataSource + where T : IShiftOperators +{ + static abstract IEnumerable> op_ShiftLeftTestData(); + static abstract IEnumerable> op_ShiftRightTestData(); + static abstract IEnumerable> op_UnsignedShiftRightTestData(); +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Data/UInt256DataSources.cs b/src/MissingValues.Tests/Data/UInt256DataSources.cs new file mode 100644 index 0000000..41a30d7 --- /dev/null +++ b/src/MissingValues.Tests/Data/UInt256DataSources.cs @@ -0,0 +1,1386 @@ +using System.Globalization; +using System.Runtime.CompilerServices; +using MissingValues.Tests.Data.Sources; + +namespace MissingValues.Tests.Data; + +public class UInt256DataSources + : IMathOperatorsDataSource, + IShiftOperatorsDataSource, + IBitwiseOperatorsDataSource, + IEqualityOperatorsDataSource, + IComparisonOperatorsDataSource, + INumberBaseDataSource, + INumberDataSource, + IBinaryNumberDataSource, + IBinaryIntegerDataSource +{ + public static IEnumerable> op_AdditionTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, UInt256.Zero); + yield return () => (UInt256.Zero, UInt256.One, UInt256.One); + yield return () => (new UInt256(0, 0, 0, 1), new UInt256(0, 0, 0, 2), new UInt256(0, 0, 0, 3)); + yield return () => (new UInt256(0, 0, 1, ulong.MaxValue), new UInt256(0, 0, 1, 1), new UInt256(0, 0, 3, 0)); + yield return () => (new UInt256(0, 1, ulong.MaxValue, ulong.MaxValue), new UInt256(0, 1, 1, 1), new UInt256(0, 3, 1, 0)); + yield return () => (new UInt256(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt256(1, 1, 1, 1), new UInt256(3, 1, 1, 0)); + yield return () => (UInt256.MaxValue, UInt256.One, UInt256.Zero); + } + public static IEnumerable> op_CheckedAdditionTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, UInt256.Zero, false); + yield return () => (UInt256.Zero, UInt256.One, UInt256.One, false); + yield return () => (new UInt256(0, 0, 0, 1), new UInt256(0, 0, 0, 2), new UInt256(0, 0, 0, 3), false); + yield return () => (new UInt256(0, 0, 1, ulong.MaxValue), new UInt256(0, 0, 1, 1), new UInt256(0, 0, 3, 0), false); + yield return () => (new UInt256(0, 1, ulong.MaxValue, ulong.MaxValue), new UInt256(0, 1, 1, 1), new UInt256(0, 3, 1, 0), false); + yield return () => (new UInt256(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt256(1, 1, 1, 1), new UInt256(3, 1, 1, 0), false); + yield return () => (UInt256.MaxValue, UInt256.One, UInt256.Zero, true); + yield return () => (new UInt256(ulong.MaxValue, 0, 0, 0), new UInt256(1, 0, 0, 0), UInt256.Zero, true); + } + public static IEnumerable> op_IncrementTestData() + { + yield return () => (UInt256.Zero, UInt256.One); + yield return () => (new UInt256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt256(1, 0, 0, 0)); + yield return () => (UInt256.MaxValue, UInt256.Zero); + } + public static IEnumerable> op_CheckedIncrementTestData() + { + yield return () => (UInt256.Zero, UInt256.One, false); + yield return () => (new UInt256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt256(1, 0, 0, 0), false); + yield return () => (UInt256.MaxValue, UInt256.Zero, true); + } + public static IEnumerable> op_SubtractionTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, UInt256.Zero); + yield return () => (new UInt256(1, 2, 3, 4), UInt256.Zero, new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), UInt256.Zero); + yield return () => (new UInt256(0, 0, 0, 5), new UInt256(0, 0, 0, 3), new UInt256(0, 0, 0, 2)); + yield return () => (new UInt256(0, 0, 1, 0), new UInt256(0, 0, 0, 1), new UInt256(0, 0, 0, ulong.MaxValue)); + yield return () => (new UInt256(1, 0, 0, 0), UInt256.One, new UInt256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + yield return () => (UInt256.Zero, UInt256.One, UInt256.MaxValue); + } + public static IEnumerable> op_CheckedSubtractionTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, UInt256.Zero, false); + yield return () => (new UInt256(1, 2, 3, 4), UInt256.Zero, new UInt256(1, 2, 3, 4), false); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), UInt256.Zero, false); + yield return () => (new UInt256(0, 0, 0, 5), new UInt256(0, 0, 0, 3), new UInt256(0, 0, 0, 2), false); + yield return () => (new UInt256(0, 0, 1, 0), new UInt256(0, 0, 0, 1), new UInt256(0, 0, 0, ulong.MaxValue), false); + yield return () => (new UInt256(1, 0, 0, 0), UInt256.One, new UInt256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), false); + yield return () => (UInt256.Zero, UInt256.One, UInt256.MaxValue, true); + } + public static IEnumerable> op_DecrementTestData() + { + yield return () => (UInt256.One, UInt256.Zero); + yield return () => (new UInt256(1, 0, 0, 0), new UInt256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + yield return () => (UInt256.Zero, UInt256.MaxValue); + } + public static IEnumerable> op_CheckedDecrementTestData() + { + yield return () => (UInt256.One, UInt256.Zero, false); + yield return () => (new UInt256(1, 0, 0, 0), new UInt256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), false); + yield return () => (UInt256.Zero, UInt256.MaxValue, true); + } + public static IEnumerable> op_MultiplyTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, UInt256.Zero); + yield return () => (new UInt256(1, 2, 3, 4), UInt256.Zero, UInt256.Zero); + yield return () => (UInt256.Zero, new UInt256(1, 2, 3, 4), UInt256.Zero); + yield return () => (new UInt256(1, 2, 3, 4), UInt256.One, new UInt256(1, 2, 3, 4)); + yield return () => (UInt256.One, new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(0, 0, 0, 3), new UInt256(0, 0, 0, 5), new UInt256(0, 0, 0, 15)); + yield return () => (new UInt256(0, 0, 0, ulong.MaxValue), new UInt256(0, 0, 0, ulong.MaxValue), new UInt256(0, 0, ulong.MaxValue - 1, 1)); + yield return () => (new UInt256(0, 0, 1, 0), new UInt256(0, 0, 0, 10), new UInt256(0, 0, 10, 0)); + yield return () => (new UInt256(1, 1, 1, 1), new UInt256(2, 2, 2, 2), new UInt256(8, 6, 4, 2)); + } + public static IEnumerable> op_CheckedMultiplyTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, UInt256.Zero, false); + yield return () => (new UInt256(1, 2, 3, 4), UInt256.Zero, UInt256.Zero, false); + yield return () => (UInt256.Zero, new UInt256(1, 2, 3, 4), UInt256.Zero, false); + yield return () => (new UInt256(1, 2, 3, 4), UInt256.One, new UInt256(1, 2, 3, 4), false); + yield return () => (UInt256.One, new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), false); + yield return () => (new UInt256(0, 0, 0, 3), new UInt256(0, 0, 0, 5), new UInt256(0, 0, 0, 15), false); + yield return () => (new UInt256(0, 0, 0, ulong.MaxValue), new UInt256(0, 0, 0, ulong.MaxValue), new UInt256(0, 0, ulong.MaxValue - 1, 1), false); + yield return () => (new UInt256(0, 0, 1, 0), new UInt256(0, 0, 0, 10), new UInt256(0, 0, 10, 0), false); + yield return () => (new UInt256(1, 1, 1, 1), new UInt256(2, 2, 2, 2), new UInt256(8, 6, 4, 2), true); + } + public static IEnumerable> op_DivisionTestData() + { + yield return () => (UInt256.One, UInt256.Zero, UInt256.Zero); + yield return () => (new UInt256(1, 2, 3, 4), UInt256.One, new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), UInt256.One); + yield return () => (new UInt256(0, 0, 0, 1), new UInt256(1, 0, 0, 0), UInt256.Zero); + yield return () => (new UInt256(0, 0, 0, 1000), new UInt256(0, 0, 0, 10), new UInt256(0, 0, 0, 100)); + yield return () => (new UInt256(0x0, 0x1, 0x0, 0x0), new UInt256(0x0, 0x0, 0x0, 0x2), new UInt256(0x0, 0x0, 0x8000_0000_0000_0000, 0x0)); + yield return () => (new UInt256(0x0, 0x1, 0x2, 0x3), new UInt256(0x0, 0x0, 0x0, 0x10), new UInt256(0x0, 0x0, 0x1000_0000_0000_0000, 0x2000_0000_0000_0000)); + } + public static IEnumerable> op_ModulusTestData() + { + yield return () => (UInt256.One, UInt256.Zero, UInt256.Zero); + yield return () => (new UInt256(1, 2, 3, 4), UInt256.One, UInt256.Zero); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), UInt256.Zero); + yield return () => (new UInt256(0, 0, 0, 1), new UInt256(1, 0, 0, 0), new UInt256(0, 0, 0, 1)); + yield return () => (new UInt256(0, 0, 0, 1000), new UInt256(0, 0, 0, 10), UInt256.Zero); + yield return () => (new UInt256(0, 0, 0, 1234), new UInt256(0, 0, 0, 1000), new UInt256(0, 0, 0, 234)); + yield return () => (new UInt256(0x2, 0x0, 0x0, 0x0), new UInt256(0x0, 0x1, 0x0, 0x0), UInt256.Zero); + yield return () => (new UInt256(0x0, 0x1, 0x2, 0x3), new UInt256(0x0, 0x0, 0x0, 0x10), new UInt256(0x0, 0x0, 0x0, 0x3)); + } + public static IEnumerable> op_OnesComplementTestData() + { + yield return () => (UInt256.Zero, UInt256.MaxValue); + yield return () => (UInt256.MaxValue, UInt256.Zero); + yield return () => (new UInt256(0xAAAAAAAAAAAAAAAA, 0x5555555555555555, 0xAAAAAAAAAAAAAAAA, 0x5555555555555555), new UInt256(0x5555555555555555, 0xAAAAAAAAAAAAAAAA, 0x5555555555555555, 0xAAAAAAAAAAAAAAAA)); + yield return () => (new UInt256(0x0123456789ABCDEF, 0xFEDCBA9876543210, 0x0F0F0F0F0F0F0F0F, 0xF0F0F0F0F0F0F0F0), new UInt256(~0x0123456789ABCDEFU, ~0xFEDCBA9876543210U, ~0x0F0F0F0F0F0F0F0FU, ~0xF0F0F0F0F0F0F0F0U)); + } + public static IEnumerable> op_BitwiseAndTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, UInt256.Zero); + yield return () => (UInt256.Zero, UInt256.MaxValue, UInt256.Zero); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(1, 2, 3, 4), UInt256.MaxValue, new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(0xFFFFFFFF00000000, 0xAAAAAAAA55555555, 0x123456789ABCDEF0, 0x0F0F0F0F0F0F0F0F), new UInt256(0x00000000FFFFFFFF, 0x55555555AAAAAAAA, 0x0F0F0F0F0F0F0F0F, 0xF0F0F0F0F0F0F0F0), new UInt256(0x0000000000000000, 0x0000000000000000, 0x020406080A0C0E00, 0x0000000000000000)); + } + public static IEnumerable> op_BitwiseOrTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, UInt256.Zero); + yield return () => (UInt256.Zero, UInt256.MaxValue, UInt256.MaxValue); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(1, 2, 3, 4), UInt256.MaxValue, UInt256.MaxValue); + yield return () => (new UInt256(0x00000000FFFFFFFF, 0xAAAAAAAA00000000, 0x00000000AAAAAAAA, 0x1234567890ABCDEF), new UInt256(0xFFFFFFFF00000000, 0x0000000055555555, 0x5555555500000000, 0xFEDCBA9876543210), new UInt256(0xFFFFFFFFFFFFFFFF, 0xAAAAAAAA55555555, 0x55555555AAAAAAAA, 0xFEFCFEF8F6FFFFFF)); + } + public static IEnumerable> op_BitwiseXorTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, UInt256.Zero); + yield return () => (UInt256.Zero, UInt256.MaxValue, UInt256.MaxValue); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), UInt256.Zero); + yield return () => (new UInt256(0x0000000000000000, 0xFFFFFFFFFFFFFFFF, 0x1234567890ABCDEF, 0xFEDCBA9876543210), UInt256.MaxValue, new UInt256(ulong.MaxValue, 0x0, 0xEDCBA9876F543210, 0x0123456789ABCDEF)); + yield return () => (new UInt256(0x1234567890ABCDEF, 0xAAAAAAAA00000000, 0x00000000AAAAAAAA, 0xFFFFFFFFFFFFFFFF), new UInt256(0xFFFFFFFFFFFFFFFF, 0x00000000AAAAAAAA, 0xAAAAAAAA00000000, 0x0000000000000000), new UInt256(0xEDCBA9876F543210, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xFFFFFFFFFFFFFFFF)); + } + public static IEnumerable> op_ShiftLeftTestData() + { + yield return () => (new UInt256(1, 2, 3, 4), 0, new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(0, 0, 0, 1), 1, new UInt256(0, 0, 0, 2)); + yield return () => (new UInt256(0, 0, 0, 1), 63, new UInt256(0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => (new UInt256(0, 0, 0, 1), 64, new UInt256(0, 0, 1, 0)); + yield return () => (new UInt256(0, 0, 0, 1), 65, new UInt256(0, 0, 2, 0)); + yield return () => (new UInt256(0, 0, 0, 1), 128, new UInt256(0, 1, 0, 0)); + yield return () => (new UInt256(0, 0, 0, 1), 192, new UInt256(1, 0, 0, 0)); + yield return () => (new UInt256(0, 0, 0, 1), 255, new UInt256(0x8000_0000_0000_0000, 0, 0, 0)); + yield return () => (new UInt256(0, 0, 0, 1), 256, new UInt256(0, 0, 0, 1)); + yield return () => (new UInt256(0, 0, 0, 1), 260, new UInt256(0, 0, 0, 16)); + } + public static IEnumerable> op_ShiftRightTestData() + { + yield return () => (new UInt256(1, 2, 3, 4), 0, new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(0, 0, 0, 16), 1, new UInt256(0, 0, 0, 8)); + yield return () => (new UInt256(0x8000_0000_0000_0000, 0, 0, 0), 63, new UInt256(1, 0, 0, 0)); + yield return () => (new UInt256(1, 2, 3, 4), 64, new UInt256(0, 1, 2, 3)); + yield return () => (new UInt256(1, 0, 0, 0), 65, new UInt256(0, 0, 0x8000_0000_0000_0000, 0)); + yield return () => (new UInt256(1, 0, 0, 0), 128, new UInt256(0, 0, 1, 0)); + yield return () => (new UInt256(1, 0, 0, 0), 192, new UInt256(0, 0, 0, 1)); + yield return () => (new UInt256(0x8000_0000_0000_0000, 0, 0, 0), 255, new UInt256(0, 0, 0, 1)); + yield return () => (new UInt256(0, 0, 0, 1), 256, new UInt256(0, 0, 0, 1)); + yield return () => (new UInt256(0, 0, 0, 16), 260, new UInt256(0, 0, 0, 1)); + } + public static IEnumerable> op_UnsignedShiftRightTestData() + { + yield return () => (new UInt256(1, 2, 3, 4), 0, new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(0, 0, 0, 16), 1, new UInt256(0, 0, 0, 8)); + yield return () => (new UInt256(0x8000_0000_0000_0000, 0, 0, 0), 63, new UInt256(1, 0, 0, 0)); + yield return () => (new UInt256(1, 2, 3, 4), 64, new UInt256(0, 1, 2, 3)); + yield return () => (new UInt256(1, 0, 0, 0), 65, new UInt256(0, 0, 0x8000_0000_0000_0000, 0)); + yield return () => (new UInt256(1, 0, 0, 0), 128, new UInt256(0, 0, 1, 0)); + yield return () => (new UInt256(1, 0, 0, 0), 192, new UInt256(0, 0, 0, 1)); + yield return () => (new UInt256(0x8000_0000_0000_0000, 0, 0, 0), 255, new UInt256(0, 0, 0, 1)); + yield return () => (new UInt256(0, 0, 0, 1), 256, new UInt256(0, 0, 0, 1)); + yield return () => (new UInt256(0, 0, 0, 16), 260, new UInt256(0, 0, 0, 1)); + } + public static IEnumerable> op_EqualityTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, true); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), true); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 5), false); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 4, 4), false); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 3, 3, 4), false); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(2, 2, 3, 4), false); + } + public static IEnumerable> op_InequalityTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, false); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), false); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 5), true); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 4, 4), true); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 3, 3, 4), true); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(2, 2, 3, 4), true); + } + public static IEnumerable> op_LessThanTestData() + { + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), false); + yield return () => (new UInt256(0, 9, 9, 9), new UInt256(1, 0, 0, 0), true); + yield return () => (new UInt256(2, 0, 0, 0), new UInt256(1, 9, 9, 9), false); + yield return () => (new UInt256(1, 1, 3, 4), new UInt256(1, 2, 3, 4), true); + yield return () => (new UInt256(1, 2, 1, 4), new UInt256(1, 2, 2, 4), true); + yield return () => (new UInt256(1, 2, 3, 3), new UInt256(1, 2, 3, 4), true); + yield return () => (new UInt256(1, 2, 3, 5), new UInt256(1, 2, 3, 4), false); + } + public static IEnumerable> op_LessThanOrEqualTestData() + { + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), true); + yield return () => (new UInt256(0, 9, 9, 9), new UInt256(1, 0, 0, 0), true); + yield return () => (new UInt256(2, 0, 0, 0), new UInt256(1, 9, 9, 9), false); + yield return () => (new UInt256(1, 1, 3, 4), new UInt256(1, 2, 3, 4), true); + yield return () => (new UInt256(1, 2, 1, 4), new UInt256(1, 2, 2, 4), true); + yield return () => (new UInt256(1, 2, 3, 3), new UInt256(1, 2, 3, 4), true); + yield return () => (new UInt256(1, 2, 3, 5), new UInt256(1, 2, 3, 4), false); + } + public static IEnumerable> op_GreaterThanTestData() + { + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), false); + yield return () => (new UInt256(0, 9, 9, 9), new UInt256(1, 0, 0, 0), false); + yield return () => (new UInt256(2, 0, 0, 0), new UInt256(1, 9, 9, 9), true); + yield return () => (new UInt256(1, 1, 3, 4), new UInt256(1, 2, 3, 4), false); + yield return () => (new UInt256(1, 2, 1, 4), new UInt256(1, 2, 2, 4), false); + yield return () => (new UInt256(1, 2, 3, 3), new UInt256(1, 2, 3, 4), false); + yield return () => (new UInt256(1, 2, 3, 5), new UInt256(1, 2, 3, 4), true); + } + public static IEnumerable> op_GreaterThanOrEqualTestData() + { + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), true); + yield return () => (new UInt256(0, 9, 9, 9), new UInt256(1, 0, 0, 0), false); + yield return () => (new UInt256(2, 0, 0, 0), new UInt256(1, 9, 9, 9), true); + yield return () => (new UInt256(1, 1, 3, 4), new UInt256(1, 2, 3, 4), false); + yield return () => (new UInt256(1, 2, 1, 4), new UInt256(1, 2, 2, 4), false); + yield return () => (new UInt256(1, 2, 3, 3), new UInt256(1, 2, 3, 4), false); + yield return () => (new UInt256(1, 2, 3, 5), new UInt256(1, 2, 3, 4), true); + } + + public static IEnumerable> AbsTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero); + yield return () => (UInt256.One, UInt256.One); + yield return () => (UInt256.MaxValue, UInt256.MaxValue); + yield return () => (UInt256.MinValue, UInt256.MinValue); + } + + public static IEnumerable> IsCanonicalTestData() + { + yield return () => (UInt256.Zero, true); + } + + public static IEnumerable> IsComplexNumberTestData() + { + yield return () => (UInt256.Zero, false); + } + + public static IEnumerable> IsEvenIntegerTestData() + { + yield return () => (UInt256.Zero, true); + yield return () => (UInt256.One, false); + yield return () => (new UInt256(0, 0, 0, 2), true); + yield return () => (new UInt256(0, 0, 0, 3), false); + yield return () => (new UInt256(0, 0, 0, 0x8000_0000_0000_0000), true); + yield return () => (new UInt256(0x8000_0000_0000_0000, 0, 0, 0), true); + yield return () => (new UInt256(0x8000_0000_0000_0000, 0, 0, 1), false); + yield return () => (UInt256.MaxValue, false); + } + + public static IEnumerable> IsFiniteTestData() + { + yield return () => (UInt256.Zero, true); + } + + public static IEnumerable> IsImaginaryNumberTestData() + { + yield return () => (UInt256.Zero, false); + } + + public static IEnumerable> IsInfinityTestData() + { + yield return () => (UInt256.Zero, false); + } + + public static IEnumerable> IsIntegerTestData() + { + yield return () => (UInt256.Zero, true); + } + + public static IEnumerable> IsNaNTestData() + { + yield return () => (UInt256.Zero, false); + } + + public static IEnumerable> IsNegativeTestData() + { + yield return () => (UInt256.Zero, false); + } + + public static IEnumerable> IsNegativeInfinityTestData() + { + yield return () => (UInt256.Zero, false); + } + + public static IEnumerable> IsNormalTestData() + { + yield return () => (UInt256.Zero, false); + yield return () => (UInt256.One, true); + yield return () => (new UInt256(0, 0, 1, 0), true); + yield return () => (new UInt256(0, 1, 0, 0), true); + yield return () => (new UInt256(1, 0, 0, 0), true); + yield return () => (UInt256.MaxValue, true); + } + + public static IEnumerable> IsOddIntegerTestData() + { + yield return () => (UInt256.Zero, false); + yield return () => (UInt256.One, true); + yield return () => (new UInt256(0, 0, 0, 2), false); + yield return () => (new UInt256(0, 0, 0, 3), true); + yield return () => (new UInt256(0, 0, 0, 0x8000_0000_0000_0000), false); + yield return () => (new UInt256(0x8000_0000_0000_0000, 0, 0, 0), false); + yield return () => (new UInt256(0x8000_0000_0000_0000, 0, 0, 1), true); + yield return () => (UInt256.MaxValue, true); + } + + public static IEnumerable> IsPositiveTestData() + { + yield return () => (UInt256.Zero, true); + } + + public static IEnumerable> IsPositiveInfinityTestData() + { + yield return () => (UInt256.Zero, false); + } + + public static IEnumerable> IsRealNumberTestData() + { + yield return () => (UInt256.Zero, true); + } + + public static IEnumerable> IsSubnormalTestData() + { + yield return () => (UInt256.Zero, false); + } + + public static IEnumerable> IsZeroTestData() + { + yield return () => (UInt256.Zero, true); + yield return () => (UInt256.One, false); + yield return () => (new UInt256(0, 0, 1, 0), false); + yield return () => (new UInt256(0, 1, 0, 0), false); + yield return () => (new UInt256(1, 0, 0, 0), false); + yield return () => (UInt256.MaxValue, false); + } + + public static IEnumerable> MaxMagnitudeTestData() + { + return MaxTestData(); + } + + public static IEnumerable> MaxMagnitudeNumberTestData() + { + return MaxTestData(); + } + + public static IEnumerable> MinMagnitudeTestData() + { + return MinTestData(); + } + + public static IEnumerable> MinMagnitudeNumberTestData() + { + return MinTestData(); + } + + public static IEnumerable> MultiplyAddEstimateTestData() + { + yield return () => (UInt256.Zero, UInt256.Zero, UInt256.Zero, UInt256.Zero); + yield return () => (UInt256.Zero, UInt256.Zero, UInt256.One, UInt256.One); + yield return () => (UInt256.One, UInt256.One, UInt256.One, new UInt256(0, 0, 0, 2)); + yield return () => (new UInt256(0, 0, 0, ulong.MaxValue), new UInt256(0, 0, 0, ulong.MaxValue), UInt256.One, new UInt256(0, 0, ulong.MaxValue - 1, 2)); + yield return () => (new UInt256(0, 0, 0, ulong.MaxValue), new UInt256(0, 0, 0, ulong.MaxValue), new UInt256(0, 0, 0, ulong.MaxValue - 1), new UInt256(0, 0, ulong.MaxValue - 1, ulong.MaxValue)); + } + + public static IEnumerable> ParseTestData() + { + yield return () => ("0", NumberStyles.Integer, CultureInfo.InvariantCulture, UInt256.Zero); + yield return () => ("1", NumberStyles.Integer, CultureInfo.InvariantCulture, UInt256.One); + yield return () => ("4294967296", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639935", NumberStyles.Integer, CultureInfo.InvariantCulture, UInt256.MaxValue); + + yield return () => ("123456789ABCDEF0", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFF)); + yield return () => ("FFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + + yield return () => ("1010101010101010", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + } + + public static IEnumerable> ParseSpanTestData() + { + yield return () => ("0".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt256.Zero); + yield return () => ("1".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt256.One); + yield return () => ("4294967296".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639935".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt256.MaxValue); + + yield return () => ("123456789ABCDEF0".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFF)); + yield return () => ("FFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + + yield return () => ("1010101010101010".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + } + + public static IEnumerable> ParseUtf8TestData() + { + yield return () => ("0"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt256.Zero); + yield return () => ("1"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt256.One); + yield return () => ("4294967296"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt256(1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639935"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt256.MaxValue); + + yield return () => ("123456789ABCDEF0"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFF)); + yield return () => ("FFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt256(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + + yield return () => ("1010101010101010"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt256(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + } + + public static IEnumerable> TryParseTestData() + { + yield return () => ("0", NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt256.Zero); + yield return () => ("1", NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt256.One); + yield return () => ("4294967296", NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616", NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456", NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896", NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639935", NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt256.MaxValue); + yield return () => ("-1", NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("2.25", NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639936", NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("1000000000000000000000000000000000000000000000000000000000000000000000000000000", NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> TryParseSpanTestData() + { + yield return () => ("0".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt256.Zero); + yield return () => ("1".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt256.One); + yield return () => ("4294967296".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639935".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt256.MaxValue); + yield return () => ("-1".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("2.25".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639936".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("1000000000000000000000000000000000000000000000000000000000000000000000000000000".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> TryParseUtf8TestData() + { + yield return () => ("0"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt256.Zero); + yield return () => ("1"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt256.One); + yield return () => ("4294967296"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt256(1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639935"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt256.MaxValue); + yield return () => ("-1"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("2.25"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639936"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("1000000000000000000000000000000000000000000000000000000000000000000000000000000"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> ClampTestData() + { + yield return () => (new UInt256(0, 0, 0, 15), new UInt256(0, 0, 0, 10), new UInt256(0, 0, 0, 20), new UInt256(0, 0, 0, 15)); + yield return () => (new UInt256(0, 0, 0, 10), new UInt256(0, 0, 0, 10), new UInt256(0, 0, 0, 20), new UInt256(0, 0, 0, 10)); + yield return () => (new UInt256(0, 0, 0, 20), new UInt256(0, 0, 0, 10), new UInt256(0, 0, 0, 20), new UInt256(0, 0, 0, 20)); + yield return () => (new UInt256(0, 0, 0, 5), new UInt256(0, 0, 0, 10), new UInt256(0, 0, 0, 20), new UInt256(0, 0, 0, 10)); + yield return () => (new UInt256(0, 0, 0, 25), new UInt256(0, 0, 0, 10), new UInt256(0, 0, 0, 20), new UInt256(0, 0, 0, 20)); + yield return () => (new UInt256(0, 0, 0, 25), new UInt256(0, 0, 0, 30), new UInt256(0, 0, 0, 20), default); + } + + public static IEnumerable> CopySignTestData() + { + yield return () => (UInt256.MaxValue, UInt256.MaxValue, UInt256.MaxValue); + } + + public static IEnumerable> MaxTestData() + { + yield return () => (UInt256.One, UInt256.One, UInt256.One); + yield return () => (UInt256.MinValue, UInt256.MaxValue, UInt256.MaxValue); + yield return () => (new UInt256(0, 0, 0, ulong.MaxValue), UInt256.MaxValue, UInt256.MaxValue); + yield return () => (new UInt256(0, 0, ulong.MaxValue, ulong.MaxValue), new UInt256(0, 0, 0, ulong.MaxValue), new UInt256(0, 0, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new UInt256(0, 1, ulong.MaxValue, ulong.MaxValue), new UInt256(0, 0, ulong.MaxValue, ulong.MaxValue), new UInt256(0, 1, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new UInt256(0, ulong.MaxValue, ulong.MaxValue, 0), new UInt256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new UInt256(1, 0, 0, 0), new UInt256(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt256(1, 0, 0, 0)); + } + + public static IEnumerable> MaxNumberTestData() + { + return MaxTestData(); + } + + public static IEnumerable> MinTestData() + { + yield return () => (UInt256.One, UInt256.One, UInt256.One); + yield return () => (UInt256.MinValue, UInt256.MaxValue, UInt256.MinValue); + yield return () => (new UInt256(0, 0, 0, ulong.MaxValue), new UInt256(0, 0, 0, ulong.MaxValue - 1), new UInt256(0, 0, 0, ulong.MaxValue - 1)); + yield return () => (new UInt256(0, 0, 0, ulong.MaxValue), new UInt256(0, 0, ulong.MaxValue, ulong.MaxValue), new UInt256(0, 0, 0, ulong.MaxValue)); + yield return () => (new UInt256(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt256(2, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt256(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + } + + public static IEnumerable> MinNumberTestData() + { + return MinTestData(); + } + + public static IEnumerable> SignTestData() + { + yield return () => (UInt256.MaxValue, 1); + yield return () => (UInt256.Zero, 0); + } + + public static IEnumerable> IsPow2TestData() + { + yield return () => (new UInt256(0, 0, 0, 1), true); + yield return () => (new UInt256(0, 0, 0, 2), true); + yield return () => (new UInt256(0, 0, 0, 4), true); + yield return () => (new UInt256(0, 0, 0, 8), true); + yield return () => (new UInt256(0, 0, 0, 16), true); + yield return () => (new UInt256(0, 0, 0, 1UL << 63), true); + yield return () => (new UInt256(1UL << 63, 0, 0, 0), true); + yield return () => (UInt256.Zero, false); + yield return () => (new UInt256(0, 0, 0, 3), false); + yield return () => (UInt256.MaxValue, false); + } + + public static IEnumerable> Log2TestData() + { + yield return () => (new UInt256(0, 0, 0, 1), new UInt256(0, 0, 0, 0)); + yield return () => (new UInt256(0, 0, 0, 2), new UInt256(0, 0, 0, 1)); + yield return () => (new UInt256(0, 0, 0, 4), new UInt256(0, 0, 0, 2)); + yield return () => (new UInt256(0, 0, 0, 8), new UInt256(0, 0, 0, 3)); + yield return () => (new UInt256(0, 0, 0, 1UL << 63), new UInt256(0, 0, 0, 63)); + yield return () => (new UInt256(0, 0, 1UL << 5, 0), new UInt256(0, 0, 0, 69)); + yield return () => (new UInt256(0, 1UL << 42, 0, 0), new UInt256(0, 0, 0, 170)); + yield return () => (new UInt256(1UL << 13, 0, 0, 0), new UInt256(0, 0, 0, 205)); + yield return () => (new UInt256(1UL << 63, 0, 0, 0), new UInt256(0, 0, 0, 255)); + yield return () => (new UInt256(0, 0, 0, 0), new UInt256(0, 0, 0, 0)); + } + + public static IEnumerable> DivRemTestData() + { + yield return () => (new UInt256(1, 2, 3, 4), UInt256.One, (new UInt256(1, 2, 3, 4), new UInt256(0, 0, 0, 0))); + yield return () => (new UInt256(1, 2, 3, 4), new UInt256(1, 2, 3, 4), (new UInt256(0, 0, 0, 1), new UInt256(0, 0, 0, 0))); + yield return () => (new UInt256(0, 0, 0, 5), new UInt256(0, 0, 0, 10), (new UInt256(0, 0, 0, 0), new UInt256(0, 0, 0, 5))); + yield return () => (new UInt256(0, 0, 0, 100), new UInt256(0, 0, 0, 30), (new UInt256(0, 0, 0, 3), new UInt256(0, 0, 0, 10))); + yield return () => (new UInt256(0, 1, 0, 0), new UInt256(0, 0, 1, 0), (new UInt256(0, 0, 1, 0), new UInt256(0, 0, 0, 0))); + } + + public static IEnumerable> LeadingZeroCountTestData() + { + yield return () => (new UInt256(0, 0, 0, 0), new UInt256(0, 0, 0, 256)); + yield return () => (new UInt256(0, 0, 0, 1), new UInt256(0, 0, 0, 255)); + yield return () => (new UInt256(0, 0, 1, 0), new UInt256(0, 0, 0, 191)); + yield return () => (new UInt256(0, 1, 0, 0), new UInt256(0, 0, 0, 127)); + yield return () => (new UInt256(1, 0, 0, 0), new UInt256(0, 0, 0, 63)); + yield return () => (new UInt256(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt256(0, 0, 0, 63)); + yield return () => (new UInt256(0, 0, 0, 1UL << 63), new UInt256(0, 0, 0, 192)); + yield return () => (new UInt256(0, 0, 1UL << 63, 0), new UInt256(0, 0, 0, 128)); + yield return () => (new UInt256(0, 1UL << 63, 0, 0), new UInt256(0, 0, 0, 64)); + yield return () => (new UInt256(1UL << 63, 0, 0, 0), new UInt256(0, 0, 0, 0)); + yield return () => (new UInt256(1UL << 62, 0, 0, 0), new UInt256(0, 0, 0, 1)); + } + + public static IEnumerable> PopCountTestData() + { + yield return () => (new UInt256(0, 0, 0, 0), new UInt256(0, 0, 0, 0)); + yield return () => (new UInt256(0, 0, 0, 1), new UInt256(0, 0, 0, 1)); + yield return () => (UInt256.MaxValue, new UInt256(0, 0, 0, 256)); + yield return () => (new UInt256(ulong.MaxValue, 0, 0, 0), new UInt256(0, 0, 0, 64)); + yield return () => (new UInt256(0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA), new UInt256(0, 0, 0, 128)); + yield return () => (new UInt256(1UL << 63, 1UL << 62, 1UL << 61, 1UL << 60), new UInt256(0, 0, 0, 4)); + } + + public static IEnumerable> ReadBigEndianTestData() + { + yield return () => ([], true, UInt256.Zero); + yield return () => ([0x01], true, UInt256.One); + yield return () => + { + byte[] array = new byte[32]; + Array.Fill(array, byte.MaxValue); + return (array, true, UInt256.MaxValue); + }; + yield return () => + { + byte[] array = new byte[35]; + for (int i = 3; i < 35; i++) + array[i] = byte.MaxValue; + return (array, true, UInt256.MaxValue); + }; + yield return () => ([0x12, 0x34], true, new UInt256(0, 0, 0, 0x1234)); + yield return () => + { + byte[] array = new byte[32]; + array[0] = 0x80; + return (array, true, new UInt256(1UL << 63, 0, 0, 0)); + }; + } + + public static IEnumerable> ReadLittleEndianTestData() + { + yield return () => ([], true, UInt256.Zero); + yield return () => ([0x01], true, UInt256.One); + yield return () => + { + byte[] array = new byte[32]; + Array.Fill(array, byte.MaxValue); + return (array, true, UInt256.MaxValue); + }; + yield return () => + { + byte[] array = new byte[35]; + for (int i = 0; i < 32; i++) + array[i] = byte.MaxValue; + return (array, true, UInt256.MaxValue); + }; + yield return () => ([0x34, 0x12], true, new UInt256(0, 0, 0, 0x1234)); + yield return () => + { + byte[] array = new byte[32]; + array[31] = 0x80; + return (array, true, new UInt256(1UL << 63, 0, 0, 0)); + }; + } + + public static IEnumerable> RotateLeftTestData() + { + yield return () => (new UInt256(1, 2, 3, 4), 0, new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(1, 2, 3, 4), 256, new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(0, 0, 0x8000_0000_0000_0000, 0), 64, new UInt256(0, 0x8000_0000_0000_0000, 0, 0)); + yield return () => (new UInt256(0x8000_0000_0000_0000, 0, 0, 0), 64, new UInt256(0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => (new UInt256(0, 0, 0x8000_0000_0000_0000, 0), 128, new UInt256(0x8000_0000_0000_0000, 0, 0, 0)); + yield return () => (new UInt256(0x8000_0000_0000_0000, 0, 0, 0), 128, new UInt256(0, 0, 0x8000_0000_0000_0000, 0)); + } + + public static IEnumerable> RotateRightTestData() + { + yield return () => (new UInt256(1, 2, 3, 4), 0, new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(1, 2, 3, 4), 256, new UInt256(1, 2, 3, 4)); + yield return () => (new UInt256(0, 0, 0x8000_0000_0000_0000, 0), 64, new UInt256(0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => (new UInt256(0, 0, 0, 0x8000_0000_0000_0000), 64, new UInt256(0x8000_0000_0000_0000, 0, 0, 0)); + yield return () => (new UInt256(0, 0, 0x8000_0000_0000_0000, 0), 128, new UInt256(0x8000_0000_0000_0000, 0, 0, 0)); + yield return () => (new UInt256(0x8000_0000_0000_0000, 0, 0, 0), 128, new UInt256(0, 0, 0x8000_0000_0000_0000, 0)); + } + + public static IEnumerable> TrailingZeroCountTestData() + { + yield return () => (new UInt256(0, 0, 0, 0), new UInt256(0, 0, 0, 256)); + yield return () => (new UInt256(0, 0, 0, 1), new UInt256(0, 0, 0, 0)); + yield return () => (new UInt256(0, 0, 8, 0), new UInt256(0, 0, 0, 67)); + yield return () => (new UInt256(0, 0x10, 0, 0), new UInt256(0, 0, 0, 132)); + yield return () => (new UInt256(0x200, 0, 0, 0), new UInt256(0, 0, 0, 201)); + } + + public static IEnumerable> GetByteCountTestData() + { + yield return () => (new UInt256(0, 0, 0, 0), Unsafe.SizeOf()); + } + + public static IEnumerable> GetShortestBitLengthTestData() + { + yield return () => (new UInt256(0, 0, 0, 0), 0); + yield return () => (new UInt256(0, 0, 0, 1), 1); + yield return () => (new UInt256(1, 0, 0, 0), 193); + yield return () => (UInt256.MaxValue, 256); + } + + public static IEnumerable> WriteBigEndianTestData() + { + yield return () => (new UInt256(0, 0, 0, 0), new byte[32], Unsafe.SizeOf()); + yield return () => + { + var buffer = new byte[32]; + + for (int i = 0; i < 31; i++) + buffer[i] = 0; + + buffer[31] = 1; + + return (new UInt256(0, 0, 0, 1), buffer, Unsafe.SizeOf()); + }; + yield return () => + { + var buffer = new byte[32]; + + for (int i = 0; i < 32; i++) + buffer[i] = 0xFF; + + return (UInt256.MaxValue, buffer, Unsafe.SizeOf()); + }; + } + + public static IEnumerable> WriteLittleEndianTestData() + { + yield return () => (new UInt256(0, 0, 0, 0), new byte[32], Unsafe.SizeOf()); + yield return () => + { + var buffer = new byte[32]; + + buffer[0] = 1; + for (int i = 1; i < 32; i++) + buffer[i] = 0; + + return (new UInt256(0, 0, 0, 1), buffer, Unsafe.SizeOf()); + }; + yield return () => + { + var buffer = new byte[32]; + + for (int i = 0; i < 32; i++) + buffer[i] = 0xFF; + + return (UInt256.MaxValue, buffer, Unsafe.SizeOf()); + }; + } + + public static IEnumerable> ConvertToCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedDoubleTestData() + { + yield return () => (UInt256.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + } + + public static IEnumerable> ConvertToSaturatingDoubleTestData() + { + yield return () => (UInt256.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + } + + public static IEnumerable> ConvertToTruncatingDoubleTestData() + { + yield return () => (UInt256.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + } + + public static IEnumerable> ConvertToCheckedQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingOctoTestData() + { + throw new NotImplementedException(); + } +} diff --git a/src/MissingValues.Tests/Data/UInt512DataSources.cs b/src/MissingValues.Tests/Data/UInt512DataSources.cs new file mode 100644 index 0000000..229a3f2 --- /dev/null +++ b/src/MissingValues.Tests/Data/UInt512DataSources.cs @@ -0,0 +1,1564 @@ +using MissingValues.Tests.Data.Sources; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace MissingValues.Tests.Data; + +public class UInt512DataSources + : IMathOperatorsDataSource, + IShiftOperatorsDataSource, + IBitwiseOperatorsDataSource, + IEqualityOperatorsDataSource, + IComparisonOperatorsDataSource, + INumberBaseDataSource, + INumberDataSource, + IBinaryNumberDataSource, + IBinaryIntegerDataSource +{ + public static IEnumerable> op_AdditionTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, UInt512.Zero); + yield return () => (UInt512.One, UInt512.Zero, UInt512.One); + yield return () => (UInt512.One, UInt512.One, new UInt512(0, 0, 0, 0, 0, 0, 0, 2)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), UInt512.One, new UInt512(0, 0, 0, 0, 0, 0, 1, 0)); + yield return () => (new UInt512(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), UInt512.One, new UInt512(1, 0, 0, 0, 0, 0, 0, 0)); + yield return () => (UInt512.One, UInt512.MaxValue, UInt512.Zero); + } + + public static IEnumerable> op_CheckedAdditionTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, UInt512.Zero, false); + yield return () => (UInt512.One, UInt512.Zero, UInt512.One, false); + yield return () => (UInt512.One, UInt512.One, new UInt512(0, 0, 0, 0, 0, 0, 0, 2), false); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), UInt512.One, new UInt512(0, 0, 0, 0, 0, 0, 1, 0), false); + yield return () => (new UInt512(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), UInt512.One, new UInt512(1, 0, 0, 0, 0, 0, 0, 0), false); + yield return () => (UInt512.One, UInt512.MaxValue, UInt512.Zero, true); + } + + public static IEnumerable> op_CheckedDecrementTestData() + { + yield return () => (UInt512.Zero, UInt512.MaxValue, true); + yield return () => (UInt512.One, UInt512.Zero, false); + yield return () => (UInt512.MaxValue, UInt512.MaxValue - UInt512.One, false); + } + + public static IEnumerable> op_CheckedIncrementTestData() + { + yield return () => (UInt512.Zero, UInt512.One, false); + yield return () => (UInt512.One, new UInt512(0, 0, 0, 0, 0, 0, 0, 2), false); + yield return () => (UInt512.MaxValue, UInt512.Zero, true); + } + + public static IEnumerable> op_CheckedMultiplyTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, UInt512.Zero, false); + yield return () => (UInt512.One, UInt512.One, UInt512.One, false); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 0, 2), + new UInt512(0, 0, 0, 0, 0, 0, 0, 3), + new UInt512(0, 0, 0, 0, 0, 0, 0, 6), + false + ); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 1, 0), + new UInt512(0, 0, 0, 0, 0, 0, 1, 0), + new UInt512(0, 0, 0, 0, 0, 1, 0, 0), + false + ); + yield return () => ( + new UInt512(0, 0, 0, 1, 0, 0, 0, 0), + new UInt512(0, 0, 0, 0, 1, 0, 0, 0), + new UInt512(1, 0, 0, 0, 0, 0, 0, 0), + false + ); + yield return () => ( + UInt512.MaxValue, + UInt512.One, + UInt512.MaxValue, + false + ); + yield return () => ( + UInt512.MaxValue, + new UInt512(0, 0, 0, 0, 0, 0, 0, 2), + default, + true + ); + } + + public static IEnumerable> op_CheckedSubtractionTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, UInt512.Zero, false); + yield return () => (UInt512.One, UInt512.Zero, UInt512.One, false); + yield return () => (UInt512.One, UInt512.One, UInt512.Zero, false); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 2), UInt512.One, UInt512.One, false); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 1, 0), + UInt512.One, + new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), + false + ); + yield return () => (UInt512.Zero, UInt512.One, UInt512.MaxValue, true); + } + + public static IEnumerable> op_DecrementTestData() + { + yield return () => (UInt512.Zero, UInt512.MaxValue); + yield return () => (UInt512.One, UInt512.Zero); + yield return () => (UInt512.MaxValue, UInt512.MaxValue - UInt512.One); + } + + public static IEnumerable> op_DivisionTestData() + { + yield return () => (UInt512.Zero, UInt512.One, UInt512.Zero); + yield return () => (UInt512.One, UInt512.One, UInt512.One); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 0, 6), + new UInt512(0, 0, 0, 0, 0, 0, 0, 2), + new UInt512(0, 0, 0, 0, 0, 0, 0, 3) + ); + yield return () => (UInt512.MaxValue, UInt512.One, UInt512.MaxValue); + yield return () => (UInt512.MaxValue, new UInt512(0, 0, 0, 0, 0, 1, 0, 0), new UInt512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF)); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 1, ulong.MaxValue - 1), + new UInt512(0, 0, 0, 0, 0, 0, 0, 2), + new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue) + ); + } + + public static IEnumerable> op_IncrementTestData() + { + yield return () => (UInt512.Zero, UInt512.One); + yield return () => (UInt512.One, new UInt512(0, 0, 0, 0, 0, 0, 0, 2)); + yield return () => (UInt512.MaxValue, UInt512.Zero); + } + + public static IEnumerable> op_ModulusTestData() + { + yield return () => (UInt512.Zero, UInt512.One, UInt512.Zero); + yield return () => (UInt512.One, UInt512.One, UInt512.Zero); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 0, 5), + new UInt512(0, 0, 0, 0, 0, 0, 0, 2), + UInt512.One + ); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 0, 7), + new UInt512(0, 0, 0, 0, 0, 0, 0, 3), + UInt512.One + ); + yield return () => (UInt512.MaxValue, UInt512.One, UInt512.Zero); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 1, 0), + new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), + UInt512.One + ); + } + + public static IEnumerable> op_MultiplyTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, UInt512.Zero); + yield return () => (UInt512.One, UInt512.Zero, UInt512.Zero); + yield return () => (UInt512.One, UInt512.One, UInt512.One); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 0, 2), + new UInt512(0, 0, 0, 0, 0, 0, 0, 3), + new UInt512(0, 0, 0, 0, 0, 0, 0, 6) + ); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), + new UInt512(0, 0, 0, 0, 0, 0, 0, 2), + new UInt512(0, 0, 0, 0, 0, 0, 1, ulong.MaxValue - 1) + ); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 1, 0), + new UInt512(0, 0, 0, 0, 0, 0, 1, 0), + new UInt512(0, 0, 0, 0, 0, 1, 0, 0) + ); + yield return () => ( + new UInt512(0, 0, 0, 1, 0, 0, 0, 0), + new UInt512(0, 0, 0, 0, 1, 0, 0, 0), + new UInt512(1, 0, 0, 0, 0, 0, 0, 0) + ); + yield return () => (UInt512.MaxValue, UInt512.One, UInt512.MaxValue); + } + + public static IEnumerable> op_SubtractionTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, UInt512.Zero); + yield return () => (UInt512.One, UInt512.Zero, UInt512.One); + yield return () => (UInt512.One, UInt512.One, UInt512.Zero); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 2), UInt512.One, UInt512.One); + yield return () => ( + new UInt512(0, 0, 0, 0, 0, 0, 1, 0), + UInt512.One, + new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue) + ); + yield return () => ( + UInt512.MaxValue, + UInt512.One, + new UInt512(ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, + ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue - 1) + ); + } + + public static IEnumerable> op_ShiftLeftTestData() + { + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), 0, new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), 1, new UInt512(0, 0, 0, 0, 0, 0, 0, 2)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), 63, new UInt512(0, 0, 0, 0, 0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), 64, new UInt512(0, 0, 0, 0, 0, 0, 1, 0)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), 128, new UInt512(0, 0, 0, 0, 0, 1, 0, 0)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), 256, new UInt512(0, 0, 0, 1, 0, 0, 0, 0)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), 511, new UInt512(0x8000_0000_0000_0000, 0, 0, 0, 0, 0, 0, 0)); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), 512, new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), 513, new UInt512(0, 0, 0, 0, 0, 0, 0, 2)); + } + + public static IEnumerable> op_ShiftRightTestData() + { + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), 0, new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 2), 1, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 0x8000_0000_0000_0000), 63, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 1, 0), 64, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 1, 0, 0), 128, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(0, 0, 0, 1, 0, 0, 0, 0), 256, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(0x8000_0000_0000_0000, 0, 0, 0, 0, 0, 0, 0), 511, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), 512, new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 2), 513, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + } + + public static IEnumerable> op_UnsignedShiftRightTestData() + { + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), 0, new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 2), 1, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 0x8000_0000_0000_0000), 63, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 1, 0), 64, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 1, 0, 0), 128, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(0, 0, 0, 1, 0, 0, 0, 0), 256, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(0x8000_0000_0000_0000, 0, 0, 0, 0, 0, 0, 0), 511, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), 512, new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 2), 513, new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + } + + public static IEnumerable> op_BitwiseAndTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, UInt512.Zero); + yield return () => (UInt512.Zero, UInt512.MaxValue, UInt512.Zero); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), UInt512.MaxValue, new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + } + + public static IEnumerable> op_BitwiseOrTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, UInt512.Zero); + yield return () => (UInt512.Zero, UInt512.MaxValue, UInt512.MaxValue); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), UInt512.MaxValue, UInt512.MaxValue); + } + + public static IEnumerable> op_BitwiseXorTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, UInt512.Zero); + yield return () => (UInt512.Zero, UInt512.MaxValue, UInt512.MaxValue); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), UInt512.Zero); + } + + public static IEnumerable> op_OnesComplementTestData() + { + yield return () => (UInt512.Zero, UInt512.MaxValue); + yield return () => (UInt512.MaxValue, UInt512.Zero); + yield return () => (new UInt512(0xAAAAAAAAAAAAAAAA, 0x5555555555555555, 0xAAAAAAAAAAAAAAAA, 0x5555555555555555, 0xAAAAAAAAAAAAAAAA, 0x5555555555555555, 0xAAAAAAAAAAAAAAAA, 0x5555555555555555), new UInt512(0x5555555555555555, 0xAAAAAAAAAAAAAAAA, 0x5555555555555555, 0xAAAAAAAAAAAAAAAA, 0x5555555555555555, 0xAAAAAAAAAAAAAAAA, 0x5555555555555555, 0xAAAAAAAAAAAAAAAA)); + yield return () => (new UInt512(0x0123456789ABCDEF, 0xFEDCBA9876543210, 0x0F0F0F0F0F0F0F0F, 0xF0F0F0F0F0F0F0F0, 0x0123456789ABCDEF, 0xFEDCBA9876543210, 0x0F0F0F0F0F0F0F0F, 0xF0F0F0F0F0F0F0F0), new UInt512(~0x0123456789ABCDEFU, ~0xFEDCBA9876543210U, ~0x0F0F0F0F0F0F0F0FU, ~0xF0F0F0F0F0F0F0F0U, ~0x0123456789ABCDEFU, ~0xFEDCBA9876543210U, ~0x0F0F0F0F0F0F0F0FU, ~0xF0F0F0F0F0F0F0F0U)); + } + + public static IEnumerable> op_EqualityTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 9), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 5, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 7, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 4, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 5, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 1, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 3, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(0, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 9), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 5, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 7, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 4, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 5, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 1, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 3, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(0, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + } + + public static IEnumerable> op_InequalityTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 9), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 5, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 7, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 4, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 5, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 1, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 3, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(0, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 9), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 5, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 7, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 4, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 5, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 1, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 3, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(0, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + } + + public static IEnumerable> op_GreaterThanOrEqualTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 9), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 5, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 7, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 4, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 5, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 1, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 3, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(0, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 9), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 5, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 7, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 4, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 5, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 1, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 3, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(0, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + } + + public static IEnumerable> op_GreaterThanTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 9), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 5, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 7, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 4, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 5, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 1, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 3, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(0, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 9), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 5, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 7, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 4, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 5, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 1, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 3, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(0, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + } + + public static IEnumerable> op_LessThanOrEqualTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 9), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 5, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 7, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 4, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 5, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 1, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 3, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(0, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 9), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 5, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 7, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 4, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 5, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 1, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 3, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(0, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + } + + public static IEnumerable> op_LessThanTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 9), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 5, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 7, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 4, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 5, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 1, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 3, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(0, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 9), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 5, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 4, 5, 7, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 3, 4, 4, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 2, 3, 5, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(1, 2, 1, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + yield return () => (new UInt512(1, 3, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), false); + yield return () => (new UInt512(0, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), true); + } + + public static IEnumerable> AbsTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero); + yield return () => (UInt512.One, UInt512.One); + yield return () => (UInt512.MaxValue, UInt512.MaxValue); + yield return () => (UInt512.MinValue, UInt512.MinValue); + } + + public static IEnumerable> IsCanonicalTestData() + { + yield return () => (UInt512.Zero, true); + } + + public static IEnumerable> IsComplexNumberTestData() + { + yield return () => (UInt512.Zero, false); + } + + public static IEnumerable> IsEvenIntegerTestData() + { + yield return () => (UInt512.Zero, true); + + } + + public static IEnumerable> IsFiniteTestData() + { + yield return () => (UInt512.Zero, true); + } + + public static IEnumerable> IsImaginaryNumberTestData() + { + yield return () => (UInt512.Zero, false); + } + + public static IEnumerable> IsInfinityTestData() + { + yield return () => (UInt512.Zero, false); + } + + public static IEnumerable> IsIntegerTestData() + { + yield return () => (UInt512.Zero, true); + } + + public static IEnumerable> IsNaNTestData() + { + yield return () => (UInt512.Zero, false); + } + + public static IEnumerable> IsNegativeTestData() + { + yield return () => (UInt512.Zero, false); + } + + public static IEnumerable> IsNegativeInfinityTestData() + { + yield return () => (UInt512.Zero, false); + } + + public static IEnumerable> IsNormalTestData() + { + yield return () => (UInt512.Zero, false); + yield return () => (UInt512.One, true); + yield return () => (UInt512.MaxValue, true); + yield return () => (UInt512.MinValue, false); + } + + public static IEnumerable> IsOddIntegerTestData() + { + yield return () => (UInt512.Zero, false); + yield return () => (UInt512.One, true); + yield return () => (UInt512.MaxValue, true); + yield return () => (UInt512.MinValue, false); + } + + public static IEnumerable> IsPositiveTestData() + { + yield return () => (UInt512.Zero, true); + } + + public static IEnumerable> IsPositiveInfinityTestData() + { + yield return () => (UInt512.Zero, false); + } + + public static IEnumerable> IsRealNumberTestData() + { + yield return () => (UInt512.Zero, true); + } + + public static IEnumerable> IsSubnormalTestData() + { + yield return () => (UInt512.Zero, false); + } + + public static IEnumerable> IsZeroTestData() + { + yield return () => (UInt512.Zero, true); + yield return () => (UInt512.One, false); + yield return () => (UInt512.MaxValue, false); + yield return () => (UInt512.MinValue, true); + } + + public static IEnumerable> MaxMagnitudeTestData() + { + return MaxTestData(); + } + + public static IEnumerable> MaxMagnitudeNumberTestData() + { + return MaxTestData(); + } + + public static IEnumerable> MinMagnitudeTestData() + { + return MinTestData(); + } + + public static IEnumerable> MinMagnitudeNumberTestData() + { + return MinTestData(); + } + + public static IEnumerable> MultiplyAddEstimateTestData() + { + yield return () => (UInt512.Zero, UInt512.Zero, UInt512.Zero, UInt512.Zero); + yield return () => (UInt512.Zero, UInt512.Zero, UInt512.One, UInt512.One); + } + + public static IEnumerable> ParseTestData() + { + yield return () => ("0", NumberStyles.Integer, CultureInfo.InvariantCulture, UInt512.Zero); + yield return () => ("1", NumberStyles.Integer, CultureInfo.InvariantCulture, UInt512.One); + yield return () => ("4294967296", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639936", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 1, 0, 0, 0, 0)); + yield return () => ("2135987035920910082395021706169552114602704522356652769947041607822219725780640550022962086936576", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 1, 0, 0, 0, 0, 0)); + yield return () => ("39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915640806627990306816", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 1, 0, 0, 0, 0, 0, 0)); + yield return () => ("726838724295606890549323807888004534353641360687318060281490199180639288113397923326191050713763565560762521606266177933534601628614656", NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(1, 0, 0, 0, 0, 0, 0, 0)); + yield return () => ("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095", NumberStyles.Integer, CultureInfo.InvariantCulture, UInt512.MaxValue); + + yield return () => ("123456789ABCDEF0", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFF)); + yield return () => ("FFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFF", + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + + yield return () => ("1010101010101010", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + } + + public static IEnumerable> ParseSpanTestData() + { + yield return () => ("0".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt512.Zero); + yield return () => ("1".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt512.One); + yield return () => ("4294967296".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639936".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 1, 0, 0, 0, 0)); + yield return () => ("2135987035920910082395021706169552114602704522356652769947041607822219725780640550022962086936576".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 1, 0, 0, 0, 0, 0)); + yield return () => ("39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915640806627990306816".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 1, 0, 0, 0, 0, 0, 0)); + yield return () => ("726838724295606890549323807888004534353641360687318060281490199180639288113397923326191050713763565560762521606266177933534601628614656".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(1, 0, 0, 0, 0, 0, 0, 0)); + yield return () => ("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt512.MaxValue); + + yield return () => ("123456789ABCDEF0".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFF)); + yield return () => ("FFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFF".ToCharArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + + yield return () => ("1010101010101010".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111".ToCharArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + } + + public static IEnumerable> ParseUtf8TestData() + { + yield return () => ("0"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt512.Zero); + yield return () => ("1"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt512.One); + yield return () => ("4294967296"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639936"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 1, 0, 0, 0, 0)); + yield return () => ("2135987035920910082395021706169552114602704522356652769947041607822219725780640550022962086936576"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 0, 1, 0, 0, 0, 0, 0)); + yield return () => ("39402006196394479212279040100143613805079739270465446667948293404245721771497210611414266254884915640806627990306816"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(0, 1, 0, 0, 0, 0, 0, 0)); + yield return () => ("726838724295606890549323807888004534353641360687318060281490199180639288113397923326191050713763565560762521606266177933534601628614656"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, new UInt512(1, 0, 0, 0, 0, 0, 0, 0)); + yield return () => ("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, UInt512.MaxValue); + + yield return () => ("123456789ABCDEF0"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0x123456789ABCDEF0)); + yield return () => ("FF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFF)); + yield return () => ("FFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFFFF)); + yield return () => ("FFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF00000000000000000000000000000000FFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF)); + yield return () => ("FFFFFFFFFFFFFFFF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFF"u8.ToArray(), + NumberStyles.HexNumber, CultureInfo.InvariantCulture, new UInt512(0xFFFFFFFFFFFFFFFF, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0xFFFFFFFFFFFFFFFF)); + + yield return () => ("1010101010101010"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b1010101010101010)); + yield return () => ("11111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b11111111)); + yield return () => ("1111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b1111111111111111)); + yield return () => ("11111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b11111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0, 0, 0, 0, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + yield return () => ("11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"u8.ToArray(), + NumberStyles.BinaryNumber, CultureInfo.InvariantCulture, new UInt512(0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111, 0b1111111111111111111111111111111111111111111111111111111111111111)); + } + + public static IEnumerable> TryParseTestData() + { + yield return () => ("0", NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt512.Zero); + yield return () => ("1", NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt512.One); + yield return () => ("4294967296", NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616", NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456", NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896", NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639936", NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 1, 0, 0, 0, 0)); + yield return () => ("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095", NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt512.MaxValue); + yield return () => ("-1", NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("2.25", NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096", NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> TryParseSpanTestData() + { + yield return () => ("0".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt512.Zero); + yield return () => ("1".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt512.One); + yield return () => ("4294967296".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639936".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 1, 0, 0, 0, 0)); + yield return () => ("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt512.MaxValue); + yield return () => ("-1".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("2.25".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".ToCharArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> TryParseUtf8TestData() + { + yield return () => ("0"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt512.Zero); + yield return () => ("1"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt512.One); + yield return () => ("4294967296"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 0, 0, 0, 4294967296)); + yield return () => ("18446744073709551616"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 0, 0, 1, 0)); + yield return () => ("340282366920938463463374607431768211456"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 0, 1, 0, 0)); + yield return () => ("6277101735386680763835789423207666416102355444464034512896"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 0, 1, 0, 0, 0)); + yield return () => ("115792089237316195423570985008687907853269984665640564039457584007913129639936"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, new UInt512(0, 0, 0, 1, 0, 0, 0, 0)); + yield return () => ("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084095"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, true, UInt512.MaxValue); + yield return () => ("-1"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("2.25"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084096"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + yield return () => ("20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"u8.ToArray(), NumberStyles.Integer, CultureInfo.InvariantCulture, false, default); + } + + public static IEnumerable> ClampTestData() + { + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 15), new UInt512(0, 0, 0, 0, 0, 0, 0, 10), new UInt512(0, 0, 0, 0, 0, 0, 0, 20), new UInt512(0, 0, 0, 0, 0, 0, 0, 15)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 10), new UInt512(0, 0, 0, 0, 0, 0, 0, 10), new UInt512(0, 0, 0, 0, 0, 0, 0, 20), new UInt512(0, 0, 0, 0, 0, 0, 0, 10)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 20), new UInt512(0, 0, 0, 0, 0, 0, 0, 10), new UInt512(0, 0, 0, 0, 0, 0, 0, 20), new UInt512(0, 0, 0, 0, 0, 0, 0, 20)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 05), new UInt512(0, 0, 0, 0, 0, 0, 0, 10), new UInt512(0, 0, 0, 0, 0, 0, 0, 20), new UInt512(0, 0, 0, 0, 0, 0, 0, 10)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 25), new UInt512(0, 0, 0, 0, 0, 0, 0, 10), new UInt512(0, 0, 0, 0, 0, 0, 0, 20), new UInt512(0, 0, 0, 0, 0, 0, 0, 20)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 25), new UInt512(0, 0, 0, 0, 0, 0, 0, 30), new UInt512(0, 0, 0, 0, 0, 0, 0, 20), default); + } + + public static IEnumerable> CopySignTestData() + { + yield return () => (UInt512.MaxValue, UInt512.MaxValue, UInt512.MaxValue); + } + + public static IEnumerable> MaxTestData() + { + yield return () => (UInt512.One, UInt512.One, UInt512.One); + yield return () => (UInt512.MinValue, UInt512.MaxValue, UInt512.MaxValue); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), UInt512.MaxValue, UInt512.MaxValue); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue), new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), new UInt512(0, 0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 1, ulong.MaxValue, ulong.MaxValue), new UInt512(0, 0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue), new UInt512(0, 0, 0, 0, 0, 1, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 1, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue), new UInt512(0, 0, 0, 0, 0, 1, 0, 0)); + yield return () => (new UInt512(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt512(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt512(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + } + + public static IEnumerable> MaxNumberTestData() + { + return MaxTestData(); + } + + public static IEnumerable> MinTestData() + { + yield return () => (UInt512.One, UInt512.One, UInt512.One); + yield return () => (UInt512.MinValue, UInt512.MaxValue, UInt512.MinValue); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), UInt512.MaxValue, new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue), new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue), new UInt512(0, 0, 0, 0, 0, 0, 0, ulong.MaxValue)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 1, ulong.MaxValue, ulong.MaxValue), new UInt512(0, 0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue), new UInt512(0, 0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 1, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue), new UInt512(0, 0, 0, 0, 0, 0, ulong.MaxValue, ulong.MaxValue)); + yield return () => (new UInt512(1, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt512(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue), new UInt512(0, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue)); + } + + public static IEnumerable> MinNumberTestData() + { + return MinTestData(); + } + + public static IEnumerable> SignTestData() + { + yield return () => (UInt512.MaxValue, 1); + yield return () => (UInt512.Zero, 0); + } + + public static IEnumerable> IsPow2TestData() + { + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), true); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 2), true); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 4), true); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 8), true); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 16), true); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1UL << 63), true); + yield return () => (new UInt512(0, 0, 0, 0, 1UL << 63, 0, 0, 0), true); + yield return () => (new UInt512(1UL << 63, 0, 0, 0, 0, 0, 0, 0), true); + yield return () => (UInt512.Zero, false); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 3), false); + yield return () => (UInt512.MaxValue, false); + } + + public static IEnumerable> Log2TestData() + { + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), new UInt512(0, 0, 0, 0, 0, 0, 0, 0)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 2), new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 4), new UInt512(0, 0, 0, 0, 0, 0, 0, 2)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 8), new UInt512(0, 0, 0, 0, 0, 0, 0, 3)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1UL << 63), new UInt512(0, 0, 0, 0, 0, 0, 0, 63)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 1UL << 5, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 69)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 1UL << 42, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 170)); + yield return () => (new UInt512(0, 0, 0, 0, 1UL << 13, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 205)); + yield return () => (new UInt512(0, 0, 0, 0, 1UL << 63, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 255)); + yield return () => (new UInt512(1UL << 63, 0, 0, 0, 0, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 511)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 0)); + } + + public static IEnumerable> DivRemTestData() + { + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(0, 0, 0, 0, 0, 0, 0, 1), (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(0, 0, 0, 0, 0, 0, 0, 0))); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), new UInt512(0, 0, 0, 0, 0, 0, 0, 0))); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 8), (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), new UInt512(0, 0, 0, 0, 0, 0, 0, 0))); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), new UInt512(1, 2, 3, 4, 5, 6, 7, 9), (new UInt512(0, 0, 0, 0, 0, 0, 0, 0), new UInt512(1, 2, 3, 4, 5, 6, 7, 8))); + yield return () => (UInt512.MaxValue, UInt256.MaxValue, (new UInt512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0001), UInt512.Zero)); + yield return () => (UInt512.MaxValue, new UInt512(0, 0, 0, 1, 0, 0, 0, 0), (new UInt512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF), new UInt512(0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0x0000_0000_0000_0000, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF, 0xFFFF_FFFF_FFFF_FFFF))); + } + + public static IEnumerable> LeadingZeroCountTestData() + { + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 512)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), new UInt512(0, 0, 0, 0, 0, 0, 0, 511)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 1, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 447)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 1UL << 36, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 411)); + yield return () => (new UInt512(0, 0, 0, 1, 0, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 255)); + yield return () => (new UInt512(1UL << 63, 0, 0, 0, 0, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 0)); + } + + public static IEnumerable> PopCountTestData() + { + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 0)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), new UInt512(0, 0, 0, 0, 0, 0, 0, 1)); + yield return () => (UInt512.MaxValue, new UInt512(0, 0, 0, 0, 0, 0, 0, 512)); + yield return () => (new UInt512(ulong.MaxValue, 0, 0, 0, 0, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 64)); + yield return () => (new UInt512(0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA, 0xAAAAAAAAAAAAAAAA), new UInt512(0, 0, 0, 0, 0, 0, 0, 256)); + yield return () => (new UInt512(0, 0, 0, 0, 1UL << 63, 1UL << 62, 1UL << 61, 1UL << 60), new UInt512(0, 0, 0, 0, 0, 0, 0, 4)); + yield return () => (new UInt512(1UL << 63, 1UL << 62, 1UL << 61, 1UL << 60, 1UL << 59, 1UL << 58, 1UL << 57, 1UL << 56), new UInt512(0, 0, 0, 0, 0, 0, 0, 8)); + } + + public static IEnumerable> ReadBigEndianTestData() + { + yield return () => ([], true, UInt512.Zero); + yield return () => ([0x01], true, UInt512.One); + yield return () => + { + byte[] array = new byte[64]; + Array.Fill(array, byte.MaxValue); + return (array, true, UInt512.MaxValue); + }; + yield return () => + { + byte[] array = new byte[67]; + for (int i = 3; i < 67; i++) + array[i] = byte.MaxValue; + return (array, true, UInt512.MaxValue); + }; + yield return () => ([0x12, 0x34], true, new UInt512(0, 0, 0, 0, 0, 0, 0, 0x1234)); + yield return () => + { + byte[] array = new byte[64]; + array[0] = 0x80; + return (array, true, new UInt512(1UL << 63, 0, 0, 0, 0, 0, 0, 0)); + }; + } + + public static IEnumerable> ReadLittleEndianTestData() + { + yield return () => ([], true, UInt512.Zero); + yield return () => ([0x01], true, UInt512.One); + yield return () => + { + byte[] array = new byte[64]; + Array.Fill(array, byte.MaxValue); + return (array, true, UInt512.MaxValue); + }; + yield return () => + { + byte[] array = new byte[67]; + for (int i = 0; i < 64; i++) + array[i] = byte.MaxValue; + return (array, true, UInt512.MaxValue); + }; + yield return () => ([0x34, 0x12], true, new UInt512(0, 0, 0, 0, 0, 0, 0, 0x1234)); + yield return () => + { + byte[] array = new byte[64]; + array[63] = 0x80; + return (array, true, new UInt512(1UL << 63, 0, 0, 0, 0, 0, 0, 0)); + }; + } + + public static IEnumerable> RotateLeftTestData() + { + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), 0, new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), 512, new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0x8000_0000_0000_0000, 0), 64, new UInt512(0, 0, 0, 0, 0, 0x8000_0000_0000_0000, 0, 0)); + yield return () => (new UInt512(0x8000_0000_0000_0000, 0, 0, 0, 0, 0, 0, 0), 64, new UInt512(0, 0, 0, 0, 0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => (new UInt512(0, 0, 0, 0, 0x8000_0000_0000_0000, 0, 0, 0), 128, new UInt512(0, 0, 0x8000_0000_0000_0000, 0, 0, 0, 0, 0)); + } + + public static IEnumerable> RotateRightTestData() + { + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), 0, new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(1, 2, 3, 4, 5, 6, 7, 8), 512, new UInt512(1, 2, 3, 4, 5, 6, 7, 8)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0x8000_0000_0000_0000, 0), 64, new UInt512(0, 0, 0, 0, 0, 0, 0, 0x8000_0000_0000_0000)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 0x8000_0000_0000_0000), 64, new UInt512(0x8000_0000_0000_0000, 0, 0, 0, 0, 0, 0, 0)); + yield return () => (new UInt512(0, 0, 0, 0, 0x8000_0000_0000_0000, 0, 0, 0), 128, new UInt512(0, 0, 0, 0, 0, 0, 0x8000_0000_0000_0000, 0)); + } + + public static IEnumerable> TrailingZeroCountTestData() + { + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 512)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), new UInt512(0, 0, 0, 0, 0, 0, 0, 0)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 1, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 64)); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 1UL << 36, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 100)); + yield return () => (new UInt512(0, 0, 0, 1, 0, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 256)); + yield return () => (new UInt512(1UL << 63, 0, 0, 0, 0, 0, 0, 0), new UInt512(0, 0, 0, 0, 0, 0, 0, 511)); + } + + public static IEnumerable> GetByteCountTestData() + { + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 0), Unsafe.SizeOf()); + } + + public static IEnumerable> GetShortestBitLengthTestData() + { + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 0), 0); + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), 1); + yield return () => (new UInt512(0, 0, 0, 0, 1, 0, 0, 0), 193); + yield return () => (new UInt512(1, 0, 0, 0, 0, 0, 0, 0), 449); + yield return () => (UInt512.MaxValue, 512); + } + + public static IEnumerable> WriteBigEndianTestData() + { + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 0), new byte[64], Unsafe.SizeOf()); + yield return () => + { + var buffer = new byte[64]; + + for (int i = 0; i < 63; i++) + buffer[i] = 0; + + buffer[63] = 1; + + return (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), buffer, Unsafe.SizeOf()); + }; + yield return () => + { + var buffer = new byte[64]; + + for (int i = 0; i < 64; i++) + buffer[i] = 0xFF; + + return (UInt512.MaxValue, buffer, Unsafe.SizeOf()); + }; + } + + public static IEnumerable> WriteLittleEndianTestData() + { + yield return () => (new UInt512(0, 0, 0, 0, 0, 0, 0, 0), new byte[64], Unsafe.SizeOf()); + yield return () => + { + var buffer = new byte[64]; + + buffer[0] = 1; + for (int i = 1; i < 64; i++) + buffer[i] = 0; + + return (new UInt512(0, 0, 0, 0, 0, 0, 0, 1), buffer, Unsafe.SizeOf()); + }; + yield return () => + { + var buffer = new byte[64]; + + for (int i = 0; i < 64; i++) + buffer[i] = 0xFF; + + return (UInt512.MaxValue, buffer, Unsafe.SizeOf()); + }; + } + + public static IEnumerable> ConvertToCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedDoubleTestData() + { + yield return () => (UInt512.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + yield return () => (UInt512.Parse("693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455"), + 693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455.0d); + } + + public static IEnumerable> ConvertToSaturatingDoubleTestData() + { + yield return () => (UInt512.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + yield return () => (UInt512.Parse("693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455"), + 693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455.0d); + } + + public static IEnumerable> ConvertToTruncatingDoubleTestData() + { + yield return () => (UInt512.Parse("781377183594418599030564404241984000000000000000000"), + 781377183594418599030564404241984000000000000000000.0d); + yield return () => (UInt512.Parse("693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455"), + 693167423530203714894603546035770925859109268843954143792619895153655326951406405759993601526034894524347802740350892957243539455.0d); + } + + public static IEnumerable> ConvertToCheckedQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToCheckedOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToSaturatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertToTruncatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingUInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSByteTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt16TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt32TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt64TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt128TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt256TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingInt512TestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingHalfTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingSingleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingDoubleTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingQuadTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromCheckedOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromSaturatingOctoTestData() + { + throw new NotImplementedException(); + } + + public static IEnumerable> ConvertFromTruncatingOctoTestData() + { + throw new NotImplementedException(); + } +} diff --git a/src/MissingValues.Tests/Extensions/NumberBaseAssertionExtensions.cs b/src/MissingValues.Tests/Extensions/NumberBaseAssertionExtensions.cs new file mode 100644 index 0000000..4db9fc3 --- /dev/null +++ b/src/MissingValues.Tests/Extensions/NumberBaseAssertionExtensions.cs @@ -0,0 +1,47 @@ +using System.ComponentModel; +using System.Globalization; +using System.Numerics; +using System.Runtime.CompilerServices; +using TUnit.Assertions.Attributes; +using TUnit.Assertions.Core; + +namespace MissingValues.Tests.Extensions; + +public static class NumberBaseAssertionExtensions +{ + [EditorBrowsable(EditorBrowsableState.Never)] + [GenerateAssertion(ExpectationMessage = "to be bitwise equivalent to {other}")] + public static bool IsBitwiseEquivalentTo(this T1 value, T2 other) + where T1 : struct, IFloatingPointIeee754 + where T2 : struct, IBinaryInteger + { + return Unsafe.SizeOf() == Unsafe.SizeOf() && Unsafe.BitCast(value) == other; + } + [EditorBrowsable(EditorBrowsableState.Never)] + [GenerateAssertion(ExpectationMessage = "to be approximately equal to {precision}")] + public static AssertionResult IsApproximately(this T value, T expected, T precision) + where T : IFloatingPointIeee754 + { + if (T.IsNaN(value)) + { + return AssertionResult.Failed($"Cannot determine approximation of a {typeof(T)} to NaN"); + } + if (T.IsNegative(precision)) + { + return AssertionResult.Failed($"Cannot determine precision of a {typeof(T)} if its negative"); + } + if (T.IsInfinity(value)) + { + return AssertionResult.Failed($"Cannot determine approximation of a {typeof(T)} to Infinity"); + } + + T actualDifference = T.Abs(expected - value); + + if (actualDifference <= precision) + { + return AssertionResult.Failed($"Expected {value} to approximate {expected} +/- {precision}, but {value} differed by {actualDifference}."); + } + + return AssertionResult.Passed; + } +} \ No newline at end of file diff --git a/src/MissingValues.Tests/GlobalSetup.cs b/src/MissingValues.Tests/GlobalSetup.cs new file mode 100644 index 0000000..07c194b --- /dev/null +++ b/src/MissingValues.Tests/GlobalSetup.cs @@ -0,0 +1,22 @@ +// Here you could define global logic that would affect all tests + +// You can use attributes at the assembly level to apply to all tests in the assembly +[assembly: Retry(3)] +[assembly: System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] + +namespace MissingValues.Tests; + +public class GlobalHooks +{ + [Before(TestSession)] + public static void SetUp() + { + Console.WriteLine(@"Or you can define methods that do stuff before..."); + } + + [After(TestSession)] + public static void CleanUp() + { + Console.WriteLine(@"...and after!"); + } +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Helper.cs b/src/MissingValues.Tests/Helper.cs new file mode 100644 index 0000000..d7315ae --- /dev/null +++ b/src/MissingValues.Tests/Helper.cs @@ -0,0 +1,258 @@ +using System.Globalization; +using System.Numerics; + +namespace MissingValues.Tests; + +public static class Helper +{ + public static TSelf Abs(TSelf value) + where TSelf : INumberBase + { + return TSelf.Abs(value); + } + public static bool IsCanonical(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsCanonical(value); + } + public static bool IsComplexNumber(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsComplexNumber(value); + } + public static bool IsEvenInteger(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsEvenInteger(value); + } + public static bool IsFinite(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsFinite(value); + } + public static bool IsImaginaryNumber(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsImaginaryNumber(value); + } + public static bool IsInfinity(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsInfinity(value); + } + public static bool IsInteger(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsInteger(value); + } + public static bool IsNaN(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsNaN(value); + } + public static bool IsNegative(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsNegative(value); + } + public static bool IsNegativeInfinity(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsNegativeInfinity(value); + } + public static bool IsNormal(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsNormal(value); + } + public static bool IsOddInteger(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsOddInteger(value); + } + public static bool IsPositive(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsPositive(value); + } + public static bool IsPositiveInfinity(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsPositiveInfinity(value); + } + public static bool IsRealNumber(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsRealNumber(value); + } + public static bool IsSubnormal(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsSubnormal(value); + } + public static bool IsZero(TSelf value) + where TSelf : INumberBase + { + return TSelf.IsZero(value); + } + public static TSelf MaxMagnitude(TSelf x, TSelf y) + where TSelf : INumberBase + { + return TSelf.MaxMagnitude(x, y); + } + public static TSelf MaxMagnitudeNumber(TSelf x, TSelf y) + where TSelf : INumberBase + { + return TSelf.MaxMagnitudeNumber(x, y); + } + public static TSelf MinMagnitude(TSelf x, TSelf y) + where TSelf : INumberBase + { + return TSelf.MinMagnitude(x, y); + } + public static TSelf MinMagnitudeNumber(TSelf x, TSelf y) + where TSelf : INumberBase + { + return TSelf.MinMagnitudeNumber(x, y); + } + public static TSelf MultiplyAddEstimate(TSelf left, TSelf right, TSelf addend) + where TSelf : INumberBase + { + return TSelf.MultiplyAddEstimate(left, right, addend); + } + public static TSelf Parse(string s, NumberStyles style, IFormatProvider? provider) + where TSelf : INumberBase + { + return TSelf.Parse(s, style, provider); + } + public static TSelf Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) + where TSelf : INumberBase + { + return TSelf.Parse(s, style, provider); + } + public static TSelf Parse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider) + where TSelf : INumberBase + { + return TSelf.Parse(utf8Text, style, provider); + } + public static bool TryParse(string s, NumberStyles style, IFormatProvider? provider, out TSelf result) + where TSelf : INumberBase + { + return TSelf.TryParse(s, style, provider, out result); + } + public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, out TSelf result) + where TSelf : INumberBase + { + return TSelf.TryParse(s, style, provider, out result); + } + public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, out TSelf result) + where TSelf : INumberBase + { + return TSelf.TryParse(utf8Text, style, provider, out result); + } + public static TSelf Clamp(TSelf value, TSelf min, TSelf max) + where TSelf : INumber + { + return TSelf.Clamp(value, min, max); + } + public static TSelf CopySign(TSelf value, TSelf sign) + where TSelf : INumber + { + return TSelf.CopySign(value, sign); + } + public static TSelf Max(TSelf x, TSelf y) + where TSelf : INumber + { + return TSelf.Max(x, y); + } + public static TSelf MaxNumber(TSelf x, TSelf y) + where TSelf : INumber + { + return TSelf.MaxNumber(x, y); + } + public static TSelf Min(TSelf x, TSelf y) + where TSelf : INumber + { + return TSelf.Min(x, y); + } + public static TSelf MinNumber(TSelf x, TSelf y) + where TSelf : INumber + { + return TSelf.MinNumber(x, y); + } + public static int Sign(TSelf value) + where TSelf : INumber + { + return TSelf.Sign(value); + } + public static bool IsPow2(TSelf value) + where TSelf : IBinaryNumber + { + return TSelf.IsPow2(value); + } + public static TSelf Log2(TSelf value) + where TSelf : IBinaryNumber + { + return TSelf.Log2(value); + } + public static (TSelf Quotient, TSelf Remainder) DivRem(TSelf left, TSelf right) + where TSelf : IBinaryInteger + { + return TSelf.DivRem(left, right); + } + public static TSelf LeadingZeroCount(TSelf value) + where TSelf : IBinaryInteger + { + return TSelf.LeadingZeroCount(value); + } + public static TSelf PopCount(TSelf value) + where TSelf : IBinaryInteger + { + return TSelf.PopCount(value); + } + public static TSelf ReadBigEndian(ReadOnlySpan source, bool isUnsigned) + where TSelf : IBinaryInteger + { + return TSelf.ReadBigEndian(source, isUnsigned); + } + public static TSelf ReadLittleEndian(ReadOnlySpan source, bool isUnsigned) + where TSelf : IBinaryInteger + { + return TSelf.ReadLittleEndian(source, isUnsigned); + } + public static TSelf RotateLeft(TSelf value, int rotateAmount) + where TSelf : IBinaryInteger + { + return TSelf.RotateLeft(value, rotateAmount); + } + public static TSelf RotateRight(TSelf value, int rotateAmount) + where TSelf : IBinaryInteger + { + return TSelf.RotateRight(value, rotateAmount); + } + public static TSelf TrailingZeroCount(TSelf value) + where TSelf : IBinaryInteger + { + return TSelf.TrailingZeroCount(value); + } + public static int GetByteCount(TSelf value) + where TSelf : IBinaryInteger + { + return value.GetByteCount(); + } + public static int GetShortestBitLength(TSelf value) + where TSelf : IBinaryInteger + { + return value.GetShortestBitLength(); + } + public static int WriteBigEndian(TSelf value, Span destination) + where TSelf : IBinaryInteger + { + return value.WriteBigEndian(destination); + } + public static int WriteLittleEndian(TSelf value, Span destination) + where TSelf : IBinaryInteger + { + return value.WriteLittleEndian(destination); + } +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Helpers/BinaryIntegerHelper.cs b/src/MissingValues.Tests/Helpers/BinaryIntegerHelper.cs deleted file mode 100644 index 5bd3a0c..0000000 --- a/src/MissingValues.Tests/Helpers/BinaryIntegerHelper.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Helpers -{ - internal static class BinaryIntegerHelper - where TSelf : IBinaryInteger - { - /// - public static (TSelf Quotient, TSelf Remainder) DivRem(TSelf left, TSelf right) - { - return TSelf.DivRem(left, right); - } - /// - public static TSelf LeadingZeroCount(TSelf value) - { - return TSelf.LeadingZeroCount(value); - } - /// - public static TSelf PopCount(TSelf value) - { - return TSelf.PopCount(value); - } - /// - public static TSelf RotateLeft(TSelf value, int rotateAmount) - { - return TSelf.RotateLeft(value, rotateAmount); - } - /// - public static TSelf RotateRight(TSelf value, int rotateAmount) - { - return TSelf.RotateRight(value, rotateAmount); - } - /// - public static TSelf TrailingZeroCount(TSelf value) - { - return TSelf.TrailingZeroCount(value); - } - /// - public static bool TryReadBigEndian(ReadOnlySpan source, bool isUnsigned, out TSelf value) - { - return TSelf.TryReadBigEndian(source, isUnsigned, out value); - } - /// - public static bool TryReadLittleEndian(ReadOnlySpan source, bool isUnsigned, out TSelf value) - { - return TSelf.TryReadLittleEndian(source, isUnsigned, out value); - } - /// - public static int GetByteCount(TSelf value) - { - return value.GetByteCount(); - } - /// - public static int GetShortestBitLength(TSelf value) - { - return value.GetShortestBitLength(); - } - /// - public static bool TryWriteBigEndian(TSelf value, Span destination, out int bytesWritten) - { - return value.TryWriteBigEndian(destination, out bytesWritten); - } - /// - public static bool TryWriteLittleEndian(TSelf value, Span destination, out int bytesWritten) - { - return value.TryWriteLittleEndian(destination, out bytesWritten); - } - - } -} diff --git a/src/MissingValues.Tests/Helpers/BinaryNumberHelper.cs b/src/MissingValues.Tests/Helpers/BinaryNumberHelper.cs deleted file mode 100644 index b182c62..0000000 --- a/src/MissingValues.Tests/Helpers/BinaryNumberHelper.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Helpers -{ - internal static class BinaryNumberHelper - where TSelf : IBinaryNumber - { - /// - public static TSelf AllBitsSet => TSelf.AllBitsSet; - /// - public static bool IsPow2(TSelf value) => TSelf.IsPow2(value); - /// - public static TSelf Log2(TSelf value) => TSelf.Log2(value); - } -} diff --git a/src/MissingValues.Tests/Helpers/FloatingPoint.cs b/src/MissingValues.Tests/Helpers/FloatingPoint.cs deleted file mode 100644 index 14ec260..0000000 --- a/src/MissingValues.Tests/Helpers/FloatingPoint.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Helpers -{ - internal static class FloatingPoint - where TSelf : IFloatingPoint - { - /// - public static TSelf Ceiling(TSelf x) => TSelf.Ceiling(x); - /// - public static TSelf Floor(TSelf x) => TSelf.Floor(x); - /// - public static TSelf Round(TSelf x) => TSelf.Round(x); - /// - public static TSelf Round(TSelf x, int digits) => TSelf.Round(x, digits); - /// - public static TSelf Round(TSelf x, MidpointRounding mode) => TSelf.Round(x, mode); - /// - public static TSelf Round(TSelf x, int digits, MidpointRounding mode) => TSelf.Round(x, digits, mode); - /// - public static TSelf Truncate(TSelf x) => TSelf.Truncate(x); - /// - public static int GetExponentByteCount(TSelf x) => x.GetExponentByteCount(); - /// - public static int GetExponentShortestBitLength(TSelf x) => x.GetExponentShortestBitLength(); - /// - public static int GetSignificandBitLength(TSelf x) => x.GetSignificandBitLength(); - /// - public static int GetSignificandByteCount(TSelf x) => x.GetSignificandByteCount(); - public static bool TryWriteExponentBigEndian(TSelf x, Span destination, out int bytesWritten) => x.TryWriteExponentBigEndian(destination, out bytesWritten); - public static bool TryWriteExponentLittleEndian(TSelf x, Span destination, out int bytesWritten) => x.TryWriteExponentLittleEndian(destination, out bytesWritten); - public static bool TryWriteSignificandBigEndian(TSelf x, Span destination, out int bytesWritten) => x.TryWriteSignificandBigEndian(destination, out bytesWritten); - public static bool TryWriteSignificandLittleEndian(TSelf x, Span destination, out int bytesWritten) => x.TryWriteSignificandLittleEndian(destination, out bytesWritten); - public static int WriteExponentBigEndian(TSelf x, byte[] destination) => x.WriteExponentBigEndian(destination); - public static int WriteExponentBigEndian(TSelf x, byte[] destination, int startIndex) => x.WriteExponentBigEndian(destination, startIndex); - public static int WriteExponentBigEndian(TSelf x, Span destination) => x.WriteExponentBigEndian(destination); - public static int WriteExponentLittleEndian(TSelf x, byte[] destination) => x.WriteExponentLittleEndian(destination); - public static int WriteExponentLittleEndian(TSelf x, byte[] destination, int startIndex) => x.WriteExponentLittleEndian(destination, startIndex); - public static int WriteExponentLittleEndian(TSelf x, Span destination) => x.WriteExponentLittleEndian(destination); - public static int WriteSignificandBigEndian(TSelf x, byte[] destination) => x.WriteSignificandBigEndian(destination); - public static int WriteSignificandBigEndian(TSelf x, byte[] destination, int startIndex) => x.WriteSignificandBigEndian(destination, startIndex); - public static int WriteSignificandBigEndian(TSelf x, Span destination) => x.WriteSignificandBigEndian(destination); - public static int WriteSignificandLittleEndian(TSelf x, byte[] destination) => x.WriteSignificandLittleEndian(destination); - public static int WriteSignificandLittleEndian(TSelf x, byte[] destination, int startIndex) => x.WriteSignificandLittleEndian(destination, startIndex); - public static int WriteSignificandLittleEndian(TSelf x, Span destination) => x.WriteSignificandLittleEndian(destination); - } -} diff --git a/src/MissingValues.Tests/Helpers/FloatingPointIeee754.cs b/src/MissingValues.Tests/Helpers/FloatingPointIeee754.cs deleted file mode 100644 index 60a45d9..0000000 --- a/src/MissingValues.Tests/Helpers/FloatingPointIeee754.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Helpers -{ - internal static class FloatingPointIeee754 - where TSelf : IFloatingPointIeee754 - { - public static TSelf Epsilon => TSelf.Epsilon; - public static TSelf NaN => TSelf.NaN; - public static TSelf NegativeInfinity => TSelf.NegativeInfinity; - public static TSelf NegativeZero => TSelf.NegativeZero; - public static TSelf PositiveInfinity => TSelf.PositiveInfinity; - public static TSelf Atan2(TSelf y, TSelf x) => TSelf.Atan2(y, x); - public static TSelf Atan2Pi(TSelf y, TSelf x) => TSelf.Atan2Pi(y, x); - public static TSelf BitDecrement(TSelf x) => TSelf.BitDecrement(x); - public static TSelf BitIncrement(TSelf x) => TSelf.BitIncrement(x); - public static TSelf FusedMultiplyAdd(TSelf left, TSelf right, TSelf addend) => TSelf.FusedMultiplyAdd(left, right, addend); - public static TSelf Ieee754Remainder(TSelf left, TSelf right) => TSelf.Ieee754Remainder(left, right); - public static int ILogB(TSelf x) => TSelf.ILogB(x); - public static TSelf ReciprocalEstimate(TSelf x) => TSelf.ReciprocalEstimate(x); - public static TSelf ReciprocalSqrtEstimate(TSelf x) => TSelf.ReciprocalSqrtEstimate(x); - public static TSelf ScaleB(TSelf x, int n) => TSelf.ScaleB(x, n); - } -} diff --git a/src/MissingValues.Tests/Helpers/FluentAssertionsExtensions.cs b/src/MissingValues.Tests/Helpers/FluentAssertionsExtensions.cs deleted file mode 100644 index 5c2c878..0000000 --- a/src/MissingValues.Tests/Helpers/FluentAssertionsExtensions.cs +++ /dev/null @@ -1,247 +0,0 @@ -using FluentAssertions.Execution; -using FluentAssertions.Numeric; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Versioning; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Helpers -{ - public static class FluentAssertionsExtensions - { - private class QuadAssertions : NumericAssertions - { - internal QuadAssertions(Quad value) - : base(value) - { - } - } - private class NullableQuadAssertions : NullableNumericAssertions - { - internal NullableQuadAssertions(Quad? value) - : base(value) - { - } - } - private class OctoAssertions : NumericAssertions - { - internal OctoAssertions(Octo value) - : base(value) - { - } - } - private class NullableOctoAssertions : NullableNumericAssertions - { - internal NullableOctoAssertions(Octo? value) - : base(value) - { - } - } - - public static NumericAssertions Should(this Quad actualValue) - { - return new QuadAssertions(actualValue); - } - public static NullableNumericAssertions Should(this Quad? actualValue) - { - return new NullableQuadAssertions(actualValue); - } - public static NumericAssertions Should(this Octo actualValue) - { - return new OctoAssertions(actualValue); - } - public static NullableNumericAssertions Should(this Octo? actualValue) - { - return new NullableOctoAssertions(actualValue); - } - - public static AndConstraint> BeApproximately(this NumericAssertions parent, Quad expectedValue, Quad precision, string because = "", params object[] becauseArgs) - { - if (Quad.IsNaN(expectedValue)) - { - throw new ArgumentException("Cannot determine approximation of a Quad to NaN", nameof(expectedValue)); - } - if (Quad.IsNegative(precision)) - { - throw new ArgumentException("Cannot determine precision of a Quad if its negative", nameof(expectedValue)); - } - - if (Quad.IsPositiveInfinity(expectedValue)) - { - FailIfDifferenceOutsidePrecision(Quad.IsPositiveInfinity(parent.Subject.Value), parent, expectedValue, precision, - Quad.NaN, because, becauseArgs); - } - else if (Quad.IsNegativeInfinity(expectedValue)) - { - FailIfDifferenceOutsidePrecision(Quad.IsNegativeInfinity(parent.Subject.Value), parent, expectedValue, precision, - Quad.NaN, because, becauseArgs); - } - else - { - Quad actualDifference = Quad.Abs(expectedValue - parent.Subject.Value); - - FailIfDifferenceOutsidePrecision(actualDifference <= precision, parent, expectedValue, precision, actualDifference, because, becauseArgs); - } - - return new AndConstraint>(parent); - } - public static AndConstraint> BeApproximately(this NumericAssertions parent, Octo expectedValue, Octo precision, string because = "", params object[] becauseArgs) - { - if (Octo.IsNaN(expectedValue)) - { - throw new ArgumentException("Cannot determine approximation of a Quad to NaN", nameof(expectedValue)); - } - if (Octo.IsNegative(precision)) - { - throw new ArgumentException("Cannot determine precision of a Quad if its negative", nameof(expectedValue)); - } - - if (Octo.IsPositiveInfinity(expectedValue)) - { - FailIfDifferenceOutsidePrecision(Octo.IsPositiveInfinity(parent.Subject.Value), parent, expectedValue, precision, - Octo.NaN, because, becauseArgs); - } - else if (Octo.IsNegativeInfinity(expectedValue)) - { - FailIfDifferenceOutsidePrecision(Octo.IsNegativeInfinity(parent.Subject.Value), parent, expectedValue, precision, - Octo.NaN, because, becauseArgs); - } - else - { - Octo actualDifference = Octo.Abs(expectedValue - parent.Subject.Value); - - FailIfDifferenceOutsidePrecision(actualDifference <= precision, parent, expectedValue, precision, actualDifference, because, becauseArgs); - } - - return new AndConstraint>(parent); - } - - public static AndConstraint> BeNaN(this NumericAssertions parent, string because = "", params object[] becauseArgs) - { - bool condition = Quad.IsNaN(parent.Subject!.Value); - - Execute.Assertion - .ForCondition(condition) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:object} to be {0}.", Quad.NaN); - - return new AndConstraint>(parent); - } - public static AndConstraint> BeNaN(this NumericAssertions parent, string because = "", params object[] becauseArgs) - { - bool condition = Octo.IsNaN(parent.Subject!.Value); - - Execute.Assertion - .ForCondition(condition) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:object} to be {0}.", Octo.NaN); - - return new AndConstraint>(parent); - } - - private static void FailIfDifferenceOutsidePrecision( - bool differenceWithinPrecision, - NumericAssertions parent, T expectedValue, T precision, T actualDifference, - string because, object[] becauseArgs) - where T : struct, IComparable - { - Execute.Assertion - .ForCondition(differenceWithinPrecision) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:value} to approximate {1} +/- {2}{reason}, but {0} differed by {3}.", - parent.Subject, expectedValue, precision, actualDifference); - } - - public static AndConstraint> BeBitwiseEquivalentTo(this NumericAssertions> assertions, Quad expected, string because = "", params object[] becauseArgs) - { - bool condition; - - Quad actualValue = assertions.Subject is null ? default : (Quad)assertions.Subject; - - if (Quad.IsNaN(actualValue) && Quad.IsNaN(expected)) - { - condition = true; - } - else - { - condition = Equals(Quad.QuadToUInt128Bits(actualValue), Quad.QuadToUInt128Bits(expected)); - } - - Execute.Assertion - .ForCondition(condition) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:object} to be equal to {0}{reason}, but found {1}.", expected, assertions.Subject); - - return new AndConstraint>((NumericAssertions)assertions); - } - public static AndConstraint> BeBitwiseEquivalentTo(this NumericAssertions> assertions, Octo expected, string because = "", params object[] becauseArgs) - { - bool condition; - - Octo actualValue = assertions.Subject is null ? default : (Octo)assertions.Subject; - - if (Octo.IsNaN(actualValue) && Octo.IsNaN(expected)) - { - condition = true; - } - else - { - condition = Equals(Octo.OctoToUInt256Bits(actualValue), Octo.OctoToUInt256Bits(expected)); - } - - Execute.Assertion - .ForCondition(condition) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:object} to be equal to {0}{reason}, but found {1}.", expected, assertions.Subject); - - return new AndConstraint>((NumericAssertions)assertions); - } - - public static AndConstraint> NotBeBitwiseEquivalentTo(this NumericAssertions> assertions, Quad expected, string because = "", params object[] becauseArgs) - { - bool condition; - - Quad actualValue = assertions.Subject is null ? default : (Quad)assertions.Subject; - - if (Quad.IsNaN(actualValue) && Quad.IsNaN(expected)) - { - condition = true; - } - else - { - condition = Equals(Quad.QuadToUInt128Bits(actualValue), Quad.QuadToUInt128Bits(expected)); - } - - Execute.Assertion - .ForCondition(!condition) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:object} to be equal to {0}{reason}, but found {1}.", expected, assertions.Subject); - - return new AndConstraint>((NumericAssertions)assertions); - } - public static AndConstraint> NotBeBitwiseEquivalentTo(this NumericAssertions> assertions, Octo expected, string because = "", params object[] becauseArgs) - { - bool condition; - - Octo actualValue = assertions.Subject is null ? default : (Octo)assertions.Subject; - - if (Octo.IsNaN(actualValue) && Octo.IsNaN(expected)) - { - condition = true; - } - else - { - condition = Equals(Octo.OctoToUInt256Bits(actualValue), Octo.OctoToUInt256Bits(expected)); - } - - Execute.Assertion - .ForCondition(!condition) - .BecauseOf(because, becauseArgs) - .FailWith("Expected {context:object} to be equal to {0}{reason}, but found {1}.", expected, assertions.Subject); - - return new AndConstraint>((NumericAssertions)assertions); - } - } -} diff --git a/src/MissingValues.Tests/Helpers/GenericFloatingPointFunctions.cs b/src/MissingValues.Tests/Helpers/GenericFloatingPointFunctions.cs deleted file mode 100644 index 7477cbf..0000000 --- a/src/MissingValues.Tests/Helpers/GenericFloatingPointFunctions.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Helpers -{ - internal static class GenericFloatingPointFunctions - { - public static T Acos(T x) where T : ITrigonometricFunctions => T.Acos(x); - public static T Acosh(T x) where T : IHyperbolicFunctions => T.Acosh(x); - public static T AcosPi(T x) where T : ITrigonometricFunctions => T.AcosPi(x); - public static T Asin(T x) where T : ITrigonometricFunctions => T.Asin(x); - public static T Asinh(T x) where T : IHyperbolicFunctions => T.Asinh(x); - public static T AsinPi(T x) where T : ITrigonometricFunctions => T.AsinPi(x); - public static T Atan(T x) where T : ITrigonometricFunctions => T.Atan(x); - public static T AtanPi(T x) where T : ITrigonometricFunctions => T.AtanPi(x); - public static T Atanh(T x) where T : IHyperbolicFunctions => T.Atanh(x); - public static T Cbrt(T x) where T : IRootFunctions => T.Cbrt(x); - public static T Cos(T x) where T : ITrigonometricFunctions => T.Cos(x); - public static T Cosh(T x) where T : IHyperbolicFunctions => T.Cosh(x); - public static T CosPi(T x) where T : ITrigonometricFunctions => T.CosPi(x); - public static T Exp(T x) where T : IExponentialFunctions => T.Exp(x); - public static T ExpM1(T x) where T : IExponentialFunctions => T.ExpM1(x); - public static T Exp2(T x) where T : IExponentialFunctions => T.Exp2(x); - public static T Exp2M1(T x) where T : IExponentialFunctions => T.Exp2M1(x); - public static T Exp10(T x) where T : IExponentialFunctions => T.Exp10(x); - public static T Exp10M1(T x) where T : IExponentialFunctions => T.Exp10M1(x); - public static T Hypot(T x, T y) where T : IRootFunctions => T.Hypot(x, y); - public static T Log(T x) where T : ILogarithmicFunctions => T.Log(x); - public static T Log(T x, T newBase) where T : ILogarithmicFunctions => T.Log(x, newBase); - public static T LogP1(T x) where T : ILogarithmicFunctions => T.LogP1(x); - public static T Log2(T x) where T : ILogarithmicFunctions => T.Log2(x); - public static T Log2P1(T x) where T : ILogarithmicFunctions => T.Log2P1(x); - public static T Log10(T x) where T : ILogarithmicFunctions => T.Log10(x); - public static T Log10P1(T x) where T : ILogarithmicFunctions => T.Log10P1(x); - public static T Pow(T x, T y) where T : IPowerFunctions => T.Pow(x, y); - public static T RootN(T x, int y) where T : IRootFunctions => T.RootN(x, y); - public static T Sin(T x) where T : ITrigonometricFunctions => T.Sin(x); - public static (T Sin, T Cos) SinCos(T x) where T : ITrigonometricFunctions => T.SinCos(x); - public static (T Sin, T Cos) SinCosPi(T x) where T : ITrigonometricFunctions => T.SinCosPi(x); - public static T Sinh(T x) where T : IHyperbolicFunctions => T.Sinh(x); - public static T SinPi(T x) where T : ITrigonometricFunctions => T.SinPi(x); - public static T Sqrt(T x) where T : IRootFunctions => T.Sqrt(x); - public static T Tan(T x) where T : ITrigonometricFunctions => T.Tan(x); - public static T Tanh(T x) where T : IHyperbolicFunctions => T.Tanh(x); - public static T TanPi(T x) where T : ITrigonometricFunctions => T.TanPi(x); - } -} diff --git a/src/MissingValues.Tests/Helpers/GenericMathOperatorsHelper.cs b/src/MissingValues.Tests/Helpers/GenericMathOperatorsHelper.cs deleted file mode 100644 index 3d49662..0000000 --- a/src/MissingValues.Tests/Helpers/GenericMathOperatorsHelper.cs +++ /dev/null @@ -1,198 +0,0 @@ -using Microsoft.VisualStudio.TestPlatform.ObjectModel; -using System; -using System.Collections.Generic; -using System.Diagnostics.Contracts; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Helpers -{ - internal static class MathOperatorsHelper - { - public static TResult AdditionOperation(TSelf left, TOther right) - where TSelf : IAdditionOperators - { - return left + right; - } - public static TResult CheckedAdditionOperation(TSelf left, TOther right) - where TSelf : IAdditionOperators - { - return checked(left + right); - } - - public static TSelf IncrementOperation(TSelf value) - where TSelf : IIncrementOperators - { - return ++value; - } - public static TSelf CheckedIncrementOperation(TSelf value) - where TSelf : IIncrementOperators - { - return checked(++value); - } - - public static TResult UnaryPlusOperation(TSelf value) - where TSelf : IUnaryPlusOperators - { - return +value; - } - public static TResult CheckedUnaryPlusOperation(TSelf value) - where TSelf : IUnaryPlusOperators - { - return checked(+value); - } - - public static TResult UnaryNegationOperation(TSelf value) - where TSelf : IUnaryNegationOperators - { - return -value; - } - public static TResult CheckedUnaryNegationOperation(TSelf value) - where TSelf : IUnaryNegationOperators - { - return checked(-value); - } - - public static TResult SubtractionOperation(TSelf left, TOther right) - where TSelf : ISubtractionOperators - { - return left - right; - } - public static TResult CheckedSubtractionOperation(TSelf left, TOther right) - where TSelf : ISubtractionOperators - { - return checked(left - right); - } - - public static TSelf DecrementOperation(TSelf value) - where TSelf : IDecrementOperators - { - return --value; - } - public static TSelf CheckedDecrementOperation(TSelf value) - where TSelf : IDecrementOperators - { - return checked(--value); - } - - public static TResult MultiplicationOperation(TSelf left, TOther right) - where TSelf : IMultiplyOperators - { - return left * right; - } - public static TResult CheckedMultiplicationOperation(TSelf left, TOther right) - where TSelf : IMultiplyOperators - { - return checked(left * right); - } - - public static TResult DivisionOperation(TSelf left, TOther right) - where TSelf : IDivisionOperators - { - return left / right; - } - public static TResult CheckedDivisionOperation(TSelf left, TOther right) - where TSelf : IDivisionOperators - { - return checked(left / right); - } - - public static TResult ModulusOperation(TSelf left, TOther right) - where TSelf : IModulusOperators - { - return left % right; - } - } - - internal static class ComparisonOperatorsHelper - where TSelf : IComparisonOperators - { - public static TResult GreaterThanOperation(TSelf left, TOther right) - { - return left > right; - } - public static TResult GreaterThanOrEqualOperation(TSelf left, TOther right) - { - return left >= right; - } - public static TResult LessThanOperation(TSelf left, TOther right) - { - return left < right; - } - public static TResult LessThanOrEqualOperation(TSelf left, TOther right) - { - return left <= right; - } - } - - internal static class EqualityOperatorsHelper - where TSelf : IEqualityOperators - { - public static TResult EqualityOperation(TSelf left, TOther right) - { - return left == right; - } - public static TResult InequalityOperation(TSelf left, TOther right) - { - return left != right; - } - } - - internal static class BitwiseOperatorsHelper - where TSelf : IBitwiseOperators - { - public static TResult BitwiseAndOperation(TSelf left, TOther right) - { - return left & right; - } - public static TResult BitwiseOrOperation(TSelf left, TOther right) - { - return left | right; - } - public static TResult ExclusiveOrOperation(TSelf left, TOther right) - { - return left ^ right; - } - public static TResult OnesComplementOperation(TSelf value) - { - return ~value; - } - } - internal static class ShiftOperatorsHelper - where TSelf : IShiftOperators - { - public static TResult LeftShiftOperation(TSelf value, TOther shiftAmount) - { - return value << shiftAmount; - } - public static TResult RightShiftOperation(TSelf value, TOther shiftAmount) - { - return value >> shiftAmount; - } - public static TResult UnsignedRightShiftOperation(TSelf value, TOther shiftAmount) - { - return value >>> shiftAmount; - } - } - - internal static class UnaryOperatorsHelper - { - public static TResult UnaryPlusOperation(TSelf value) - where TSelf : IUnaryPlusOperators - { - return +value; - } - public static TResult UnaryNegationOperation(TSelf value) - where TSelf : IUnaryNegationOperators - { - return -value; - } - public static TResult CheckedUnaryNegationOperation(TSelf value) - where TSelf : IUnaryNegationOperators - { - return checked(-value); - } - } -} diff --git a/src/MissingValues.Tests/Helpers/MathConstantsHelper.cs b/src/MissingValues.Tests/Helpers/MathConstantsHelper.cs deleted file mode 100644 index f9e9a7f..0000000 --- a/src/MissingValues.Tests/Helpers/MathConstantsHelper.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Helpers -{ - internal static class MathConstantsHelper - { - /// - public static TResult AdditiveIdentityHelper() - where TSelf : IAdditiveIdentity - { - return TSelf.AdditiveIdentity; - } - /// - public static TResult MultiplicativeIdentityHelper() - where TSelf : IMultiplicativeIdentity - { - return TSelf.MultiplicativeIdentity; - } - /// - public static TSelf MaxValue() - where TSelf : IMinMaxValue - { - return TSelf.MaxValue; - } - /// - public static TSelf MinValue() - where TSelf : IMinMaxValue - { - return TSelf.MinValue; - } - /// - public static TSelf NegativeOne() - where TSelf : ISignedNumber - { - return TSelf.NegativeOne; - } - public static TSelf Pi() - where TSelf : IFloatingPointConstants - { - return TSelf.Pi; - } - public static TSelf Tau() - where TSelf : IFloatingPointConstants - { - return TSelf.Tau; - } - public static TSelf E() - where TSelf : IFloatingPointConstants - { - return TSelf.E; - } - public static TSelf PositiveInfinity() - where TSelf : IFloatingPointIeee754 - { - return TSelf.PositiveInfinity; - } - public static TSelf NegativeInfinity() - where TSelf : IFloatingPointIeee754 - { - return TSelf.NegativeInfinity; - } - public static TSelf NaN() - where TSelf : IFloatingPointIeee754 - { - return TSelf.NaN; - } - } -} diff --git a/src/MissingValues.Tests/Helpers/NumberBaseHelper.cs b/src/MissingValues.Tests/Helpers/NumberBaseHelper.cs deleted file mode 100644 index ebe5241..0000000 --- a/src/MissingValues.Tests/Helpers/NumberBaseHelper.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Helpers -{ - internal static class NumberBaseHelper - where TSelf : INumberBase - { - public static TSelf One => TSelf.One; - public static int Radix => TSelf.Radix; - public static TSelf Zero => TSelf.Zero; - public static TSelf Abs(TSelf value) => TSelf.Abs(value); - - public static TSelf CreateChecked(TOther value) - where TOther : INumberBase => TSelf.CreateChecked(value); - public static TSelf CreateSaturating(TOther value) - where TOther : INumberBase => TSelf.CreateSaturating(value); - public static TSelf CreateTruncating(TOther value) - where TOther : INumberBase => TSelf.CreateTruncating(value); - - public static bool IsCanonical(TSelf value) => TSelf.IsCanonical(value); - public static bool IsComplexNumber(TSelf value) => TSelf.IsComplexNumber(value); - public static bool IsEvenInteger(TSelf value) => TSelf.IsEvenInteger(value); - public static bool IsFinite(TSelf value) => TSelf.IsFinite(value); - public static bool IsImaginaryNumber(TSelf value) => TSelf.IsImaginaryNumber(value); - public static bool IsInfinity(TSelf value) => TSelf.IsInfinity(value); - public static bool IsInteger(TSelf value) => TSelf.IsInteger(value); - public static bool IsNaN(TSelf value) => TSelf.IsNaN(value); - public static bool IsNegative(TSelf value) => TSelf.IsNegative(value); - public static bool IsNegativeInfinity(TSelf value) => TSelf.IsNegativeInfinity(value); - public static bool IsNormal(TSelf value) => TSelf.IsNormal(value); - public static bool IsOddInteger(TSelf value) => TSelf.IsOddInteger(value); - public static bool IsPositive(TSelf value) => TSelf.IsPositive(value); - public static bool IsPositiveInfinity(TSelf value) => TSelf.IsPositiveInfinity(value); - public static bool IsRealNumber(TSelf value) => TSelf.IsRealNumber(value); - public static bool IsSubnormal(TSelf value) => TSelf.IsSubnormal(value); - public static bool IsZero(TSelf value) => TSelf.IsZero(value); - - public static TSelf MaxMagnitude(TSelf x, TSelf y) => TSelf.MaxMagnitude(x, y); - public static TSelf MaxMagnitudeNumber(TSelf x, TSelf y) => TSelf.MaxMagnitudeNumber(x, y); - public static TSelf MinMagnitude(TSelf x, TSelf y) => TSelf.MinMagnitude(x, y); - public static TSelf MinMagnitudeNumber(TSelf x, TSelf y) => TSelf.MinMagnitudeNumber(x, y); - - public static TSelf Parse(string s, NumberStyles style, IFormatProvider? provider) => TSelf.Parse(s, style, provider); - public static TSelf Parse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider) => TSelf.Parse(s, style, provider); - public static TSelf Parse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider) => TSelf.Parse(utf8Text, style, provider); - - public static bool TryParse([NotNullWhen(true)] string? s, NumberStyles style, IFormatProvider? provider, [MaybeNullWhen(false)] out TSelf result) => TSelf.TryParse(s, style, provider, out result); - public static bool TryParse(ReadOnlySpan s, NumberStyles style, IFormatProvider? provider, [MaybeNullWhen(false)] out TSelf result) => TSelf.TryParse(s, style, provider, out result); - public static bool TryParse(ReadOnlySpan utf8Text, NumberStyles style, IFormatProvider? provider, [MaybeNullWhen(false)] out TSelf result) => TSelf.TryParse(utf8Text, style, provider, out result); - } -} diff --git a/src/MissingValues.Tests/Helpers/NumberHelper.cs b/src/MissingValues.Tests/Helpers/NumberHelper.cs deleted file mode 100644 index f31d15d..0000000 --- a/src/MissingValues.Tests/Helpers/NumberHelper.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Helpers -{ - internal static class NumberHelper - where TSelf : INumber - { - /// - public static TSelf Clamp(TSelf value, TSelf min, TSelf max) => TSelf.Clamp(value, min, max); - /// - public static TSelf CopySign(TSelf value, TSelf sign) => TSelf.CopySign(value, sign); - /// - public static TSelf Max(TSelf x, TSelf y) => TSelf.Max(x, y); - /// - public static TSelf MaxNumber(TSelf x, TSelf y) => TSelf.MaxNumber(x, y); - /// - public static TSelf Min(TSelf x, TSelf y) => TSelf.Min(x, y); - /// - public static TSelf MinNumber(TSelf x, TSelf y) => TSelf.MinNumber(x, y); - /// - public static int Sign(TSelf value) => TSelf.Sign(value); - } -} diff --git a/src/MissingValues.Tests/Helpers/TheoryDataTypes.cs b/src/MissingValues.Tests/Helpers/TheoryDataTypes.cs deleted file mode 100644 index 29ef7b8..0000000 --- a/src/MissingValues.Tests/Helpers/TheoryDataTypes.cs +++ /dev/null @@ -1,145 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.Contracts; -using System.Globalization; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; -using static System.Runtime.InteropServices.JavaScript.JSType; - -namespace MissingValues.Tests.Helpers -{ - public class NumberTheoryData : TheoryData - where TSelf : INumberBase - { - public NumberTheoryData(IEnumerable data) - { - Contract.Assert(data is not null && data.Any()); - - foreach (var dat in data) - { - Add(dat); - } - } - } - - public class OperationTheoryData : TheoryData - { - public OperationTheoryData(IEnumerable<(TSelf, TOther, TResult)> data) - { - Contract.Assert(data is not null && data.Any()); - - foreach (var dat in data) - { - Add(dat.Item1, dat.Item2, dat.Item3); - } - } - } - - public class FusedMultiplyAddTheoryData : TheoryData - where TSelf : IFloatingPointIeee754 - { - public FusedMultiplyAddTheoryData(IEnumerable<(TSelf, TSelf, TSelf, TSelf)> data) - { - Contract.Assert(data is not null && data.Any()); - - foreach (var dat in data) - { - Add(dat.Item1, dat.Item2, dat.Item3, dat.Item4); - } - } - } - - public class RoundTheoryData : TheoryData - { - public RoundTheoryData(IEnumerable<(TFloat, int, MidpointRounding, TFloat)> data) - { - Contract.Assert(data is not null && data.Any()); - - foreach (var dat in data) - { - Add(dat.Item1, dat.Item2, dat.Item3, dat.Item4); - } - } - } - - public class UnaryTheoryData : TheoryData - { - public UnaryTheoryData(IEnumerable<(TSelf, TResult)> data) - { - Contract.Assert(data is not null && data.Any()); - - foreach (var dat in data) - { - Add(dat.Item1, dat.Item2); - } - } - } - - public class CastingTheoryData : TheoryData - { - public CastingTheoryData(IEnumerable<(TFrom, TTo)> data) - { - Contract.Assert(data is not null && data.Any()); - - foreach (var dat in data) - { - Add(dat.Item1, dat.Item2); - } - } - } - - public class ComparisonOperatorsTheoryData : TheoryData - { - public ComparisonOperatorsTheoryData(IEnumerable<(TSelf, TOther, bool)> data) - { - Contract.Assert(data is not null && data.Any()); - - foreach (var dat in data) - { - Add(dat.Item1, dat.Item2, dat.Item3); - } - } - } - - public class TryParseTheoryData : TheoryData - where T : IParsable - { - public TryParseTheoryData(IEnumerable<(string, bool, T)> data) - { - Contract.Assert(data is not null && data.Any()); - - foreach (var dat in data) - { - Add(dat.Item1, dat.Item2, dat.Item3); - } - } - } - - public class FormatStringTheoryData : TheoryData - { - public FormatStringTheoryData(IEnumerable<(IFormattable, string, NumberFormatInfo?, string)> data) - { - Contract.Assert(data is not null && data.Any()); - - foreach (var dat in data) - { - Add(dat.Item1, dat.Item2, dat.Item3, dat.Item4); - } - } - } - public class FormatParsingTheoryData : TheoryData - where TNumber : INumber - { - public FormatParsingTheoryData(IEnumerable<(string, NumberStyles, NumberFormatInfo?, TNumber, bool)> data) - { - Contract.Assert(data is not null && data.Any()); - - foreach (var dat in data) - { - Add(dat.Item1, dat.Item2, dat.Item3, dat.Item4, dat.Item5); - } - } - } -} diff --git a/src/MissingValues.Tests/Helpers/Values.cs b/src/MissingValues.Tests/Helpers/Values.cs deleted file mode 100644 index 82df81d..0000000 --- a/src/MissingValues.Tests/Helpers/Values.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Text; -using System.Threading.Tasks; - -namespace MissingValues.Tests.Helpers -{ - internal static class Values - { - public static TFloat CreateFloat(params ulong[] bits) - where TFloat : unmanaged, IBinaryFloatingPointIeee754 - { - if (typeof(TFloat) == typeof(Quad) && bits.Length == 2) - { - return (TFloat)(object)Quad.UInt128BitsToQuad(new UInt128(bits[0], bits[1])); - } - else if (typeof(TFloat) == typeof(Octo) && bits.Length == 4) - { - return (TFloat)(object)Octo.UInt256BitsToOcto(new UInt256(bits[0], bits[1], bits[2], bits[3])); - } - else - { - throw new InvalidOperationException($"{typeof(TFloat)} does not match the bits({bits.Length}): {StringifyBits(bits)}"); - } - - static string StringifyBits(ReadOnlySpan bits) - { - StringBuilder sb = new StringBuilder(); - - sb.Append($"0x{bits[0]:X16}"); - for (int i = 1; i < bits.Length; i++) - { - sb.Append($"_{bits[i]:X16}"); - } - - return sb.ToString(); - } - } - } -} diff --git a/src/MissingValues.Tests/MissingValues.Tests.csproj b/src/MissingValues.Tests/MissingValues.Tests.csproj index 5a178aa..fe3499c 100644 --- a/src/MissingValues.Tests/MissingValues.Tests.csproj +++ b/src/MissingValues.Tests/MissingValues.Tests.csproj @@ -1,30 +1,18 @@  - net9.0 enable enable - - false - true + Exe + net10.0 - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - + - + \ No newline at end of file diff --git a/src/MissingValues.Tests/Numerics/Int256GenericMathTests.cs b/src/MissingValues.Tests/Numerics/Int256GenericMathTests.cs new file mode 100644 index 0000000..f620c5f --- /dev/null +++ b/src/MissingValues.Tests/Numerics/Int256GenericMathTests.cs @@ -0,0 +1,665 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MissingValues.Tests.Data; +using static MissingValues.Tests.Data.Int256DataSources; + +using DataSources = MissingValues.Tests.Data.Int256DataSources; + +namespace MissingValues.Tests.Numerics; + +public class Int256GenericMathTests +{ + #region Operators + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_AdditionTestData))] + public async Task op_AdditionTest(Int256 left, Int256 right, Int256 expected) + { + var result = left + right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedAdditionTestData))] + public async Task op_CheckedAdditionTest(Int256 left, Int256 right, Int256 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left + right)).Throws(); + } + else + { + var result = checked(left + right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_IncrementTestData))] + public async Task op_IncrementTest(Int256 value, Int256 expected) + { + var result = ++value; + + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedIncrementTestData))] + public async Task op_CheckedIncrementTest(Int256 value, Int256 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(++value)).Throws(); + } + else + { + var result = checked(++value); + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_SubtractionTestData))] + public async Task op_SubtractionTest(Int256 left, Int256 right, Int256 expected) + { + var result = left - right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedSubtractionTestData))] + public async Task op_CheckedSubtractionTest(Int256 left, Int256 right, Int256 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left - right)).Throws(); + } + else + { + var result = checked(left - right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_DecrementTestData))] + public async Task op_DecrementTest(Int256 value, Int256 expected) + { + var result = --value; + + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedDecrementTestData))] + public async Task op_CheckedDecrementTest(Int256 value, Int256 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(--value)).Throws(); + } + else + { + var result = checked(--value); + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_MultiplyTestData))] + public async Task op_MultiplyTest(Int256 left, Int256 right, Int256 expected) + { + var result = left * right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedMultiplyTestData))] + public async Task op_CheckedMultiplyTest(Int256 left, Int256 right, Int256 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left * right)).Throws(); + } + else + { + var result = checked(left * right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_DivisionTestData))] + public async Task op_DivisionTest(Int256 left, Int256 right, Int256 expected) + { + if (right == Int256.Zero) + { + await Assert.That(() => left / right).Throws(); + } + else + { + var result = left / right; + + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ModulusTestData))] + public async Task op_ModulusTest(Int256 left, Int256 right, Int256 expected) + { + if (right == Int256.Zero) + { + await Assert.That(() => left % right).Throws(); + } + else + { + var result = left % right; + + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_OnesComplementTestData))] + public async Task op_OnesComplementTest(Int256 value, Int256 expected) + { + var result = ~value; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseAndTestData))] + public async Task op_BitwiseAndTest(Int256 left, Int256 right, Int256 expected) + { + var result = left & right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseOrTestData))] + public async Task op_BitwiseOrTest(Int256 left, Int256 right, Int256 expected) + { + var result = left | right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseXorTestData))] + public async Task op_BitwiseXorTest(Int256 left, Int256 right, Int256 expected) + { + var result = left ^ right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ShiftLeftTestData))] + public async Task op_ShiftLeftTest(Int256 value, int shiftAmount, Int256 expected) + { + var result = value << shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ShiftRightTestData))] + public async Task op_ShiftRightTest(Int256 value, int shiftAmount, Int256 expected) + { + var result = value >> shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_UnsignedShiftRightTestData))] + public async Task op_UnsignedShiftRightTest(Int256 value, int shiftAmount, Int256 expected) + { + var result = value >>> shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_EqualityTestData))] + public async Task op_EqualityTest(Int256 left, Int256 right, bool expected) + { + var result = left == right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_InequalityTestData))] + public async Task op_InequalityTest(Int256 left, Int256 right, bool expected) + { + var result = left != right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_LessThanTestData))] + public async Task op_LessThanTest(Int256 left, Int256 right, bool expected) + { + var result = left < right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_LessThanOrEqualTestData))] + public async Task op_LessThanOrEqualTest(Int256 left, Int256 right, bool expected) + { + var result = left <= right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_GreaterThanTestData))] + public async Task op_GreaterThanTest(Int256 left, Int256 right, bool expected) + { + var result = left > right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_GreaterThanOrEqualTestData))] + public async Task op_GreaterThanOrEqualTest(Int256 left, Int256 right, bool expected) + { + var result = left >= right; + + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region INumberBase + [Test] + [MethodDataSource(typeof(DataSources), nameof(AbsTestData))] + public async Task AbsTest(Int256 value, Int256 expected) + { + Int256 result = Helper.Abs(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsCanonicalTestData))] + public async Task IsCanonicalTest(Int256 value, bool expected) + { + bool result = Helper.IsCanonical(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsComplexNumberTestData))] + public async Task IsComplexNumberTest(Int256 value, bool expected) + { + bool result = Helper.IsComplexNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsEvenIntegerTestData))] + public async Task IsEvenIntegerTest(Int256 value, bool expected) + { + bool result = Helper.IsEvenInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsFiniteTestData))] + public async Task IsFiniteTest(Int256 value, bool expected) + { + bool result = Helper.IsFinite(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsImaginaryNumberTestData))] + public async Task IsImaginaryNumberTest(Int256 value, bool expected) + { + bool result = Helper.IsImaginaryNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsInfinityTestData))] + public async Task IsInfinityTest(Int256 value, bool expected) + { + bool result = Helper.IsInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsIntegerTestData))] + public async Task IsIntegerTest(Int256 value, bool expected) + { + bool result = Helper.IsInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNaNTestData))] + public async Task IsNaNTest(Int256 value, bool expected) + { + bool result = Helper.IsNaN(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNegativeTestData))] + public async Task IsNegativeTest(Int256 value, bool expected) + { + bool result = Helper.IsNegative(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNegativeInfinityTestData))] + public async Task IsNegativeInfinityTest(Int256 value, bool expected) + { + bool result = Helper.IsNegativeInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNormalTestData))] + public async Task IsNormalTest(Int256 value, bool expected) + { + bool result = Helper.IsNormal(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsOddIntegerTestData))] + public async Task IsOddIntegerTest(Int256 value, bool expected) + { + bool result = Helper.IsOddInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPositiveTestData))] + public async Task IsPositiveTest(Int256 value, bool expected) + { + bool result = Helper.IsPositive(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPositiveInfinityTestData))] + public async Task IsPositiveInfinityTest(Int256 value, bool expected) + { + bool result = Helper.IsPositiveInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsRealNumberTestData))] + public async Task IsRealNumberTest(Int256 value, bool expected) + { + bool result = Helper.IsRealNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsSubnormalTestData))] + public async Task IsSubnormalTest(Int256 value, bool expected) + { + bool result = Helper.IsSubnormal(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsZeroTestData))] + public async Task IsZeroTest(Int256 value, bool expected) + { + bool result = Helper.IsZero(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxMagnitudeTestData))] + public async Task MaxMagnitudeTest(Int256 x, Int256 y, Int256 expected) + { + var result = Helper.MaxMagnitude(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxMagnitudeNumberTestData))] + public async Task MaxMagnitudeNumberTest(Int256 x, Int256 y, Int256 expected) + { + var result = Helper.MaxMagnitudeNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinMagnitudeTestData))] + public async Task MinMagnitudeTest(Int256 x, Int256 y, Int256 expected) + { + var result = Helper.MinMagnitude(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinMagnitudeNumberTestData))] + public async Task MinMagnitudeNumberTest(Int256 x, Int256 y, Int256 expected) + { + var result = Helper.MinMagnitudeNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MultiplyAddEstimateTestData))] + public async Task MultiplyAddEstimateTest(Int256 left, Int256 right, Int256 addend, Int256 expected) + { + var result = Helper.MultiplyAddEstimate(left, right, addend); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseTestData))] + public async Task ParseTest(string s, NumberStyles style, IFormatProvider? provider, Int256 expected) + { + var result = Helper.Parse(s, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseSpanTestData))] + public async Task ParseTest(char[] s, NumberStyles style, IFormatProvider? provider, Int256 expected) + { + var result = Helper.Parse(s, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseUtf8TestData))] + public async Task ParseTest(byte[] utf8Text, NumberStyles style, IFormatProvider? provider, Int256 expected) + { + var result = Helper.Parse(utf8Text, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseTestData))] + public async Task TryParseTest(string s, NumberStyles style, IFormatProvider? provider, bool expected, Int256 expectedValue) + { + var success = Helper.TryParse(s, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseSpanTestData))] + public async Task TryParseTest(char[] s, NumberStyles style, IFormatProvider? provider, bool expected, Int256 expectedValue) + { + var success = Helper.TryParse(s, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseUtf8TestData))] + public async Task TryParseTest(byte[] utf8Text, NumberStyles style, IFormatProvider? provider, bool expected, Int256 expectedValue) + { + var success = Helper.TryParse(utf8Text, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + #endregion + + #region INumber + [Test] + [MethodDataSource(typeof(DataSources), nameof(ClampTestData))] + public async Task ClampTest(Int256 value, Int256 min, Int256 max, Int256 expected) + { + if (min > max) + { + await Assert.That(() => Helper.Clamp(value, min, max)).Throws(); + } + else + { + var result = Helper.Clamp(value, min, max); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(CopySignTestData))] + public async Task CopySignTest(Int256 value, Int256 sign, Int256 expected) + { + var result = Helper.CopySign(value, sign); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxTestData))] + public async Task MaxTest(Int256 x, Int256 y, Int256 expected) + { + var result = Helper.Max(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxNumberTestData))] + public async Task MaxNumberTest(Int256 x, Int256 y, Int256 expected) + { + var result = Helper.MaxNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinTestData))] + public async Task MinTest(Int256 x, Int256 y, Int256 expected) + { + var result = Helper.Min(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinNumberTestData))] + public async Task MinNumberTest(Int256 x, Int256 y, Int256 expected) + { + var result = Helper.MinNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(SignTestData))] + public async Task SignTest(Int256 value, int expected) + { + var result = Helper.Sign(value); + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region IBinaryNumber + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPow2TestData))] + public async Task IsPow2Test(Int256 value, bool expected) + { + var result = Helper.IsPow2(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(Log2TestData))] + public async Task Log2Test(Int256 value, Int256 expected) + { + var result = Helper.Log2(value); + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region IBinaryInteger + [Test] + [MethodDataSource(typeof(DataSources), nameof(DivRemTestData))] + public async Task DivRemTest(Int256 left, Int256 right, (Int256, Int256) expected) + { + var result = Helper.DivRem(left, right); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(LeadingZeroCountTestData))] + public async Task LeadingZeroCountTest(Int256 value, Int256 expected) + { + var result = Helper.LeadingZeroCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(PopCountTestData))] + public async Task PopCountTest(Int256 value, Int256 expected) + { + var result = Helper.PopCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ReadBigEndianTestData))] + public async Task ReadBigEndianTest(byte[] source, bool isUnsigned, Int256 expected) + { + var result = Helper.ReadBigEndian(source, isUnsigned); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ReadLittleEndianTestData))] + public async Task ReadLittleEndianTest(byte[] source, bool isUnsigned, Int256 expected) + { + var result = Helper.ReadLittleEndian(source, isUnsigned); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(RotateLeftTestData))] + public async Task RotateLeftTest(Int256 value, int shiftAmount, Int256 expected) + { + var result = Helper.RotateLeft(value, shiftAmount); + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(RotateRightTestData))] + public async Task RotateRightTest(Int256 value, int shiftAmount, Int256 expected) + { + var result = Helper.RotateRight(value, shiftAmount); + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TrailingZeroCountTestData))] + public async Task TrailingZeroCountTest(Int256 value, Int256 expected) + { + var result = Helper.TrailingZeroCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(GetByteCountTestData))] + public async Task GetByteCountTest(Int256 value, int expected) + { + var result = Helper.GetByteCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(GetShortestBitLengthTestData))] + public async Task GetShortestBitLengthTest(Int256 value, int expected) + { + var result = Helper.GetShortestBitLength(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(WriteBigEndianTestData))] + public async Task WriteBigEndianTest(Int256 value, byte[] expectedDestination, int expected) + { + byte[] buffer = new byte[Int256.Size]; + var result = Helper.WriteBigEndian(value, buffer); + + using (Assert.Multiple()) + { + await Assert.That(result).IsEqualTo(expected); + await Assert.That(buffer.Length).IsEqualTo(expectedDestination.Length); + for (int i = 0; i < buffer.Length; i++) + { + await Assert.That(buffer[i]).IsEqualTo(expectedDestination[i]); + } + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(WriteLittleEndianTestData))] + public async Task WriteLittleEndianTest(Int256 value, byte[] expectedDestination, int expected) + { + byte[] buffer = new byte[Int256.Size]; + var result = Helper.WriteLittleEndian(value, buffer); + + using (Assert.Multiple()) + { + await Assert.That(result).IsEqualTo(expected); + await Assert.That(buffer.Length).IsEqualTo(expectedDestination.Length); + for (int i = 0; i < buffer.Length; i++) + { + await Assert.That(buffer[i]).IsEqualTo(expectedDestination[i]); + } + } + } + #endregion +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Numerics/Int512GenericMathTests.cs b/src/MissingValues.Tests/Numerics/Int512GenericMathTests.cs new file mode 100644 index 0000000..8d85a28 --- /dev/null +++ b/src/MissingValues.Tests/Numerics/Int512GenericMathTests.cs @@ -0,0 +1,664 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static MissingValues.Tests.Data.Int512DataSources; + +using DataSources = MissingValues.Tests.Data.Int512DataSources; + +namespace MissingValues.Tests.Numerics; + +public class Int512GenericMathTests +{ + #region Operators + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_AdditionTestData))] + public async Task op_AdditionTest(Int512 left, Int512 right, Int512 expected) + { + var result = left + right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedAdditionTestData))] + public async Task op_CheckedAdditionTest(Int512 left, Int512 right, Int512 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left + right)).Throws(); + } + else + { + var result = checked(left + right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_IncrementTestData))] + public async Task op_IncrementTest(Int512 value, Int512 expected) + { + var result = ++value; + + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedIncrementTestData))] + public async Task op_CheckedIncrementTest(Int512 value, Int512 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(++value)).Throws(); + } + else + { + var result = checked(++value); + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_SubtractionTestData))] + public async Task op_SubtractionTest(Int512 left, Int512 right, Int512 expected) + { + var result = left - right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedSubtractionTestData))] + public async Task op_CheckedSubtractionTest(Int512 left, Int512 right, Int512 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left - right)).Throws(); + } + else + { + var result = checked(left - right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_DecrementTestData))] + public async Task op_DecrementTest(Int512 value, Int512 expected) + { + var result = --value; + + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedDecrementTestData))] + public async Task op_CheckedDecrementTest(Int512 value, Int512 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(--value)).Throws(); + } + else + { + var result = checked(--value); + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_MultiplyTestData))] + public async Task op_MultiplyTest(Int512 left, Int512 right, Int512 expected) + { + var result = left * right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedMultiplyTestData))] + public async Task op_CheckedMultiplyTest(Int512 left, Int512 right, Int512 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left * right)).Throws(); + } + else + { + var result = checked(left * right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_DivisionTestData))] + public async Task op_DivisionTest(Int512 left, Int512 right, Int512 expected) + { + if (right == Int512.Zero) + { + await Assert.That(() => left / right).Throws(); + } + else + { + var result = left / right; + + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ModulusTestData))] + public async Task op_ModulusTest(Int512 left, Int512 right, Int512 expected) + { + if (right == Int512.Zero) + { + await Assert.That(() => left % right).Throws(); + } + else + { + var result = left % right; + + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_OnesComplementTestData))] + public async Task op_OnesComplementTest(Int512 value, Int512 expected) + { + var result = ~value; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseAndTestData))] + public async Task op_BitwiseAndTest(Int512 left, Int512 right, Int512 expected) + { + var result = left & right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseOrTestData))] + public async Task op_BitwiseOrTest(Int512 left, Int512 right, Int512 expected) + { + var result = left | right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseXorTestData))] + public async Task op_BitwiseXorTest(Int512 left, Int512 right, Int512 expected) + { + var result = left ^ right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ShiftLeftTestData))] + public async Task op_ShiftLeftTest(Int512 value, int shiftAmount, Int512 expected) + { + var result = value << shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ShiftRightTestData))] + public async Task op_ShiftRightTest(Int512 value, int shiftAmount, Int512 expected) + { + var result = value >> shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_UnsignedShiftRightTestData))] + public async Task op_UnsignedShiftRightTest(Int512 value, int shiftAmount, Int512 expected) + { + var result = value >>> shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_EqualityTestData))] + public async Task op_EqualityTest(Int512 left, Int512 right, bool expected) + { + var result = left == right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_InequalityTestData))] + public async Task op_InequalityTest(Int512 left, Int512 right, bool expected) + { + var result = left != right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_LessThanTestData))] + public async Task op_LessThanTest(Int512 left, Int512 right, bool expected) + { + var result = left < right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_LessThanOrEqualTestData))] + public async Task op_LessThanOrEqualTest(Int512 left, Int512 right, bool expected) + { + var result = left <= right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_GreaterThanTestData))] + public async Task op_GreaterThanTest(Int512 left, Int512 right, bool expected) + { + var result = left > right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_GreaterThanOrEqualTestData))] + public async Task op_GreaterThanOrEqualTest(Int512 left, Int512 right, bool expected) + { + var result = left >= right; + + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region INumberBase + [Test] + [MethodDataSource(typeof(DataSources), nameof(AbsTestData))] + public async Task AbsTest(Int512 value, Int512 expected) + { + Int512 result = Helper.Abs(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsCanonicalTestData))] + public async Task IsCanonicalTest(Int512 value, bool expected) + { + bool result = Helper.IsCanonical(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsComplexNumberTestData))] + public async Task IsComplexNumberTest(Int512 value, bool expected) + { + bool result = Helper.IsComplexNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsEvenIntegerTestData))] + public async Task IsEvenIntegerTest(Int512 value, bool expected) + { + bool result = Helper.IsEvenInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsFiniteTestData))] + public async Task IsFiniteTest(Int512 value, bool expected) + { + bool result = Helper.IsFinite(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsImaginaryNumberTestData))] + public async Task IsImaginaryNumberTest(Int512 value, bool expected) + { + bool result = Helper.IsImaginaryNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsInfinityTestData))] + public async Task IsInfinityTest(Int512 value, bool expected) + { + bool result = Helper.IsInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsIntegerTestData))] + public async Task IsIntegerTest(Int512 value, bool expected) + { + bool result = Helper.IsInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNaNTestData))] + public async Task IsNaNTest(Int512 value, bool expected) + { + bool result = Helper.IsNaN(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNegativeTestData))] + public async Task IsNegativeTest(Int512 value, bool expected) + { + bool result = Helper.IsNegative(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNegativeInfinityTestData))] + public async Task IsNegativeInfinityTest(Int512 value, bool expected) + { + bool result = Helper.IsNegativeInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNormalTestData))] + public async Task IsNormalTest(Int512 value, bool expected) + { + bool result = Helper.IsNormal(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsOddIntegerTestData))] + public async Task IsOddIntegerTest(Int512 value, bool expected) + { + bool result = Helper.IsOddInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPositiveTestData))] + public async Task IsPositiveTest(Int512 value, bool expected) + { + bool result = Helper.IsPositive(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPositiveInfinityTestData))] + public async Task IsPositiveInfinityTest(Int512 value, bool expected) + { + bool result = Helper.IsPositiveInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsRealNumberTestData))] + public async Task IsRealNumberTest(Int512 value, bool expected) + { + bool result = Helper.IsRealNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsSubnormalTestData))] + public async Task IsSubnormalTest(Int512 value, bool expected) + { + bool result = Helper.IsSubnormal(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsZeroTestData))] + public async Task IsZeroTest(Int512 value, bool expected) + { + bool result = Helper.IsZero(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxMagnitudeTestData))] + public async Task MaxMagnitudeTest(Int512 x, Int512 y, Int512 expected) + { + var result = Helper.MaxMagnitude(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxMagnitudeNumberTestData))] + public async Task MaxMagnitudeNumberTest(Int512 x, Int512 y, Int512 expected) + { + var result = Helper.MaxMagnitudeNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinMagnitudeTestData))] + public async Task MinMagnitudeTest(Int512 x, Int512 y, Int512 expected) + { + var result = Helper.MinMagnitude(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinMagnitudeNumberTestData))] + public async Task MinMagnitudeNumberTest(Int512 x, Int512 y, Int512 expected) + { + var result = Helper.MinMagnitudeNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MultiplyAddEstimateTestData))] + public async Task MultiplyAddEstimateTest(Int512 left, Int512 right, Int512 addend, Int512 expected) + { + var result = Helper.MultiplyAddEstimate(left, right, addend); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseTestData))] + public async Task ParseTest(string s, NumberStyles style, IFormatProvider? provider, Int512 expected) + { + var result = Helper.Parse(s, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseSpanTestData))] + public async Task ParseTest(char[] s, NumberStyles style, IFormatProvider? provider, Int512 expected) + { + var result = Helper.Parse(s, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseUtf8TestData))] + public async Task ParseTest(byte[] utf8Text, NumberStyles style, IFormatProvider? provider, Int512 expected) + { + var result = Helper.Parse(utf8Text, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseTestData))] + public async Task TryParseTest(string s, NumberStyles style, IFormatProvider? provider, bool expected, Int512 expectedValue) + { + var success = Helper.TryParse(s, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseSpanTestData))] + public async Task TryParseTest(char[] s, NumberStyles style, IFormatProvider? provider, bool expected, Int512 expectedValue) + { + var success = Helper.TryParse(s, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseUtf8TestData))] + public async Task TryParseTest(byte[] utf8Text, NumberStyles style, IFormatProvider? provider, bool expected, Int512 expectedValue) + { + var success = Helper.TryParse(utf8Text, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + #endregion + + #region INumber + [Test] + [MethodDataSource(typeof(DataSources), nameof(ClampTestData))] + public async Task ClampTest(Int512 value, Int512 min, Int512 max, Int512 expected) + { + if (min > max) + { + await Assert.That(() => Helper.Clamp(value, min, max)).Throws(); + } + else + { + var result = Helper.Clamp(value, min, max); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(CopySignTestData))] + public async Task CopySignTest(Int512 value, Int512 sign, Int512 expected) + { + var result = Helper.CopySign(value, sign); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxTestData))] + public async Task MaxTest(Int512 x, Int512 y, Int512 expected) + { + var result = Helper.Max(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxNumberTestData))] + public async Task MaxNumberTest(Int512 x, Int512 y, Int512 expected) + { + var result = Helper.MaxNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinTestData))] + public async Task MinTest(Int512 x, Int512 y, Int512 expected) + { + var result = Helper.Min(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinNumberTestData))] + public async Task MinNumberTest(Int512 x, Int512 y, Int512 expected) + { + var result = Helper.MinNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(SignTestData))] + public async Task SignTest(Int512 value, int expected) + { + var result = Helper.Sign(value); + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region IBinaryNumber + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPow2TestData))] + public async Task IsPow2Test(Int512 value, bool expected) + { + var result = Helper.IsPow2(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(Log2TestData))] + public async Task Log2Test(Int512 value, Int512 expected) + { + var result = Helper.Log2(value); + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region IBinaryInteger + [Test] + [MethodDataSource(typeof(DataSources), nameof(DivRemTestData))] + public async Task DivRemTest(Int512 left, Int512 right, (Int512, Int512) expected) + { + var result = Helper.DivRem(left, right); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(LeadingZeroCountTestData))] + public async Task LeadingZeroCountTest(Int512 value, Int512 expected) + { + var result = Helper.LeadingZeroCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(PopCountTestData))] + public async Task PopCountTest(Int512 value, Int512 expected) + { + var result = Helper.PopCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ReadBigEndianTestData))] + public async Task ReadBigEndianTest(byte[] source, bool isUnsigned, Int512 expected) + { + var result = Helper.ReadBigEndian(source, isUnsigned); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ReadLittleEndianTestData))] + public async Task ReadLittleEndianTest(byte[] source, bool isUnsigned, Int512 expected) + { + var result = Helper.ReadLittleEndian(source, isUnsigned); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(RotateLeftTestData))] + public async Task RotateLeftTest(Int512 value, int shiftAmount, Int512 expected) + { + var result = Helper.RotateLeft(value, shiftAmount); + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(RotateRightTestData))] + public async Task RotateRightTest(Int512 value, int shiftAmount, Int512 expected) + { + var result = Helper.RotateRight(value, shiftAmount); + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TrailingZeroCountTestData))] + public async Task TrailingZeroCountTest(Int512 value, Int512 expected) + { + var result = Helper.TrailingZeroCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(GetByteCountTestData))] + public async Task GetByteCountTest(Int512 value, int expected) + { + var result = Helper.GetByteCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(GetShortestBitLengthTestData))] + public async Task GetShortestBitLengthTest(Int512 value, int expected) + { + var result = Helper.GetShortestBitLength(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(WriteBigEndianTestData))] + public async Task WriteBigEndianTest(Int512 value, byte[] expectedDestination, int expected) + { + byte[] buffer = new byte[Int512.Size]; + var result = Helper.WriteBigEndian(value, buffer); + + using (Assert.Multiple()) + { + await Assert.That(result).IsEqualTo(expected); + await Assert.That(buffer.Length).IsEqualTo(expectedDestination.Length); + for (int i = 0; i < buffer.Length; i++) + { + await Assert.That(buffer[i]).IsEqualTo(expectedDestination[i]); + } + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(WriteLittleEndianTestData))] + public async Task WriteLittleEndianTest(Int512 value, byte[] expectedDestination, int expected) + { + byte[] buffer = new byte[Int512.Size]; + var result = Helper.WriteLittleEndian(value, buffer); + + using (Assert.Multiple()) + { + await Assert.That(result).IsEqualTo(expected); + await Assert.That(buffer.Length).IsEqualTo(expectedDestination.Length); + for (int i = 0; i < buffer.Length; i++) + { + await Assert.That(buffer[i]).IsEqualTo(expectedDestination[i]); + } + } + } + #endregion +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Numerics/OctoGenericMathTests.cs b/src/MissingValues.Tests/Numerics/OctoGenericMathTests.cs new file mode 100644 index 0000000..4895b42 --- /dev/null +++ b/src/MissingValues.Tests/Numerics/OctoGenericMathTests.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using static MissingValues.Tests.Data.OctoDataSources; + +using DataSources = MissingValues.Tests.Data.OctoDataSources; + +namespace MissingValues.Tests.Numerics; + +public class OctoGenericMathTests +{ +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Numerics/QuadGenericMathTests.cs b/src/MissingValues.Tests/Numerics/QuadGenericMathTests.cs new file mode 100644 index 0000000..c8146e1 --- /dev/null +++ b/src/MissingValues.Tests/Numerics/QuadGenericMathTests.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using static MissingValues.Tests.Data.QuadDataSources; + +using DataSources = MissingValues.Tests.Data.QuadDataSources; + +namespace MissingValues.Tests.Numerics; + +public class QuadGenericMathTests +{ +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Numerics/UInt256GenericMathTests.cs b/src/MissingValues.Tests/Numerics/UInt256GenericMathTests.cs new file mode 100644 index 0000000..355e51a --- /dev/null +++ b/src/MissingValues.Tests/Numerics/UInt256GenericMathTests.cs @@ -0,0 +1,665 @@ +using MissingValues.Tests.Data; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static MissingValues.Tests.Data.UInt256DataSources; + +using DataSources = MissingValues.Tests.Data.UInt256DataSources; + +namespace MissingValues.Tests.Numerics; + +public class UInt256GenericMathTests +{ + #region Operators + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_AdditionTestData))] + public async Task op_AdditionTest(UInt256 left, UInt256 right, UInt256 expected) + { + var result = left + right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedAdditionTestData))] + public async Task op_CheckedAdditionTest(UInt256 left, UInt256 right, UInt256 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left + right)).Throws(); + } + else + { + var result = checked(left + right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_IncrementTestData))] + public async Task op_IncrementTest(UInt256 value, UInt256 expected) + { + var result = ++value; + + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedIncrementTestData))] + public async Task op_CheckedIncrementTest(UInt256 value, UInt256 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(++value)).Throws(); + } + else + { + var result = checked(++value); + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_SubtractionTestData))] + public async Task op_SubtractionTest(UInt256 left, UInt256 right, UInt256 expected) + { + var result = left - right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedSubtractionTestData))] + public async Task op_CheckedSubtractionTest(UInt256 left, UInt256 right, UInt256 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left - right)).Throws(); + } + else + { + var result = checked(left - right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_DecrementTestData))] + public async Task op_DecrementTest(UInt256 value, UInt256 expected) + { + var result = --value; + + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedDecrementTestData))] + public async Task op_CheckedDecrementTest(UInt256 value, UInt256 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(--value)).Throws(); + } + else + { + var result = checked(--value); + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_MultiplyTestData))] + public async Task op_MultiplyTest(UInt256 left, UInt256 right, UInt256 expected) + { + var result = left * right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedMultiplyTestData))] + public async Task op_CheckedMultiplyTest(UInt256 left, UInt256 right, UInt256 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left * right)).Throws(); + } + else + { + var result = checked(left * right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_DivisionTestData))] + public async Task op_DivisionTest(UInt256 left, UInt256 right, UInt256 expected) + { + if (right == UInt256.Zero) + { + await Assert.That(() => left / right).Throws(); + } + else + { + var result = left / right; + + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ModulusTestData))] + public async Task op_ModulusTest(UInt256 left, UInt256 right, UInt256 expected) + { + if (right == UInt256.Zero) + { + await Assert.That(() => left % right).Throws(); + } + else + { + var result = left % right; + + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_OnesComplementTestData))] + public async Task op_OnesComplementTest(UInt256 value, UInt256 expected) + { + var result = ~value; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseAndTestData))] + public async Task op_BitwiseAndTest(UInt256 left, UInt256 right, UInt256 expected) + { + var result = left & right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseOrTestData))] + public async Task op_BitwiseOrTest(UInt256 left, UInt256 right, UInt256 expected) + { + var result = left | right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseXorTestData))] + public async Task op_BitwiseXorTest(UInt256 left, UInt256 right, UInt256 expected) + { + var result = left ^ right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ShiftLeftTestData))] + public async Task op_ShiftLeftTest(UInt256 value, int shiftAmount, UInt256 expected) + { + var result = value << shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ShiftRightTestData))] + public async Task op_ShiftRightTest(UInt256 value, int shiftAmount, UInt256 expected) + { + var result = value >> shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_UnsignedShiftRightTestData))] + public async Task op_UnsignedShiftRightTest(UInt256 value, int shiftAmount, UInt256 expected) + { + var result = value >>> shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_EqualityTestData))] + public async Task op_EqualityTest(UInt256 left, UInt256 right, bool expected) + { + var result = left == right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_InequalityTestData))] + public async Task op_InequalityTest(UInt256 left, UInt256 right, bool expected) + { + var result = left != right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_LessThanTestData))] + public async Task op_LessThanTest(UInt256 left, UInt256 right, bool expected) + { + var result = left < right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_LessThanOrEqualTestData))] + public async Task op_LessThanOrEqualTest(UInt256 left, UInt256 right, bool expected) + { + var result = left <= right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_GreaterThanTestData))] + public async Task op_GreaterThanTest(UInt256 left, UInt256 right, bool expected) + { + var result = left > right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_GreaterThanOrEqualTestData))] + public async Task op_GreaterThanOrEqualTest(UInt256 left, UInt256 right, bool expected) + { + var result = left >= right; + + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region INumberBase + [Test] + [MethodDataSource(typeof(DataSources), nameof(AbsTestData))] + public async Task AbsTest(UInt256 value, UInt256 expected) + { + UInt256 result = Helper.Abs(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsCanonicalTestData))] + public async Task IsCanonicalTest(UInt256 value, bool expected) + { + bool result = Helper.IsCanonical(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsComplexNumberTestData))] + public async Task IsComplexNumberTest(UInt256 value, bool expected) + { + bool result = Helper.IsComplexNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsEvenIntegerTestData))] + public async Task IsEvenIntegerTest(UInt256 value, bool expected) + { + bool result = Helper.IsEvenInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsFiniteTestData))] + public async Task IsFiniteTest(UInt256 value, bool expected) + { + bool result = Helper.IsFinite(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsImaginaryNumberTestData))] + public async Task IsImaginaryNumberTest(UInt256 value, bool expected) + { + bool result = Helper.IsImaginaryNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsInfinityTestData))] + public async Task IsInfinityTest(UInt256 value, bool expected) + { + bool result = Helper.IsInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsIntegerTestData))] + public async Task IsIntegerTest(UInt256 value, bool expected) + { + bool result = Helper.IsInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNaNTestData))] + public async Task IsNaNTest(UInt256 value, bool expected) + { + bool result = Helper.IsNaN(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNegativeTestData))] + public async Task IsNegativeTest(UInt256 value, bool expected) + { + bool result = Helper.IsNegative(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNegativeInfinityTestData))] + public async Task IsNegativeInfinityTest(UInt256 value, bool expected) + { + bool result = Helper.IsNegativeInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNormalTestData))] + public async Task IsNormalTest(UInt256 value, bool expected) + { + bool result = Helper.IsNormal(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsOddIntegerTestData))] + public async Task IsOddIntegerTest(UInt256 value, bool expected) + { + bool result = Helper.IsOddInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPositiveTestData))] + public async Task IsPositiveTest(UInt256 value, bool expected) + { + bool result = Helper.IsPositive(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPositiveInfinityTestData))] + public async Task IsPositiveInfinityTest(UInt256 value, bool expected) + { + bool result = Helper.IsPositiveInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsRealNumberTestData))] + public async Task IsRealNumberTest(UInt256 value, bool expected) + { + bool result = Helper.IsRealNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsSubnormalTestData))] + public async Task IsSubnormalTest(UInt256 value, bool expected) + { + bool result = Helper.IsSubnormal(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsZeroTestData))] + public async Task IsZeroTest(UInt256 value, bool expected) + { + bool result = Helper.IsZero(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxMagnitudeTestData))] + public async Task MaxMagnitudeTest(UInt256 x, UInt256 y, UInt256 expected) + { + var result = Helper.MaxMagnitude(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxMagnitudeNumberTestData))] + public async Task MaxMagnitudeNumberTest(UInt256 x, UInt256 y, UInt256 expected) + { + var result = Helper.MaxMagnitudeNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinMagnitudeTestData))] + public async Task MinMagnitudeTest(UInt256 x, UInt256 y, UInt256 expected) + { + var result = Helper.MinMagnitude(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinMagnitudeNumberTestData))] + public async Task MinMagnitudeNumberTest(UInt256 x, UInt256 y, UInt256 expected) + { + var result = Helper.MinMagnitudeNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MultiplyAddEstimateTestData))] + public async Task MultiplyAddEstimateTest(UInt256 left, UInt256 right, UInt256 addend, UInt256 expected) + { + var result = Helper.MultiplyAddEstimate(left, right, addend); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseTestData))] + public async Task ParseTest(string s, NumberStyles style, IFormatProvider? provider, UInt256 expected) + { + var result = Helper.Parse(s, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseSpanTestData))] + public async Task ParseTest(char[] s, NumberStyles style, IFormatProvider? provider, UInt256 expected) + { + var result = Helper.Parse(s, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseUtf8TestData))] + public async Task ParseTest(byte[] utf8Text, NumberStyles style, IFormatProvider? provider, UInt256 expected) + { + var result = Helper.Parse(utf8Text, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseTestData))] + public async Task TryParseTest(string s, NumberStyles style, IFormatProvider? provider, bool expected, UInt256 expectedValue) + { + var success = Helper.TryParse(s, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseSpanTestData))] + public async Task TryParseTest(char[] s, NumberStyles style, IFormatProvider? provider, bool expected, UInt256 expectedValue) + { + var success = Helper.TryParse(s, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseUtf8TestData))] + public async Task TryParseTest(byte[] utf8Text, NumberStyles style, IFormatProvider? provider, bool expected, UInt256 expectedValue) + { + var success = Helper.TryParse(utf8Text, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + #endregion + + #region INumber + [Test] + [MethodDataSource(typeof(DataSources), nameof(ClampTestData))] + public async Task ClampTest(UInt256 value, UInt256 min, UInt256 max, UInt256 expected) + { + if (min > max) + { + await Assert.That(() => Helper.Clamp(value, min, max)).Throws(); + } + else + { + var result = Helper.Clamp(value, min, max); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(CopySignTestData))] + public async Task CopySignTest(UInt256 value, UInt256 sign, UInt256 expected) + { + var result = Helper.CopySign(value, sign); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxTestData))] + public async Task MaxTest(UInt256 x, UInt256 y, UInt256 expected) + { + var result = Helper.Max(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxNumberTestData))] + public async Task MaxNumberTest(UInt256 x, UInt256 y, UInt256 expected) + { + var result = Helper.MaxNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinTestData))] + public async Task MinTest(UInt256 x, UInt256 y, UInt256 expected) + { + var result = Helper.Min(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinNumberTestData))] + public async Task MinNumberTest(UInt256 x, UInt256 y, UInt256 expected) + { + var result = Helper.MinNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(SignTestData))] + public async Task SignTest(UInt256 value, int expected) + { + var result = Helper.Sign(value); + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region IBinaryNumber + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPow2TestData))] + public async Task IsPow2Test(UInt256 value, bool expected) + { + var result = Helper.IsPow2(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(Log2TestData))] + public async Task Log2Test(UInt256 value, UInt256 expected) + { + var result = Helper.Log2(value); + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region IBinaryInteger + [Test] + [MethodDataSource(typeof(DataSources), nameof(DivRemTestData))] + public async Task DivRemTest(UInt256 left, UInt256 right, (UInt256, UInt256) expected) + { + var result = Helper.DivRem(left, right); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(LeadingZeroCountTestData))] + public async Task LeadingZeroCountTest(UInt256 value, UInt256 expected) + { + var result = Helper.LeadingZeroCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(PopCountTestData))] + public async Task PopCountTest(UInt256 value, UInt256 expected) + { + var result = Helper.PopCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ReadBigEndianTestData))] + public async Task ReadBigEndianTest(byte[] source, bool isUnsigned, UInt256 expected) + { + var result = Helper.ReadBigEndian(source, isUnsigned); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ReadLittleEndianTestData))] + public async Task ReadLittleEndianTest(byte[] source, bool isUnsigned, UInt256 expected) + { + var result = Helper.ReadLittleEndian(source, isUnsigned); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(RotateLeftTestData))] + public async Task RotateLeftTest(UInt256 value, int shiftAmount, UInt256 expected) + { + var result = Helper.RotateLeft(value, shiftAmount); + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(RotateRightTestData))] + public async Task RotateRightTest(UInt256 value, int shiftAmount, UInt256 expected) + { + var result = Helper.RotateRight(value, shiftAmount); + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TrailingZeroCountTestData))] + public async Task TrailingZeroCountTest(UInt256 value, UInt256 expected) + { + var result = Helper.TrailingZeroCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(GetByteCountTestData))] + public async Task GetByteCountTest(UInt256 value, int expected) + { + var result = Helper.GetByteCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(GetShortestBitLengthTestData))] + public async Task GetShortestBitLengthTest(UInt256 value, int expected) + { + var result = Helper.GetShortestBitLength(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(WriteBigEndianTestData))] + public async Task WriteBigEndianTest(UInt256 value, byte[] expectedDestination, int expected) + { + byte[] buffer = new byte[UInt256.Size]; + var result = Helper.WriteBigEndian(value, buffer); + + using (Assert.Multiple()) + { + await Assert.That(result).IsEqualTo(expected); + await Assert.That(buffer.Length).IsEqualTo(expectedDestination.Length); + for (int i = 0; i < buffer.Length; i++) + { + await Assert.That(buffer[i]).IsEqualTo(expectedDestination[i]); + } + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(WriteLittleEndianTestData))] + public async Task WriteLittleEndianTest(UInt256 value, byte[] expectedDestination, int expected) + { + byte[] buffer = new byte[UInt256.Size]; + var result = Helper.WriteLittleEndian(value, buffer); + + using (Assert.Multiple()) + { + await Assert.That(result).IsEqualTo(expected); + await Assert.That(buffer.Length).IsEqualTo(expectedDestination.Length); + for (int i = 0; i < buffer.Length; i++) + { + await Assert.That(buffer[i]).IsEqualTo(expectedDestination[i]); + } + } + } + #endregion +} diff --git a/src/MissingValues.Tests/Numerics/UInt512GenericMathTests.cs b/src/MissingValues.Tests/Numerics/UInt512GenericMathTests.cs new file mode 100644 index 0000000..4223cae --- /dev/null +++ b/src/MissingValues.Tests/Numerics/UInt512GenericMathTests.cs @@ -0,0 +1,664 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static MissingValues.Tests.Data.UInt512DataSources; + +using DataSources = MissingValues.Tests.Data.UInt512DataSources; + +namespace MissingValues.Tests.Numerics; + +public class UInt512GenericMathTests +{ + #region Operators + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_AdditionTestData))] + public async Task op_AdditionTest(UInt512 left, UInt512 right, UInt512 expected) + { + var result = left + right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedAdditionTestData))] + public async Task op_CheckedAdditionTest(UInt512 left, UInt512 right, UInt512 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left + right)).Throws(); + } + else + { + var result = checked(left + right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_IncrementTestData))] + public async Task op_IncrementTest(UInt512 value, UInt512 expected) + { + var result = ++value; + + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedIncrementTestData))] + public async Task op_CheckedIncrementTest(UInt512 value, UInt512 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(++value)).Throws(); + } + else + { + var result = checked(++value); + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_SubtractionTestData))] + public async Task op_SubtractionTest(UInt512 left, UInt512 right, UInt512 expected) + { + var result = left - right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedSubtractionTestData))] + public async Task op_CheckedSubtractionTest(UInt512 left, UInt512 right, UInt512 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left - right)).Throws(); + } + else + { + var result = checked(left - right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_DecrementTestData))] + public async Task op_DecrementTest(UInt512 value, UInt512 expected) + { + var result = --value; + + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedDecrementTestData))] + public async Task op_CheckedDecrementTest(UInt512 value, UInt512 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(--value)).Throws(); + } + else + { + var result = checked(--value); + await Assert.That(result).IsEqualTo(expected).And.IsEqualTo(value); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_MultiplyTestData))] + public async Task op_MultiplyTest(UInt512 left, UInt512 right, UInt512 expected) + { + var result = left * right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_CheckedMultiplyTestData))] + public async Task op_CheckedMultiplyTest(UInt512 left, UInt512 right, UInt512 expected, bool overflows) + { + if (overflows) + { + await Assert.That(() => checked(left * right)).Throws(); + } + else + { + var result = checked(left * right); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_DivisionTestData))] + public async Task op_DivisionTest(UInt512 left, UInt512 right, UInt512 expected) + { + if (right == UInt512.Zero) + { + await Assert.That(() => left / right).Throws(); + } + else + { + var result = left / right; + + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ModulusTestData))] + public async Task op_ModulusTest(UInt512 left, UInt512 right, UInt512 expected) + { + if (right == UInt512.Zero) + { + await Assert.That(() => left % right).Throws(); + } + else + { + var result = left % right; + + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_OnesComplementTestData))] + public async Task op_OnesComplementTest(UInt512 value, UInt512 expected) + { + var result = ~value; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseAndTestData))] + public async Task op_BitwiseAndTest(UInt512 left, UInt512 right, UInt512 expected) + { + var result = left & right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseOrTestData))] + public async Task op_BitwiseOrTest(UInt512 left, UInt512 right, UInt512 expected) + { + var result = left | right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_BitwiseXorTestData))] + public async Task op_BitwiseXorTest(UInt512 left, UInt512 right, UInt512 expected) + { + var result = left ^ right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ShiftLeftTestData))] + public async Task op_ShiftLeftTest(UInt512 value, int shiftAmount, UInt512 expected) + { + var result = value << shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_ShiftRightTestData))] + public async Task op_ShiftRightTest(UInt512 value, int shiftAmount, UInt512 expected) + { + var result = value >> shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_UnsignedShiftRightTestData))] + public async Task op_UnsignedShiftRightTest(UInt512 value, int shiftAmount, UInt512 expected) + { + var result = value >>> shiftAmount; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_EqualityTestData))] + public async Task op_EqualityTest(UInt512 left, UInt512 right, bool expected) + { + var result = left == right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_InequalityTestData))] + public async Task op_InequalityTest(UInt512 left, UInt512 right, bool expected) + { + var result = left != right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_LessThanTestData))] + public async Task op_LessThanTest(UInt512 left, UInt512 right, bool expected) + { + var result = left < right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_LessThanOrEqualTestData))] + public async Task op_LessThanOrEqualTest(UInt512 left, UInt512 right, bool expected) + { + var result = left <= right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_GreaterThanTestData))] + public async Task op_GreaterThanTest(UInt512 left, UInt512 right, bool expected) + { + var result = left > right; + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(op_GreaterThanOrEqualTestData))] + public async Task op_GreaterThanOrEqualTest(UInt512 left, UInt512 right, bool expected) + { + var result = left >= right; + + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region INumberBase + [Test] + [MethodDataSource(typeof(DataSources), nameof(AbsTestData))] + public async Task AbsTest(UInt512 value, UInt512 expected) + { + UInt512 result = Helper.Abs(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsCanonicalTestData))] + public async Task IsCanonicalTest(UInt512 value, bool expected) + { + bool result = Helper.IsCanonical(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsComplexNumberTestData))] + public async Task IsComplexNumberTest(UInt512 value, bool expected) + { + bool result = Helper.IsComplexNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsEvenIntegerTestData))] + public async Task IsEvenIntegerTest(UInt512 value, bool expected) + { + bool result = Helper.IsEvenInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsFiniteTestData))] + public async Task IsFiniteTest(UInt512 value, bool expected) + { + bool result = Helper.IsFinite(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsImaginaryNumberTestData))] + public async Task IsImaginaryNumberTest(UInt512 value, bool expected) + { + bool result = Helper.IsImaginaryNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsInfinityTestData))] + public async Task IsInfinityTest(UInt512 value, bool expected) + { + bool result = Helper.IsInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsIntegerTestData))] + public async Task IsIntegerTest(UInt512 value, bool expected) + { + bool result = Helper.IsInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNaNTestData))] + public async Task IsNaNTest(UInt512 value, bool expected) + { + bool result = Helper.IsNaN(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNegativeTestData))] + public async Task IsNegativeTest(UInt512 value, bool expected) + { + bool result = Helper.IsNegative(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNegativeInfinityTestData))] + public async Task IsNegativeInfinityTest(UInt512 value, bool expected) + { + bool result = Helper.IsNegativeInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsNormalTestData))] + public async Task IsNormalTest(UInt512 value, bool expected) + { + bool result = Helper.IsNormal(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsOddIntegerTestData))] + public async Task IsOddIntegerTest(UInt512 value, bool expected) + { + bool result = Helper.IsOddInteger(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPositiveTestData))] + public async Task IsPositiveTest(UInt512 value, bool expected) + { + bool result = Helper.IsPositive(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPositiveInfinityTestData))] + public async Task IsPositiveInfinityTest(UInt512 value, bool expected) + { + bool result = Helper.IsPositiveInfinity(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsRealNumberTestData))] + public async Task IsRealNumberTest(UInt512 value, bool expected) + { + bool result = Helper.IsRealNumber(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsSubnormalTestData))] + public async Task IsSubnormalTest(UInt512 value, bool expected) + { + bool result = Helper.IsSubnormal(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsZeroTestData))] + public async Task IsZeroTest(UInt512 value, bool expected) + { + bool result = Helper.IsZero(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxMagnitudeTestData))] + public async Task MaxMagnitudeTest(UInt512 x, UInt512 y, UInt512 expected) + { + var result = Helper.MaxMagnitude(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxMagnitudeNumberTestData))] + public async Task MaxMagnitudeNumberTest(UInt512 x, UInt512 y, UInt512 expected) + { + var result = Helper.MaxMagnitudeNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinMagnitudeTestData))] + public async Task MinMagnitudeTest(UInt512 x, UInt512 y, UInt512 expected) + { + var result = Helper.MinMagnitude(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinMagnitudeNumberTestData))] + public async Task MinMagnitudeNumberTest(UInt512 x, UInt512 y, UInt512 expected) + { + var result = Helper.MinMagnitudeNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MultiplyAddEstimateTestData))] + public async Task MultiplyAddEstimateTest(UInt512 left, UInt512 right, UInt512 addend, UInt512 expected) + { + var result = Helper.MultiplyAddEstimate(left, right, addend); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseTestData))] + public async Task ParseTest(string s, NumberStyles style, IFormatProvider? provider, UInt512 expected) + { + var result = Helper.Parse(s, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseSpanTestData))] + public async Task ParseTest(char[] s, NumberStyles style, IFormatProvider? provider, UInt512 expected) + { + var result = Helper.Parse(s, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ParseUtf8TestData))] + public async Task ParseTest(byte[] utf8Text, NumberStyles style, IFormatProvider? provider, UInt512 expected) + { + var result = Helper.Parse(utf8Text, style, provider); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseTestData))] + public async Task TryParseTest(string s, NumberStyles style, IFormatProvider? provider, bool expected, UInt512 expectedValue) + { + var success = Helper.TryParse(s, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseSpanTestData))] + public async Task TryParseTest(char[] s, NumberStyles style, IFormatProvider? provider, bool expected, UInt512 expectedValue) + { + var success = Helper.TryParse(s, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TryParseUtf8TestData))] + public async Task TryParseTest(byte[] utf8Text, NumberStyles style, IFormatProvider? provider, bool expected, UInt512 expectedValue) + { + var success = Helper.TryParse(utf8Text, style, provider, out var result); + using (Assert.Multiple()) + { + await Assert.That(success).IsEqualTo(expected); + await Assert.That(result).IsEqualTo(expectedValue); + } + } + #endregion + + #region INumber + [Test] + [MethodDataSource(typeof(DataSources), nameof(ClampTestData))] + public async Task ClampTest(UInt512 value, UInt512 min, UInt512 max, UInt512 expected) + { + if (min > max) + { + await Assert.That(() => Helper.Clamp(value, min, max)).Throws(); + } + else + { + var result = Helper.Clamp(value, min, max); + await Assert.That(result).IsEqualTo(expected); + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(CopySignTestData))] + public async Task CopySignTest(UInt512 value, UInt512 sign, UInt512 expected) + { + var result = Helper.CopySign(value, sign); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxTestData))] + public async Task MaxTest(UInt512 x, UInt512 y, UInt512 expected) + { + var result = Helper.Max(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MaxNumberTestData))] + public async Task MaxNumberTest(UInt512 x, UInt512 y, UInt512 expected) + { + var result = Helper.MaxNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinTestData))] + public async Task MinTest(UInt512 x, UInt512 y, UInt512 expected) + { + var result = Helper.Min(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(MinNumberTestData))] + public async Task MinNumberTest(UInt512 x, UInt512 y, UInt512 expected) + { + var result = Helper.MinNumber(x, y); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(SignTestData))] + public async Task SignTest(UInt512 value, int expected) + { + var result = Helper.Sign(value); + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region IBinaryNumber + [Test] + [MethodDataSource(typeof(DataSources), nameof(IsPow2TestData))] + public async Task IsPow2Test(UInt512 value, bool expected) + { + var result = Helper.IsPow2(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(Log2TestData))] + public async Task Log2Test(UInt512 value, UInt512 expected) + { + var result = Helper.Log2(value); + await Assert.That(result).IsEqualTo(expected); + } + #endregion + + #region IBinaryInteger + [Test] + [MethodDataSource(typeof(DataSources), nameof(DivRemTestData))] + public async Task DivRemTest(UInt512 left, UInt512 right, (UInt512, UInt512) expected) + { + var result = Helper.DivRem(left, right); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(LeadingZeroCountTestData))] + public async Task LeadingZeroCountTest(UInt512 value, UInt512 expected) + { + var result = Helper.LeadingZeroCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(PopCountTestData))] + public async Task PopCountTest(UInt512 value, UInt512 expected) + { + var result = Helper.PopCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ReadBigEndianTestData))] + public async Task ReadBigEndianTest(byte[] source, bool isUnsigned, UInt512 expected) + { + var result = Helper.ReadBigEndian(source, isUnsigned); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(ReadLittleEndianTestData))] + public async Task ReadLittleEndianTest(byte[] source, bool isUnsigned, UInt512 expected) + { + var result = Helper.ReadLittleEndian(source, isUnsigned); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(RotateLeftTestData))] + public async Task RotateLeftTest(UInt512 value, int shiftAmount, UInt512 expected) + { + var result = Helper.RotateLeft(value, shiftAmount); + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(RotateRightTestData))] + public async Task RotateRightTest(UInt512 value, int shiftAmount, UInt512 expected) + { + var result = Helper.RotateRight(value, shiftAmount); + + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(TrailingZeroCountTestData))] + public async Task TrailingZeroCountTest(UInt512 value, UInt512 expected) + { + var result = Helper.TrailingZeroCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(GetByteCountTestData))] + public async Task GetByteCountTest(UInt512 value, int expected) + { + var result = Helper.GetByteCount(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(GetShortestBitLengthTestData))] + public async Task GetShortestBitLengthTest(UInt512 value, int expected) + { + var result = Helper.GetShortestBitLength(value); + await Assert.That(result).IsEqualTo(expected); + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(WriteBigEndianTestData))] + public async Task WriteBigEndianTest(UInt512 value, byte[] expectedDestination, int expected) + { + byte[] buffer = new byte[UInt512.Size]; + var result = Helper.WriteBigEndian(value, buffer); + + using (Assert.Multiple()) + { + await Assert.That(result).IsEqualTo(expected); + await Assert.That(buffer.Length).IsEqualTo(expectedDestination.Length); + for (int i = 0; i < buffer.Length; i++) + { + await Assert.That(buffer[i]).IsEqualTo(expectedDestination[i]); + } + } + } + [Test] + [MethodDataSource(typeof(DataSources), nameof(WriteLittleEndianTestData))] + public async Task WriteLittleEndianTest(UInt512 value, byte[] expectedDestination, int expected) + { + byte[] buffer = new byte[UInt512.Size]; + var result = Helper.WriteLittleEndian(value, buffer); + + using (Assert.Multiple()) + { + await Assert.That(result).IsEqualTo(expected); + await Assert.That(buffer.Length).IsEqualTo(expectedDestination.Length); + for (int i = 0; i < buffer.Length; i++) + { + await Assert.That(buffer[i]).IsEqualTo(expectedDestination[i]); + } + } + } + #endregion +} \ No newline at end of file diff --git a/src/MissingValues.Tests/Usings.cs b/src/MissingValues.Tests/Usings.cs deleted file mode 100644 index 261e222..0000000 --- a/src/MissingValues.Tests/Usings.cs +++ /dev/null @@ -1,4 +0,0 @@ -global using Xunit; -global using FluentAssertions; -global using MissingValues; -global using MissingValues.Tests.Helpers; \ No newline at end of file diff --git a/src/MissingValues.Tests/Values.cs b/src/MissingValues.Tests/Values.cs new file mode 100644 index 0000000..956196d --- /dev/null +++ b/src/MissingValues.Tests/Values.cs @@ -0,0 +1,33 @@ +using System.Text; + +namespace MissingValues.Tests; + +public static class Values +{ + public static TFloat CreateFloat(params ReadOnlySpan bits) + { + if (typeof(TFloat) == typeof(Quad) && bits.Length == 2) + { + return (TFloat)(object)Quad.UInt128BitsToQuad(new UInt128(bits[0], bits[1])); + } + if (typeof(TFloat) == typeof(Octo) && bits.Length == 4) + { + return (TFloat)(object)Octo.UInt256BitsToOcto(new UInt256(bits[0], bits[1], bits[2], bits[3])); + } + + throw new InvalidOperationException($"{typeof(TFloat)} does not match the bits({bits.Length}): {StringifyBits(bits)}"); + + static string StringifyBits(ReadOnlySpan bits) + { + StringBuilder sb = new StringBuilder(); + + sb.Append($"0x{bits[0]:X16}"); + for (int i = 1; i < bits.Length; i++) + { + sb.Append($"_{bits[i]:X16}"); + } + + return sb.ToString(); + } + } +} \ No newline at end of file diff --git a/src/MissingValues.sln b/src/MissingValues.sln index 8edf16b..64e0f8d 100644 --- a/src/MissingValues.sln +++ b/src/MissingValues.sln @@ -5,10 +5,10 @@ VisualStudioVersion = 17.6.33723.286 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MissingValues", "MissingValues\MissingValues.csproj", "{2C6A1B89-E93F-4DC1-B5B2-9E062CEACF18}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MissingValues.Tests", "MissingValues.Tests\MissingValues.Tests.csproj", "{F370A95B-2718-4C84-BC74-1CA1EF7B2F3B}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MissingValues.Benchmarks", "MissingValues.Benchmarks\MissingValues.Benchmarks.csproj", "{FE774888-7645-4298-B3F3-751111ACAA36}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MissingValues.Tests", "MissingValues.Tests\MissingValues.Tests.csproj", "{EA33A386-2C6C-4541-93CB-4FC40905DE67}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -19,14 +19,14 @@ Global {2C6A1B89-E93F-4DC1-B5B2-9E062CEACF18}.Debug|Any CPU.Build.0 = Debug|Any CPU {2C6A1B89-E93F-4DC1-B5B2-9E062CEACF18}.Release|Any CPU.ActiveCfg = Release|Any CPU {2C6A1B89-E93F-4DC1-B5B2-9E062CEACF18}.Release|Any CPU.Build.0 = Release|Any CPU - {F370A95B-2718-4C84-BC74-1CA1EF7B2F3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F370A95B-2718-4C84-BC74-1CA1EF7B2F3B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F370A95B-2718-4C84-BC74-1CA1EF7B2F3B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F370A95B-2718-4C84-BC74-1CA1EF7B2F3B}.Release|Any CPU.Build.0 = Release|Any CPU {FE774888-7645-4298-B3F3-751111ACAA36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {FE774888-7645-4298-B3F3-751111ACAA36}.Debug|Any CPU.Build.0 = Debug|Any CPU {FE774888-7645-4298-B3F3-751111ACAA36}.Release|Any CPU.ActiveCfg = Release|Any CPU {FE774888-7645-4298-B3F3-751111ACAA36}.Release|Any CPU.Build.0 = Release|Any CPU + {EA33A386-2C6C-4541-93CB-4FC40905DE67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA33A386-2C6C-4541-93CB-4FC40905DE67}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA33A386-2C6C-4541-93CB-4FC40905DE67}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA33A386-2C6C-4541-93CB-4FC40905DE67}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE