Skip to content

Commit

Permalink
Microsoft.VisualBasic.Core.Tests fail tests with NaN conversion (#59321)
Browse files Browse the repository at this point in the history
* Microsoft.VisualBasic.Core.Tests fails tests with NaN conversion

* Update src/libraries/Microsoft.VisualBasic.Core/tests/SingleTypeTests.cs

Co-authored-by: Dan Moseley <danmose@microsoft.com>
  • Loading branch information
AlexRadch and danmoseley committed Sep 20, 2021
1 parent f807a6b commit fd5b60f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2639,15 +2639,15 @@ public static IEnumerable<object[]> ToString_IConvertible_TestData()
yield return new object[] { (float)1, "1" };
yield return new object[] { float.PositiveInfinity, float.PositiveInfinity.ToString() };
yield return new object[] { float.NegativeInfinity, float.NegativeInfinity.ToString() };
yield return new object[] { float.NaN, "NaN" };
yield return new object[] { float.NaN, float.NaN.ToString() };

// double.
yield return new object[] { (double)(-1), "-1" };
yield return new object[] { (double)0, "0" };
yield return new object[] { (double)1, "1" };
yield return new object[] { double.PositiveInfinity, double.PositiveInfinity.ToString() };
yield return new object[] { double.NegativeInfinity, double.NegativeInfinity.ToString() };
yield return new object[] { double.NaN, "NaN" };
yield return new object[] { double.NaN, double.NaN.ToString() };

// decimal.
yield return new object[] { decimal.MinValue, decimal.MinValue.ToString() };
Expand Down
29 changes: 22 additions & 7 deletions src/libraries/Microsoft.VisualBasic.Core/tests/SingleTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ public class SingleTypeTests
[Theory]
[MemberData(nameof(FromObject_TestData))]
[MemberData(nameof(FromString_TestData))]
public void FromObject(object value, float expected)
public void FromObject(object value, float expected, System.Globalization.NumberFormatInfo numberFormat = null)
{
Assert.Equal(expected, SingleType.FromObject(value));
Assert.Equal(expected, SingleType.FromObject(value, System.Globalization.NumberFormatInfo.InvariantInfo));
if (numberFormat is null)
{
Assert.Equal(expected, SingleType.FromObject(value));
Assert.Equal(expected, SingleType.FromObject(value, System.Globalization.NumberFormatInfo.InvariantInfo));
}
else
{
Assert.Equal(expected, SingleType.FromObject(value, numberFormat));
}
}

[Theory]
Expand Down Expand Up @@ -50,10 +57,17 @@ public void FromObject_ThrowsOverflowException(object value)

[Theory]
[MemberData(nameof(FromString_TestData))]
public void FromString(string value, float expected)
public void FromString(string value, float expected, System.Globalization.NumberFormatInfo numberFormat = null)
{
Assert.Equal(expected, SingleType.FromString(value));
Assert.Equal(expected, SingleType.FromString(value, System.Globalization.NumberFormatInfo.InvariantInfo));
if (numberFormat is null)
{
Assert.Equal(expected, SingleType.FromString(value));
Assert.Equal(expected, SingleType.FromString(value, System.Globalization.NumberFormatInfo.InvariantInfo));
}
else
{
Assert.Equal(expected, SingleType.FromString(value, numberFormat));
}
}

[Theory]
Expand Down Expand Up @@ -228,7 +242,8 @@ public static IEnumerable<object[]> FromString_TestData()
yield return new object[] { " &o5", (float)5 };
yield return new object[] { "&o0", (float)0 };
yield return new object[] { "18446744073709551616", 18446744073709551616.0f };
yield return new object[] { double.NaN.ToString(), float.NaN };
yield return new object[] { double.NaN.ToString(), float.NaN, System.Globalization.NumberFormatInfo.CurrentInfo };
yield return new object[] { "NaN", float.NaN, System.Globalization.NumberFormatInfo.InvariantInfo };
}

public static IEnumerable<object[]> FromString_Other_TestData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public static IEnumerable<object[]> FromSingle_TestData()
yield return new object[] { (float)1, "1" };
yield return new object[] { float.PositiveInfinity, float.PositiveInfinity.ToString() };
yield return new object[] { float.NegativeInfinity, float.NegativeInfinity.ToString() };
yield return new object[] { float.NaN, "NaN" };
yield return new object[] { float.NaN, float.NaN.ToString() };
}

public static IEnumerable<object[]> FromDouble_TestData()
Expand All @@ -256,7 +256,7 @@ public static IEnumerable<object[]> FromDouble_TestData()
yield return new object[] { (double)1, "1" };
yield return new object[] { double.PositiveInfinity, double.PositiveInfinity.ToString() };
yield return new object[] { double.NegativeInfinity, double.NegativeInfinity.ToString() };
yield return new object[] { double.NaN, "NaN" };
yield return new object[] { double.NaN, double.NaN.ToString() };
}

public static IEnumerable<object[]> FromDecimal_TestData()
Expand Down

0 comments on commit fd5b60f

Please sign in to comment.