Added Boolean Test Suite
[mono.git] / mcs / class / corlib / Test / System / UInt64Test.cs
1 // UInt64Test.cs - NUnit Test Cases for the System.UInt64 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 UInt64Test : TestCase
16 {
17         private const UInt64 MyUInt64_1 = 42;
18         private const UInt64 MyUInt64_2 = 0;
19         private const UInt64 MyUInt64_3 = 18446744073709551615;
20         private const string MyString1 = "42";
21         private const string MyString2 = "0";
22         private const string MyString3 = "18446744073709551615";
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+"18,446,744,073,709,551,615.00000",
32                                         "18446744073709551615", "1.84467e+019", "18446744073709551615.00000",
33                                         "1.8447e+19", "18,446,744,073,709,551,615.00000",
34                                         "1,844,674,407,370,955,161,500.00000 %", "ffffffffffffffff"};
35         private string[] ResultsNfi2 = {NumberFormatInfo.InvariantInfo.CurrencySymbol+"18,446,744,073,709,551,615.00000",
36                                         "18446744073709551615", "1.84467e+019", "18446744073709551615.00000",
37                                         "1.8447e+19", "18,446,744,073,709,551,615.00000",
38                                         "1,844,674,407,370,955,161,500.00000 %", "ffffffffffffffff"};
39
40         private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
41         
42         public UInt64Test(string name) : base(name) {}
43
44         protected override void SetUp() 
45         {
46         }
47
48         public static ITest Suite {
49                 get { 
50                         return new TestSuite(typeof(UInt64Test)); 
51                 }
52         }
53     
54         public void TestMinMax()
55         {
56                 
57                 AssertEquals(UInt64.MinValue, MyUInt64_2);
58                 AssertEquals(UInt64.MaxValue, MyUInt64_3);
59         }
60         
61         public void TestCompareTo()
62         {
63                 Assert(MyUInt64_3.CompareTo(MyUInt64_2) > 0);
64                 Assert(MyUInt64_2.CompareTo(MyUInt64_2) == 0);
65                 Assert(MyUInt64_1.CompareTo((UInt64)(42)) == 0);
66                 Assert(MyUInt64_2.CompareTo(MyUInt64_3) < 0);
67                 try {
68                         MyUInt64_2.CompareTo((Int16)100);
69                         Fail("Should raise a System.ArgumentException");
70                 }
71                 catch (Exception e) {
72                         Assert(typeof(ArgumentException) == e.GetType());
73                 }
74         }
75
76         public void TestEquals()
77         {
78                 Assert(MyUInt64_1.Equals(MyUInt64_1));
79                 Assert(MyUInt64_1.Equals((UInt64)(42)));
80                 Assert(MyUInt64_1.Equals((SByte)(42)) == false);
81                 Assert(MyUInt64_1.Equals(MyUInt64_2) == false);
82         }
83         
84         public void TestGetHashCode()
85         {
86                 try {
87                         MyUInt64_1.GetHashCode();
88                         MyUInt64_2.GetHashCode();
89                         MyUInt64_3.GetHashCode();
90                 }
91                 catch {
92                         Fail("GetHashCode should not raise an exception here");
93                 }
94         }
95         
96         public void TestParse()
97         {
98                 //test Parse(string s)
99                 Assert(MyUInt64_1 == UInt64.Parse(MyString1));
100                 Assert(MyUInt64_2 == UInt64.Parse(MyString2));
101                 Assert(MyUInt64_3 == UInt64.Parse(MyString3));
102                 try {
103                         UInt64.Parse(null);
104                         Fail("Should raise a ArgumentNullException");
105                 }
106                 catch (Exception e) {
107                         Assert(typeof(ArgumentNullException) == e.GetType());
108                 }
109                 try {
110                         UInt64.Parse("not-a-number");
111                         Fail("Should raise a System.FormatException");
112                 }
113                 catch (Exception e) {
114                         Assert(typeof(FormatException) == e.GetType());
115                 }
116                 //test Parse(string s, NumberStyles style)
117                 try {
118                         double OverInt = (double)UInt64.MaxValue + 1;
119                         UInt64.Parse(OverInt.ToString(), NumberStyles.Float);
120                         Fail("Should raise a OverflowException");
121                 }
122                 catch (Exception e) {
123                         Assert(typeof(OverflowException) == e.GetType());
124                 }
125                 try {
126                         double OverInt = (double)UInt64.MaxValue + 1;
127                         UInt64.Parse(OverInt.ToString(), NumberStyles.Integer);
128                         Fail("Should raise a System.FormatException");
129                 }
130                 catch (Exception e) {
131                         Assert(typeof(FormatException) == e.GetType());
132                 }
133                 Assert(42 == UInt64.Parse(" $42 ", NumberStyles.Currency));
134                 try {
135                         UInt64.Parse("$42", NumberStyles.Integer);
136                         Fail("Should raise a FormatException");
137                 }
138                 catch (Exception e) {
139                         Assert(typeof(FormatException) == e.GetType());
140                 }
141                 //test Parse(string s, IFormatProvider provider)
142                 Assert(42 == UInt64.Parse(" 42 ", Nfi));
143                 try {
144                         UInt64.Parse("%42", Nfi);
145                         Fail("Should raise a System.FormatException");
146                 }
147                 catch (Exception e) {
148                         Assert(typeof(FormatException) == e.GetType());
149                 }
150                 //test Parse(string s, NumberStyles style, IFormatProvider provider)
151                 Assert(16 == UInt64.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
152                 try {
153                         UInt64.Parse("$42", NumberStyles.Integer, Nfi);
154                         Fail("Should raise a System.FormatException");
155                 }
156                 catch (Exception e) {
157                         Assert(typeof(FormatException) == e.GetType());
158                 }
159         }
160         
161         public void TestToString()
162         {
163                 //test ToString()
164                 AssertEquals(MyString1, MyUInt64_1.ToString());
165                 AssertEquals(MyString2, MyUInt64_2.ToString());
166                 AssertEquals(MyString3, MyUInt64_3.ToString());
167                 //test ToString(string format)
168                 for (int i=0; i < Formats1.Length; i++) {
169                         AssertEquals(Results1[i], MyUInt64_2.ToString(Formats1[i]));
170                         AssertEquals(Results2[i], MyUInt64_3.ToString(Formats2[i]));
171                 }
172                 //test ToString(string format, IFormatProvider provider);
173                 for (int i=0; i < Formats1.Length; i++) {
174                         AssertEquals(ResultsNfi1[i], MyUInt64_2.ToString(Formats1[i], Nfi));
175                         AssertEquals(ResultsNfi2[i], MyUInt64_3.ToString(Formats2[i], Nfi));
176                 }
177                 try {
178                         MyUInt64_1.ToString("z");
179                         Fail("Should raise a System.FormatException");
180                 }
181                 catch (Exception e) {
182                         Assert(typeof(FormatException) == e.GetType());
183                 }
184         }
185 }
186
187 }