Merge pull request #1541 from alexrp/mcs-build-cleanup
[mono.git] / mcs / class / corlib / Test / System / UInt16Test.cs
index ff324fa5385784d6cc4ff49d4cdeb77ccca3e83b..a0b8565e045d0d0aef818226a82e1d4774ffad0b 100644 (file)
@@ -41,7 +41,7 @@ public class UInt16Test
        
        private CultureInfo old_culture;
 
-       [TestFixtureSetUp]
+       [SetUp]
        public void SetUp () 
        {
                old_culture = Thread.CurrentThread.CurrentCulture;
@@ -61,34 +61,35 @@ public class UInt16Test
                Results2 [6] = perPattern.Replace ("n","6,553,500.00000");
        }
 
-       [TestFixtureTearDown]
+       [TearDown]
        public void TearDown ()
        {
                Thread.CurrentThread.CurrentCulture = old_culture;
        }
 
+       [Test]
        public void TestMinMax()
        {
                
                Assert.AreEqual(UInt16.MinValue, MyUInt16_2);
                Assert.AreEqual(UInt16.MaxValue, MyUInt16_3);
        }
-       
+
+       [Test]
        public void TestCompareTo()
        {
-               Assert.IsTrue(MyUInt16_3.CompareTo(MyUInt16_2) > 0);
-               Assert.IsTrue(MyUInt16_2.CompareTo(MyUInt16_2) == 0);
-               Assert.IsTrue(MyUInt16_1.CompareTo((UInt16)(42)) == 0);
-               Assert.IsTrue(MyUInt16_2.CompareTo(MyUInt16_3) < 0);
+               Assert.AreEqual(65535, MyUInt16_3.CompareTo(MyUInt16_2), "#1");
+               Assert.AreEqual(0, MyUInt16_2.CompareTo(MyUInt16_2), "#2");
+               Assert.AreEqual(0, MyUInt16_1.CompareTo((UInt16)(42)), "#3");
+               Assert.AreEqual(-65535, MyUInt16_2.CompareTo(MyUInt16_3), "#4");
                try {
                        MyUInt16_2.CompareTo((object)100);
                        Assert.Fail("Should raise a System.ArgumentException");
-               }
-               catch (Exception e) {
-                       Assert.IsTrue(typeof(ArgumentException) == e.GetType());
+               } catch (ArgumentException e) {
                }
        }
 
+       [Test]
        public void TestEquals()
        {
                Assert.IsTrue(MyUInt16_1.Equals(MyUInt16_1));
@@ -96,7 +97,8 @@ public class UInt16Test
                Assert.IsTrue(MyUInt16_1.Equals((object)(SByte)(42)) == false);
                Assert.IsTrue(MyUInt16_1.Equals(MyUInt16_2) == false);
        }
-       
+
+       [Test]
        public void TestGetHashCode()
        {
                try {
@@ -108,7 +110,8 @@ public class UInt16Test
                        Assert.Fail("GetHashCode should not raise an exception here");
                }
        }
-       
+
+       [Test]
        public void TestParse()
        {
                //test Parse(string s)
@@ -165,7 +168,67 @@ public class UInt16Test
                        Assert.IsTrue(typeof(FormatException) == e.GetType());
                }
        }
-       
+
+       [Test]
+       public void TestParseExponent ()
+       {
+               Assert.AreEqual (2, UInt16.Parse ("2E0", NumberStyles.AllowExponent), "A#1");
+               Assert.AreEqual (20, UInt16.Parse ("2E1", NumberStyles.AllowExponent), "A#2");
+               Assert.AreEqual (200, UInt16.Parse ("2E2", NumberStyles.AllowExponent), "A#3");
+               Assert.AreEqual (200, UInt16.Parse ("2E+2", NumberStyles.AllowExponent), "A#4");
+               Assert.AreEqual (2, UInt16.Parse ("2", NumberStyles.AllowExponent), "A#5");
+
+               try {
+                       UInt16.Parse ("2E");
+                       Assert.Fail ("B#1");
+               } catch (FormatException) {
+               }
+
+               try {
+                       UInt16.Parse ("2E3.0", NumberStyles.AllowExponent); // decimal notation for the exponent
+                       Assert.Fail ("B#2");
+               } catch (FormatException) {
+               }
+
+               try {
+                       UInt16.Parse ("2E 2", NumberStyles.AllowExponent);
+                       Assert.Fail ("B#3");
+               } catch (FormatException) {
+               }
+
+               try {
+                       UInt16.Parse ("2E2 ", NumberStyles.AllowExponent);
+                       Assert.Fail ("B#4");
+               } catch (FormatException) {
+               }
+
+               try {
+                       UInt16.Parse ("2E66", NumberStyles.AllowExponent); // final result overflow
+                       Assert.Fail ("B#5");
+               } catch (OverflowException) {
+               }
+
+               try {
+                       long exponent = (long) Int32.MaxValue + 10;
+                       UInt16.Parse ("2E" + exponent.ToString (), NumberStyles.AllowExponent);
+                       Assert.Fail ("B#6");
+               } catch (OverflowException) {
+               }
+
+               try {
+                       UInt16.Parse ("2E-1", NumberStyles.AllowExponent); // negative exponent
+                       Assert.Fail ("B#7");
+               } catch (OverflowException) {
+               }
+               
+               try {
+                       UInt16.Parse ("2 math e1", NumberStyles.AllowExponent);
+                       Assert.Fail ("B#8");
+               } catch (FormatException) {
+               }
+       }
+
+       [Test]
        public void TestToString()
        {
                //test ToString()