From bea8d9564c4e63e204efa97bcd584fb0099c72b0 Mon Sep 17 00:00:00 2001 From: Prashanth Govindarajan Date: Mon, 21 Jun 2021 18:22:30 -0700 Subject: [PATCH] More Parse tests for double, single and Half (#50394) * Test ibm-fpgen locally for validation * sq --- THIRD-PARTY-NOTICES.TXT | 2 +- eng/Version.Details.xml | 4 ++ eng/Versions.props | 1 + .../tests/System.Runtime.Tests.csproj | 3 +- .../System.Runtime/tests/System/DoubleTests.cs | 65 ++++++++++++++++++++++ 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/THIRD-PARTY-NOTICES.TXT b/THIRD-PARTY-NOTICES.TXT index a877e8f..14c806c 100644 --- a/THIRD-PARTY-NOTICES.TXT +++ b/THIRD-PARTY-NOTICES.TXT @@ -680,7 +680,7 @@ worldwide. This software is distributed without any warranty. See . -License for fastmod (https://github.com/lemire/fastmod) +License for fastmod (https://github.com/lemire/fastmod) and ibm-fpgen (https://github.com/nigeltao/parse-number-fxx-test-data) -------------------------------------- Copyright 2018 Daniel Lemire diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 2485b69..f1ef354 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -214,5 +214,9 @@ https://github.com/dotnet/hotreload-utils 25b814e010cd4796cedfbcce72a274c26928f496 + + https://github.com/dotnet/runtime-assets + 8d7b898b96cbdb868cac343e938173105287ed9e + diff --git a/eng/Versions.props b/eng/Versions.props index 493ee88..b62b9b4 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -110,6 +110,7 @@ 4.5.0 6.0.0-preview.6.21314.1 + 6.0.0-beta.21314.1 6.0.0-beta.21307.1 6.0.0-beta.21307.1 6.0.0-beta.21307.1 diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj index 2a68cc1..2ca6739 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests.csproj @@ -1,4 +1,4 @@ - + true $(NoWarn),1718,SYSLIB0013 @@ -282,6 +282,7 @@ + diff --git a/src/libraries/System.Runtime/tests/System/DoubleTests.cs b/src/libraries/System.Runtime/tests/System/DoubleTests.cs index cfe3690..a80eb05 100644 --- a/src/libraries/System.Runtime/tests/System/DoubleTests.cs +++ b/src/libraries/System.Runtime/tests/System/DoubleTests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; +using System.IO; using Xunit; #pragma warning disable xUnit1025 // reporting duplicate test cases due to not distinguishing 0.0 from -0.0, NaN from -NaN @@ -346,6 +347,70 @@ namespace System.Tests } } + internal static string SplitPairs(string input) + { + string[] splitPairs = input.Split('-'); + string ret = ""; + foreach (var pair in splitPairs) + { + string reversedPair = Reverse(pair); + ret += reversedPair; + } + + return ret; + } + + internal static string Reverse(string s) + { + char[] charArray = s.ToCharArray(); + Array.Reverse(charArray); + return new string(charArray); + } + + [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + public static void ParsePatterns() + { + string path = Directory.GetCurrentDirectory(); + using (FileStream file = new FileStream(Path.Combine(path, "ibm-fpgen.txt"), FileMode.Open)) + { + using (var streamReader = new StreamReader(file)) + { + string line = streamReader.ReadLine(); + while (line != null) + { + string[] data = line.Split(' '); + string inputHalfBytes = data[0]; + string inputFloatBytes = data[1]; + string inputDoubleBytes = data[2]; + string correctValue = data[3]; + + double doubleValue = double.Parse(correctValue, NumberFormatInfo.InvariantInfo); + string doubleBytes = BitConverter.ToString(BitConverter.GetBytes(doubleValue)); + float floatValue = float.Parse(correctValue, NumberFormatInfo.InvariantInfo); + string floatBytes = BitConverter.ToString(BitConverter.GetBytes(floatValue)); + Half halfValue = Half.Parse(correctValue, NumberFormatInfo.InvariantInfo); + string halfBytes = BitConverter.ToString(BitConverter.GetBytes(halfValue)); + + doubleBytes = SplitPairs(doubleBytes); + floatBytes = SplitPairs(floatBytes); + halfBytes = SplitPairs(halfBytes); + + if (BitConverter.IsLittleEndian) + { + doubleBytes = Reverse(doubleBytes); + floatBytes = Reverse(floatBytes); + halfBytes = Reverse(halfBytes); + } + + Assert.Equal(doubleBytes, inputDoubleBytes); + Assert.Equal(floatBytes, inputFloatBytes); + Assert.Equal(halfBytes, inputHalfBytes); + line = streamReader.ReadLine(); + } + } + } + } + public static IEnumerable Parse_Invalid_TestData() { NumberStyles defaultStyle = NumberStyles.Float; -- 2.7.4