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(string name) : base(name) {}
44 protected override void SetUp()
48 public static ITest Suite {
50 return new TestSuite(typeof(UInt64Test));
54 public void TestMinMax()
57 AssertEquals(UInt64.MinValue, MyUInt64_2);
58 AssertEquals(UInt64.MaxValue, MyUInt64_3);
61 public void TestCompareTo()
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);
68 MyUInt64_2.CompareTo((Int16)100);
69 Fail("Should raise a System.ArgumentException");
72 Assert(typeof(ArgumentException) == e.GetType());
76 public void TestEquals()
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);
84 public void TestGetHashCode()
87 MyUInt64_1.GetHashCode();
88 MyUInt64_2.GetHashCode();
89 MyUInt64_3.GetHashCode();
92 Fail("GetHashCode should not raise an exception here");
96 public void TestParse()
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));
104 Fail("Should raise a ArgumentNullException");
106 catch (Exception e) {
107 Assert(typeof(ArgumentNullException) == e.GetType());
110 UInt64.Parse("not-a-number");
111 Fail("Should raise a System.FormatException");
113 catch (Exception e) {
114 Assert(typeof(FormatException) == e.GetType());
116 //test Parse(string s, NumberStyles style)
118 double OverInt = (double)UInt64.MaxValue + 1;
119 UInt64.Parse(OverInt.ToString(), NumberStyles.Float);
120 Fail("Should raise a OverflowException");
122 catch (Exception e) {
123 Assert(typeof(OverflowException) == e.GetType());
126 double OverInt = (double)UInt64.MaxValue + 1;
127 UInt64.Parse(OverInt.ToString(), NumberStyles.Integer);
128 Fail("Should raise a System.FormatException");
130 catch (Exception e) {
131 Assert(typeof(FormatException) == e.GetType());
133 Assert(42 == UInt64.Parse(" $42 ", NumberStyles.Currency));
135 UInt64.Parse("$42", NumberStyles.Integer);
136 Fail("Should raise a FormatException");
138 catch (Exception e) {
139 Assert(typeof(FormatException) == e.GetType());
141 //test Parse(string s, IFormatProvider provider)
142 Assert(42 == UInt64.Parse(" 42 ", Nfi));
144 UInt64.Parse("%42", Nfi);
145 Fail("Should raise a System.FormatException");
147 catch (Exception e) {
148 Assert(typeof(FormatException) == e.GetType());
150 //test Parse(string s, NumberStyles style, IFormatProvider provider)
151 Assert(16 == UInt64.Parse(" 10 ", NumberStyles.HexNumber, Nfi));
153 UInt64.Parse("$42", NumberStyles.Integer, Nfi);
154 Fail("Should raise a System.FormatException");
156 catch (Exception e) {
157 Assert(typeof(FormatException) == e.GetType());
161 public void TestToString()
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]));
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));
178 MyUInt64_1.ToString("z");
179 Fail("Should raise a System.FormatException");
181 catch (Exception e) {
182 Assert(typeof(FormatException) == e.GetType());