1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-08 03:27:04 +09:00

More Parse tests for double, single and Half (#50394)

* Test ibm-fpgen locally for validation

* sq
This commit is contained in:
Prashanth Govindarajan 2021-06-21 18:22:30 -07:00 committed by GitHub
parent 2a43c07bb8
commit bea8d9564c
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 2 deletions

View file

@ -680,7 +680,7 @@ worldwide. This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>.
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

View file

@ -214,5 +214,9 @@
<Uri>https://github.com/dotnet/hotreload-utils</Uri>
<Sha>25b814e010cd4796cedfbcce72a274c26928f496</Sha>
</Dependency>
<Dependency Name="System.Runtime.Numerics.TestData" Version="6.0.0-beta.21314.1">
<Uri>https://github.com/dotnet/runtime-assets
<Sha>8d7b898b96cbdb868cac343e938173105287ed9e</Sha>
</Dependency>
</ToolsetDependencies>
</Dependencies>

View file

@ -110,6 +110,7 @@
<SystemValueTupleVersion>4.5.0</SystemValueTupleVersion>
<runtimenativeSystemIOPortsVersion>6.0.0-preview.6.21314.1</runtimenativeSystemIOPortsVersion>
<!-- Runtime-Assets dependencies -->
<SystemRuntimeNumericsTestDataVersion>6.0.0-beta.21314.1</SystemRuntimeNumericsTestDataVersion>
<SystemComponentModelTypeConverterTestDataVersion>6.0.0-beta.21307.1</SystemComponentModelTypeConverterTestDataVersion>
<SystemDrawingCommonTestDataVersion>6.0.0-beta.21307.1</SystemDrawingCommonTestDataVersion>
<SystemIOCompressionTestDataVersion>6.0.0-beta.21307.1</SystemIOCompressionTestDataVersion>

View file

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn),1718,SYSLIB0013</NoWarn>
@ -282,6 +282,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Moq" Version="$(MoqVersion)" />
<PackageReference Include="System.Runtime.Numerics.TestData" Version="$(SystemRuntimeNumericsTestDataVersion)" GeneratePathProperty="true"/>
<ProjectReference Include="TestLoadAssembly\TestLoadAssembly.csproj" />
<ProjectReference Include="TestCollectibleAssembly\TestCollectibleAssembly.csproj" />
<ProjectReference Include="TestModule\System.Reflection.TestModule.ilproj" />

View file

@ -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<object[]> Parse_Invalid_TestData()
{
NumberStyles defaultStyle = NumberStyles.Float;