1 // DoubleTest.cs - NUnit Test Cases for the System.Double class
3 // Bob Doan <bdoan@sicompos.com>
5 // (C) Ximian, Inc. http://www.ximian.com
6 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 using System
.Collections
;
11 using System
.Globalization
;
12 using System
.Threading
;
14 using NUnit
.Framework
;
16 namespace MonoTests
.System
19 public class DoubleTest
21 private const Double d_zero
= 0.0;
22 private const Double d_neg
= -1234.5678;
23 private const Double d_pos
= 1234.9999;
24 private const Double d_pos2
= 1234.9999;
25 private const Double d_nan
= Double
.NaN
;
26 private const Double d_pinf
= Double
.PositiveInfinity
;
27 private const Double d_ninf
= Double
.NegativeInfinity
;
28 private const String s
= "What Ever";
29 private NumberFormatInfo Nfi
= NumberFormatInfo
.InvariantInfo
;
31 private string [] string_values
;
32 private string [] string_values_fail
= {
34 "- 1.0", // Inner whitespace
35 "3 5" // Inner whitespace 2
38 private double [] double_values
= {
39 1, .1, 1.1, -12, 44.444432, .000021121,
40 .00001, .223, -221.3233,
41 1.7976931348623157e308
, 1.7976931348623157e308
, -1.7976931348623157e308
,
42 4.9406564584124650e-324,
43 6.28318530717958647692528676655900577,
49 public void GetReady ()
51 string sep
= NumberFormatInfo
.CurrentInfo
.NumberDecimalSeparator
;
52 string_values
= new string [15];
53 string_values
[0] = "1";
54 string_values
[1] = sep
+ "1";
55 string_values
[2] = "1" + sep
+ "1";
56 string_values
[3] = "-12";
57 string_values
[4] = "44" + sep
+ "444432";
58 string_values
[5] = sep
+ "000021121";
59 string_values
[6] = " " + sep
+ "00001";
60 string_values
[7] = " " + sep
+ "223 ";
61 string_values
[8] = " -221" + sep
+ "3233";
62 string_values
[9] = " 1" + sep
+ "7976931348623157e308 ";
63 string_values
[10] = "+1" + sep
+ "7976931348623157E308";
64 string_values
[11] = "-1" + sep
+ "7976931348623157e308";
65 string_values
[12] = "4" + sep
+ "9406564584124650e-324";
66 string_values
[13] = "6" + sep
+ "28318530717958647692528676655900577";
67 string_values
[14] = "1e-05";
71 public void PublicFields ()
73 Assert
.AreEqual (3.9406564584124654e-324, Double
.Epsilon
, "#1");
74 Assert
.AreEqual (1.7976931348623157e+308, Double
.MaxValue
, "#2");
75 Assert
.AreEqual (-1.7976931348623157e+308, Double
.MinValue
, "#3");
76 Assert
.AreEqual ((double) -1.0 / (double) (0.0), Double
.NegativeInfinity
, "#4");
77 Assert
.AreEqual ((double) 1.0 / (double) (0.0), Double
.PositiveInfinity
, "#5");
81 public void CompareTo ()
83 //If you do int foo = d_ninf.CompareTo(d_pinf); Assertion.Assert(".." foo < 0, true) this works.... WHY???
84 Assert
.IsTrue (d_ninf
.CompareTo (d_pinf
) < 0, "#A1");
85 Assert
.IsTrue (d_neg
.CompareTo (d_pos
) < 0, "#A2");
86 Assert
.IsTrue (d_nan
.CompareTo (d_neg
) < 0, "#A3");
88 Assert
.AreEqual (0, d_pos
.CompareTo (d_pos2
), "#B1");
89 Assert
.AreEqual (0, d_pinf
.CompareTo (d_pinf
), "#B2");
90 Assert
.AreEqual (0, d_ninf
.CompareTo (d_ninf
), "#B3");
91 Assert
.AreEqual (0, d_nan
.CompareTo (d_nan
), "#B4");
93 Assert
.IsTrue (d_pos
.CompareTo (d_neg
) > 0, "#C1");
94 Assert
.IsTrue (d_pos
.CompareTo (d_nan
) > 0, "#C2");
95 Assert
.IsTrue (d_pos
.CompareTo (null) > 0, "#C3");
100 } catch (ArgumentException ex
) {
101 Assert
.AreEqual (typeof (ArgumentException
), ex
.GetType (), "#D2");
106 public void Equals ()
108 Assert
.IsTrue (d_pos
.Equals (d_pos2
), "#1");
109 Assert
.IsFalse (d_pos
.Equals (d_neg
), "#2");
110 Assert
.IsFalse (d_pos
.Equals (s
), "#3");
114 public void TestTypeCode ()
116 Assert
.AreEqual (TypeCode
.Double
, d_pos
.GetTypeCode ());
120 public void IsInfinity ()
122 Assert
.IsTrue (Double
.IsInfinity (Double
.PositiveInfinity
), "#1");
123 Assert
.IsTrue (Double
.IsInfinity (Double
.NegativeInfinity
), "#2");
124 Assert
.IsFalse (Double
.IsInfinity (12), "#3");
130 Assert
.IsTrue (Double
.IsNaN (Double
.NaN
), "#1");
131 Assert
.IsFalse (Double
.IsNaN (12), "#2");
132 Assert
.IsFalse (Double
.IsNaN (Double
.PositiveInfinity
), "#3");
136 public void IsNegativeInfinity ()
138 Assert
.IsTrue (Double
.IsNegativeInfinity (Double
.NegativeInfinity
), "#1");
139 Assert
.IsFalse (Double
.IsNegativeInfinity (12), "#2");
143 public void IsPositiveInfinity ()
145 Assert
.IsTrue (Double
.IsPositiveInfinity (Double
.PositiveInfinity
), "#1");
146 Assert
.IsFalse (Double
.IsPositiveInfinity (12), "#2");
154 for (i
= 0; i
< string_values
.Length
; i
++) {
155 Assert
.AreEqual (double_values
[i
], Double
.Parse (string_values
[i
]), "#A1");
157 } catch (Exception e
) {
158 Assert
.Fail ("#A2: i=" + i
+ " failed with e = " + e
.ToString ());
162 Assert
.AreEqual (10.1111, Double
.Parse (" 10.1111 ", NumberStyles
.Float
, Nfi
), "#B1");
163 } catch (Exception e
) {
164 Assert
.Fail ("#B2: Parse Failed NumberStyles.Float with e = " + e
.ToString ());
168 Assert
.AreEqual (1234.5678, Double
.Parse ("1,234.5678", NumberStyles
.Float
| NumberStyles
.AllowThousands
, Nfi
), "#C1");
169 } catch (Exception e
) {
170 Assert
.Fail ("#C2: Parse Failed NumberStyles.AllowThousands with e = " + e
.ToString ());
176 } catch (ArgumentNullException ex
) {
177 Assert
.AreEqual (typeof (ArgumentNullException
), ex
.GetType (), "#D2");
178 Assert
.IsNull (ex
.InnerException
, "#D3");
179 Assert
.IsNotNull (ex
.Message
, "#D4");
180 Assert
.IsNotNull (ex
.ParamName
, "#D5");
184 Double
.Parse ("save the elk");
186 } catch (FormatException ex
) {
187 Assert
.AreEqual (typeof (FormatException
), ex
.GetType (), "#E2");
188 Assert
.IsNull (ex
.InnerException
, "#E3");
189 Assert
.IsNotNull (ex
.Message
, "#E4");
192 string sep
= NumberFormatInfo
.CurrentInfo
.NumberDecimalSeparator
;
195 ovf_plus
= Double
.Parse ("1" + sep
+ "79769313486232e308");
197 } catch (OverflowException ex
) {
198 Assert
.AreEqual (typeof (OverflowException
), ex
.GetType (), "#F2");
199 Assert
.IsNull (ex
.InnerException
, "#F3");
200 Assert
.IsNotNull (ex
.Message
, "#F4");
204 Double
.Parse ("-1" + sep
+ "79769313486232e308");
206 } catch (OverflowException ex
) {
207 Assert
.AreEqual (typeof (OverflowException
), ex
.GetType (), "#G2");
208 Assert
.IsNull (ex
.InnerException
, "#G3");
209 Assert
.IsNotNull (ex
.Message
, "#G4");
212 for (i
= 0; i
< string_values_fail
.Length
; ++i
) {
214 Double
.Parse (string_values_fail
[i
]);
215 Assert
.Fail ("#H1: " + string_values_fail
[i
]);
216 } catch (FormatException ex
) {
217 Assert
.AreEqual (typeof (FormatException
), ex
.GetType (), "#H2");
218 Assert
.IsNull (ex
.InnerException
, "#H3");
219 Assert
.IsNotNull (ex
.Message
, "#H4");
225 public void Parse_Whitespace ()
230 } catch (FormatException ex
) {
231 Assert
.AreEqual (typeof (FormatException
), ex
.GetType (), "#2");
232 Assert
.IsNull (ex
.InnerException
, "#3");
233 Assert
.IsNotNull (ex
.Message
, "#4");
237 [Test
] // //bug #81777
238 public void Parse_TrailingGarbage ()
241 double.Parse ("22 foo");
243 } catch (FormatException ex
) {
244 Assert
.AreEqual (typeof (FormatException
), ex
.GetType (), "#2");
245 Assert
.IsNull (ex
.InnerException
, "#3");
246 Assert
.IsNotNull (ex
.Message
, "#4");
251 public void TestToString ()
257 } catch (FormatException ex
) {
258 Assert
.AreEqual (typeof (FormatException
), ex
.GetType (), "#A2");
259 Assert
.IsNull (ex
.InnerException
, "#A3");
260 Assert
.IsNotNull (ex
.Message
, "#A4");
267 } catch (FormatException ex
) {
268 Assert
.AreEqual (typeof (FormatException
), ex
.GetType (), "#B2");
269 Assert
.IsNull (ex
.InnerException
, "#B3");
270 Assert
.IsNotNull (ex
.Message
, "#B4");
273 CustomFormatHelper ();
276 private class Element
279 public string format
;
280 public string result
;
282 public Element (double value, string format
, string result
)
285 this.format
= format
;
286 this.result
= result
;
290 public void CustomFormatHelper ()
292 NumberFormatInfo nfi
= new NumberFormatInfo ();
294 nfi
.NaNSymbol
= "NaN";
295 nfi
.PositiveSign
= "+";
296 nfi
.NegativeSign
= "-";
297 nfi
.PerMilleSymbol
= "x";
298 nfi
.PositiveInfinitySymbol
= "Infinity";
299 nfi
.NegativeInfinitySymbol
= "-Infinity";
301 nfi
.NumberDecimalDigits
= 5;
302 nfi
.NumberDecimalSeparator
= ".";
303 nfi
.NumberGroupSeparator
= ",";
304 nfi
.NumberGroupSizes
= new int [] { 3 }
;
305 nfi
.NumberNegativePattern
= 2;
307 nfi
.CurrencyDecimalDigits
= 2;
308 nfi
.CurrencyDecimalSeparator
= ".";
309 nfi
.CurrencyGroupSeparator
= ",";
310 nfi
.CurrencyGroupSizes
= new int [] { 3 }
;
311 nfi
.CurrencyNegativePattern
= 8;
312 nfi
.CurrencyPositivePattern
= 3;
313 nfi
.CurrencySymbol
= "$";
315 nfi
.PercentDecimalDigits
= 5;
316 nfi
.PercentDecimalSeparator
= ".";
317 nfi
.PercentGroupSeparator
= ",";
318 nfi
.PercentGroupSizes
= new int [] { 3 }
;
319 nfi
.PercentNegativePattern
= 0;
320 nfi
.PercentPositivePattern
= 0;
321 nfi
.PercentSymbol
= "%";
323 ArrayList list
= new ArrayList ();
324 list
.Add (new Element (123d
, "#####", "123"));
325 list
.Add (new Element (123d
, "00000", "00123"));
326 list
.Add (new Element (123d
, "(###) ### - ####", "() - 123"));
327 list
.Add (new Element (123d
, "#.##", "123"));
328 list
.Add (new Element (123d
, "0.00", "123.00"));
329 list
.Add (new Element (123d
, "00.00", "123.00"));
330 list
.Add (new Element (123d
, "#,#", "123"));
331 list
.Add (new Element (123d
, "#,,", ""));
332 list
.Add (new Element (123d
, "#,,,", ""));
333 list
.Add (new Element (123d
, "#,##0,,", "0"));
334 list
.Add (new Element (123d
, "#0.##%", "12300%"));
335 list
.Add (new Element (123d
, "0.###E+0", "1.23E+2"));
336 list
.Add (new Element (123d
, "0.###E+000", "1.23E+002"));
337 list
.Add (new Element (123d
, "0.###E-000", "1.23E002"));
338 list
.Add (new Element (123d
, "[##-##-##]", "[-1-23]"));
339 list
.Add (new Element (123d
, "##;(##)", "123"));
340 list
.Add (new Element (123d
, "##;(##)", "123"));
341 list
.Add (new Element (1234567890d
, "#####", "1234567890"));
342 list
.Add (new Element (1234567890d
, "00000", "1234567890"));
343 list
.Add (new Element (1234567890d
,
344 "(###) ### - ####", "(123) 456 - 7890"));
345 list
.Add (new Element (1234567890d
, "#.##", "1234567890"));
346 list
.Add (new Element (1234567890d
, "0.00", "1234567890.00"));
347 list
.Add (new Element (1234567890d
, "00.00", "1234567890.00"));
348 list
.Add (new Element (1234567890d
, "#,#", "1,234,567,890"));
349 list
.Add (new Element (1234567890d
, "#,,", "1235"));
350 list
.Add (new Element (1234567890d
, "#,,,", "1"));
351 list
.Add (new Element (1234567890d
, "#,##0,,", "1,235"));
352 list
.Add (new Element (1234567890d
, "#0.##%", "123456789000%"));
353 list
.Add (new Element (1234567890d
, "0.###E+0", "1.235E+9"));
354 list
.Add (new Element (1234567890d
, "0.###E+000", "1.235E+009"));
355 list
.Add (new Element (1234567890d
, "0.###E-000", "1.235E009"));
356 list
.Add (new Element (1234567890d
, "[##-##-##]", "[123456-78-90]"));
357 list
.Add (new Element (1234567890d
, "##;(##)", "1234567890"));
358 list
.Add (new Element (1234567890d
, "##;(##)", "1234567890"));
359 list
.Add (new Element (1.2d
, "#####", "1"));
360 list
.Add (new Element (1.2d
, "00000", "00001"));
361 list
.Add (new Element (1.2d
, "(###) ### - ####", "() - 1"));
362 list
.Add (new Element (1.2d
, "#.##", "1.2"));
363 list
.Add (new Element (1.2d
, "0.00", "1.20"));
364 list
.Add (new Element (1.2d
, "00.00", "01.20"));
365 list
.Add (new Element (1.2d
, "#,#", "1"));
366 list
.Add (new Element (1.2d
, "#,,", ""));
367 list
.Add (new Element (1.2d
, "#,,,", ""));
368 list
.Add (new Element (1.2d
, "#,##0,,", "0"));
369 list
.Add (new Element (1.2d
, "#0.##%", "120%"));
370 list
.Add (new Element (1.2d
, "0.###E+0", "1.2E+0"));
371 list
.Add (new Element (1.2d
, "0.###E+000", "1.2E+000"));
372 list
.Add (new Element (1.2d
, "0.###E-000", "1.2E000"));
373 list
.Add (new Element (1.2d
, "[##-##-##]", "[--1]"));
374 list
.Add (new Element (1.2d
, "##;(##)", "1"));
375 list
.Add (new Element (1.2d
, "##;(##)", "1"));
376 list
.Add (new Element (0.086d
, "#####", ""));
377 list
.Add (new Element (0.086d
, "00000", "00000"));
378 list
.Add (new Element (0.086d
, "(###) ### - ####", "() - "));
379 list
.Add (new Element (0.086d
, "#.##", ".09"));
380 list
.Add (new Element (0.086d
, "#.#", ".1"));
381 list
.Add (new Element (0.086d
, "0.00", "0.09"));
382 list
.Add (new Element (0.086d
, "00.00", "00.09"));
383 list
.Add (new Element (0.086d
, "#,#", ""));
384 list
.Add (new Element (0.086d
, "#,,", ""));
385 list
.Add (new Element (0.086d
, "#,,,", ""));
386 list
.Add (new Element (0.086d
, "#,##0,,", "0"));
387 list
.Add (new Element (0.086d
, "#0.##%", "8.6%"));
388 list
.Add (new Element (0.086d
, "0.###E+0", "8.6E-2"));
389 list
.Add (new Element (0.086d
, "0.###E+000", "8.6E-002"));
390 list
.Add (new Element (0.086d
, "0.###E-000", "8.6E-002"));
391 list
.Add (new Element (0.086d
, "[##-##-##]", "[--]"));
392 list
.Add (new Element (0.086d
, "##;(##)", ""));
393 list
.Add (new Element (0.086d
, "##;(##)", ""));
394 list
.Add (new Element (86000d
, "#####", "86000"));
395 list
.Add (new Element (86000d
, "00000", "86000"));
396 list
.Add (new Element (86000d
, "(###) ### - ####", "() 8 - 6000"));
397 list
.Add (new Element (86000d
, "#.##", "86000"));
398 list
.Add (new Element (86000d
, "0.00", "86000.00"));
399 list
.Add (new Element (86000d
, "00.00", "86000.00"));
400 list
.Add (new Element (86000d
, "#,#", "86,000"));
401 list
.Add (new Element (86000d
, "#,,", ""));
402 list
.Add (new Element (86000d
, "#,,,", ""));
403 list
.Add (new Element (86000d
, "#,##0,,", "0"));
404 list
.Add (new Element (86000d
, "#0.##%", "8600000%"));
405 list
.Add (new Element (86000d
, "0.###E+0", "8.6E+4"));
406 list
.Add (new Element (86000d
, "0.###E+000", "8.6E+004"));
407 list
.Add (new Element (86000d
, "0.###E-000", "8.6E004"));
408 list
.Add (new Element (86000d
, "[##-##-##]", "[8-60-00]"));
409 list
.Add (new Element (86000d
, "##;(##)", "86000"));
410 list
.Add (new Element (86000d
, "##;(##)", "86000"));
411 list
.Add (new Element (123456d
, "#####", "123456"));
412 list
.Add (new Element (123456d
, "00000", "123456"));
413 list
.Add (new Element (123456d
, "(###) ### - ####", "() 12 - 3456"));
414 list
.Add (new Element (123456d
, "#.##", "123456"));
415 list
.Add (new Element (123456d
, "0.00", "123456.00"));
416 list
.Add (new Element (123456d
, "00.00", "123456.00"));
417 list
.Add (new Element (123456d
, "#,#", "123,456"));
418 list
.Add (new Element (123456d
, "#,,", ""));
419 list
.Add (new Element (123456d
, "#,,,", ""));
420 list
.Add (new Element (123456d
, "#,##0,,", "0"));
421 list
.Add (new Element (123456d
, "#0.##%", "12345600%"));
422 list
.Add (new Element (123456d
, "0.###E+0", "1.235E+5"));
423 list
.Add (new Element (123456d
, "0.###E+000", "1.235E+005"));
424 list
.Add (new Element (123456d
, "0.###E-000", "1.235E005"));
425 list
.Add (new Element (123456d
, "[##-##-##]", "[12-34-56]"));
426 list
.Add (new Element (123456d
, "##;(##)", "123456"));
427 list
.Add (new Element (123456d
, "##;(##)", "123456"));
428 list
.Add (new Element (1234d
, "#####", "1234"));
429 list
.Add (new Element (1234d
, "00000", "01234"));
430 list
.Add (new Element (1234d
, "(###) ### - ####", "() - 1234"));
431 list
.Add (new Element (1234d
, "#.##", "1234"));
432 list
.Add (new Element (1234d
, "0.00", "1234.00"));
433 list
.Add (new Element (1234d
, "00.00", "1234.00"));
434 list
.Add (new Element (1234d
, "#,#", "1,234"));
435 list
.Add (new Element (1234d
, "#,,", ""));
436 list
.Add (new Element (1234d
, "#,,,", ""));
437 list
.Add (new Element (1234d
, "#,##0,,", "0"));
438 list
.Add (new Element (1234d
, "#0.##%", "123400%"));
439 list
.Add (new Element (1234d
, "0.###E+0", "1.234E+3"));
440 list
.Add (new Element (1234d
, "0.###E+000", "1.234E+003"));
441 list
.Add (new Element (1234d
, "0.###E-000", "1.234E003"));
442 list
.Add (new Element (1234d
, "[##-##-##]", "[-12-34]"));
443 list
.Add (new Element (1234d
, "##;(##)", "1234"));
444 list
.Add (new Element (1234d
, "##;(##)", "1234"));
445 list
.Add (new Element (-1234d
, "#####", "-1234"));
446 list
.Add (new Element (-1234d
, "00000", "-01234"));
447 list
.Add (new Element (-1234d
, "(###) ### - ####", "-() - 1234"));
448 list
.Add (new Element (-1234d
, "#.##", "-1234"));
449 list
.Add (new Element (-1234d
, "0.00", "-1234.00"));
450 list
.Add (new Element (-1234d
, "00.00", "-1234.00"));
451 list
.Add (new Element (-1234d
, "#,#", "-1,234"));
452 list
.Add (new Element (-1234d
, "#,,", ""));
453 list
.Add (new Element (-1234d
, "#,,,", ""));
454 list
.Add (new Element (-1234d
, "#,##0,,", "0"));
455 list
.Add (new Element (-1234d
, "#0.##%", "-123400%"));
456 list
.Add (new Element (-1234d
, "0.###E+0", "-1.234E+3"));
457 list
.Add (new Element (-1234d
, "0.###E+000", "-1.234E+003"));
458 list
.Add (new Element (-1234d
, "0.###E-000", "-1.234E003"));
459 list
.Add (new Element (-1234d
, "[##-##-##]", "-[-12-34]"));
460 list
.Add (new Element (-1234d
, "##;(##)", "(1234)"));
461 list
.Add (new Element (-1234d
, "##;(##)", "(1234)"));
462 list
.Add (new Element (12345678901234567890.123d
,
463 "#####", "12345678901234600000"));
464 list
.Add (new Element (12345678901234567890.123d
,
465 "00000", "12345678901234600000"));
466 list
.Add (new Element (12345678901234567890.123d
,
467 "(###) ### - ####", "(1234567890123) 460 - 0000"));
468 list
.Add (new Element (12345678901234567890.123d
,
469 "#.##", "12345678901234600000"));
470 list
.Add (new Element (12345678901234567890.123d
,
471 "0.00", "12345678901234600000.00"));
472 list
.Add (new Element (12345678901234567890.123d
,
473 "00.00", "12345678901234600000.00"));
474 list
.Add (new Element (12345678901234567890.123d
,
475 "#,#", "12,345,678,901,234,600,000"));
476 list
.Add (new Element (12345678901234567890.123d
,
477 "#,,", "12345678901235"));
478 list
.Add (new Element (12345678901234567890.123d
,
479 "#,,,", "12345678901"));
480 list
.Add (new Element (12345678901234567890.123d
,
481 "#,##0,,", "12,345,678,901,235"));
482 list
.Add (new Element (12345678901234567890.123d
,
483 "#0.##%", "1234567890123460000000%"));
484 list
.Add (new Element (12345678901234567890.123d
,
485 "0.###E+0", "1.235E+19"));
486 list
.Add (new Element (12345678901234567890.123d
,
487 "0.###E+000", "1.235E+019"));
488 list
.Add (new Element (12345678901234567890.123d
,
489 "0.###E-000", "1.235E019"));
490 list
.Add (new Element (12345678901234567890.123d
,
491 "[##-##-##]", "[1234567890123460-00-00]"));
492 list
.Add (new Element (12345678901234567890.123d
,
493 "##;(##)", "12345678901234600000"));
494 list
.Add (new Element (12345678901234567890.123d
,
495 "##;(##)", "12345678901234600000"));
496 foreach (Element e
in list
) {
497 Assert
.AreEqual (e
.result
, e
.value.ToString (e
.format
, nfi
),
498 "ToString Failed: '" + e
.value + "' Should be \"" + e
.result
+ "\" with \"" + e
.format
+ "\"");
503 public void ToString_Defaults ()
505 CultureInfo originalCulture
= CultureInfo
.CurrentCulture
;
506 Thread
.CurrentThread
.CurrentCulture
= new CultureInfo ("nl-BE");
509 // everything defaults to "G"
510 string def
= i
.ToString ("G");
511 Assert
.AreEqual (def
, i
.ToString (), "#1");
512 Assert
.AreEqual (def
, i
.ToString ((IFormatProvider
) null), "#2");
513 Assert
.AreEqual (def
, i
.ToString ((string) null), "#3");
514 Assert
.AreEqual (def
, i
.ToString (String
.Empty
), "#4");
515 Assert
.AreEqual (def
, i
.ToString (null, null), "#5");
516 Assert
.AreEqual (def
, i
.ToString (String
.Empty
, null), "#6");
517 Assert
.AreEqual ("254,9", def
, "#7");
519 // restore original culture
520 Thread
.CurrentThread
.CurrentCulture
= originalCulture
;
525 public void TestRoundtrip () // bug #320433
527 Assert
.AreEqual ("10.78", 10.78.ToString ("R", NumberFormatInfo
.InvariantInfo
));
531 public void LongLongValueRoundtrip ()
533 CultureInfo originalCulture
= CultureInfo
.CurrentCulture
;
534 Thread
.CurrentThread
.CurrentCulture
= new CultureInfo ("nl-BE");
536 double d
= 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000222;
537 Assert
.AreEqual ("1,97626258336499E-323", d
.ToString ("R"));
539 // restore original culture
540 Thread
.CurrentThread
.CurrentCulture
= originalCulture
;
546 [ExpectedException (typeof (ArgumentException
))]
548 [Category ("NotWorking")]
549 // MS accept hex values under 1.x but the results neither match the long value
550 // nor the value of a 64bits double
552 public void HexNumber_WithHexToParse ()
556 Assert
.IsTrue (Double
.TryParse ("0dead", NumberStyles
.HexNumber
, null, out d
), "#1");
557 Assert
.AreEqual (57842, d
, "#2");
562 [ExpectedException (typeof (ArgumentException
))]
564 [Category ("NotWorking")]
565 // MS accept hex values under 1.x but the results neither match the long value
566 // nor the value of a 64bits double
568 public void HexNumber_NoHexToParse ()
571 Assert
.IsTrue (Double
.TryParse ("0", NumberStyles
.HexNumber
, null, out d
), "#1");
572 Assert
.AreEqual (0, d
, "#2");
576 public void TryParseBug78546 ()
579 Assert
.IsFalse (Double
.TryParse ("error", NumberStyles
.Integer
,
584 public void TryParse_NonDigitStrings ()
587 Assert
.IsFalse (Double
.TryParse ("string", NumberStyles
.Any
, null, out value), "#1");
588 Assert
.IsFalse (Double
.TryParse ("with whitespace", NumberStyles
.Any
, null, out value), "#2");
591 Assert
.IsFalse (Double
.TryParse ("string", out value), "#3");
592 Assert
.IsFalse (Double
.TryParse ("with whitespace", out value), "#4");
598 public void ParseCurrency ()
600 CultureInfo originalCulture
= CultureInfo
.CurrentCulture
;
601 Thread
.CurrentThread
.CurrentCulture
= new CultureInfo ("en-US");
603 NumberFormatInfo f
= NumberFormatInfo
.CurrentInfo
;
604 double d
= double.Parse ("$4.56", NumberStyles
.Currency
, f
);
605 Assert
.AreEqual (4.56, d
);
607 // restore original culture
608 Thread
.CurrentThread
.CurrentCulture
= originalCulture
;