Skip to content

Commit

Permalink
[RISC-V] Test TotalOrderIeee754ComparerTests: Fix NFloat - NaN testca…
Browse files Browse the repository at this point in the history
…ses for RISC-V (#97340)

* Fix ieeeComparerTests NFloat NaN testcases for RISC-V

* Fix comment

* Specify test data for NaN test cases based on platform bitness

* Delete extra comment

* Fix CI failure

---------

Co-authored-by: d.paranichev <d.paranichev@partner.samsung.com>
  • Loading branch information
denis-paranichev and d.paranichev authored Feb 1, 2024
1 parent 52e1ad3 commit 541857c
Showing 1 changed file with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,41 @@ public void TotalOrderTestHalf(Half x, Half y, int result)
Assert.Equal(result, Math.Sign(comparer.Compare(x, y)));
}

public static IEnumerable<object[]> NFloatTestData
{
get
{
yield return new object[] { (NFloat)(0.0f), (NFloat)(0.0f), 0 };
yield return new object[] { (NFloat)(-0.0f), (NFloat)(-0.0f), 0 };
yield return new object[] { (NFloat)(0.0f), (NFloat)(-0.0f), 1 };
yield return new object[] { (NFloat)(-0.0f), (NFloat)(0.0f), -1 };
yield return new object[] { (NFloat)(0.0f), (NFloat)(1.0f), -1 };
yield return new object[] { NFloat.PositiveInfinity, (NFloat)(1.0f), 1 };
yield return new object[] { NFloat.NaN, NFloat.NaN, 0 };
if (Environment.Is64BitProcess)
{
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), (NFloat)(1.0d), 1 };
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), NFloat.PositiveInfinity, 1 };
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), NFloat.NegativeInfinity, -1 };
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), (NFloat)(-1.0d), -1 };
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), (NFloat)(BitConverter.UInt64BitsToDouble(0x7FF80000_00000000)), -1 };
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), (NFloat)(BitConverter.UInt64BitsToDouble(0x7FF80000_00000001)), -1 };
}
else
{
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0x7FC00000), (NFloat)(1.0f), 1 };
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0x7FC00000), NFloat.PositiveInfinity, 1 };
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0xFFC00000), NFloat.NegativeInfinity, -1 };
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0xFFC00000), (NFloat)(-1.0f), -1 };
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0xFFC00000), (NFloat)(BitConverter.UInt32BitsToSingle(0x7FC00000)), -1 };
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0x7FC00000), (NFloat)(BitConverter.UInt32BitsToSingle(0x7FC00001)), -1 };
}
}
}

[Theory]
[MemberData(nameof(SingleTestData))]
public void TotalOrderTestNFloat(float x, float y, int result)
[MemberData(nameof(NFloatTestData))]
public void TotalOrderTestNFloat(NFloat x, NFloat y, int result)
{
var comparer = new TotalOrderIeee754Comparer<NFloat>();
Assert.Equal(result, Math.Sign(comparer.Compare(x, y)));
Expand Down

0 comments on commit 541857c

Please sign in to comment.