Added Boolean Test Suite
[mono.git] / mcs / class / corlib / Test / System / UInt16Test.cs
1 // UInt16Test.cs - NUnit Test Cases for the System.UInt16 struct
2 //
3 // Mario Martinez (mariom925@home.om)
4 //
5 // (C) Ximian, Inc.  http://www.ximian.com
6 // 
7
8 using NUnit.Framework;
9 using System;
10 using System.Globalization;
11
12 namespace MonoTests.System
13 {
14
15 public class UInt16Test : TestCase
16 {
17         private const UInt16 MyUInt16_1 = 42;
18         private const UInt16 MyUInt16_2 = 0;
19         private const UInt16 MyUInt16_3 = 65535;
20         private const string MyString1 = "42";
21         private const string MyString2 = "0";
22         private const string MyString3 = "65535";
23         private string[] Formats1 = {"c", "d", "e", "f", "g", "n", "p", "x" };
24         private string[] Formats2 = {"c5", "d5", "e5", "f5", "g5", "n5", "p5", "x5" };
25         private string[] Results1 = {NumberFormatInfo.CurrentInfo.CurrencySymbol+"0.00",
26                                         "0", "0.000000e+000", "0.00",
27                                         "0", "0.00", "0.00 %", "0"};
28         private string[] ResultsNfi1 = {NumberFormatInfo.InvariantInfo.CurrencySymbol+"0.00",
29                                         "0", "0.000000e+000", "0.00",
30                                         "0", "0.00", "0.00 %", "0"};
31         private string[] Results2 = {NumberFormatInfo.CurrentInfo.CurrencySymbol+"65,535.00000",
32                                         "65535", "6.55350e+004", "65535.00000",
33                                         "65535", "65,535.00000", "6,553,500.00000 %", "0ffff"};
34         private string[] ResultsNfi2 = {NumberFormatInfo.InvariantInfo.CurrencySymbol+"65,535.00000",
35                                         "65535", "6.55350e+004", "65535.00000",
36                                         "65535", "65,535.00000", "6,553,500.00000 %", "0ffff"};
37
38         private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
39         
40         public UInt16Test(string name) : base(name) {}
41
42         protected override void SetUp() 
43         {
44         }
45
46         public static ITest Suite {
47                 get { 
48                         return new TestSuite(typeof(UInt16Test)); 
49                 }
50         }
51     
52         public void TestMinMax()
53         {
54                 
55                 AssertEquals(UInt16.MinValue, MyUInt16_2);
56                 AssertEquals(UInt16.MaxValue, MyUInt16_3);
57         }
58         
59         public void TestCompareTo()
60         {
61                 Assert(MyUInt16_3.CompareTo(MyUInt16_2) > 0);
62                 Assert(MyUInt16_2.CompareTo(MyUInt16_2) == 0);
63                 Assert(MyUInt16_1.CompareTo((UInt16)(42)) == 0);
64                 Assert(MyUInt16_2.CompareTo(MyUInt16_3) < 0);
65                 try {
66                         MyUInt16_2.CompareTo(100);
67                         Fail("Should raise a System.ArgumentException");
68                 }
69                 catch (Exception e) {
70                         Assert(typeof(ArgumentException) == e.GetType());
71                 }
72         }
73
74         public void TestEquals()
75         {
76                 Assert(MyUInt16_1.Equals(MyUInt16_1));
77                 Assert(MyUInt16_1.Equals((UInt16)(42)));
78                 Assert(MyUInt16_1.Equals((SByte)(42)) == false);
79                 Assert(MyUInt16_1.Equals(MyUInt16_2) == false);
80         }
81         
82         public void TestGetHashCode()
83         {
84                 try {
85                         MyUInt16_1.GetHashCode();
86                         MyUInt16_2.GetHashCode();
87                         MyUInt16_3.GetHashCode();
88                 }
89                 catch {
90                         Fail("GetHashCode should not raise an exception here");
91                 }
92         }
93         
94         public void TestParse()
95         {
96                 //test Parse(string s)
97                 Assert(MyUInt16_1 == UInt16.Parse(MyString1));
98                 Assert(MyUInt16_2 == UInt16.Parse(MyString2));
99                 Assert(MyUInt16_3 == UInt16.Parse(MyString3));
100                 try {
101                         UInt16.Parse(null);
102                         Fail("Should raise a System.ArgumentNullException");
103                 }
104                 catch (Exception e) {
105                         Assert(typeof(ArgumentNullException) == e.GetType());
106                 }
107                 try {
108                         UInt16.Parse("not-a-number");
109                         Fail("Should raise a System.FormatException");
110                 }
111                 catch (Exception e) {
112                         Assert(typeof(FormatException) == e.GetType());
113                 }
114                 try {
115                         int OverInt = UInt16.MaxValue + 1;
116                         UInt16.Parse(OverInt.ToString());
117                         Fail("Should raise a System.OverflowException");
118                 }
119                 catch (Exception e) {
120                         Assert(typeof(OverflowException) == e.GetType());
121                 }
122                 //test Parse(string s, NumberStyles style)
123                 Assert(42 == UInt16.Parse(" $42 ", NumberStyles.Currency));
124                 try {
125                         UInt16.Parse("$42", NumberStyles.Integer);
126                         Fail("Should raise a System.FormatException");
127                 }
128                 catch (Exception e) {
129                         Assert(typeof(FormatException) == e.GetType());
130                 }
131                 //test Parse(string s, IFormatProvider provider)
132                 Assert(42 == UInt16.Parse(" 42 ", Nfi));
133                 try {
134                         UInt16.Parse("%42", Nfi);
135                         Fail("Should raise a System.FormatException");
136                 }
137                 catch (Exception e) {
138                         Assert(typeof(FormatException) == e.GetType());
139                 }
140                 //test Parse(string s, NumberStyles style, IFormatProvider provider)
141                 Assert(16 == UInt16.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
142                 try {
143                         UInt16.Parse("$42", NumberStyles.Integer, Nfi);
144                         Fail("Should raise a System.FormatException");
145                 }
146                 catch (Exception e) {
147                         Assert(typeof(FormatException) == e.GetType());
148                 }
149         }
150         
151         public void TestToString()
152         {
153                 //test ToString()
154                 AssertEquals(MyString1, MyUInt16_1.ToString());
155                 AssertEquals(MyString2, MyUInt16_2.ToString());
156                 AssertEquals(MyString3, MyUInt16_3.ToString());
157                 //test ToString(string format)
158                 for (int i=0; i < Formats1.Length; i++) {
159                         AssertEquals(Results1[i], MyUInt16_2.ToString(Formats1[i]));
160                         AssertEquals(Results2[i], MyUInt16_3.ToString(Formats2[i]));
161                 }
162                 //test ToString(string format, IFormatProvider provider);
163                 for (int i=0; i < Formats1.Length; i++) {
164                         AssertEquals(ResultsNfi1[i], MyUInt16_2.ToString(Formats1[i], Nfi));
165                         AssertEquals(ResultsNfi2[i], MyUInt16_3.ToString(Formats2[i], Nfi));
166                 }
167                 try {
168                         MyUInt16_1.ToString("z");
169                         Fail("Should raise a System.FormatException");
170                 }
171                 catch (Exception e) {
172                         Assert(typeof(FormatException) == e.GetType());
173                 }
174         }
175 }
176
177
178 }