[RISC-V] Test TotalOrderIeee754ComparerTests: Fix NFloat - NaN testcases for RISC...
authorDenis Paranichev <48580269+denis-paranichev@users.noreply.github.com>
Thu, 1 Feb 2024 17:13:33 +0000 (20:13 +0300)
committerGleb Balykov/Advanced System SW Lab /SRR/Staff Engineer/Samsung Electronics <g.balykov@samsung.com>
Thu, 22 Feb 2024 11:52:55 +0000 (14:52 +0300)
* 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>
src/libraries/System.Runtime/tests/System/Numerics/TotalOrderIeee754ComparerTests.cs

index 019aabc..9ec0d21 100644 (file)
@@ -94,9 +94,41 @@ namespace System.Runtime.Tests
             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)));