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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
//
// IntegerFormatterTest.cs
//
// Author:
// Derek Holden (dholden@draper.com)
//
// (C) Derek Holden dholden@draper.com
//
//
// Simple test for IntegerFormatter.
//
// Pull out IntegerFormatter.cs and NumberFormatInfo.cs and compile w/
// csc /nowarn:1595 /nowarn:0168 /out:test.exe *.cs
//
using System;
using System.Globalization;
namespace System {
public class Test {
public static void Main() {
bool checkShorts = true; // false;
bool checkInts = true; // false;
bool checkLongs = true; // false;
bool checkUShorts = true; // false;
bool checkUInts = true; // false;
bool checkULongs = true; // false;
bool checkBytes = true; // false;
bool checkSBytes = true; // false;
string[] formats = {
"C", "C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9", "C10", "C99",
"D", "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "D10", "D99",
"E", "E0", "E1", "E2", "E3", "E4", "E5", "E6", "E7", "E8", "E9", "E10", "E99",
"F", "F0", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F99",
"G", "G0", "G1", "G2", "G3", "G4", "G5", "G6", "G7", "G8", "G9", "G10", "G99",
"N", "N0", "N1", "N2", "N3", "N4", "N5", "N6", "N7", "N8", "N9", "N10", "N99",
"P", "P0", "P1", "P2", "P3", "P4", "P5", "P6", "P7", "P8", "P9", "P10", "P99",
//"R", "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8", "R9", "R10", "R99",
"X", "X0", "X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10", "X99"
};
short[] shortBoundries = { Int16.MinValue, Int16.MaxValue };
int[] intBoundries = { Int32.MinValue, Int32.MaxValue };
long[] longBoundries = { Int64.MinValue, Int64.MaxValue };
ushort[] ushortBoundries = { UInt16.MinValue, UInt16.MaxValue };
uint[] uintBoundries = { UInt32.MinValue, UInt32.MaxValue };
ulong[] ulongBoundries = { UInt64.MinValue, UInt64.MaxValue };
byte[] byteBoundries = { Byte.MinValue, Byte.MaxValue };
sbyte[] sbyteBoundries = { SByte.MinValue, SByte.MaxValue };
int count;
string s1, s2;
NumberFormatInfo nfi = new NumberFormatInfo();
// shorts
if (checkShorts) {
count = 0;
Console.WriteLine ("Checking shorts...");
for (short n = -1000; n < 1000; n++) {
for (int idx = 0; idx < formats.Length; idx++) {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
}
}
Console.WriteLine ("Checking boundries...");
foreach (short n in shortBoundries) {
for (int idx = 0; idx < formats.Length; idx++) {
try {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
} catch (Exception e) {
Console.WriteLine ("Exception Caught! Number: {0} Format: {1}", n, formats[idx]);
count++;
}
}
}
if (count == 0)
Console.WriteLine ("Passed all tests\n");
else Console.WriteLine ("Failed on {0} tests\n", count);
}
// ints
if (checkInts) {
count = 0;
Console.WriteLine ("Checking ints...");
for (int n = -10000; n < 10000; n++) {
for (int idx = 0; idx < formats.Length; idx++) {
try {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
} catch (Exception e) {
Console.WriteLine ("Exception Caught! Number: {0} Format: {1}", n, formats[idx]);
}
}
}
Console.WriteLine ("Checking boundries...");
foreach (int n in intBoundries) {
for (int idx = 0; idx < formats.Length; idx++) {
try {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
} catch (Exception e) {
Console.WriteLine ("Exception Caught! Number: {0} Format: {1}", n, formats[idx]);
count++;
}
}
}
if (count == 0)
Console.WriteLine ("Passed all tests\n");
else Console.WriteLine ("Failed on {0} tests\n", count);
}
// longs
if (checkLongs) {
count = 0;
Console.WriteLine ("Checking longs...");
for (long n = -10000; n < 10000; n++) {
for (int idx = 0; idx < formats.Length; idx++) {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
}
}
Console.WriteLine ("Checking boundries...");
foreach (long n in longBoundries) {
for (int idx = 0; idx < formats.Length; idx++) {
try {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
} catch (Exception e) {
Console.WriteLine ("Exception Caught! Number: {0} Format: {1}", n, formats[idx]);
count++;
}
}
}
if (count == 0)
Console.WriteLine ("Passed all tests\n");
else Console.WriteLine ("Failed on {0} tests\n", count);
}
// ushorts
if (checkUShorts) {
count = 0;
Console.WriteLine ("Checking ushorts...");
for (ushort n = 0; n < 1000; n++) {
for (int idx = 0; idx < formats.Length; idx++) {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
}
}
Console.WriteLine ("Checking boundries...");
foreach (ushort n in shortBoundries) {
for (int idx = 0; idx < formats.Length; idx++) {
try {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
} catch (Exception e) {
Console.WriteLine ("Exception Caught! Number: {0} Format: {1}", n, formats[idx]);
count++;
}
}
}
if (count == 0)
Console.WriteLine ("Passed all tests\n");
else Console.WriteLine ("Failed on {0} tests\n", count);
}
// uint
if (checkUInts) {
count = 0;
Console.WriteLine ("Checking uints...");
for (uint n = 0; n < 10000; n++) {
for (int idx = 0; idx < formats.Length; idx++) {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
}
}
Console.WriteLine ("Checking boundries...");
foreach (uint n in uintBoundries) {
for (int idx = 0; idx < formats.Length; idx++) {
try {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
} catch (Exception e) {
Console.WriteLine ("Exception Caught! Number: {0} Format: {1}", n, formats[idx]);
count++;
}
}
}
if (count == 0)
Console.WriteLine ("Passed all tests\n");
else Console.WriteLine ("Failed on {0} tests\n", count);
}
// ulong
if (checkULongs) {
count = 0;
Console.WriteLine ("Checking ulongs...");
for (ulong n = 0; n < 10000; n++) {
for (int idx = 0; idx < formats.Length; idx++) {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
}
}
Console.WriteLine ("Checking boundries...");
foreach (ulong n in ulongBoundries) {
for (int idx = 0; idx < formats.Length; idx++) {
try {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
} catch (Exception e) {
Console.WriteLine ("Exception Caught! Number: {0} Format: {1}", n, formats[idx]);
count++;
}
}
}
if (count == 0)
Console.WriteLine ("Passed all tests\n");
else Console.WriteLine ("Failed on {0} tests\n", count);
}
// bytes
if (checkBytes) {
count = 0;
Console.WriteLine ("Checking bytes...");
for (byte n = 0; n < 100; n++) {
for (int idx = 0; idx < formats.Length; idx++) {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
}
}
Console.WriteLine ("Checking boundries...");
foreach (byte n in byteBoundries) {
for (int idx = 0; idx < formats.Length; idx++) {
try {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
} catch (Exception e) {
Console.WriteLine ("Exception Caught! Number: {0} Format: {1}", n, formats[idx]);
count++;
}
}
}
if (count == 0)
Console.WriteLine ("Passed all tests\n");
else Console.WriteLine ("Failed on {0} tests\n", count);
}
// sbytes
if (checkSBytes) {
count = 0;
Console.WriteLine ("Checking sbytes...");
for (sbyte n = -100; n < 100; n++) {
for (int idx = 0; idx < formats.Length; idx++) {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
}
}
Console.WriteLine ("Checking boundries...");
foreach (sbyte n in sbyteBoundries) {
for (int idx = 0; idx < formats.Length; idx++) {
try {
s1 = n.ToString (formats[idx]);
s2 = IntegerFormatter.NumberToString (formats[idx], nfi, n);
if (!s2.Equals (s1)) {
Console.WriteLine ("Number: {0} Format: {1} MS: ({2}) Me: ({3})",
n, formats[idx], s1, s2);
count++;
}
} catch (Exception e) {
Console.WriteLine ("Exception Caught! Number: {0} Format: {1}", n, formats[idx]);
count++;
}
}
}
if (count == 0)
Console.WriteLine ("Passed all tests\n");
else Console.WriteLine ("Failed on {0} tests\n", count);
}
}
}
}
|