3 // Jon Guymon (guymon@slackworks.com)
4 // Pedro Martínez Juliá (yoros@wanadoo.es)
7 // Copyright (C) 2003 Pedro Martínez Juliá <yoros@wanadoo.es>
8 // Copyright (C) 2004 Novell (http://www.novell.com)
12 using NUnit
.Framework
;
14 namespace MonoTests
.System
18 public class MathTest
: Assertion
{
20 static double x
= 0.1234;
21 static double y
= 12.345;
23 public void TestDecimalAbs() {
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
));
35 public void TestDoubleAbs() {
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
)));
46 public void TestFloatAbs() {
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
)));
58 public void TestLongAbs() {
60 long b
= Int64
.MinValue
;
62 Assert(9L == Math
.Abs(a
));
65 Fail("Should raise System.OverflowException");
66 } catch(Exception e
) {
67 Assert(typeof(OverflowException
) == e
.GetType());
69 Assert(Int64
.MaxValue
== Math
.Abs(Int64
.MaxValue
));
72 public void TestIntAbs() {
74 int b
= Int32
.MinValue
;
76 Assert(9 == Math
.Abs(a
));
79 Fail("Should raise System.OverflowException");
80 } catch(Exception e
) {
81 Assert(typeof(OverflowException
) == e
.GetType());
83 Assert(Int32
.MaxValue
== Math
.Abs(Int32
.MaxValue
));
86 public void TestSbyteAbs() {
88 sbyte b
= SByte
.MinValue
;
90 Assert(9 == Math
.Abs(a
));
93 Fail("Should raise System.OverflowException");
94 } catch(Exception e
) {
95 Assert(typeof(OverflowException
) == e
.GetType());
97 Assert(SByte
.MaxValue
== Math
.Abs(SByte
.MaxValue
));
100 public void TestShortAbs() {
102 short b
= Int16
.MinValue
;
104 Assert(9 == Math
.Abs(a
));
107 Fail("Should raise System.OverflowException");
108 } catch(Exception e
) {
109 Assert(typeof(OverflowException
) == e
.GetType());
111 Assert(Int16
.MaxValue
== Math
.Abs(Int16
.MaxValue
));
114 public void TestAcos() {
115 double a
= Math
.Acos(x
);
116 double b
= 1.4470809809523457;
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
)));
128 public void TestAsin() {
129 double a
= Math
.Asin(x
);
130 double b
= 0.12371534584255098;
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
)));
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;
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);
158 public void TestAtan2() {
159 double a
= Math
.Atan2(x
, y
);
160 double b
= 0.0099956168687207747;
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
)));
168 // The following test is for methods that are in ECMA but they are
169 // not implemented in MS.NET. I leave them commented.
171 public void TestBigMul () {
172 int a = int.MaxValue;
173 int b = int.MaxValue;
175 Assert(((long)a * (long)b) == Math.BigMul(a,b));
179 public void TestCos() {
180 double a
= Math
.Cos(x
);
181 double b
= 0.99239587670489104;
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
)));
190 public void TestCosh() {
191 double a
= Math
.Cosh(x
);
192 double b
= 1.0076234465130722;
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
)));
201 // The following test is for methods that are in ECMA but they are
202 // not implemented in MS.NET. I leave them commented.
204 public void TestIntDivRem () {
207 int div = 0, rem = 0;
209 div = Math.DivRem(a, b, out rem);
215 public void TestLongDivRem () {
218 long div = 0, rem = 0;
220 div = Math.DivRem(a, b, out rem);
227 public void TestSin() {
228 double a
= Math
.Sin(x
);
229 double b
= 0.12308705821137626;
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
)));
238 public void TestSinh() {
239 double a
= Math
.Sinh(x
);
240 double b
= 0.12371341868561381;
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
)));
249 public void TestTan() {
250 double a
= Math
.Tan(x
);
251 double b
= 0.12403019913793806;
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
)));
260 public void TestTanh() {
261 double a
= Math
.Tanh(x
);
262 double b
= 0.12277743150353424;
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
));
274 public void TestSqrt() {
275 double a
= Math
.Sqrt(x
);
276 double b
= 0.35128336140500593;
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
)));
285 public void TestExp() {
286 double a
= Math
.Exp(x
);
287 double b
= 1.1313368651986859;
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
);
296 public void TestCeiling() {
299 double a
= Math
.Ceiling(1.5);
303 Assert(a
.ToString("G99") + " != " + b
.ToString("G99"),
304 (Math
.Abs(a
- b
) <= double.Epsilon
));
306 Assert(Math
.Ceiling(double.NegativeInfinity
) == double.NegativeInfinity
);
308 Assert(Math
.Ceiling(double.PositiveInfinity
) == double.PositiveInfinity
);
310 Assert(double.IsNaN(Math
.Ceiling(double.NaN
)));
313 Assert(Double
.MaxValue
== Math
.Ceiling(Double
.MaxValue
));
316 Assert(Double
.MinValue
== Math
.Ceiling(Double
.MinValue
));
317 } catch (Exception e
) {
318 Fail("Unexpected Exception at iTest=" + iTest
+ ": " + e
);
322 public void TestFloor() {
324 double a
= Math
.Floor(1.5);
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
)));
333 Assert(Double
.MaxValue
== Math
.Floor(Double
.MaxValue
));
335 Assert(Double
.MinValue
== Math
.Floor(Double
.MinValue
));
336 } catch (Exception e
) {
337 Fail("Unexpected Exception: " + e
.ToString());
341 public void TestIEEERemainder() {
342 double a
= Math
.IEEERemainder(y
, x
);
343 double b
= 0.0050000000000007816;
345 Assert(a
.ToString("G99") + " != " + b
.ToString("G99"),
346 (Math
.Abs(a
- b
) <= double.Epsilon
));
348 Assert ("Positive 0", double.IsNaN (Math
.IEEERemainder (y
, 0)));
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)));
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
);
359 public void TestLog() {
360 double a
= Math
.Log(y
);
361 double b
= 2.513251122797143;
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
)));
368 // MS docs say this should be PositiveInfinity
369 Assert(Math
.Log(0) == double.NegativeInfinity
);
370 Assert(Math
.Log(double.PositiveInfinity
) == double.PositiveInfinity
);
373 public void TestLog2() {
374 double a
= Math
.Log(x
, y
);
375 double b
= -0.83251695325303621;
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
)));
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);
391 public void TestLog10() {
392 double a
= Math
.Log10(x
);
393 double b
= -0.90868484030277719;
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
)));
400 // MS docs say this should be PositiveInfinity
401 Assert(Math
.Log10(0) == double.NegativeInfinity
);
402 Assert(Math
.Log10(double.PositiveInfinity
) == double.PositiveInfinity
);
406 public void TestPow() {
410 double a
= Math
.Pow(y
, x
);
411 double b
= 1.363609446060212;
413 Assert(a
.ToString("G99") + " != " + b
.ToString("G99"), (Math
.Abs(a
- b
) <= double.Epsilon
));
415 Assert (double.IsNaN(Math
.Pow(y
, double.NaN
)));
417 Assert (double.IsNaN(Math
.Pow(double.NaN
, x
)));
419 Assert ("Math.Pow(double.NegativeInfinity, 1) should be NegativeInfinity", double.IsNegativeInfinity(Math
.Pow(double.NegativeInfinity
, 1)));
421 Assert ("Math.Pow(double.NegativeInfinity, 2) should be PositiveInfinity", double.IsPositiveInfinity(Math
.Pow(double.NegativeInfinity
, 2)));
423 // MS docs say this should be 0
425 Assert(double.IsNaN(Math
.Pow(1, double.NegativeInfinity
)));
427 AssertEquals ("Math.Pow(double.PositiveInfinity, double.NegativeInfinity)", (double)0, Math
.Pow(double.PositiveInfinity
, double.NegativeInfinity
));
429 Assert ("Math.Pow(double.PositiveInfinity, 1) should be PositiveInfinity", double.IsPositiveInfinity(Math
.Pow(double.PositiveInfinity
, 1)));
431 // MS docs say this should be PositiveInfinity
433 Assert ("Math.Pow(1, double.PositiveInfinity) should be NaN", double.IsNaN(Math
.Pow(1, double.PositiveInfinity
)));
436 Assert("Math.Pow(1, NaN) should be NaN",
437 Double
.IsNaN(Math
.Pow(1, Double
.NaN
)));
440 Assert("Math.Pow(NaN, 0) should be NaN",
441 Double
.IsNaN(Math
.Pow(Double
.NaN
, 0)));
444 Assert("Math.Pow(-1, MaxValue) should be 1.0",
445 1.0 == Math
.Pow(-1, Double
.MaxValue
));
448 Assert("Math.Pow(-1, MinValue) should be 1.0",
449 1.0 == Math
.Pow(-1, Double
.MinValue
));
452 Assert("Math.Pow(MinValue, MaxValue) should be +Infinity",
453 Double
.IsPositiveInfinity(
454 Math
.Pow(Double
.MinValue
, Double
.MaxValue
)));
457 Assert("Math.Pow(MinValue, MinValue) should be 0.0",
458 0.0 == Math
.Pow(Double
.MinValue
, Double
.MinValue
));
461 // The following bugs were present because we tried to outsmart the C Pow:
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
);
481 public void TestByteMax() {
485 Assert(b
== Math
.Max(a
, b
));
486 Assert(b
== Math
.Max(b
, a
));
489 public void TestDecimalMax() {
493 Assert(b
== Math
.Max(a
, b
));
494 Assert(b
== Math
.Max(b
, a
));
497 public void TestDoubleMax() {
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
)));
511 public void TestFloatMax() {
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
)));
525 public void TestIntMax() {
529 Assert(b
== Math
.Max(a
, b
));
530 Assert(b
== Math
.Max(b
, a
));
533 public void TestLongMax() {
537 Assert(b
== Math
.Max(a
, b
));
538 Assert(b
== Math
.Max(b
, a
));
541 public void TestSbyteMax() {
545 Assert(b
== Math
.Max(a
, b
));
546 Assert(b
== Math
.Max(b
, a
));
549 public void TestShortMax() {
553 Assert(b
== Math
.Max(a
, b
));
554 Assert(b
== Math
.Max(b
, a
));
557 public void TestUintMax() {
561 Assert(b
== Math
.Max(a
, b
));
562 Assert(b
== Math
.Max(b
, a
));
565 public void TestUlongMax() {
569 Assert(b
== Math
.Max(a
, b
));
570 Assert(b
== Math
.Max(b
, a
));
573 public void TestUshortMax() {
577 Assert(b
== Math
.Max(a
, b
));
578 Assert(b
== Math
.Max(b
, a
));
581 public void TestByteMin() {
585 Assert(a
== Math
.Min(a
, b
));
586 Assert(a
== Math
.Min(b
, a
));
589 public void TestDecimalMin() {
593 Assert(a
== Math
.Min(a
, b
));
594 Assert(a
== Math
.Min(b
, a
));
597 public void TestDoubleMin() {
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
)));
611 public void TestFloatMin() {
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
)));
625 public void TestIntMin() {
629 Assert(a
== Math
.Min(a
, b
));
630 Assert(a
== Math
.Min(b
, a
));
633 public void TestLongMin() {
637 Assert(a
== Math
.Min(a
, b
));
638 Assert(a
== Math
.Min(b
, a
));
641 public void TestSbyteMin() {
645 Assert(a
== Math
.Min(a
, b
));
646 Assert(a
== Math
.Min(b
, a
));
649 public void TestShortMin() {
653 Assert(a
== Math
.Min(a
, b
));
654 Assert(a
== Math
.Min(b
, a
));
657 public void TestUintMin() {
661 Assert(a
== Math
.Min(a
, b
));
662 Assert(a
== Math
.Min(b
, a
));
665 public void TestUlongMin() {
669 Assert(a
== Math
.Min(a
, b
));
670 Assert(a
== Math
.Min(b
, a
));
673 public void TestUshortMin() {
677 Assert(a
== Math
.Min(a
, b
));
678 Assert(a
== Math
.Min(b
, a
));
681 public void TestDecimalRound() {
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
));
691 public void TestDecimalRound2() {
695 AssertEquals ("Should round down", Math
.Round(a
, 1), 3.4M
);
696 AssertEquals ("Should round up", Math
.Round(b
, 1), 3.5M
);
699 public void TestDoubleRound() {
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
));
709 public void TestDoubleRound2() {
713 AssertEquals ("Should round down", Math
.Round(a
, 1), 3.4D
);
714 AssertEquals ("Should round up", Math
.Round(b
, 1), 3.5D
);
717 public void TestDecimalSign() {
721 Assert(Math
.Sign(a
) == -1);
722 Assert(Math
.Sign(b
) == 1);
723 Assert(Math
.Sign(0M
) == 0);
726 public void TestDoubleSign() {
730 Assert(Math
.Sign(a
) == -1);
731 Assert(Math
.Sign(b
) == 1);
732 Assert(Math
.Sign(0D
) == 0);
735 public void TestFloatSign() {
739 Assert(Math
.Sign(a
) == -1);
740 Assert(Math
.Sign(b
) == 1);
741 Assert(Math
.Sign(0F
) == 0);
744 public void TestIntSign() {
748 Assert(Math
.Sign(a
) == -1);
749 Assert(Math
.Sign(b
) == 1);
750 Assert(Math
.Sign(0) == 0);
753 public void TestLongSign() {
757 Assert(Math
.Sign(a
) == -1);
758 Assert(Math
.Sign(b
) == 1);
759 Assert(Math
.Sign(0L) == 0);
762 public void TestSbyteSign() {
766 Assert(Math
.Sign(a
) == -1);
767 Assert(Math
.Sign(b
) == 1);
768 Assert(Math
.Sign(0) == 0);
771 public void TestShortSign() {
775 Assert(Math
.Sign(a
) == -1);
776 Assert(Math
.Sign(b
) == 1);
777 Assert(Math
.Sign(0) == 0);