From: Tanner Gooding Date: Tue, 18 Sep 2018 17:36:59 +0000 (-0700) Subject: Some cleanup of DoubleTests and SingleTests to make literals more readable X-Git-Tag: submit/tizen/20210909.063632~11031^2~3502 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1abc6c6e28a8af9692d528a47cbe8613911097b9;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Some cleanup of DoubleTests and SingleTests to make literals more readable Commit migrated from https://github.com/dotnet/corefx/commit/b95ccd913c63174083284efdc9a5b6e71ba04196 --- diff --git a/src/libraries/System.Runtime/tests/System/DoubleTests.cs b/src/libraries/System.Runtime/tests/System/DoubleTests.cs index 458fadc..618e14a 100644 --- a/src/libraries/System.Runtime/tests/System/DoubleTests.cs +++ b/src/libraries/System.Runtime/tests/System/DoubleTests.cs @@ -11,26 +11,28 @@ namespace System.Tests { public partial class DoubleTests : RemoteExecutorTestBase { + // NOTE: Consider duplicating any tests added here in SingleTests.cs + [Theory] [InlineData("a")] - [InlineData((float)234)] + [InlineData(234.0f)] public void CompareTo_ObjectNotDouble_ThrowsArgumentException(object value) { AssertExtensions.Throws(null, () => ((double)123).CompareTo(value)); } [Theory] - [InlineData((double)234, (double)234, 0)] - [InlineData((double)234, double.MinValue, 1)] - [InlineData((double)234, (double)-123, 1)] - [InlineData((double)234, (double)0, 1)] - [InlineData((double)234, (double)123, 1)] - [InlineData((double)234, (double)456, -1)] - [InlineData((double)234, double.MaxValue, -1)] - [InlineData((double)234, double.NaN, 1)] + [InlineData(234.0, 234.0, 0)] + [InlineData(234.0, double.MinValue, 1)] + [InlineData(234.0, -123.0, 1)] + [InlineData(234.0, 0.0, 1)] + [InlineData(234.0, 123.0, 1)] + [InlineData(234.0, 456.0, -1)] + [InlineData(234.0, double.MaxValue, -1)] + [InlineData(234.0, double.NaN, 1)] [InlineData(double.NaN, double.NaN, 0)] - [InlineData(double.NaN, (double)0, -1)] - [InlineData((double)234, null, 1)] + [InlineData(double.NaN, 0.0, -1)] + [InlineData(234.0, null, 1)] public void CompareTo_Other_ReturnsExpected(double d1, object value, int expected) { if (value is double d2) @@ -95,13 +97,13 @@ namespace System.Tests } [Theory] - [InlineData((double)789, (double)789, true)] - [InlineData((double)789, (double)-789, false)] - [InlineData((double)789, (double)0, false)] + [InlineData(789.0, 789.0, true)] + [InlineData(789.0, -789.0, false)] + [InlineData(789.0, 0.0, false)] [InlineData(double.NaN, double.NaN, true)] [InlineData(double.NaN, -double.NaN, true)] - [InlineData((double)789, (float)789, false)] - [InlineData((double)789, "789", false)] + [InlineData(789.0, 789.0f, false)] + [InlineData(789.0, "789", false)] [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "The fix was made in coreclr that is not in netfx. See https://github.com/dotnet/coreclr/issues/6237")] public static void Equals(double d1, object value, bool expected) { @@ -135,11 +137,11 @@ namespace System.Tests [InlineData(double.MinValue, false)] // Min Negative Normal [InlineData(-2.2250738585072014E-308, false)] // Max Negative Normal [InlineData(-2.2250738585072009E-308, false)] // Min Negative Subnormal - [InlineData(-4.94065645841247E-324, false)] // Max Negative Subnormal + [InlineData(-double.Epsilon, false)] // Max Negative Subnormal (Negative Epsilon) [InlineData(-0.0, false)] // Negative Zero [InlineData(double.NaN, false)] // NaN [InlineData(0.0, false)] // Positive Zero - [InlineData(4.94065645841247E-324, false)] // Min Positive Subnormal + [InlineData(double.Epsilon, false)] // Min Positive Subnormal (Positive Epsilon) [InlineData(2.2250738585072009E-308, false)] // Max Positive Subnormal [InlineData(2.2250738585072014E-308, false)] // Min Positive Normal [InlineData(double.MaxValue, false)] // Max Positive Normal @@ -154,11 +156,11 @@ namespace System.Tests [InlineData(double.MinValue, false)] // Min Negative Normal [InlineData(-2.2250738585072014E-308, false)] // Max Negative Normal [InlineData(-2.2250738585072009E-308, false)] // Min Negative Subnormal - [InlineData(-4.94065645841247E-324, false)] // Max Negative Subnormal + [InlineData(-double.Epsilon, false)] // Max Negative Subnormal (Negative Epsilon) [InlineData(-0.0, false)] // Negative Zero [InlineData(double.NaN, true)] // NaN [InlineData(0.0, false)] // Positive Zero - [InlineData(4.94065645841247E-324, false)] // Min Positive Subnormal + [InlineData(double.Epsilon, false)] // Min Positive Subnormal (Positive Epsilon) [InlineData(2.2250738585072009E-308, false)] // Max Positive Subnormal [InlineData(2.2250738585072014E-308, false)] // Min Positive Normal [InlineData(double.MaxValue, false)] // Max Positive Normal @@ -173,11 +175,11 @@ namespace System.Tests [InlineData(double.MinValue, false)] // Min Negative Normal [InlineData(-2.2250738585072014E-308, false)] // Max Negative Normal [InlineData(-2.2250738585072009E-308, false)] // Min Negative Subnormal - [InlineData(-4.94065645841247E-324, false)] // Max Negative Subnormal + [InlineData(-double.Epsilon, false)] // Max Negative Subnormal (Negative Epsilon) [InlineData(-0.0, false)] // Negative Zero [InlineData(double.NaN, false)] // NaN [InlineData(0.0, false)] // Positive Zero - [InlineData(4.94065645841247E-324, false)] // Min Positive Subnormal + [InlineData(double.Epsilon, false)] // Min Positive Subnormal (Positive Epsilon) [InlineData(2.2250738585072009E-308, false)] // Max Positive Subnormal [InlineData(2.2250738585072014E-308, false)] // Min Positive Normal [InlineData(double.MaxValue, false)] // Max Positive Normal @@ -192,11 +194,11 @@ namespace System.Tests [InlineData(double.MinValue, false)] // Min Negative Normal [InlineData(-2.2250738585072014E-308, false)] // Max Negative Normal [InlineData(-2.2250738585072009E-308, false)] // Min Negative Subnormal - [InlineData(-4.94065645841247E-324, false)] // Max Negative Subnormal + [InlineData(-double.Epsilon, false)] // Max Negative Subnormal (Negative Epsilon) [InlineData(-0.0, false)] // Negative Zero [InlineData(double.NaN, false)] // NaN [InlineData(0.0, false)] // Positive Zero - [InlineData(4.94065645841247E-324, false)] // Min Positive Subnormal + [InlineData(double.Epsilon, false)] // Min Positive Subnormal (Positive Epsilon) [InlineData(2.2250738585072009E-308, false)] // Max Positive Subnormal [InlineData(2.2250738585072014E-308, false)] // Min Positive Normal [InlineData(double.MaxValue, false)] // Max Positive Normal @@ -249,24 +251,24 @@ namespace System.Tests NumberFormatInfo invariantFormat = NumberFormatInfo.InvariantInfo; - yield return new object[] { "-123", defaultStyle, null, (double)-123 }; - yield return new object[] { "0", defaultStyle, null, (double)0 }; - yield return new object[] { "123", defaultStyle, null, (double)123 }; - yield return new object[] { " 123 ", defaultStyle, null, (double)123 }; + yield return new object[] { "-123", defaultStyle, null, -123.0 }; + yield return new object[] { "0", defaultStyle, null, 0.0 }; + yield return new object[] { "123", defaultStyle, null, 123.0 }; + yield return new object[] { " 123 ", defaultStyle, null, 123.0 }; yield return new object[] { (567.89).ToString(), defaultStyle, null, 567.89 }; yield return new object[] { (-567.89).ToString(), defaultStyle, null, -567.89 }; yield return new object[] { "1E23", defaultStyle, null, 1E23 }; yield return new object[] { (123.1).ToString(), NumberStyles.AllowDecimalPoint, null, 123.1 }; - yield return new object[] { 1000.ToString("N0"), NumberStyles.AllowThousands, null, (double)1000 }; + yield return new object[] { (1000.0).ToString("N0"), NumberStyles.AllowThousands, null, 1000.0 }; - yield return new object[] { "123", NumberStyles.Any, emptyFormat, (double)123 }; + yield return new object[] { "123", NumberStyles.Any, emptyFormat, 123.0 }; yield return new object[] { (123.567).ToString(), NumberStyles.Any, emptyFormat, 123.567 }; - yield return new object[] { "123", NumberStyles.Float, emptyFormat, (double)123 }; - yield return new object[] { "$1,000", NumberStyles.Currency, dollarSignCommaSeparatorFormat, (double)1000 }; - yield return new object[] { "$1000", NumberStyles.Currency, dollarSignCommaSeparatorFormat, (double)1000 }; + yield return new object[] { "123", NumberStyles.Float, emptyFormat, 123.0 }; + yield return new object[] { "$1,000", NumberStyles.Currency, dollarSignCommaSeparatorFormat, 1000.0 }; + yield return new object[] { "$1000", NumberStyles.Currency, dollarSignCommaSeparatorFormat, 1000.0 }; yield return new object[] { "123.123", NumberStyles.Float, decimalSeparatorFormat, 123.123 }; - yield return new object[] { "(123)", NumberStyles.AllowParentheses, decimalSeparatorFormat, -123 }; + yield return new object[] { "(123)", NumberStyles.AllowParentheses, decimalSeparatorFormat, -123.0 }; yield return new object[] { "NaN", NumberStyles.Any, invariantFormat, double.NaN }; yield return new object[] { "Infinity", NumberStyles.Any, invariantFormat, double.PositiveInfinity }; @@ -327,7 +329,7 @@ namespace System.Tests yield return new object[] { "ab", defaultStyle, null, typeof(FormatException) }; // Hex value yield return new object[] { "(123)", defaultStyle, null, typeof(FormatException) }; // Parentheses - yield return new object[] { 100.ToString("C0"), defaultStyle, null, typeof(FormatException) }; // Currency + yield return new object[] { (100.0).ToString("C0"), defaultStyle, null, typeof(FormatException) }; // Currency yield return new object[] { (123.456).ToString(), NumberStyles.Integer, null, typeof(FormatException) }; // Decimal yield return new object[] { " " + (123.456).ToString(), NumberStyles.None, null, typeof(FormatException) }; // Leading space @@ -384,21 +386,21 @@ namespace System.Tests public static IEnumerable ToString_TestData() { yield return new object[] { double.MinValue, "G", null, "-1.79769313486232E+308" }; - yield return new object[] { (double)-4567, "G", null, "-4567" }; + yield return new object[] { -4567.0, "G", null, "-4567" }; yield return new object[] { -4567.89101, "G", null, "-4567.89101" }; - yield return new object[] { (double)0, "G", null, "0" }; - yield return new object[] { (double)4567, "G", null, "4567" }; + yield return new object[] { 0.0, "G", null, "0" }; + yield return new object[] { 4567.0, "G", null, "4567" }; yield return new object[] { 4567.89101, "G", null, "4567.89101" }; yield return new object[] { double.MaxValue, "G", null, "1.79769313486232E+308" }; - yield return new object[] { double.Epsilon, "G", null, "4.94065645841247E-324" }; + yield return new object[] { double.Epsilon, "G", null, "double.Epsilon" }; yield return new object[] { double.NaN, "G", null, "NaN" }; - yield return new object[] { (double)2468, "N", null, "2,468.00" }; + yield return new object[] { 2468.0, "N", null, "2,468.00" }; // Changing the negative pattern doesn't do anything without also passing in a format string var customNegativePattern = new NumberFormatInfo() { NumberNegativePattern = 0 }; - yield return new object[] { (double)-6310, "G", customNegativePattern, "-6310" }; + yield return new object[] { -6310.0, "G", customNegativePattern, "-6310" }; var customNegativeSignDecimalGroupSeparator = new NumberFormatInfo() { @@ -406,8 +408,8 @@ namespace System.Tests NumberDecimalSeparator = "~", NumberGroupSeparator = "*" }; - yield return new object[] { (double)-2468, "N", customNegativeSignDecimalGroupSeparator, "#2*468~00" }; - yield return new object[] { (double)2468, "N", customNegativeSignDecimalGroupSeparator, "2*468~00" }; + yield return new object[] { -2468.0, "N", customNegativeSignDecimalGroupSeparator, "#2*468~00" }; + yield return new object[] { 2468.0, "N", customNegativeSignDecimalGroupSeparator, "2*468~00" }; var customNegativeSignGroupSeparatorNegativePattern = new NumberFormatInfo() { @@ -415,10 +417,10 @@ namespace System.Tests NumberGroupSeparator = "*", NumberNegativePattern = 0, }; - yield return new object[] { (double)-2468, "N", customNegativeSignGroupSeparatorNegativePattern, "(2*468.00)" }; + yield return new object[] { -2468.0, "N", customNegativeSignGroupSeparatorNegativePattern, "(2*468.00)" }; NumberFormatInfo invariantFormat = NumberFormatInfo.InvariantInfo; - yield return new object[] { double.Epsilon, "G", invariantFormat, "4.94065645841247E-324" }; + yield return new object[] { double.Epsilon, "G", invariantFormat, "double.Epsilon" }; yield return new object[] { double.NaN, "G", invariantFormat, "NaN" }; yield return new object[] { double.PositiveInfinity, "G", invariantFormat, "Infinity" }; yield return new object[] { double.NegativeInfinity, "G", invariantFormat, "-Infinity" }; @@ -465,7 +467,7 @@ namespace System.Tests [Fact] public static void ToString_InvalidFormat_ThrowsFormatException() { - double d = 123; + double d = 123.0; Assert.Throws(() => d.ToString("Y")); // Invalid format Assert.Throws(() => d.ToString("Y", null)); // Invalid format } diff --git a/src/libraries/System.Runtime/tests/System/SingleTests.cs b/src/libraries/System.Runtime/tests/System/SingleTests.cs index 0d76b18..d5ad71c 100644 --- a/src/libraries/System.Runtime/tests/System/SingleTests.cs +++ b/src/libraries/System.Runtime/tests/System/SingleTests.cs @@ -11,26 +11,28 @@ namespace System.Tests { public partial class SingleTests : RemoteExecutorTestBase { + // NOTE: Consider duplicating any tests added here in DoubleTests.cs + [Theory] [InlineData("a")] - [InlineData((double)234)] + [InlineData(234.0)] public void CompareTo_ObjectNotFloat_ThrowsArgumentException(object value) { AssertExtensions.Throws(null, () => ((float)123).CompareTo(value)); } [Theory] - [InlineData((float)234, (float)234, 0)] - [InlineData((float)234, float.MinValue, 1)] - [InlineData((float)234, (float)-123, 1)] - [InlineData((float)234, (float)0, 1)] - [InlineData((float)234, (float)123, 1)] - [InlineData((float)234, (float)456, -1)] - [InlineData((float)234, float.MaxValue, -1)] - [InlineData((float)234, float.NaN, 1)] + [InlineData(234.0f, 234.0f, 0)] + [InlineData(234.0f, float.MinValue, 1)] + [InlineData(234.0f, -123.0f, 1)] + [InlineData(234.0f, 0.0f, 1)] + [InlineData(234.0f, 123.0f, 1)] + [InlineData(234.0f, 456.0f, -1)] + [InlineData(234.0f, float.MaxValue, -1)] + [InlineData(234.0f, float.NaN, 1)] [InlineData(float.NaN, float.NaN, 0)] - [InlineData(float.NaN, (float)0, -1)] - [InlineData((float)234, null, 1)] + [InlineData(float.NaN, 0.0f, -1)] + [InlineData(234.0f, null, 1)] public void CompareTo_Other_ReturnsExpected(float f1, object value, int expected) { if (value is float f2) @@ -91,17 +93,17 @@ namespace System.Tests [Fact] public static void Epsilon() { - Assert.Equal((float)1.4e-45, float.Epsilon); + Assert.Equal(1.40129846E-45f, float.Epsilon); } [Theory] - [InlineData((float)789, (float)789, true)] - [InlineData((float)789, (float)-789, false)] - [InlineData((float)789, (float)0, false)] + [InlineData(789.0f, 789.0f, true)] + [InlineData(789.0f, -789.0f, false)] + [InlineData(789.0f, 0.0f, false)] [InlineData(float.NaN, float.NaN, true)] [InlineData(float.NaN, -float.NaN, true)] - [InlineData((float)789, (double)789, false)] - [InlineData((float)789, "789", false)] + [InlineData(789.0f, 789.0, false)] + [InlineData(789.0f, "789", false)] [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "The fix was made in coreclr that is not in netfx. See https://github.com/dotnet/coreclr/issues/6237")] public static void Equals(float f1, object value, bool expected) { @@ -135,11 +137,11 @@ namespace System.Tests [InlineData(float.MinValue, false)] // Min Negative Normal [InlineData(-1.17549435E-38f, false)] // Max Negative Normal [InlineData(-1.17549421E-38f, false)] // Min Negative Subnormal - [InlineData(-1.401298E-45, false)] // Max Negative Subnormal + [InlineData(-float.Epsilon, false)] // Max Negative Subnormal (Negative Epsilon) [InlineData(-0.0f, false)] // Negative Zero [InlineData(float.NaN, false)] // NaN [InlineData(0.0f, false)] // Positive Zero - [InlineData(1.401298E-45, false)] // Min Positive Subnormal + [InlineData(float.Epsilon, false)] // Min Positive Subnormal (Positive Epsilon) [InlineData(1.17549421E-38f, false)] // Max Positive Subnormal [InlineData(1.17549435E-38f, false)] // Min Positive Normal [InlineData(float.MaxValue, false)] // Max Positive Normal @@ -154,11 +156,11 @@ namespace System.Tests [InlineData(float.MinValue, false)] // Min Negative Normal [InlineData(-1.17549435E-38f, false)] // Max Negative Normal [InlineData(-1.17549421E-38f, false)] // Min Negative Subnormal - [InlineData(-1.401298E-45, false)] // Max Negative Subnormal + [InlineData(-float.Epsilon, false)] // Max Negative Subnormal (Negative Epsilon) [InlineData(-0.0f, false)] // Negative Zero [InlineData(float.NaN, true)] // NaN [InlineData(0.0f, false)] // Positive Zero - [InlineData(1.401298E-45, false)] // Min Positive Subnormal + [InlineData(float.Epsilon, false)] // Min Positive Subnormal (Positive Epsilon) [InlineData(1.17549421E-38f, false)] // Max Positive Subnormal [InlineData(1.17549435E-38f, false)] // Min Positive Normal [InlineData(float.MaxValue, false)] // Max Positive Normal @@ -173,11 +175,11 @@ namespace System.Tests [InlineData(float.MinValue, false)] // Min Negative Normal [InlineData(-1.17549435E-38f, false)] // Max Negative Normal [InlineData(-1.17549421E-38f, false)] // Min Negative Subnormal - [InlineData(-1.401298E-45, false)] // Max Negative Subnormal + [InlineData(-float.Epsilon, false)] // Max Negative Subnormal (Negative Epsilon) [InlineData(-0.0f, false)] // Negative Zero [InlineData(float.NaN, false)] // NaN [InlineData(0.0f, false)] // Positive Zero - [InlineData(1.401298E-45, false)] // Min Positive Subnormal + [InlineData(float.Epsilon, false)] // Min Positive Subnormal (Positive Epsilon) [InlineData(1.17549421E-38f, false)] // Max Positive Subnormal [InlineData(1.17549435E-38f, false)] // Min Positive Normal [InlineData(float.MaxValue, false)] // Max Positive Normal @@ -192,11 +194,11 @@ namespace System.Tests [InlineData(float.MinValue, false)] // Min Negative Normal [InlineData(-1.17549435E-38f, false)] // Max Negative Normal [InlineData(-1.17549421E-38f, false)] // Min Negative Subnormal - [InlineData(-1.401298E-45, false)] // Max Negative Subnormal + [InlineData(-float.Epsilon, false)] // Max Negative Subnormal (Negative Epsilon) [InlineData(-0.0f, false)] // Negative Zero [InlineData(float.NaN, false)] // NaN [InlineData(0.0f, false)] // Positive Zero - [InlineData(1.401298E-45, false)] // Min Positive Subnormal + [InlineData(float.Epsilon, false)] // Min Positive Subnormal (Positive Epsilon) [InlineData(1.17549421E-38f, false)] // Max Positive Subnormal [InlineData(1.17549435E-38f, false)] // Min Positive Normal [InlineData(float.MaxValue, false)] // Max Positive Normal @@ -209,25 +211,26 @@ namespace System.Tests [Fact] public static void MaxValue() { - Assert.Equal((float)3.40282346638528859e+38, float.MaxValue); + Assert.Equal(3.40282347E+38f, float.MaxValue); } [Fact] public static void MinValue() { - Assert.Equal((float)-3.40282346638528859e+38, float.MinValue); + Assert.Equal(-3.40282347E+38f, float.MinValue); + } [Fact] public static void NaN() { - Assert.Equal((float)0.0 / (float)0.0, float.NaN); + Assert.Equal(0.0f / 0.0f, float.NaN); } [Fact] public static void NegativeInfinity() { - Assert.Equal((float)-1.0 / (float)0.0, float.NegativeInfinity); + Assert.Equal(-1.0f / 0.0f, float.NegativeInfinity); } public static IEnumerable Parse_Valid_TestData() @@ -249,24 +252,24 @@ namespace System.Tests NumberFormatInfo invariantFormat = NumberFormatInfo.InvariantInfo; - yield return new object[] { "-123", defaultStyle, null, (float)-123 }; - yield return new object[] { "0", defaultStyle, null, (float)0 }; - yield return new object[] { "123", defaultStyle, null, (float)123 }; - yield return new object[] { " 123 ", defaultStyle, null, (float)123 }; - yield return new object[] { (567.89f).ToString(), defaultStyle, null, (float)567.89 }; - yield return new object[] { (-567.89f).ToString(), defaultStyle, null, (float)-567.89 }; - yield return new object[] { "1E23", defaultStyle, null, (float)1E23 }; - - yield return new object[] { (123.1f).ToString(), NumberStyles.AllowDecimalPoint, null, (float)123.1 }; - yield return new object[] { 1000.ToString("N0"), NumberStyles.AllowThousands, null, (float)1000 }; - - yield return new object[] { "123", NumberStyles.Any, emptyFormat, (float)123 }; - yield return new object[] { (123.567f).ToString(), NumberStyles.Any, emptyFormat, 123.567 }; - yield return new object[] { "123", NumberStyles.Float, emptyFormat, (float)123 }; - yield return new object[] { "$1,000", NumberStyles.Currency, dollarSignCommaSeparatorFormat, (float)1000 }; - yield return new object[] { "$1000", NumberStyles.Currency, dollarSignCommaSeparatorFormat, (float)1000 }; - yield return new object[] { "123.123", NumberStyles.Float, decimalSeparatorFormat, (float)123.123 }; - yield return new object[] { "(123)", NumberStyles.AllowParentheses, decimalSeparatorFormat, (float)-123 }; + yield return new object[] { "-123", defaultStyle, null, -123.0f }; + yield return new object[] { "0", defaultStyle, null, 0.0f }; + yield return new object[] { "123", defaultStyle, null, 123.0f }; + yield return new object[] { " 123 ", defaultStyle, null, 123.0f }; + yield return new object[] { (567.89f).ToString(), defaultStyle, null, 567.89f }; + yield return new object[] { (-567.89f).ToString(), defaultStyle, null, -567.89f }; + yield return new object[] { "1E23", defaultStyle, null, 1E23f }; + + yield return new object[] { (123.1f).ToString(), NumberStyles.AllowDecimalPoint, null, 123.1f }; + yield return new object[] { (1000.0f).ToString("N0"), NumberStyles.AllowThousands, null, 1000.0f }; + + yield return new object[] { "123", NumberStyles.Any, emptyFormat, 123.0f }; + yield return new object[] { (123.567f).ToString(), NumberStyles.Any, emptyFormat, 123.567f }; + yield return new object[] { "123", NumberStyles.Float, emptyFormat, 123.0f }; + yield return new object[] { "$1,000", NumberStyles.Currency, dollarSignCommaSeparatorFormat, 1000.0f }; + yield return new object[] { "$1000", NumberStyles.Currency, dollarSignCommaSeparatorFormat, 1000.0f }; + yield return new object[] { "123.123", NumberStyles.Float, decimalSeparatorFormat, 123.123f }; + yield return new object[] { "(123)", NumberStyles.AllowParentheses, decimalSeparatorFormat, -123.0f }; yield return new object[] { "NaN", NumberStyles.Any, invariantFormat, float.NaN }; yield return new object[] { "Infinity", NumberStyles.Any, invariantFormat, float.PositiveInfinity }; @@ -325,7 +328,7 @@ namespace System.Tests yield return new object[] { "ab", defaultStyle, null, typeof(FormatException) }; // Hex value yield return new object[] { "(123)", defaultStyle, null, typeof(FormatException) }; // Parentheses - yield return new object[] { 100.ToString("C0"), defaultStyle, null, typeof(FormatException) }; // Currency + yield return new object[] { (100.0f).ToString("C0"), defaultStyle, null, typeof(FormatException) }; // Currency yield return new object[] { (123.456f).ToString(), NumberStyles.Integer, null, typeof(FormatException) }; // Decimal yield return new object[] { " " + (123.456f).ToString(), NumberStyles.None, null, typeof(FormatException) }; // Leading space @@ -376,27 +379,27 @@ namespace System.Tests [Fact] public static void PositiveInfinity() { - Assert.Equal((float)1.0 / (float)0.0, float.PositiveInfinity); + Assert.Equal(1.0f / 0.0f, float.PositiveInfinity); } public static IEnumerable ToString_TestData() { yield return new object[] { float.MinValue, "G", null, "-3.402823E+38" }; - yield return new object[] { (float)-4567, "G", null, "-4567" }; - yield return new object[] { (float)-4567.89101, "G", null, "-4567.891" }; - yield return new object[] { (float)0, "G", null, "0" }; - yield return new object[] { (float)4567, "G", null, "4567" }; - yield return new object[] { (float)4567.89101, "G", null, "4567.891" }; + yield return new object[] { -4567.0f, "G", null, "-4567" }; + yield return new object[] { -4567.89101f, "G", null, "-4567.891" }; + yield return new object[] { 0.0f, "G", null, "0" }; + yield return new object[] { 4567.0f, "G", null, "4567" }; + yield return new object[] { 4567.89101f, "G", null, "4567.891" }; yield return new object[] { float.MaxValue, "G", null, "3.402823E+38" }; - yield return new object[] { float.Epsilon, "G", null, "1.401298E-45" }; + yield return new object[] { float.Epsilon, "G", null, "float.Epsilon" }; yield return new object[] { float.NaN, "G", null, "NaN" }; - yield return new object[] { (float)2468, "N", null, "2,468.00" }; + yield return new object[] { 2468.0f, "N", null, "2,468.00" }; // Changing the negative pattern doesn't do anything without also passing in a format string var customNegativePattern = new NumberFormatInfo() { NumberNegativePattern = 0 }; - yield return new object[] { (float)-6310, "G", customNegativePattern, "-6310" }; + yield return new object[] { -6310.0f, "G", customNegativePattern, "-6310" }; var customNegativeSignDecimalGroupSeparator = new NumberFormatInfo() { @@ -404,8 +407,8 @@ namespace System.Tests NumberDecimalSeparator = "~", NumberGroupSeparator = "*" }; - yield return new object[] { (float)-2468, "N", customNegativeSignDecimalGroupSeparator, "#2*468~00" }; - yield return new object[] { (float)2468, "N", customNegativeSignDecimalGroupSeparator, "2*468~00" }; + yield return new object[] { -2468.0f, "N", customNegativeSignDecimalGroupSeparator, "#2*468~00" }; + yield return new object[] { 2468.0f, "N", customNegativeSignDecimalGroupSeparator, "2*468~00" }; var customNegativeSignGroupSeparatorNegativePattern = new NumberFormatInfo() { @@ -413,10 +416,10 @@ namespace System.Tests NumberGroupSeparator = "*", NumberNegativePattern = 0 }; - yield return new object[] { (float)-2468, "N", customNegativeSignGroupSeparatorNegativePattern, "(2*468.00)" }; + yield return new object[] { -2468.0f, "N", customNegativeSignGroupSeparatorNegativePattern, "(2*468.00)" }; NumberFormatInfo invariantFormat = NumberFormatInfo.InvariantInfo; - yield return new object[] { float.Epsilon, "G", invariantFormat, "1.401298E-45" }; + yield return new object[] { float.Epsilon, "G", invariantFormat, "float.Epsilon" }; yield return new object[] { float.NaN, "G", invariantFormat, "NaN" }; yield return new object[] { float.PositiveInfinity, "G", invariantFormat, "Infinity" }; yield return new object[] { float.NegativeInfinity, "G", invariantFormat, "-Infinity" }; @@ -463,7 +466,7 @@ namespace System.Tests [Fact] public static void ToString_InvalidFormat_ThrowsFormatException() { - float f = 123; + float f = 123.0f; Assert.Throws(() => f.ToString("Y")); // Invalid format Assert.Throws(() => f.ToString("Y", null)); // Invalid format }