1 // UInt64Test.cs - NUnit Test Cases for the System.UInt64 struct
3 // Mario Martinez (mariom925@home.om)
5 // (C) Ximian, Inc. http://www.ximian.com
10 using System.Globalization;
12 namespace MonoTests.System
15 public class UInt64Test : TestCase
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"};
40 private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
42 public UInt64Test() : base ("MonoTests.System.UInt64Test testcase") {}
\r
43 public UInt64Test(string name) : base(name) {}
45 protected override void SetUp()
49 public static ITest Suite {
51 return new TestSuite(typeof(UInt64Test));
55 public void TestMinMax()
58 AssertEquals(UInt64.MinValue, MyUInt64_2);
59 AssertEquals(UInt64.MaxValue, MyUInt64_3);
62 public void TestCompareTo()
64 Assert(MyUInt64_3.CompareTo(MyUInt64_2) > 0);
65 Assert(MyUInt64_2.CompareTo(MyUInt64_2) == 0);
66 Assert(MyUInt64_1.CompareTo((UInt64)(42)) == 0);
67 Assert(MyUInt64_2.CompareTo(MyUInt64_3) < 0);
69 MyUInt64_2.CompareTo((Int16)100);
70 Fail("Should raise a System.ArgumentException");
73 Assert(typeof(ArgumentException) == e.GetType());
77 public void TestEquals()
79 Assert(MyUInt64_1.Equals(MyUInt64_1));
80 Assert(MyUInt64_1.Equals((UInt64)(42)));
81 Assert(MyUInt64_1.Equals((SByte)(42)) == false);
82 Assert(MyUInt64_1.Equals(MyUInt64_2) == false);
85 public void TestGetHashCode()
88 MyUInt64_1.GetHashCode();
89 MyUInt64_2.GetHashCode();
90 MyUInt64_3.GetHashCode();
93 Fail("GetHashCode should not raise an exception here");
97 public void TestParse()
99 //test Parse(string s)
100 Assert(MyUInt64_1 == UInt64.Parse(MyString1));
101 Assert(MyUInt64_2 == UInt64.Parse(MyString2));
102 Assert(MyUInt64_3 == UInt64.Parse(MyString3));
105 Fail("Should raise a ArgumentNullException");
107 catch (Exception e) {
108 Assert(typeof(ArgumentNullException) == e.GetType());
111 UInt64.Parse("not-a-number");
112 Fail("Should raise a System.FormatException");
114 catch (Exception e) {
115 Assert(typeof(FormatException) == e.GetType());
117 //test Parse(string s, NumberStyles style)
119 double OverInt = (double)UInt64.MaxValue + 1;
120 UInt64.Parse(OverInt.ToString(), NumberStyles.Float);
121 Fail("Should raise a OverflowException");
123 catch (Exception e) {
124 Assert(typeof(OverflowException) == e.GetType());
127 double OverInt = (double)UInt64.MaxValue + 1;
128 UInt64.Parse(OverInt.ToString(), NumberStyles.Integer);
129 Fail("Should raise a System.FormatException");
131 catch (Exception e) {
132 Assert(typeof(FormatException) == e.GetType());
134 Assert(42 == UInt64.Parse(" $42 ", NumberStyles.Currency));
136 UInt64.Parse("$42", NumberStyles.Integer);
137 Fail("Should raise a FormatException");
139 catch (Exception e) {
140 Assert(typeof(FormatException) == e.GetType());
142 //test Parse(string s, IFormatProvider provider)
143 Assert(42 == UInt64.Parse(" 42 ", Nfi));
145 UInt64.Parse("%42", Nfi);
146 Fail("Should raise a System.FormatException");
148 catch (Exception e) {
149 Assert(typeof(FormatException) == e.GetType());
151 //test Parse(string s, NumberStyles style, IFormatProvider provider)
152 Assert(16 == UInt64.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
154 UInt64.Parse("$42", NumberStyles.Integer, Nfi);
155 Fail("Should raise a System.FormatException");
157 catch (Exception e) {
158 Assert(typeof(FormatException) == e.GetType());
162 public void TestToString()
165 AssertEquals(MyString1, MyUInt64_1.ToString());
166 AssertEquals(MyString2, MyUInt64_2.ToString());
167 AssertEquals(MyString3, MyUInt64_3.ToString());
168 //test ToString(string format)
169 for (int i=0; i < Formats1.Length; i++) {
170 AssertEquals(Results1[i], MyUInt64_2.ToString(Formats1[i]));
171 AssertEquals(Results2[i], MyUInt64_3.ToString(Formats2[i]));
173 //test ToString(string format, IFormatProvider provider);
174 for (int i=0; i < Formats1.Length; i++) {
175 AssertEquals(ResultsNfi1[i], MyUInt64_2.ToString(Formats1[i], Nfi));
176 AssertEquals(ResultsNfi2[i], MyUInt64_3.ToString(Formats2[i], Nfi));
179 MyUInt64_1.ToString("z");
180 Fail("Should raise a System.FormatException");
182 catch (Exception e) {
183 Assert(typeof(FormatException) == e.GetType());