From 752a8d2b9bcf73f4a8ae9cd70a5133be344d0ecf Mon Sep 17 00:00:00 2001 From: Roman Marusyk Date: Thu, 19 Dec 2019 03:16:39 +0200 Subject: [PATCH] Consolidate .netcoreapp.cs test files in System.Runtime.* (#999) * Consolidate .netcoreapp.cs files because System.Runtime.* projects is no longer cross-compiled --- .../tests/CheckPlatformTests.cs | 32 +++++- .../tests/CheckPlatformTests.netcoreapp.cs | 36 ------ ...InteropServices.RuntimeInformation.Tests.csproj | 1 - .../tests/BigInteger/BigIntegerToStringTests.cs | 26 ++++- .../BigIntegerToStringTests.netcoreapp.cs | 35 ------ .../tests/BigInteger/ToByteArray.cs | 109 +++++++++++++++++++ .../tests/BigInteger/ToByteArray.netcoreapp.cs | 121 --------------------- .../tests/BigInteger/ctor.cs | 6 +- .../tests/BigInteger/ctor.netcoreapp.cs | 14 --- .../tests/BigInteger/parse.cs | 83 +++++++++++++- .../tests/BigInteger/parse.netcoreapp.cs | 93 ---------------- .../System.Runtime.Numerics/tests/ComplexTests.cs | 57 +++++++++- .../tests/ComplexTests.netcoreapp.cs | 70 ------------ .../tests/System.Runtime.Numerics.Tests.csproj | 7 +- .../tests/System.Runtime.Tests.csproj | 2 +- ...arserTests.netcoreapp.cs => RealParserTests.cs} | 0 16 files changed, 301 insertions(+), 391 deletions(-) delete mode 100644 src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.netcoreapp.cs delete mode 100644 src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.netcoreapp.cs delete mode 100644 src/libraries/System.Runtime.Numerics/tests/BigInteger/ToByteArray.netcoreapp.cs delete mode 100644 src/libraries/System.Runtime.Numerics/tests/BigInteger/ctor.netcoreapp.cs delete mode 100644 src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.netcoreapp.cs delete mode 100644 src/libraries/System.Runtime.Numerics/tests/ComplexTests.netcoreapp.cs rename src/libraries/System.Runtime/tests/System/{RealParserTests.netcoreapp.cs => RealParserTests.cs} (100%) diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs index 877fe39..e94b489 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs @@ -7,7 +7,7 @@ using Xunit; namespace System.Runtime.InteropServices.RuntimeInformationTests { - public partial class CheckPlatformTests + public class CheckPlatformTests { [Fact, PlatformSpecific(TestPlatforms.Linux)] // Tests RuntimeInformation OS platform public void CheckLinux() @@ -25,15 +25,16 @@ namespace System.Runtime.InteropServices.RuntimeInformationTests 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"))); @@ -43,6 +44,7 @@ namespace System.Runtime.InteropServices.RuntimeInformationTests 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 @@ -55,12 +57,13 @@ namespace System.Runtime.InteropServices.RuntimeInformationTests 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 @@ -68,14 +71,33 @@ namespace System.Runtime.InteropServices.RuntimeInformationTests { 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] diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.netcoreapp.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.netcoreapp.cs deleted file mode 100644 index a780153..0000000 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.netcoreapp.cs +++ /dev/null @@ -1,36 +0,0 @@ -// 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"))); - } - } -} diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj index 21a0333..fe095f3 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj @@ -5,7 +5,6 @@ - Common\Interop\Linux\Interop.cgroups.cs diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs index 2e99d07..3255438 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs @@ -11,7 +11,7 @@ using Xunit; namespace System.Numerics.Tests { - public partial class ToStringTest + public class ToStringTest { private static bool s_noZeroOut = true; @@ -1460,7 +1460,29 @@ namespace System.Numerics.Tests } } - 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(); + 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) { diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.netcoreapp.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.netcoreapp.cs deleted file mode 100644 index 449f0e3..0000000 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.netcoreapp.cs +++ /dev/null @@ -1,35 +0,0 @@ -// 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(); - 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); - } - } - } -} diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/ToByteArray.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/ToByteArray.cs index 0a9c20f..34c784d 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/ToByteArray.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/ToByteArray.cs @@ -124,5 +124,114 @@ namespace System.Numerics.Tests BigInteger bi2 = new BigInteger(bytes); Assert.Equal(bi, bi2); } + + public static IEnumerable 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(() => 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 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(() => 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 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(() => 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 MatrixGenerator(IEnumerable 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(leSignedBytes, 0, leSignedBytes.Length - 1).ToArray(); + beUnsignedBytes = new Span(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 }; + } + } } } diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/ToByteArray.netcoreapp.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/ToByteArray.netcoreapp.cs deleted file mode 100644 index 80a354c..0000000 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/ToByteArray.netcoreapp.cs +++ /dev/null @@ -1,121 +0,0 @@ -// 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 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(() => 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 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(() => 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 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(() => 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 MatrixGenerator(IEnumerable 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(leSignedBytes, 0, leSignedBytes.Length - 1).ToArray(); - beUnsignedBytes = new Span(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 }; - } - } - } -} diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/ctor.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/ctor.cs index f9b5512..b28fcfd 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/ctor.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/ctor.cs @@ -6,7 +6,7 @@ using Xunit; 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); @@ -957,7 +957,9 @@ namespace System.Numerics.Tests VerifyCtorByteArray(value); } - static partial void VerifyCtorByteSpan(byte[] value); + + static void VerifyCtorByteSpan(byte[] value) => + Assert.Equal(new BigInteger(value), new BigInteger(new ReadOnlySpan(value))); private static void VerifyCtorByteArray(byte[] value) { diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/ctor.netcoreapp.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/ctor.netcoreapp.cs deleted file mode 100644 index d11723b..0000000 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/ctor.netcoreapp.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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(value))); - } -} diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs index 8b184c2..dfdec5c 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs @@ -12,7 +12,7 @@ using Xunit; 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); @@ -83,6 +83,29 @@ namespace System.Numerics.Tests } } + [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(); @@ -397,7 +420,33 @@ namespace System.Numerics.Tests 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(() => { 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) { @@ -428,7 +477,20 @@ namespace System.Numerics.Tests } } - 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(() => { 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) { @@ -452,7 +514,20 @@ namespace System.Numerics.Tests } } - 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(() => { 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) { diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.netcoreapp.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.netcoreapp.cs deleted file mode 100644 index 1231cd9..0000000 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.netcoreapp.cs +++ /dev/null @@ -1,93 +0,0 @@ -// 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(() => { 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(() => { 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(() => { 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)); - } - } - } -} diff --git a/src/libraries/System.Runtime.Numerics/tests/ComplexTests.cs b/src/libraries/System.Runtime.Numerics/tests/ComplexTests.cs index 2903b37..0cfd48f 100644 --- a/src/libraries/System.Runtime.Numerics/tests/ComplexTests.cs +++ b/src/libraries/System.Runtime.Numerics/tests/ComplexTests.cs @@ -10,7 +10,7 @@ using Xunit; 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; @@ -1909,6 +1909,61 @@ namespace System.Numerics.Tests 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); diff --git a/src/libraries/System.Runtime.Numerics/tests/ComplexTests.netcoreapp.cs b/src/libraries/System.Runtime.Numerics/tests/ComplexTests.netcoreapp.cs deleted file mode 100644 index 75068c8..0000000 --- a/src/libraries/System.Runtime.Numerics/tests/ComplexTests.netcoreapp.cs +++ /dev/null @@ -1,70 +0,0 @@ -// 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)); - } - } -} diff --git a/src/libraries/System.Runtime.Numerics/tests/System.Runtime.Numerics.Tests.csproj b/src/libraries/System.Runtime.Numerics/tests/System.Runtime.Numerics.Tests.csproj index bdc7136..6db2419 100644 --- a/src/libraries/System.Runtime.Numerics/tests/System.Runtime.Numerics.Tests.csproj +++ b/src/libraries/System.Runtime.Numerics/tests/System.Runtime.Numerics.Tests.csproj @@ -6,7 +6,6 @@ - @@ -14,7 +13,6 @@ - @@ -43,16 +41,13 @@ - - - + - \ No newline at end of file diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj index 0996f12..a31bad6 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj @@ -259,7 +259,7 @@ - + diff --git a/src/libraries/System.Runtime/tests/System/RealParserTests.netcoreapp.cs b/src/libraries/System.Runtime/tests/System/RealParserTests.cs similarity index 100% rename from src/libraries/System.Runtime/tests/System/RealParserTests.netcoreapp.cs rename to src/libraries/System.Runtime/tests/System/RealParserTests.cs -- 2.7.4