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