This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / class / corlib / Test / System / MathTest.cs
1 // MathTest.cs
2 //
3 // Jon Guymon (guymon@slackworks.com)
4 // Pedro Martínez Juliá (yoros@wanadoo.es)
5 //
6 // (C) 2002 Jon Guymon
7 // Copyright (C) 2003 Pedro Martínez Juliá <yoros@wanadoo.es>
8 // Copyright (C) 2004 Novell (http://www.novell.com)
9 // 
10
11 using System;
12 using NUnit.Framework;
13
14 namespace MonoTests.System 
15 {
16
17 [TestFixture]
18 public class MathTest : Assertion {
19
20         static double x = 0.1234;
21         static double y = 12.345;
22
23         public void TestDecimalAbs() {
24                 decimal a = -9.0M;
25
26                 Assert(9.0M == Math.Abs(a));
27                 Assert(Decimal.MaxValue == Math.Abs(Decimal.MaxValue));
28                 Assert(Decimal.MaxValue == Math.Abs(Decimal.MinValue));
29                 Assert(Decimal.Zero == Math.Abs(Decimal.Zero));
30                 Assert(Decimal.One == Math.Abs(Decimal.One));
31                 Assert(Decimal.One == Math.Abs(Decimal.MinusOne));
32         }
33
34
35         public void TestDoubleAbs() {
36                 double a = -9.0D;
37                 Assert(9.0D == Math.Abs(a));
38                 Assert(0.0D == Math.Abs(0.0D));
39                 Assert(Double.MaxValue == Math.Abs(Double.MaxValue));
40                 Assert(Double.MaxValue == Math.Abs(Double.MinValue));
41                 Assert(Double.IsPositiveInfinity(Math.Abs(Double.PositiveInfinity)));
42                 Assert(Double.IsPositiveInfinity(Math.Abs(Double.NegativeInfinity)));
43                 Assert(Double.IsNaN(Math.Abs(Double.NaN)));
44         }
45
46         public void TestFloatAbs() {
47                 float a = -9.0F;
48
49                 Assert(9.0F == Math.Abs(a));
50                 Assert(0.0F == Math.Abs(0.0F));
51                 Assert(Single.MaxValue == Math.Abs(Single.MaxValue));
52                 Assert(Single.MaxValue == Math.Abs(Single.MinValue));
53                 Assert(Single.PositiveInfinity == Math.Abs(Single.PositiveInfinity));
54                 Assert(Single.PositiveInfinity == Math.Abs(Single.NegativeInfinity));
55                 Assert(Single.IsNaN(Math.Abs(Single.NaN)));
56         }
57
58         public void TestLongAbs() {
59                 long a = -9L;
60                 long b = Int64.MinValue;
61
62                 Assert(9L == Math.Abs(a));
63                 try {
64                         Math.Abs(b);
65                         Fail("Should raise System.OverflowException");
66                 } catch(Exception e) {
67                         Assert(typeof(OverflowException) == e.GetType());
68                 }
69                 Assert(Int64.MaxValue == Math.Abs(Int64.MaxValue));
70         }
71
72         public void TestIntAbs() {
73                 int a = -9;
74                 int b = Int32.MinValue;
75
76                 Assert(9 == Math.Abs(a));
77                 try {
78                         Math.Abs(b);
79                         Fail("Should raise System.OverflowException");
80                 } catch(Exception e) {
81                         Assert(typeof(OverflowException) == e.GetType());
82                 }
83                 Assert(Int32.MaxValue == Math.Abs(Int32.MaxValue));
84         }
85
86         public void TestSbyteAbs() {
87                 sbyte a = -9;
88                 sbyte b = SByte.MinValue;
89
90                 Assert(9 == Math.Abs(a));
91                 try {
92                         Math.Abs(b);
93                         Fail("Should raise System.OverflowException");
94                 } catch(Exception e) {
95                         Assert(typeof(OverflowException) == e.GetType());
96                 }
97                 Assert(SByte.MaxValue == Math.Abs(SByte.MaxValue));
98         }
99
100         public void TestShortAbs() {
101                 short a = -9;
102                 short b = Int16.MinValue;
103
104                 Assert(9 == Math.Abs(a));
105                 try {
106                         Math.Abs(b);
107                         Fail("Should raise System.OverflowException");
108                 } catch(Exception e) {
109                         Assert(typeof(OverflowException) == e.GetType());
110                 }
111                 Assert(Int16.MaxValue == Math.Abs(Int16.MaxValue));
112         }
113
114         public void TestAcos() {
115                 double a = Math.Acos(x);
116                 double b = 1.4470809809523457;
117
118                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
119                        (Math.Abs(a - b) <= double.Epsilon));
120                 Assert(double.IsNaN(Math.Acos(-1.01D)));
121                 Assert(double.IsNaN(Math.Acos(1.01D)));
122                 Assert(double.IsNaN(Math.Acos(Double.MinValue)));
123                 Assert(double.IsNaN(Math.Acos(Double.MaxValue)));
124                 Assert(double.IsNaN(Math.Acos(Double.NegativeInfinity)));
125                 Assert(double.IsNaN(Math.Acos(Double.PositiveInfinity)));
126         }
127
128         public void TestAsin() {
129                 double a = Math.Asin(x);
130                 double b = 0.12371534584255098;
131
132                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
133                        (Math.Abs(a - b) <= double.Epsilon));
134                 Assert(double.IsNaN(Math.Asin(-1.01D)));
135                 Assert(double.IsNaN(Math.Asin(1.01D)));
136                 Assert(double.IsNaN(Math.Asin(Double.MinValue)));
137                 Assert(double.IsNaN(Math.Asin(Double.MaxValue)));
138                 Assert(double.IsNaN(Math.Asin(Double.NegativeInfinity)));
139                 Assert(double.IsNaN(Math.Asin(Double.PositiveInfinity)));
140         }
141
142         public void TestAtan() {
143                 double a = Math.Atan(x);
144                 double b = 0.12277930094473837;
145                 double c = 1.5707963267948966;
146                 double d = -1.5707963267948966;
147
148                 Assert("#1: " + a.ToString("G99") + " != " + b.ToString("G99"), 
149                        (Math.Abs(a - b) <= double.Epsilon));
150                 Assert("should return NaN", 
151                        double.IsNaN(Math.Atan(double.NaN)));
152                 Assert("#2: " + Math.Atan(double.PositiveInfinity).ToString("G99")+" != "+c.ToString("G99"), 
153                        Math.Abs((double)Math.Atan(double.PositiveInfinity) - c) <= 0.0000000000000001);
154                 Assert("#3: " + Math.Atan(double.NegativeInfinity).ToString("G99")+" != "+d.ToString("G99"),
155                        Math.Abs((double)Math.Atan(double.NegativeInfinity) - d) <= 0.0000000000000001);
156         }
157
158         public void TestAtan2() {
159                 double a = Math.Atan2(x, y);
160                 double b = 0.0099956168687207747;
161
162                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
163                        (Math.Abs(a - b) <= double.Epsilon));
164                 Assert(double.IsNaN(Math.Acos(-2D)));
165                 Assert(double.IsNaN(Math.Acos(2D)));
166         }
167
168         // The following test is for methods that are in ECMA but they are
169         // not implemented in MS.NET. I leave them commented.
170         /*
171         public void TestBigMul () {
172                 int a = int.MaxValue;
173                 int b = int.MaxValue;
174
175                 Assert(((long)a * (long)b) == Math.BigMul(a,b));
176         }
177         */
178
179         public void TestCos() {
180                 double a = Math.Cos(x);
181                 double b = 0.99239587670489104;
182
183                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
184                        (Math.Abs(a - b) <= double.Epsilon));
185                 Assert(double.IsNaN(Math.Cos(Double.NaN)));
186                 Assert(double.IsNaN(Math.Cos(Double.NegativeInfinity)));
187                 Assert(double.IsNaN(Math.Cos(Double.PositiveInfinity)));
188         }
189
190         public void TestCosh() {
191                 double a = Math.Cosh(x);
192                 double b = 1.0076234465130722;
193
194                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
195                        (Math.Abs(a - b) <= double.Epsilon));
196                 Assert(Math.Cosh(double.NegativeInfinity) == double.PositiveInfinity);
197                 Assert(Math.Cosh(double.PositiveInfinity) == double.PositiveInfinity);
198                 Assert(double.IsNaN(Math.Cosh(double.NaN)));
199         }
200
201         // The following test is for methods that are in ECMA but they are
202         // not implemented in MS.NET. I leave them commented.
203         /*
204         public void TestIntDivRem () {
205                 int a = 5;
206                 int b = 2;
207                 int div = 0, rem = 0;
208
209                 div = Math.DivRem(a, b, out rem);
210
211                 Assert(rem == 1);
212                 Assert(div == 2);
213         }
214
215         public void TestLongDivRem () {
216                 long a = 5;
217                 long b = 2;
218                 long div = 0, rem = 0;
219
220                 div = Math.DivRem(a, b, out rem);
221
222                 Assert(rem == 1);
223                 Assert(div == 2);
224         }
225         */
226
227         public void TestSin() {
228                 double a = Math.Sin(x);
229                 double b = 0.12308705821137626;
230
231                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
232                        (Math.Abs(a - b) <= double.Epsilon));
233                 Assert(double.IsNaN(Math.Sin(Double.NaN)));
234                 Assert(double.IsNaN(Math.Sin(Double.NegativeInfinity)));
235                 Assert(double.IsNaN(Math.Sin(Double.PositiveInfinity)));
236         }
237
238         public void TestSinh() {
239                 double a = Math.Sinh(x);
240                 double b = 0.12371341868561381;
241
242                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
243                        Math.Abs(a - b) <= 0.0000000000000001);
244                 Assert(double.IsNaN(Math.Sinh(Double.NaN)));
245                 Assert(double.IsNegativeInfinity(Math.Sinh(Double.NegativeInfinity)));
246                 Assert(double.IsPositiveInfinity(Math.Sinh(Double.PositiveInfinity)));
247         }
248
249         public void TestTan() {
250                 double a = Math.Tan(x);
251                 double b = 0.12403019913793806;
252
253                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
254                        (Math.Abs(a - b) <= double.Epsilon));
255                 Assert(Double.IsNaN(Math.Tan(Double.NaN)));
256                 Assert(Double.IsNaN(Math.Tan(Double.PositiveInfinity)));
257                 Assert(Double.IsNaN(Math.Tan(Double.NegativeInfinity)));
258         }
259
260         public void TestTanh() {
261                 double a = Math.Tanh(x);
262                 double b = 0.12277743150353424;
263
264                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
265                        (Math.Abs(a - b) <= double.Epsilon));
266                 Assert("Tanh(NaN) should be NaN",
267                         Double.IsNaN(Math.Tanh(Double.NaN)));
268                 Assert("Tanh(+Infinity) should be 1",
269                         1 == Math.Tanh(Double.PositiveInfinity));
270                 Assert("Tanh(-Infinity) should be -1",
271                         -1 == Math.Tanh(Double.NegativeInfinity));
272         }
273
274         public void TestSqrt() {
275                 double a = Math.Sqrt(x);
276                 double b = 0.35128336140500593;
277
278                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
279                        (Math.Abs(a - b) <= double.Epsilon));
280                 Assert(Double.IsNaN(Math.Sqrt(Double.NaN)));
281                 Assert(Double.IsPositiveInfinity(Math.Sqrt(Double.PositiveInfinity)));
282                 Assert(Double.IsNaN(Math.Sqrt(Double.NegativeInfinity)));
283         }
284
285         public void TestExp() {
286                 double a = Math.Exp(x);
287                 double b = 1.1313368651986859;
288
289                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
290                        (Math.Abs(a - b) <= double.Epsilon));
291                 Assert(double.IsNaN(Math.Exp(double.NaN)));
292                 Assert(Math.Exp(double.NegativeInfinity) == 0);
293                 Assert(Math.Exp(double.PositiveInfinity) == double.PositiveInfinity);
294         }
295
296         public void TestCeiling() {
297                 int iTest = 1;
298                 try {
299                         double a = Math.Ceiling(1.5);
300                         double b = 2;
301         
302                         iTest++;
303                         Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
304                                (Math.Abs(a - b) <= double.Epsilon));
305                         iTest++;
306                         Assert(Math.Ceiling(double.NegativeInfinity) == double.NegativeInfinity);
307                         iTest++;
308                         Assert(Math.Ceiling(double.PositiveInfinity) == double.PositiveInfinity);
309                         iTest++;
310                         Assert(double.IsNaN(Math.Ceiling(double.NaN)));
311
312                         iTest++;
313                         Assert(Double.MaxValue == Math.Ceiling(Double.MaxValue));
314
315                         iTest++;
316                         Assert(Double.MinValue == Math.Ceiling(Double.MinValue));
317                 } catch (Exception e) {
318                         Fail("Unexpected Exception at iTest=" + iTest + ": " + e);
319                 }
320         }
321
322         public void TestFloor() {
323                 try {
324                         double a = Math.Floor(1.5);
325                         double b = 1;
326
327                         Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
328                                (Math.Abs(a - b) <= double.Epsilon));
329                         Assert(Math.Floor(double.NegativeInfinity) == double.NegativeInfinity);
330                         Assert(Math.Floor(double.PositiveInfinity) == double.PositiveInfinity);
331                         Assert(double.IsNaN(Math.Floor(double.NaN)));
332
333                         Assert(Double.MaxValue == Math.Floor(Double.MaxValue));
334
335                         Assert(Double.MinValue == Math.Floor(Double.MinValue));
336                 } catch (Exception e) {
337                         Fail("Unexpected Exception: " + e.ToString());
338                 }
339         }
340
341         public void TestIEEERemainder() {
342                 double a = Math.IEEERemainder(y, x);
343                 double b = 0.0050000000000007816;
344
345                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
346                        (Math.Abs(a - b) <= double.Epsilon));
347
348                 Assert ("Positive 0", double.IsNaN (Math.IEEERemainder (y, 0)));
349
350                 // http://www.obtuse.com/resources/negative_zero.html
351                 double n0 = BitConverter.Int64BitsToDouble (Int64.MinValue);
352                 Assert ("Negative 0", double.IsNaN (Math.IEEERemainder (n0, 0)));
353
354                 // the "zero" remainder of negative number is negative
355                 long result = BitConverter.DoubleToInt64Bits (Math.IEEERemainder (-1, 1));
356                 AssertEquals ("Negative Dividend", Int64.MinValue, result);
357         }
358
359         public void TestLog() {
360                 double a = Math.Log(y);
361                 double b = 2.513251122797143;
362
363                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
364                        (Math.Abs(a - b) <= double.Epsilon));
365                 Assert(double.IsNaN(Math.Log(-1)));
366                 Assert(double.IsNaN(Math.Log(double.NaN)));
367
368                 // MS docs say this should be PositiveInfinity
369                 Assert(Math.Log(0) == double.NegativeInfinity);
370                 Assert(Math.Log(double.PositiveInfinity) == double.PositiveInfinity);
371         }
372
373         public void TestLog2() {
374                 double a = Math.Log(x, y);
375                 double b = -0.83251695325303621;
376
377                 Assert(a + " != " + b + " because diff is " + Math.Abs(a - b), (Math.Abs(a - b) <= 1e-14));
378                 Assert(double.IsNaN(Math.Log(-1, y)));
379                 Assert(double.IsNaN(Math.Log(double.NaN, y)));
380                 Assert(double.IsNaN(Math.Log(x, double.NaN)));
381                 Assert(double.IsNaN(Math.Log(double.NegativeInfinity, y)));
382                 Assert(double.IsNaN(Math.Log(x, double.NegativeInfinity)));
383                 Assert(double.IsNaN(Math.Log(double.PositiveInfinity, double.PositiveInfinity)));
384
385                 // MS docs say this should be PositiveInfinity
386                 Assert(Math.Log(0, y) == double.NegativeInfinity);
387                 Assert(Math.Log(double.PositiveInfinity, y) == double.PositiveInfinity);
388                 Assert(Math.Log(x, double.PositiveInfinity) == 0);
389         }
390
391         public void TestLog10() {
392                 double a = Math.Log10(x);
393                 double b = -0.90868484030277719;
394
395                 Assert(a.ToString("G99") + " != " + b.ToString("G99"), 
396                        (Math.Abs(a - b) <= double.Epsilon));
397                 Assert(double.IsNaN(Math.Log10(-1)));
398                 Assert(double.IsNaN(Math.Log10(double.NaN)));
399
400                 // MS docs say this should be PositiveInfinity
401                 Assert(Math.Log10(0) == double.NegativeInfinity);
402                 Assert(Math.Log10(double.PositiveInfinity) == double.PositiveInfinity);
403
404         }       
405
406         public void TestPow() {
407                 int iTest = 1;
408
409                 try {
410                         double a = Math.Pow(y, x);
411                         double b = 1.363609446060212;
412
413                         Assert(a.ToString("G99") + " != " + b.ToString("G99"), (Math.Abs(a - b) <= double.Epsilon));
414                         iTest++;
415                         Assert (double.IsNaN(Math.Pow(y, double.NaN)));
416                         iTest++;
417                         Assert (double.IsNaN(Math.Pow(double.NaN, x)));
418                         iTest++;
419                         Assert ("Math.Pow(double.NegativeInfinity, 1) should be NegativeInfinity", double.IsNegativeInfinity(Math.Pow(double.NegativeInfinity, 1)));
420                         iTest++;
421                         Assert ("Math.Pow(double.NegativeInfinity, 2) should be PositiveInfinity", double.IsPositiveInfinity(Math.Pow(double.NegativeInfinity, 2)));
422
423                         // MS docs say this should be 0
424                         iTest++;
425                         Assert(double.IsNaN(Math.Pow(1, double.NegativeInfinity)));
426                         iTest++;
427                         AssertEquals ("Math.Pow(double.PositiveInfinity, double.NegativeInfinity)", (double)0, Math.Pow(double.PositiveInfinity, double.NegativeInfinity));
428                         iTest++;
429                         Assert ("Math.Pow(double.PositiveInfinity, 1) should be PositiveInfinity", double.IsPositiveInfinity(Math.Pow(double.PositiveInfinity, 1)));
430
431                         // MS docs say this should be PositiveInfinity
432                         iTest++;
433                         Assert ("Math.Pow(1, double.PositiveInfinity) should be NaN", double.IsNaN(Math.Pow(1, double.PositiveInfinity)));
434
435                         iTest++;
436                         Assert("Math.Pow(1, NaN) should be NaN",
437                                 Double.IsNaN(Math.Pow(1, Double.NaN)));
438
439                         iTest++;
440                         Assert("Math.Pow(NaN, 0) should be NaN",
441                                 Double.IsNaN(Math.Pow(Double.NaN, 0)));
442
443                         iTest++;
444                         Assert("Math.Pow(-1, MaxValue) should be 1.0",
445                                 1.0 == Math.Pow(-1, Double.MaxValue));
446
447                         iTest++;
448                         Assert("Math.Pow(-1, MinValue) should be 1.0",
449                                 1.0 == Math.Pow(-1, Double.MinValue));
450
451                         iTest++;
452                         Assert("Math.Pow(MinValue, MaxValue) should be +Infinity",
453                                 Double.IsPositiveInfinity(
454                                         Math.Pow(Double.MinValue, Double.MaxValue)));
455
456                         iTest++;
457                         Assert("Math.Pow(MinValue, MinValue) should be 0.0",
458                                 0.0 == Math.Pow(Double.MinValue, Double.MinValue));
459
460                         //
461                         // The following bugs were present because we tried to outsmart the C Pow:
462                         //
463                         double infinity = Double.PositiveInfinity;
464                         Assert ("Math.Pow(0.5, Infinity) == 0.0",
465                                 Math.Pow(0.5, infinity) == 0.0);
466                         Assert ("Math.Pow(0.5, -Infinity) == Infinity",
467                                 Math.Pow(0.5, -infinity) == infinity);
468                         Assert ("Math.Pow(2, Infinity) == Infinity",
469                                 Math.Pow(2, infinity) == infinity);
470                         Assert ("Math.Pow(2, -Infinity) == 0",
471                                 Math.Pow(2, -infinity) == 0.0);
472                         Assert ("Math.Pow(Infinity, 0) == 1.0",
473                                 Math.Pow(infinity, 0) == 1.0);
474                         Assert ("Math.Pow(-Infinity, 0) == 1.0",
475                                 Math.Pow(-infinity, 0) == 1.0);
476                 } catch (Exception e) {
477                         Fail ("Unexpected exception at iTest=" + iTest + ". e=" + e);
478                 }
479         }       
480
481         public void TestByteMax() {
482                 byte a = 1;
483                 byte b = 2;
484
485                 Assert(b == Math.Max(a, b));
486                 Assert(b == Math.Max(b, a));
487         }
488
489         public void TestDecimalMax() {
490                 decimal a = 1.5M;
491                 decimal b = 2.5M;
492
493                 Assert(b == Math.Max(a, b));
494                 Assert(b == Math.Max(b, a));
495         }
496
497         public void TestDoubleMax() {
498                 double a = 1.5D;
499                 double b = 2.5D;
500
501                 Assert(b == Math.Max(a, b));
502                 Assert(b == Math.Max(b, a));
503                 Assert("Max(NaN,NaN) should be NaN",
504                         Double.IsNaN(Math.Max(Double.NaN, Double.NaN)));
505                 Assert("Max(NaN,x) should be NaN",
506                         Double.IsNaN(Math.Max(Double.NaN, a)));
507                 Assert("Max(x,NaN) should be NaN",
508                         Double.IsNaN(Math.Max(b, Double.NaN)));
509         }
510
511         public void TestFloatMax() {
512                 float a = 1.5F;
513                 float b = 2.5F;
514
515                 Assert(b == Math.Max(a, b));
516                 Assert(b == Math.Max(b, a));
517                 Assert("Max(NaN,NaN) should be NaN",
518                         Single.IsNaN(Math.Max(Single.NaN, Single.NaN)));
519                 Assert("Max(NaN,x) should be NaN",
520                         Single.IsNaN(Math.Max(Single.NaN, a)));
521                 Assert("Max(x,NaN) should be NaN",
522                         Single.IsNaN(Math.Max(b, Single.NaN)));
523         }
524
525         public void TestIntMax() {
526                 int a = 1;
527                 int b = 2;
528
529                 Assert(b == Math.Max(a, b));
530                 Assert(b == Math.Max(b, a));
531         }
532
533         public void TestLongMax() {
534                 long a = 1L;
535                 long b = 2L;
536
537                 Assert(b == Math.Max(a, b));
538                 Assert(b == Math.Max(b, a));
539         }
540
541         public void TestSbyteMax() {
542                 sbyte a = 1;
543                 sbyte b = 2;
544
545                 Assert(b == Math.Max(a, b));
546                 Assert(b == Math.Max(b, a));
547         }
548
549         public void TestShortMax() {
550                 short a = 1;
551                 short b = 2;
552
553                 Assert(b == Math.Max(a, b));
554                 Assert(b == Math.Max(b, a));
555         }
556
557         public void TestUintMax() {
558                 uint a = 1U;
559                 uint b = 2U;
560
561                 Assert(b == Math.Max(a, b));
562                 Assert(b == Math.Max(b, a));
563         }
564
565         public void TestUlongMax() {
566                 ulong a = 1UL;
567                 ulong b = 2UL;
568
569                 Assert(b == Math.Max(a, b));
570                 Assert(b == Math.Max(b, a));
571         }
572
573         public void TestUshortMax() {
574                 ushort a = 1;
575                 ushort b = 2;
576
577                 Assert(b == Math.Max(a, b));
578                 Assert(b == Math.Max(b, a));
579         }
580
581         public void TestByteMin() {
582                 byte a = 1;
583                 byte b = 2;
584
585                 Assert(a == Math.Min(a, b));
586                 Assert(a == Math.Min(b, a));
587         }
588
589         public void TestDecimalMin() {
590                 decimal a = 1.5M;
591                 decimal b = 2.5M;
592
593                 Assert(a == Math.Min(a, b));
594                 Assert(a == Math.Min(b, a));
595         }
596
597         public void TestDoubleMin() {
598                 double a = 1.5D;
599                 double b = 2.5D;
600
601                 Assert(a == Math.Min(a, b));
602                 Assert(a == Math.Min(b, a));
603                 Assert("Min(NaN,NaN) should be NaN",
604                         Double.IsNaN(Math.Min(Double.NaN, Double.NaN)));
605                 Assert("Min(NaN,x) should be NaN",
606                         Double.IsNaN(Math.Min(Double.NaN, a)));
607                 Assert("Min(x,NaN) should be NaN",
608                         Double.IsNaN(Math.Min(b, Double.NaN)));
609         }
610
611         public void TestFloatMin() {
612                 float a = 1.5F;
613                 float b = 2.5F;
614
615                 Assert(a == Math.Min(a, b));
616                 Assert(a == Math.Min(b, a));
617                 Assert("Min(NaN,NaN) should be NaN",
618                         Single.IsNaN(Math.Min(Single.NaN, Single.NaN)));
619                 Assert("Min(NaN,x) should be NaN",
620                         Single.IsNaN(Math.Min(Single.NaN, a)));
621                 Assert("Min(x,NaN) should be NaN",
622                         Single.IsNaN(Math.Min(b, Single.NaN)));
623         }
624
625         public void TestIntMin() {
626                 int a = 1;
627                 int b = 2;
628
629                 Assert(a == Math.Min(a, b));
630                 Assert(a == Math.Min(b, a));
631         }
632
633         public void TestLongMin() {
634                 long a = 1L;
635                 long b = 2L;
636
637                 Assert(a == Math.Min(a, b));
638                 Assert(a == Math.Min(b, a));
639         }
640
641         public void TestSbyteMin() {
642                 sbyte a = 1;
643                 sbyte b = 2;
644
645                 Assert(a == Math.Min(a, b));
646                 Assert(a == Math.Min(b, a));
647         }
648
649         public void TestShortMin() {
650                 short a = 1;
651                 short b = 2;
652
653                 Assert(a == Math.Min(a, b));
654                 Assert(a == Math.Min(b, a));
655         }
656
657         public void TestUintMin() {
658                 uint a = 1U;
659                 uint b = 2U;
660
661                 Assert(a == Math.Min(a, b));
662                 Assert(a == Math.Min(b, a));
663         }
664
665         public void TestUlongMin() {
666                 ulong a = 1UL;
667                 ulong b = 2UL;
668
669                 Assert(a == Math.Min(a, b));
670                 Assert(a == Math.Min(b, a));
671         }
672
673         public void TestUshortMin() {
674                 ushort a = 1;
675                 ushort b = 2;
676
677                 Assert(a == Math.Min(a, b));
678                 Assert(a == Math.Min(b, a));
679         }
680
681         public void TestDecimalRound() {
682                 decimal a = 1.5M;
683                 decimal b = 2.5M;
684
685                 Assert(Math.Round(a) + " != 2", Math.Round(a) == 2);
686                 Assert(Math.Round(b) + " != 2", Math.Round(b) == 2);
687                 Assert(Decimal.MaxValue == Math.Round(Decimal.MaxValue));
688                 Assert(Decimal.MinValue == Math.Round(Decimal.MinValue));
689         }
690
691         public void TestDecimalRound2() {
692                 decimal a = 3.45M;
693                 decimal b = 3.46M;
694
695                 AssertEquals ("Should round down", Math.Round(a, 1), 3.4M);
696                 AssertEquals ("Should round up", Math.Round(b, 1), 3.5M);
697         }
698
699         public void TestDoubleRound() {
700                 double a = 1.5D;
701                 double b = 2.5D;
702
703                 AssertEquals ("Should round up", Math.Round(a), 2D);
704                 AssertEquals ("Should round down", Math.Round(b), 2D);
705                 Assert(Double.MaxValue == Math.Round(Double.MaxValue));
706                 Assert(Double.MinValue == Math.Round(Double.MinValue));
707         }
708
709         public void TestDoubleRound2() {
710                 double a = 3.45D;
711                 double b = 3.46D;
712
713                 AssertEquals ("Should round down", Math.Round(a, 1), 3.4D);
714                 AssertEquals ("Should round up", Math.Round(b, 1), 3.5D);
715         }
716         
717         public void TestDecimalSign() {
718                 decimal a = -5M;
719                 decimal b = 5M;
720
721                 Assert(Math.Sign(a) == -1);
722                 Assert(Math.Sign(b) == 1);
723                 Assert(Math.Sign(0M) == 0);
724         }
725
726         public void TestDoubleSign() {
727                 double a = -5D;
728                 double b = 5D;
729
730                 Assert(Math.Sign(a) == -1);
731                 Assert(Math.Sign(b) == 1);
732                 Assert(Math.Sign(0D) == 0);
733         }
734
735         public void TestFloatSign() {
736                 float a = -5F;
737                 float b = 5F;
738
739                 Assert(Math.Sign(a) == -1);
740                 Assert(Math.Sign(b) == 1);
741                 Assert(Math.Sign(0F) == 0);
742         }
743
744         public void TestIntSign() {
745                 int a = -5;
746                 int b = 5;
747
748                 Assert(Math.Sign(a) == -1);
749                 Assert(Math.Sign(b) == 1);
750                 Assert(Math.Sign(0) == 0);
751         }
752
753         public void TestLongSign() {
754                 long a = -5L;
755                 long b = 5L;
756
757                 Assert(Math.Sign(a) == -1);
758                 Assert(Math.Sign(b) == 1);
759                 Assert(Math.Sign(0L) == 0);
760         }
761
762         public void TestSbyteSign() {
763                 sbyte a = -5;
764                 sbyte b = 5;
765
766                 Assert(Math.Sign(a) == -1);
767                 Assert(Math.Sign(b) == 1);
768                 Assert(Math.Sign(0) == 0);
769         }
770
771         public void TestShortSign() {
772                 short a = -5;
773                 short b = 5;
774
775                 Assert(Math.Sign(a) == -1);
776                 Assert(Math.Sign(b) == 1);
777                 Assert(Math.Sign(0) == 0);
778         }
779
780 }
781
782 }