File: SingleTest.cs

package info (click to toggle)
mono 1.2.2.1-1
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 142,728 kB
  • ctags: 256,408
  • sloc: cs: 1,495,736; ansic: 249,442; sh: 18,304; xml: 12,463; makefile: 5,046; perl: 1,248; asm: 635; yacc: 285; sql: 7
file content (107 lines) | stat: -rw-r--r-- 2,966 bytes parent folder | download | duplicates (2)
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
// 
// System.SingleTest.cs - Unit test for Single
//	adapted from a subset of DoubleTest.cs
//
// Authors
//	Bob Doan  <bdoan@sicompos.com>
//	Sebastien Pouliot  <sebastien@ximian.com>
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//

using System;
using System.Globalization;
using NUnit.Framework;

namespace MonoTests.System  {

	[TestFixture]
	public class SingleTest : Assertion {

		[Test]
		public void Equals () 
		{
			Single s1 = 1f;
			Single s2 = 1f;
			Assert ("Equals s1==s2", s1.Equals (s2));
			Assert ("Equals s1!=NaN", !s1.Equals (Single.NaN));

			Assert ("Equals NaN=!s2", !Single.NaN.Equals (s2));
			Assert ("Equals NaN==NaN", Single.NaN.Equals (Single.NaN));

			Single p0 = 0.0f;
			Single m0 = -0.0f;
			Assert ("0.0==-0.0", p0.Equals (m0));
			Assert ("-0.0==0.0", m0.Equals (p0));
		}

		[Test]
		public void IsInfinity ()
		{
			Assert ("PositiveInfinity",  Single.IsInfinity (Single.PositiveInfinity));
			Assert ("NegativeInfinity", Single.IsInfinity (Single.NegativeInfinity));
			Assert ("12", !Single.IsInfinity(12));		
			Assert ("NaN", !Single.IsInfinity (Single.NaN));		
		}

		[Test]
		public void IsNan ()
		{
			Assert ("Nan", Single.IsNaN (Single.NaN));
			Assert ("12", !Single.IsNaN (12));
			Assert ("PositiveInfinity", !Single.IsNaN (Single.PositiveInfinity));
			Assert ("NegativeInfinity", !Single.IsNaN (Single.PositiveInfinity));
		}

		[Test]
		public void IsNegativeInfinity ()
		{
			Assert ("IsNegativeInfinity", Single.IsNegativeInfinity (Single.NegativeInfinity));
			Assert ("12", !Single.IsNegativeInfinity (12));		
			Assert ("NaN", !Single.IsNegativeInfinity (Single.NaN));		
		}

		[Test]
		public void IsPositiveInfinity ()
		{
			Assert ("PositiveInfinity", Single.IsPositiveInfinity (Single.PositiveInfinity));
			Assert ("12", !Single.IsPositiveInfinity (12));		
			Assert ("NaN", !Single.IsPositiveInfinity (Single.NaN));		
		}

		[Test]
		public void ToString_Defaults () 
		{
			Single i = 254.9f;
			// everything defaults to "G"
			string def = i.ToString ("G");
			AssertEquals ("ToString()", def, i.ToString ());
			AssertEquals ("ToString((IFormatProvider)null)", def, i.ToString ((IFormatProvider)null));
			AssertEquals ("ToString((string)null)", def, i.ToString ((string)null));
			AssertEquals ("ToString(empty)", def, i.ToString (String.Empty));
			AssertEquals ("ToString(null,null)", def, i.ToString (null, null));
			AssertEquals ("ToString(empty,null)", def, i.ToString (String.Empty, null));

			AssertEquals ("ToString(G)", "254.9", def);
		}

#if NET_2_0
		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void HexNumber_WithHexToParse ()
		{
			// from bug #72221
			float f;
			Single.TryParse ("0dead", NumberStyles.HexNumber, null, out f);
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void HexNumber_NoHexToParse ()
		{
			float f;
			Single.TryParse ("0", NumberStyles.HexNumber, null, out f);
		}
#endif
	}
}