2010-01-11 Carlos Alberto Cortez <calberto.cortez@gmail.com>
authorCarlos Alberto Cortez <calberto.cortez@gmail.com>
Mon, 11 Jan 2010 23:42:22 +0000 (23:42 -0000)
committerCarlos Alberto Cortez <calberto.cortez@gmail.com>
Mon, 11 Jan 2010 23:42:22 +0000 (23:42 -0000)
* Int32Test.cs: Add test case for exponent support in the Parse
methods.

svn path=/trunk/mcs/; revision=149357

mcs/class/corlib/Test/System/ChangeLog
mcs/class/corlib/Test/System/Int32Test.cs

index fc49870c09b8a65956bbadaa862d9be7cbcbd152..647d44f0627cbd124963a533a1d28f8432890a89 100644 (file)
@@ -1,3 +1,8 @@
+2010-01-11  Carlos Alberto Cortez <calberto.cortez@gmail.com>
+
+       * Int32Test.cs: Add test case for exponent support in the Parse
+       methods.
+
 2010-01-08 Rodrigo Kumpera  <rkumpera@novell.com>
 
        * TypeTest.cs: Test for variant use of GetInterfaceMap.
index 69c4ff348f850d829a0fb0c46277d306ff5f8c99..99157af92909b3bf5c36f24cf1ab932c6d96645d 100644 (file)
@@ -240,6 +240,59 @@ public class Int32Test
                Assert.AreEqual (734561, Int64.Parse ("734561\0\0\0"), "C#46");
        }
 
+       [Test]
+       public void TestParseExponent ()
+       {
+               Assert.AreEqual (2, Int32.Parse ("2E0", NumberStyles.AllowExponent), "A#1");
+               Assert.AreEqual (20, Int32.Parse ("2E1", NumberStyles.AllowExponent), "A#2");
+               Assert.AreEqual (200, Int32.Parse ("2E2", NumberStyles.AllowExponent), "A#3");
+               Assert.AreEqual (2000000, Int32.Parse ("2E6", NumberStyles.AllowExponent), "A#4");
+               Assert.AreEqual (200, Int32.Parse ("2E+2", NumberStyles.AllowExponent), "A#5");
+
+               try {
+                       Int32.Parse ("2E");
+                       Assert.Fail ("B#1");
+               } catch (FormatException) {
+               }
+
+               try {
+                       Int32.Parse ("2E3.0", NumberStyles.AllowExponent); // decimal notation for the exponent
+                       Assert.Fail ("B#2");
+               } catch (FormatException) {
+               }
+
+               try {
+                       Int32.Parse ("2E 2", NumberStyles.AllowExponent);
+                       Assert.Fail ("B#3");
+               } catch (FormatException) {
+               }
+
+               try {
+                       Int32.Parse ("2E2 ", NumberStyles.AllowExponent);
+                       Assert.Fail ("B#4");
+               } catch (FormatException) {
+               }
+
+               try {
+                       Int32.Parse ("2E66", NumberStyles.AllowExponent); // final result overflow
+                       Assert.Fail ("B#5");
+               } catch (OverflowException) {
+               }
+
+               try {
+                       long exponent = (long)Int32.MaxValue + 10;
+                       Int32.Parse ("2E" + exponent.ToString (), NumberStyles.AllowExponent);
+                       Assert.Fail ("B#6");
+               } catch (OverflowException) {
+               }
+
+               try {
+                       Int32.Parse ("2E-1", NumberStyles.AllowExponent); // negative exponent
+                       Assert.Fail ("B#7");
+               } catch (OverflowException) {
+               }
+       }
+
 #if NET_2_0    
        [Test]
        public void TestTryParse()