* Consolidate .netcoreapp.cs files because System.Runtime.* projects is no longer cross-compiled
namespace System.Runtime.InteropServices.RuntimeInformationTests
{
- public partial class CheckPlatformTests
+ public class CheckPlatformTests
{
[Fact, PlatformSpecific(TestPlatforms.Linux)] // Tests RuntimeInformation OS platform
public void CheckLinux()
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("UNIX")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
}
[Fact, PlatformSpecific(TestPlatforms.NetBSD)] // Tests RuntimeInformation OS platform
public void CheckNetBSD()
{
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")));
+
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("netbsd")));
-
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("LINUX")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
}
[Fact, PlatformSpecific(TestPlatforms.OSX)] // Tests RuntimeInformation OS platform
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("netbsd")));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("osx")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("mac")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACOSX")));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
}
[Fact, PlatformSpecific(TestPlatforms.Windows)] // Tests RuntimeInformation OS platform
{
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("WINDOWS")));
+
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("netbsd")));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("windows")));
Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("Windows NT")));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
+ }
+
+ [Fact, PlatformSpecific(TestPlatforms.FreeBSD)] // Tests RuntimeInformation OS platform
+ public void CheckFreeBSD()
+ {
+ Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
+ Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
+
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("LINUX")));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("linux")));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("ubuntu")));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("UNIX")));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
+ Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
}
[Fact]
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Runtime.InteropServices;
-using Xunit;
-
-namespace System.Runtime.InteropServices.RuntimeInformationTests
-{
- public partial class CheckPlatformTests
- {
- [Fact, PlatformSpecific(TestPlatforms.FreeBSD)]
- public void CheckFreeBSD()
- {
- Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
- Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
-
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("LINUX")));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("linux")));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("ubuntu")));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("UNIX")));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
- }
-
- [Fact, PlatformSpecific(~TestPlatforms.FreeBSD)]
- public void CheckFreeBSDOnOtherPlatforms()
- {
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
- Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
- }
- }
-}
<ItemGroup>
<Compile Include="CheckArchitectureTests.cs" />
<Compile Include="CheckPlatformTests.cs" />
- <Compile Include="CheckPlatformTests.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
<Compile Include="DescriptionNameTests.cs" />
<Compile Include="$(CommonPath)Interop\Linux\cgroups\Interop.cgroups.cs">
<Link>Common\Interop\Linux\Interop.cgroups.cs</Link>
namespace System.Numerics.Tests
{
- public partial class ToStringTest
+ public class ToStringTest
{
private static bool s_noZeroOut = true;
}
}
- static partial void VerifyTryFormat(string test, string format, IFormatProvider provider, bool expectError, string expectedResult);
+ static void VerifyTryFormat(string test, string format, IFormatProvider provider, bool expectError, string expectedResult)
+ {
+ try
+ {
+ BigInteger bi = BigInteger.Parse(test, provider);
+
+ char[] destination = expectedResult != null ? new char[expectedResult.Length] : Array.Empty<char>();
+ Assert.True(bi.TryFormat(destination, out int charsWritten, format, provider));
+ Assert.False(expectError);
+
+ VerifyExpectedStringResult(expectedResult, new string(destination, 0, charsWritten));
+
+ if (expectedResult.Length > 0)
+ {
+ Assert.False(bi.TryFormat(new char[expectedResult.Length - 1], out charsWritten, format, provider));
+ Assert.Equal(0, charsWritten);
+ }
+ }
+ catch (FormatException)
+ {
+ Assert.True(expectError);
+ }
+ }
private static string GetDigitSequence(int min, int max, Random random)
{
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using Xunit;
-
-namespace System.Numerics.Tests
-{
- public partial class ToStringTest
- {
- static partial void VerifyTryFormat(string test, string format, IFormatProvider provider, bool expectError, string expectedResult)
- {
- try
- {
- BigInteger bi = BigInteger.Parse(test, provider);
-
- char[] destination = expectedResult != null ? new char[expectedResult.Length] : Array.Empty<char>();
- Assert.True(bi.TryFormat(destination, out int charsWritten, format, provider));
- Assert.False(expectError);
-
- VerifyExpectedStringResult(expectedResult, new string(destination, 0, charsWritten));
-
- if (expectedResult.Length > 0)
- {
- Assert.False(bi.TryFormat(new char[expectedResult.Length - 1], out charsWritten, format, provider));
- Assert.Equal(0, charsWritten);
- }
- }
- catch (FormatException)
- {
- Assert.True(expectError);
- }
- }
- }
-}
BigInteger bi2 = new BigInteger(bytes);
Assert.Equal(bi, bi2);
}
+
+ public static IEnumerable<object[]> FromIntTests_MemberData() =>
+ MatrixGenerator(FromIntTests_MemberDataSeed(), false);
+
+ [Theory]
+ [MemberData(nameof(FromIntTests_MemberData))]
+ public void ToByteArray_FromIntTests(int i, bool isUnsigned, bool isBigEndian, byte[] expectedBytes)
+ {
+ BigInteger bi = new BigInteger(i);
+
+ if (i < 0 && isUnsigned)
+ {
+ Assert.Throws<OverflowException>(() => bi.ToByteArray(isUnsigned, isBigEndian));
+ return;
+ }
+
+ byte[] bytes = bi.ToByteArray(isUnsigned, isBigEndian);
+ Assert.Equal(expectedBytes, bytes);
+ BigInteger bi2 = new BigInteger(bytes, isUnsigned, isBigEndian);
+ Assert.Equal(bi, bi2);
+ }
+
+ public static IEnumerable<object[]> FromLongTests_MemberData() =>
+ MatrixGenerator(FromLongTests_MemberDataSeed(), false);
+
+ [Theory]
+ [MemberData(nameof(FromLongTests_MemberData))]
+ public void ToByteArray_FromLongTests(long l, bool isUnsigned, bool isBigEndian, byte[] expectedBytes)
+ {
+ BigInteger bi = new BigInteger(l);
+
+ if (l < 0 && isUnsigned)
+ {
+ Assert.Throws<OverflowException>(() => bi.ToByteArray(isUnsigned, isBigEndian));
+ return;
+ }
+
+ byte[] bytes = bi.ToByteArray(isUnsigned, isBigEndian);
+ Assert.Equal(expectedBytes, bytes);
+ BigInteger bi2 = new BigInteger(bytes, isUnsigned, isBigEndian);
+ Assert.Equal(bi, bi2);
+ }
+
+ public static IEnumerable<object[]> FromStringTests_MemberData() =>
+ MatrixGenerator(FromStringTests_MemberDataSeed(), true);
+
+ [Theory]
+ [MemberData(nameof(FromStringTests_MemberData))]
+ public void ToByteArray_FromStringTests(string str, bool isUnsigned, bool isBigEndian, byte[] expectedBytes)
+ {
+ BigInteger bi = BigInteger.Parse(str);
+
+ if (str[0] == '-' && isUnsigned)
+ {
+ Assert.Throws<OverflowException>(() => bi.ToByteArray(isUnsigned, isBigEndian));
+ return;
+ }
+
+ byte[] bytes = bi.ToByteArray(isUnsigned, isBigEndian);
+ Assert.Equal(expectedBytes, bytes);
+ BigInteger bi2 = new BigInteger(bytes, isUnsigned, isBigEndian);
+ Assert.Equal(bi, bi2);
+ }
+
+ private static IEnumerable<object[]> MatrixGenerator(IEnumerable<object[]> seedData, bool dataIsBigEndian)
+ {
+ foreach (object[] seed in seedData)
+ {
+ object value = seed[0];
+ byte[] leSignedBytes = (byte[])seed[1];
+ byte[] beSignedBytes = (byte[])leSignedBytes.Clone();
+ Array.Reverse(beSignedBytes);
+
+ if (dataIsBigEndian)
+ {
+ var tmp = leSignedBytes;
+ leSignedBytes = beSignedBytes;
+ beSignedBytes = tmp;
+ }
+
+ // Signed Little Endian
+ yield return new object[] { value, false, false, leSignedBytes };
+
+ // Signed Big Endian
+ yield return new object[] { value, false, true, beSignedBytes };
+
+ byte[] leUnsignedBytes;
+ byte[] beUnsignedBytes;
+
+ if (beSignedBytes.Length > 1 &&
+ beSignedBytes[0] == 0)
+ {
+ leUnsignedBytes = new Span<byte>(leSignedBytes, 0, leSignedBytes.Length - 1).ToArray();
+ beUnsignedBytes = new Span<byte>(beSignedBytes, 1, beSignedBytes.Length - 1).ToArray();
+ }
+ else
+ {
+ // No padding was required, the unsigned data is the same as the signed data.
+ leUnsignedBytes = leSignedBytes;
+ beUnsignedBytes = beSignedBytes;
+ }
+
+ // Unsigned Big Endian
+ yield return new object[] { value, true, true, beUnsignedBytes };
+
+ // Unsigned Little Endian
+ yield return new object[] { value, true, false, leUnsignedBytes };
+ }
+ }
}
}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using Xunit;
-
-namespace System.Numerics.Tests
-{
- public partial class ExtractBytesMembersTests
- {
- public static IEnumerable<object[]> FromIntTests_MemberData() =>
- MatrixGenerator(FromIntTests_MemberDataSeed(), false);
-
- [Theory]
- [MemberData(nameof(FromIntTests_MemberData))]
- public void ToByteArray_FromIntTests(int i, bool isUnsigned, bool isBigEndian, byte[] expectedBytes)
- {
- BigInteger bi = new BigInteger(i);
-
- if (i < 0 && isUnsigned)
- {
- Assert.Throws<OverflowException>(() => bi.ToByteArray(isUnsigned, isBigEndian));
- return;
- }
-
- byte[] bytes = bi.ToByteArray(isUnsigned, isBigEndian);
- Assert.Equal(expectedBytes, bytes);
- BigInteger bi2 = new BigInteger(bytes, isUnsigned, isBigEndian);
- Assert.Equal(bi, bi2);
- }
-
- public static IEnumerable<object[]> FromLongTests_MemberData() =>
- MatrixGenerator(FromLongTests_MemberDataSeed(), false);
-
- [Theory]
- [MemberData(nameof(FromLongTests_MemberData))]
- public void ToByteArray_FromLongTests(long l, bool isUnsigned, bool isBigEndian, byte[] expectedBytes)
- {
- BigInteger bi = new BigInteger(l);
-
- if (l < 0 && isUnsigned)
- {
- Assert.Throws<OverflowException>(() => bi.ToByteArray(isUnsigned, isBigEndian));
- return;
- }
-
- byte[] bytes = bi.ToByteArray(isUnsigned, isBigEndian);
- Assert.Equal(expectedBytes, bytes);
- BigInteger bi2 = new BigInteger(bytes, isUnsigned, isBigEndian);
- Assert.Equal(bi, bi2);
- }
-
- public static IEnumerable<object[]> FromStringTests_MemberData() =>
- MatrixGenerator(FromStringTests_MemberDataSeed(), true);
-
- [Theory]
- [MemberData(nameof(FromStringTests_MemberData))]
- public void ToByteArray_FromStringTests(string str, bool isUnsigned, bool isBigEndian, byte[] expectedBytes)
- {
- BigInteger bi = BigInteger.Parse(str);
-
- if (str[0] == '-' && isUnsigned)
- {
- Assert.Throws<OverflowException>(() => bi.ToByteArray(isUnsigned, isBigEndian));
- return;
- }
-
- byte[] bytes = bi.ToByteArray(isUnsigned, isBigEndian);
- Assert.Equal(expectedBytes, bytes);
- BigInteger bi2 = new BigInteger(bytes, isUnsigned, isBigEndian);
- Assert.Equal(bi, bi2);
- }
-
- private static IEnumerable<object[]> MatrixGenerator(IEnumerable<object[]> seedData, bool dataIsBigEndian)
- {
- foreach (object[] seed in seedData)
- {
- object value = seed[0];
- byte[] leSignedBytes = (byte[])seed[1];
- byte[] beSignedBytes = (byte[])leSignedBytes.Clone();
- Array.Reverse(beSignedBytes);
-
- if (dataIsBigEndian)
- {
- var tmp = leSignedBytes;
- leSignedBytes = beSignedBytes;
- beSignedBytes = tmp;
- }
-
- // Signed Little Endian
- yield return new object[] { value, false, false, leSignedBytes };
-
- // Signed Big Endian
- yield return new object[] { value, false, true, beSignedBytes };
-
- byte[] leUnsignedBytes;
- byte[] beUnsignedBytes;
-
- if (beSignedBytes.Length > 1 &&
- beSignedBytes[0] == 0)
- {
- leUnsignedBytes = new Span<byte>(leSignedBytes, 0, leSignedBytes.Length - 1).ToArray();
- beUnsignedBytes = new Span<byte>(beSignedBytes, 1, beSignedBytes.Length - 1).ToArray();
- }
- else
- {
- // No padding was required, the unsigned data is the same as the signed data.
- leUnsignedBytes = leSignedBytes;
- beUnsignedBytes = beSignedBytes;
- }
-
- // Unsigned Big Endian
- yield return new object[] { value, true, true, beUnsignedBytes };
-
- // Unsigned Little Endian
- yield return new object[] { value, true, false, leUnsignedBytes };
- }
- }
- }
-}
namespace System.Numerics.Tests
{
- public partial class BigIntegerConstructorTest
+ public class BigIntegerConstructorTest
{
private static int s_samples = 10;
private static Random s_random = new Random(100);
VerifyCtorByteArray(value);
}
- static partial void VerifyCtorByteSpan(byte[] value);
+
+ static void VerifyCtorByteSpan(byte[] value) =>
+ Assert.Equal(new BigInteger(value), new BigInteger(new ReadOnlySpan<byte>(value)));
private static void VerifyCtorByteArray(byte[] value)
{
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using Xunit;
-
-namespace System.Numerics.Tests
-{
- public partial class BigIntegerConstructorTest
- {
- static partial void VerifyCtorByteSpan(byte[] value) =>
- Assert.Equal(new BigInteger(value), new BigInteger(new ReadOnlySpan<byte>(value)));
- }
-}
namespace System.Numerics.Tests
{
- public partial class parseTest
+ public class parseTest
{
private static readonly int s_samples = 10;
private static readonly Random s_random = new Random(100);
}
}
+ [Theory]
+ [InlineData("123456789", 0, 9, "123456789")]
+ [InlineData("123456789", 0, 1, "1")]
+ [InlineData("123456789", 1, 3, "234")]
+ [InlineData("123456789", 8, 1, "9")]
+ [InlineData("123456789abc", 8, 1, "9")]
+ [InlineData("1\03456789", 0, 1, "1")]
+ [InlineData("1\03456789", 0, 2, "1")]
+ [InlineData("123456789\0", 0, 10, "123456789")]
+ public void Parse_Subspan_Success(string input, int offset, int length, string expected)
+ {
+ Eval(BigInteger.Parse(input.AsSpan(offset, length)), expected);
+ Assert.True(BigInteger.TryParse(input.AsSpan(offset, length), out BigInteger test));
+ Eval(test, expected);
+ }
+
+ [Fact]
+ public void Parse_EmptySubspan_Fails()
+ {
+ Assert.False(BigInteger.TryParse("12345".AsSpan(0, 0), out BigInteger result));
+ Assert.Equal(0, result);
+ }
+
private static void RunFormatProviderParseStrings()
{
NumberFormatInfo nfi = new NumberFormatInfo();
VerifyParseToString(num1, ns, failureNotExpected, Fix(num1.Trim(), ((ns & NumberStyles.AllowHexSpecifier) != 0), failureNotExpected));
}
- static partial void VerifyParseSpanToString(string num1, NumberStyles ns, bool failureNotExpected, string expected);
+ static void VerifyParseSpanToString(string num1, NumberStyles ns, bool failureNotExpected, string expected)
+ {
+ if (failureNotExpected)
+ {
+ Eval(BigInteger.Parse(num1.AsSpan(), ns), expected);
+
+ Assert.True(BigInteger.TryParse(num1.AsSpan(), ns, provider: null, out BigInteger test));
+ Eval(test, expected);
+
+ if (ns == NumberStyles.Integer)
+ {
+ Assert.True(BigInteger.TryParse(num1.AsSpan(), out test));
+ Eval(test, expected);
+ }
+ }
+ else
+ {
+ Assert.Throws<FormatException>(() => { BigInteger.Parse(num1.AsSpan(), ns); });
+
+ Assert.False(BigInteger.TryParse(num1.AsSpan(), ns, provider: null, out BigInteger test));
+
+ if (ns == NumberStyles.Integer)
+ {
+ Assert.False(BigInteger.TryParse(num1.AsSpan(), out test));
+ }
+ }
+ }
private static void VerifyParseToString(string num1, NumberStyles ns, bool failureNotExpected, string expected)
{
}
}
- static partial void VerifySimpleFormatParseSpan(string num1, NumberFormatInfo nfi, BigInteger expected, bool failureExpected);
+ static void VerifySimpleFormatParseSpan(string num1, NumberFormatInfo nfi, BigInteger expected, bool failureExpected)
+ {
+ if (!failureExpected)
+ {
+ Assert.Equal(expected, BigInteger.Parse(num1.AsSpan(), provider: nfi));
+ Assert.True(BigInteger.TryParse(num1.AsSpan(), NumberStyles.Any, nfi, out BigInteger test));
+ Assert.Equal(expected, test);
+ }
+ else
+ {
+ Assert.Throws<FormatException>(() => { BigInteger.Parse(num1.AsSpan(), provider: nfi); });
+ Assert.False(BigInteger.TryParse(num1.AsSpan(), NumberStyles.Any, nfi, out BigInteger test), string.Format("Expected TryParse to fail on {0}", num1));
+ }
+ }
private static void VerifySimpleFormatParse(string num1, NumberFormatInfo nfi, BigInteger expected, bool failureExpected = false)
{
}
}
- static partial void VerifyFormatParseSpan(string s, NumberStyles ns, NumberFormatInfo nfi, BigInteger expected, bool failureExpected);
+ static void VerifyFormatParseSpan(string num1, NumberStyles ns, NumberFormatInfo nfi, BigInteger expected, bool failureExpected)
+ {
+ if (!failureExpected)
+ {
+ Assert.Equal(expected, BigInteger.Parse(num1.AsSpan(), ns, nfi));
+ Assert.True(BigInteger.TryParse(num1.AsSpan(), NumberStyles.Any, nfi, out BigInteger test));
+ Assert.Equal(expected, test);
+ }
+ else
+ {
+ Assert.Throws<FormatException>(() => { BigInteger.Parse(num1.AsSpan(), ns, nfi); });
+ Assert.False(BigInteger.TryParse(num1.AsSpan(), ns, nfi, out BigInteger test), string.Format("Expected TryParse to fail on {0}", num1));
+ }
+ }
private static void VerifyFormatParse(string num1, NumberStyles ns, NumberFormatInfo nfi, BigInteger expected, bool failureExpected = false)
{
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Globalization;
-using Xunit;
-
-namespace System.Numerics.Tests
-{
- public partial class parseTest
- {
- [Theory]
- [InlineData("123456789", 0, 9, "123456789")]
- [InlineData("123456789", 0, 1, "1")]
- [InlineData("123456789", 1, 3, "234")]
- [InlineData("123456789", 8, 1, "9")]
- [InlineData("123456789abc", 8, 1, "9")]
- [InlineData("1\03456789", 0, 1, "1")]
- [InlineData("1\03456789", 0, 2, "1")]
- [InlineData("123456789\0", 0, 10, "123456789")]
- public void Parse_Subspan_Success(string input, int offset, int length, string expected)
- {
- Eval(BigInteger.Parse(input.AsSpan(offset, length)), expected);
- Assert.True(BigInteger.TryParse(input.AsSpan(offset, length), out BigInteger test));
- Eval(test, expected);
- }
-
- [Fact]
- public void Parse_EmptySubspan_Fails()
- {
- Assert.False(BigInteger.TryParse("12345".AsSpan(0, 0), out BigInteger result));
- Assert.Equal(0, result);
- }
-
- static partial void VerifyParseSpanToString(string num1, NumberStyles ns, bool failureNotExpected, string expected)
- {
- if (failureNotExpected)
- {
- Eval(BigInteger.Parse(num1.AsSpan(), ns), expected);
-
- Assert.True(BigInteger.TryParse(num1.AsSpan(), ns, provider: null, out BigInteger test));
- Eval(test, expected);
-
- if (ns == NumberStyles.Integer)
- {
- Assert.True(BigInteger.TryParse(num1.AsSpan(), out test));
- Eval(test, expected);
- }
- }
- else
- {
- Assert.Throws<FormatException>(() => { BigInteger.Parse(num1.AsSpan(), ns); });
-
- Assert.False(BigInteger.TryParse(num1.AsSpan(), ns, provider: null, out BigInteger test));
-
- if (ns == NumberStyles.Integer)
- {
- Assert.False(BigInteger.TryParse(num1.AsSpan(), out test));
- }
- }
- }
-
- static partial void VerifySimpleFormatParseSpan(string num1, NumberFormatInfo nfi, BigInteger expected, bool failureExpected)
- {
- if (!failureExpected)
- {
- Assert.Equal(expected, BigInteger.Parse(num1.AsSpan(), provider: nfi));
- Assert.True(BigInteger.TryParse(num1.AsSpan(), NumberStyles.Any, nfi, out BigInteger test));
- Assert.Equal(expected, test);
- }
- else
- {
- Assert.Throws<FormatException>(() => { BigInteger.Parse(num1.AsSpan(), provider: nfi); });
- Assert.False(BigInteger.TryParse(num1.AsSpan(), NumberStyles.Any, nfi, out BigInteger test), string.Format("Expected TryParse to fail on {0}", num1));
- }
- }
-
- static partial void VerifyFormatParseSpan(string num1, NumberStyles ns, NumberFormatInfo nfi, BigInteger expected, bool failureExpected)
- {
- if (!failureExpected)
- {
- Assert.Equal(expected, BigInteger.Parse(num1.AsSpan(), ns, nfi));
- Assert.True(BigInteger.TryParse(num1.AsSpan(), NumberStyles.Any, nfi, out BigInteger test));
- Assert.Equal(expected, test);
- }
- else
- {
- Assert.Throws<FormatException>(() => { BigInteger.Parse(num1.AsSpan(), ns, nfi); });
- Assert.False(BigInteger.TryParse(num1.AsSpan(), ns, nfi, out BigInteger test), string.Format("Expected TryParse to fail on {0}", num1));
- }
- }
- }
-}
namespace System.Numerics.Tests
{
- public partial class ComplexTests
+ public class ComplexTests
{
private static Random s_random = new Random(-55);
private static bool Is64Bit => IntPtr.Size == 8;
VerifyRealImaginaryProperties(complex, (double)value, 0);
}
+ [Fact]
+ public static void NaN()
+ {
+ Assert.True(Complex.IsNaN(new Complex(double.NaN, double.NaN)));
+ Assert.True(Complex.IsNaN(new Complex(1, double.NaN)));
+ Assert.True(Complex.IsNaN(new Complex(double.NaN, 1)));
+ Assert.True(Complex.IsNaN(Complex.NaN));
+
+ Assert.False(Complex.IsNaN(new Complex(double.PositiveInfinity, double.NaN)));
+ Assert.False(Complex.IsNaN(new Complex(double.NaN, double.PositiveInfinity)));
+ Assert.False(Complex.IsNaN(Complex.Infinity));
+
+ VerifyRealImaginaryProperties(Complex.NaN, double.NaN, double.NaN);
+ VerifyMagnitudePhaseProperties(Complex.NaN, double.NaN, double.NaN);
+ }
+
+ [Fact]
+ public static void Infinity()
+ {
+ Assert.True(Complex.IsInfinity(new Complex(double.PositiveInfinity, double.PositiveInfinity)));
+ Assert.True(Complex.IsInfinity(new Complex(1, double.PositiveInfinity)));
+ Assert.True(Complex.IsInfinity(new Complex(double.PositiveInfinity, 1)));
+
+ Assert.True(Complex.IsInfinity(new Complex(double.NegativeInfinity, double.NegativeInfinity)));
+ Assert.True(Complex.IsInfinity(new Complex(1, double.NegativeInfinity)));
+ Assert.True(Complex.IsInfinity(new Complex(double.NegativeInfinity, 1)));
+
+ Assert.True(Complex.IsInfinity(Complex.Infinity));
+ Assert.False(Complex.IsInfinity(Complex.NaN));
+
+
+ VerifyRealImaginaryProperties(Complex.Infinity, double.PositiveInfinity, double.PositiveInfinity);
+ VerifyMagnitudePhaseProperties(Complex.Infinity, double.PositiveInfinity, Math.PI / 4);
+ }
+
+ [Fact]
+ public static void Finite()
+ {
+ Assert.False(Complex.IsFinite(new Complex(double.NaN, double.NaN)));
+ Assert.False(Complex.IsFinite(new Complex(1, double.NaN)));
+ Assert.False(Complex.IsFinite(new Complex(double.NaN, 1)));
+
+ Assert.False(Complex.IsFinite(new Complex(double.PositiveInfinity, double.PositiveInfinity)));
+ Assert.False(Complex.IsFinite(new Complex(1, double.PositiveInfinity)));
+ Assert.False(Complex.IsFinite(new Complex(double.PositiveInfinity, 1)));
+
+ Assert.False(Complex.IsFinite(new Complex(double.NegativeInfinity, double.NegativeInfinity)));
+ Assert.False(Complex.IsFinite(new Complex(1, double.NegativeInfinity)));
+ Assert.False(Complex.IsFinite(new Complex(double.NegativeInfinity, 1)));
+
+ Assert.False(Complex.IsFinite(Complex.Infinity));
+ Assert.False(Complex.IsFinite(Complex.NaN));
+ Assert.True(Complex.IsFinite(Complex.ImaginaryOne));
+ }
+
private static double SmallRandomPositiveDouble()
{
return RandomPositiveValue(1);
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Collections.Generic;
-using System.Globalization;
-using System.Runtime.CompilerServices;
-
-using Xunit;
-
-namespace System.Numerics.Tests
-{
- public partial class ComplexTests
- {
- [Fact]
- public static void NaN()
- {
- Assert.True(Complex.IsNaN(new Complex(double.NaN, double.NaN)));
- Assert.True(Complex.IsNaN(new Complex(1, double.NaN)));
- Assert.True(Complex.IsNaN(new Complex(double.NaN, 1)));
- Assert.True(Complex.IsNaN(Complex.NaN));
-
- Assert.False(Complex.IsNaN(new Complex(double.PositiveInfinity, double.NaN)));
- Assert.False(Complex.IsNaN(new Complex(double.NaN, double.PositiveInfinity)));
- Assert.False(Complex.IsNaN(Complex.Infinity));
-
- VerifyRealImaginaryProperties(Complex.NaN, double.NaN, double.NaN);
- VerifyMagnitudePhaseProperties(Complex.NaN, double.NaN, double.NaN);
- }
-
- [Fact]
- public static void Infinity()
- {
- Assert.True(Complex.IsInfinity(new Complex(double.PositiveInfinity, double.PositiveInfinity)));
- Assert.True(Complex.IsInfinity(new Complex(1, double.PositiveInfinity)));
- Assert.True(Complex.IsInfinity(new Complex(double.PositiveInfinity, 1)));
-
- Assert.True(Complex.IsInfinity(new Complex(double.NegativeInfinity, double.NegativeInfinity)));
- Assert.True(Complex.IsInfinity(new Complex(1, double.NegativeInfinity)));
- Assert.True(Complex.IsInfinity(new Complex(double.NegativeInfinity, 1)));
-
- Assert.True(Complex.IsInfinity(Complex.Infinity));
- Assert.False(Complex.IsInfinity(Complex.NaN));
-
-
- VerifyRealImaginaryProperties(Complex.Infinity, double.PositiveInfinity, double.PositiveInfinity);
- VerifyMagnitudePhaseProperties(Complex.Infinity, double.PositiveInfinity, Math.PI / 4);
- }
-
- [Fact]
- public static void Finite()
- {
- Assert.False(Complex.IsFinite(new Complex(double.NaN, double.NaN)));
- Assert.False(Complex.IsFinite(new Complex(1, double.NaN)));
- Assert.False(Complex.IsFinite(new Complex(double.NaN, 1)));
-
- Assert.False(Complex.IsFinite(new Complex(double.PositiveInfinity, double.PositiveInfinity)));
- Assert.False(Complex.IsFinite(new Complex(1, double.PositiveInfinity)));
- Assert.False(Complex.IsFinite(new Complex(double.PositiveInfinity, 1)));
-
- Assert.False(Complex.IsFinite(new Complex(double.NegativeInfinity, double.NegativeInfinity)));
- Assert.False(Complex.IsFinite(new Complex(1, double.NegativeInfinity)));
- Assert.False(Complex.IsFinite(new Complex(double.NegativeInfinity, 1)));
-
- Assert.False(Complex.IsFinite(Complex.Infinity));
- Assert.False(Complex.IsFinite(Complex.NaN));
- Assert.True(Complex.IsFinite(Complex.ImaginaryOne));
- }
- }
-}
<ItemGroup>
<Compile Include="BigInteger\absolutevalue.cs" />
<Compile Include="BigInteger\BigIntegerToStringTests.cs" />
- <Compile Include="BigInteger\BigIntegerToStringTests.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
<Compile Include="BigInteger\BigInteger.AddTests.cs" />
<Compile Include="BigInteger\BigInteger.SubtractTests.cs" />
<Compile Include="BigInteger\BigIntTools.cs" />
<Compile Include="BigInteger\cast_to.cs" />
<Compile Include="BigInteger\Comparison.cs" />
<Compile Include="BigInteger\ctor.cs" />
- <Compile Include="BigInteger\ctor.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
<Compile Include="BigInteger\divide.cs" />
<Compile Include="BigInteger\divrem.cs" />
<Compile Include="BigInteger\Driver.cs" />
<Compile Include="BigInteger\op_rightshift.cs" />
<Compile Include="BigInteger\op_xor.cs" />
<Compile Include="BigInteger\parse.cs" />
- <Compile Include="BigInteger\parse.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
<Compile Include="BigInteger\pow.cs" />
<Compile Include="BigInteger\properties.cs" />
<Compile Include="BigInteger\remainder.cs" />
<Compile Include="BigInteger\sign.cs" />
<Compile Include="BigInteger\stackcalculator.cs" />
<Compile Include="BigInteger\ToByteArray.cs" />
- <Compile Include="BigInteger\ToByteArray.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
- <Compile Include="BigInteger\TryWriteBytes.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
+ <Compile Include="BigInteger\TryWriteBytes.cs" />
<Compile Include="ComplexTests.cs" />
- <Compile Include="ComplexTests.netcoreapp.cs" Condition="'$(TargetsNetCoreApp)' == 'true'" />
</ItemGroup>
</Project>
\ No newline at end of file
<Compile Include="$(CommonPath)..\tests\System\RealFormatterTestsBase.netcoreapp.cs" Link="System\RealFormatterTestsBase.netcoreapp.cs" />
<Compile Include="System\RealFormatterTests.cs" />
<Compile Include="$(CommonPath)..\tests\System\RealParserTestsBase.netcoreapp.cs" Link="System\RealParserTestsBase.netcoreapp.cs" />
- <Compile Include="System\RealParserTests.netcoreapp.cs" />
+ <Compile Include="System\RealParserTests.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsNetCoreApp)' != 'true'">
<Compile Include="System\StringSplitExtensions.cs" />