You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assert.Equal(float.Parse(strArr[i]),_float[i],$"Failed while parsing string: {strArr[i]} expecting: {_float[i]}");
607
+
608
+
Assert.True(float.TryParse(strArr[i],outresult),$"TryParse failed for {strArr[i]} expecting: {_float[i]}");
609
+
Assert.Equal(_float[i],result);
610
+
}
611
+
612
+
floatf=float.Parse("-0.1");
613
+
Assert.Equal(f,-0.1f);
614
+
615
+
Assert.True(float.TryParse("-0.1",outresult),$"TryParse failed for -0.1 expecting: {f}");
616
+
Assert.Equal(-0.1f,result);
617
+
618
+
f=float.Parse("0.1");
619
+
Assert.Equal(f,0.1f);
620
+
621
+
Assert.True(float.TryParse("0.1",outresult),$"TryParse failed for 0.1 expecting: {f}");
622
+
Assert.Equal(0.1f,result);
623
+
624
+
f=float.Parse(" -1.1");
625
+
Assert.Equal(f,-1.1f);
626
+
627
+
Assert.True(float.TryParse(" -1.1",outresult),$"TryParse failed for -1.1 expecting: {f}");
628
+
Assert.Equal(-1.1f,result);
629
+
630
+
f=float.Parse(" -0.0001");
631
+
Assert.Equal(f,-0.0001f);
632
+
633
+
Assert.True(float.TryParse(" -0.0001",outresult),$"TryParse failed for -0.0001 expecting: {f}");
634
+
Assert.Equal(-0.0001f,result);
635
+
636
+
f=float.Parse(" -10.0001");
637
+
Assert.Equal(f,-10.0001f);
638
+
639
+
Assert.True(float.TryParse(" -10.0001",outresult),$"TryParse failed for -10.0001 expecting: {f}");
640
+
Assert.Equal(-10.0001f,result);
641
+
642
+
f=float.Parse("-0.01e-10");
643
+
Assert.Equal(f,-0.01e-10f);
644
+
645
+
Assert.True(float.TryParse("-0.01e-10",outresult),$"TryParse failed for -0.01e-10 expecting: {f}");
646
+
Assert.Equal(-0.01e-10f,result);
647
+
648
+
// can't use Min/MaxValue.ToString() because the fast float-to-string routine only works in the range 2^64 to 2^-64 (there-about).
649
+
stringt="-3.40282347E+38";// float.MinValue
650
+
Assert.Equal(float.MinValue,float.Parse(t),"Testing float min value parse");
651
+
652
+
t="3.40282347E+38";// float.MaxValue
653
+
Assert.Equal(float.MaxValue,float.Parse(t),"Testing float max value parse");
654
+
}
655
+
656
+
[TestMethod]
657
+
publicvoidParseFloat_Test_Invalid_Values()
658
+
{
659
+
string[]strArr=newstring[]{
660
+
"",
661
+
" ",
662
+
" ",
663
+
"-0e-a",
664
+
"+123a4",
665
+
" +123f.1",
666
+
"123ea2",
667
+
"1.111.1",
668
+
" -123-e3",
669
+
" 123.456 777",
670
+
"1234567ee73",
671
+
" +1234e-77+",
672
+
"++1",
673
+
"--1",
674
+
"+1+",
675
+
" .1123abc",
676
+
" .123+456",
677
+
"+123e++10",
678
+
"+123e--10",
679
+
"-123e++10"
680
+
};
681
+
682
+
for(inti=0;i<strArr.Length;i++)
683
+
{
684
+
OutputHelper.WriteLine($"parse {strArr[i]}");
685
+
686
+
Assert.Throws(typeof(FormatException),
687
+
()=>{float.Parse(strArr[i]);},
688
+
$"Should throw exception of type FormatExeception while parsing string: '{strArr[i]}'");
689
+
690
+
Assert.False(float.TryParse(strArr[i],outfloat_),$"TryParse should return false while parsing string: '{strArr[i]}'");
691
+
}
692
+
}
693
+
694
+
[TestMethod]
695
+
publicvoidParseFloat_OverflowTests()
696
+
{
697
+
// Note we have to check hex values - again, the ToString() works over a subset of the range for double/float, and returns 'oor' or '-oor' for anything outside that range
698
+
stringt="-3.40282380E+38";
542
699
Assert.Equal(float.NegativeInfinity,float.Parse(t),"High negative values should return float.NegativeInfinity value when parsed");
543
700
544
701
t="3.40282380E+38";
545
702
Assert.Equal(float.PositiveInfinity,float.Parse(t),"High positive values should return float.PositiveInfinity value when parsed");
546
-
547
703
}
548
704
549
705
privatevoidCheckUValues(ulongstart)
@@ -849,8 +1005,8 @@ public void ParseByte_FormatException_Test_26()
849
1005
850
1006
for(inti=0;i<5;i++)
851
1007
{
852
-
stringrdmString=GetRandomString();
853
-
1008
+
stringrdmString=GetRandomString();
1009
+
854
1010
Assert.Throws(typeof(FormatException),()=>{_=byte.Parse(rdmString);},$"Random string '{rdmString}' did not throw exception of FormatException");
855
1011
856
1012
Assert.False(byte.TryParse(rdmString,out_));
@@ -863,8 +1019,8 @@ public void ParseInt16_FormatException_Test_27()
0 commit comments