Просмотр исходного кода

2003-01-29 Sebastien Pouliot <[email protected]>

	* ByteTest.cs: Updated Setup to support my Locale. Better but
	probably still incomplete.
	* DoubleTest.cs: Updated Setup to support my Locale. You can now
	use a comma (or anything else) instead of a dot (.).
	* ConvertTest.cs: Updated TestToDecimal and TestToDouble to
	support my Locale. You can now use a comma (or anything else)
	instead of a dot (.).

svn path=/trunk/mcs/; revision=11037
Sebastien Pouliot 23 лет назад
Родитель
Сommit
febc5e8dfc

+ 34 - 4
mcs/class/corlib/Test/System/ByteTest.cs

@@ -29,7 +29,7 @@ public class ByteTest : TestCase
 	private string[] Results1_Nfi = {NumberFormatInfo.InvariantInfo.CurrencySymbol+"0.00",
 					"0", "0.000000e+000", "0.00",
 					"0", "0.00", "0.00 %", "0"};
-	private string[] Results2 = {NumberFormatInfo.CurrentInfo.CurrencySymbol+"255.00000",
+	private string[] Results2 = {	"",
 					"00255", "2.55000e+002", "255.00000",
 					"255", "255.00000", "25,500.00000 %", "000ff"};
 	private string[] Results2_Nfi = {NumberFormatInfo.InvariantInfo.CurrencySymbol+"255.00000", 
@@ -40,11 +40,41 @@ public class ByteTest : TestCase
 	
 	public ByteTest() {}
 
-	protected override void SetUp() {
+	protected override void SetUp() 
+	{
 		int cdd = NumberFormatInfo.CurrentInfo.CurrencyDecimalDigits;
+		string sep = NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator;
 		string csym = NumberFormatInfo.CurrentInfo.CurrencySymbol;
-		string csuffix = (cdd > 0 ? "." : "").PadRight(cdd + (cdd > 0 ? 1 : 0), '0');
-		Results1[0] = csym + "0" + csuffix;
+		string csuffix = (cdd > 0 ? sep : "").PadRight(cdd + (cdd > 0 ? 1 : 0), '0');
+		switch (NumberFormatInfo.CurrentInfo.CurrencyPositivePattern) {
+			case 0: // $n
+				Results1[0] = csym + "0" + csuffix;
+				Results2[0] = csym + "255" + sep + "00000";
+				break;
+			case 1: // n$
+				Results1[0] = "0" + csuffix + csym;
+				Results2[0] = "255" + sep + "00000" + csym;
+				break;
+			case 2: // $ n
+				Results1[0] = csym + " 0" + csuffix;
+				Results2[0] = csym + " 255" + sep + "00000";
+				break;
+			case 3: // n $
+				Results1[0] = "0" + csuffix + " " + csym;
+				Results2[0] = "255" + sep + "00000 " + csym;
+				break;
+		}
+		sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
+		Results1[2] = "0" + sep + "000000e+000";
+		Results1[3] = "0" + sep + "00";
+		Results1[5] = "0" + sep + "00";
+		Results1[6] = "0" + sep + "00 %";
+		Results2[2] = "2" + sep + "55000e+002";
+		Results2[3] = "255" + sep + "00000";
+		Results2[3] = "255" + sep + "00000";
+		Results2[5] = "255" + sep + "00000";
+		string gsep = NumberFormatInfo.CurrentInfo.NumberGroupSeparator;
+		Results2[6] = "25" + gsep + "500" + sep + "00000 %";
 	}
 
         protected override void TearDown () {

+ 125 - 115
mcs/class/corlib/Test/System/ChangeLog

@@ -1,3 +1,13 @@
+2003-01-29  Sebastien Pouliot  <[email protected]>
+
+	* ByteTest.cs: Updated Setup to support my Locale. Better but
+	probably still incomplete.
+	* DoubleTest.cs: Updated Setup to support my Locale. You can now
+	use a comma (or anything else) instead of a dot (.).
+	* ConvertTest.cs: Updated TestToDecimal and TestToDouble to 
+	support my Locale. You can now use a comma (or anything else) 
+	instead of a dot (.).
+
 2003-01-28  Nick Drochak <[email protected]>
 
         * ArrayTest.cs: Avoid nulls in arrays. This crashes mono.
@@ -197,10 +207,10 @@
 	* RandomTest.cs: Split Assert into two to figure out which one part is
 	failing.
 
-2002-06-09  Lawrence Pit  <[email protected]>
-
-	* DateTimeTest.cs: Making tests culture independent
-
+2002-06-09  Lawrence Pit  <[email protected]>
+
+	* DateTimeTest.cs: Making tests culture independent
+
 2002-06-07  Nick Drochak  <[email protected]>
 
 	* DecimalTest.cs: Catch unexpected exception and report it.
@@ -240,15 +250,15 @@
 	* DecimalTest.cs: Use AssertEquals to get nice error report, and mark
 	each one with a unique message string so we know which one failed.
 
-2002-05-29  Lawrence Pit  <[email protected]>
-
-	* DateTimeTest.cs: Added tests M01 to M03 to TestParseExact, 
-	passing typeof this class as arg in property Suite.
-
-2002-05-22  Lawrence Pit  <[email protected]>
-
-	* ConsoleTest.cs: Added test writing null.
-
+2002-05-29  Lawrence Pit  <[email protected]>
+
+	* DateTimeTest.cs: Added tests M01 to M03 to TestParseExact, 
+	passing typeof this class as arg in property Suite.
+
+2002-05-22  Lawrence Pit  <[email protected]>
+
+	* ConsoleTest.cs: Added test writing null.
+
 2002-05-21  Nick Drochak  <[email protected]>
 
 	* MathTest.cs:
@@ -279,10 +289,10 @@
 
 	* ExceptionTest.cs: New File. Provided by Linus Upson.
 
-2002-05-05  Lawrence Pit  <[email protected]>
-
-	* StringTest.cs: Added test for replace function
-
+2002-05-05  Lawrence Pit  <[email protected]>
+
+	* StringTest.cs: Added test for replace function
+
 2002-04-30  Nick Drochak  <[email protected]>
 
 	* UInt32Test.cs: More verbose on unexepected exception to eliminate
@@ -419,27 +429,27 @@
 	* ArrayTest.cs: Use unique labels for all the tests.
 	(TestSetValue4): A big new testcase.
 
-2002-03-06  Nick Drochak  <[email protected]>
-
-	* VersionTest.cs: Fix for mscorlib behavior vs. docs. CompareTo(null)
-	is legal.
-	* UInt16Test.cs:
-	* UInt32Test.cs:
-	* UInt64Test.cs: Use NumberFormatInfo.InvariantInfo.CurrencySymbol
-	where "$" was used. Should help suppress false negatives on systems
-	where "$" is not the currency symbol.
-
+2002-03-06  Nick Drochak  <[email protected]>
+
+	* VersionTest.cs: Fix for mscorlib behavior vs. docs. CompareTo(null)
+	is legal.
+	* UInt16Test.cs:
+	* UInt32Test.cs:
+	* UInt64Test.cs: Use NumberFormatInfo.InvariantInfo.CurrencySymbol
+	where "$" was used. Should help suppress false negatives on systems
+	where "$" is not the currency symbol.
+
 2002-03-04  Duco Fijma  <[email protected]>
 	* VersionTest.cs: created test cases for System.Version
 
 2002-03-03  Duco Fijma  <[email protected]>
 	* CharEnumeratorTest.cs: completed the test cases
 
-2002-03-03  Nick Drochak  <[email protected]>
-
-	* DateTimeTest.cs: make static member non-static -- wouldn't work on 
-	Windows if it was static. Doesn't _need_ to be static anyway.
-
+2002-03-03  Nick Drochak  <[email protected]>
+
+	* DateTimeTest.cs: make static member non-static -- wouldn't work on 
+	Windows if it was static. Doesn't _need_ to be static anyway.
+
 2002-03-01  Duco Fijma  <[email protected]>
 	* AttributeTest.cs: created, far from complete. 
 	* CharEnumeratorTest.cs: created. Contains just the basic case.
@@ -521,86 +531,86 @@
 2002-02-21  Duco Fijma <[email protected]>
 	* GuidTest.cs: changed according to fix in System.Guid
 
-2002-02-20  Nick Drochak  <[email protected]>
-
-	* Int64Test.cs: One array was giving us trouble.  Not sure why, but
-	it's related to the number of elements in an Array.  For short Arrays
-	the compiler doesn't use the PrivateImplmentationDetails struct,
-	but for longer ones it does.  That's when our corlib fails. I paired
-	down the array for now.
-
-2002-02-19  Duco Fijma <[email protected]>
-	* GuidTest.cs: added a few cases
-
-2002-02-18  Nick Drochak  <[email protected]>
-
-	* GuidTest.cs: Fix compile error.  Needed to cast the null in the call to
-	constructor to avoid ambiguity.
-
-2002-02-11  Nick Drochak  <[email protected]>
-
-	* Int64Test.cs: Various fixes to make tests work against the ms corlib.
-	Currency Symbol tests seem to be system dependant.  Not sure if this
-	will work on other systems, so please test it if you can. The most
-	disturbing one is negative numbers.  Should they be (n) or -n ?
-
-2002-02-10  Nick Drochak  <[email protected]>
-
-	* AllTests.cs: Add Int64Test to the Suite
-	* Int64Test.cs: Change static member to instance member. This was
-	causing NUnitConsole some grief.  Should be instance member anyway.
-
-2002-02-09  Nick Drochak  <[email protected]>
-
-	* ByteTest.cs:
-	* Int16Test.cs:
-	* Int32Test.cs:
-	* SByteTest.cs:
-	* UInt16Test.cs:
-	* UInt32Test.cs:
-	* UInt64Test.cs: Fixed tests where a "$" was hard coded.  Change it to
-	use NumberFormatInfo.CurrentInfo.CurrencySymbol.  Also used
-	NumberFormatInfo.InvariantInfo.CurrencySymbol where appropriate. These
-	tests all pass now with mscorlib.
-
-2002-01-06  Nick Drochak  <[email protected]>
-
-	* ResolveEventArgsTest.cs: New test.
-	* AllTests.cs: Added new test to suite.
-
-2001-12-27  Nick Drochak <[email protected]>
-
-	* UInt32Test.cs: Added messages to Asserts()'s to find out which one was faliing.
-
-2001-12-21  Miguel de Icaza  <[email protected]>
-
-	* UInt32Test.cs: Added tests for UInt32.Parse.
-
-	* Int32Test.cs: Added tests for Int32.Parse for various cases.
-
-2001-12-08  Nick Drochak  <[email protected]>
-
-	* ByteTest.cs: Added messages to Assert()'s to find out which one was failing.
-
-2001-11-28  Nick Drochak <[email protected]>
-
-	* Int16Test.cs Int32Test.cs SByteTest.cs: Surgically removed tests that rely on culture of system.  These need to be crafted a bit differently.
-
-2001-11-27  Nick Drochak  <[email protected]>
-
-	* SByteTest.cs: Add messages to Assert()'s so we can tell where the tests fail.
-
-2002-02-21  Bob Doan  <[email protected]>
-
-	* BooleanTest.cs: Added New test suite
-	* AllTests.cs: Added new Boolean test to suite.
-
-2002-02-24  Bob Doan  <[email protected]>
-
-	* BooleanTest.cs: Use correct argument order in AssertEquals
-	* AllTests.cs: Added new Double test to suite.
-	* DoubleTest.cs: Add new test suite
-
-2002-02-24  Bob Doan  <[email protected]>
-
-	* DoubleTest.cs: Added parse tests to Double test suite, removed GetHashCodeTests
+2002-02-20  Nick Drochak  <[email protected]>
+
+	* Int64Test.cs: One array was giving us trouble.  Not sure why, but
+	it's related to the number of elements in an Array.  For short Arrays
+	the compiler doesn't use the PrivateImplmentationDetails struct,
+	but for longer ones it does.  That's when our corlib fails. I paired
+	down the array for now.
+
+2002-02-19  Duco Fijma <[email protected]>
+	* GuidTest.cs: added a few cases
+
+2002-02-18  Nick Drochak  <[email protected]>
+
+	* GuidTest.cs: Fix compile error.  Needed to cast the null in the call to
+	constructor to avoid ambiguity.
+
+2002-02-11  Nick Drochak  <[email protected]>
+
+	* Int64Test.cs: Various fixes to make tests work against the ms corlib.
+	Currency Symbol tests seem to be system dependant.  Not sure if this
+	will work on other systems, so please test it if you can. The most
+	disturbing one is negative numbers.  Should they be (n) or -n ?
+
+2002-02-10  Nick Drochak  <[email protected]>
+
+	* AllTests.cs: Add Int64Test to the Suite
+	* Int64Test.cs: Change static member to instance member. This was
+	causing NUnitConsole some grief.  Should be instance member anyway.
+
+2002-02-09  Nick Drochak  <[email protected]>
+
+	* ByteTest.cs:
+	* Int16Test.cs:
+	* Int32Test.cs:
+	* SByteTest.cs:
+	* UInt16Test.cs:
+	* UInt32Test.cs:
+	* UInt64Test.cs: Fixed tests where a "$" was hard coded.  Change it to
+	use NumberFormatInfo.CurrentInfo.CurrencySymbol.  Also used
+	NumberFormatInfo.InvariantInfo.CurrencySymbol where appropriate. These
+	tests all pass now with mscorlib.
+
+2002-01-06  Nick Drochak  <[email protected]>
+
+	* ResolveEventArgsTest.cs: New test.
+	* AllTests.cs: Added new test to suite.
+
+2001-12-27  Nick Drochak <[email protected]>
+
+	* UInt32Test.cs: Added messages to Asserts()'s to find out which one was faliing.
+
+2001-12-21  Miguel de Icaza  <[email protected]>
+
+	* UInt32Test.cs: Added tests for UInt32.Parse.
+
+	* Int32Test.cs: Added tests for Int32.Parse for various cases.
+
+2001-12-08  Nick Drochak  <[email protected]>
+
+	* ByteTest.cs: Added messages to Assert()'s to find out which one was failing.
+
+2001-11-28  Nick Drochak <[email protected]>
+
+	* Int16Test.cs Int32Test.cs SByteTest.cs: Surgically removed tests that rely on culture of system.  These need to be crafted a bit differently.
+
+2001-11-27  Nick Drochak  <[email protected]>
+
+	* SByteTest.cs: Add messages to Assert()'s so we can tell where the tests fail.
+
+2002-02-21  Bob Doan  <[email protected]>
+
+	* BooleanTest.cs: Added New test suite
+	* AllTests.cs: Added new Boolean test to suite.
+
+2002-02-24  Bob Doan  <[email protected]>
+
+	* BooleanTest.cs: Use correct argument order in AssertEquals
+	* AllTests.cs: Added new Double test to suite.
+	* DoubleTest.cs: Add new test suite
+
+2002-02-24  Bob Doan  <[email protected]>
+
+	* DoubleTest.cs: Added parse tests to Double test suite, removed GetHashCodeTests

+ 4 - 2
mcs/class/corlib/Test/System/ConvertTest.cs

@@ -786,7 +786,8 @@ namespace MonoTests.System
 			AssertEquals("#H08", (decimal)tryInt64, Convert.ToDecimal(tryInt64));
 			AssertEquals("#H09", (decimal)trySByte, Convert.ToDecimal(trySByte));
 			AssertEquals("#H10", (decimal)tryFloat, Convert.ToDecimal(tryFloat));
-			AssertEquals("#H11", (decimal)23456.432, Convert.ToDecimal("23456.432"));
+			string sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
+			AssertEquals("#H11", (decimal)23456.432, Convert.ToDecimal("23456" + sep + "432"));
 			AssertEquals("#H12", (decimal)tryUI16, Convert.ToDecimal(tryUI16));
 			AssertEquals("#H13", (decimal)tryUI32, Convert.ToDecimal(tryUI32));
 			AssertEquals("#H14", (decimal)tryUI64, Convert.ToDecimal(tryUI64));
@@ -900,7 +901,8 @@ namespace MonoTests.System
 				iTest++;
 				AssertEquals("#I10", (double)tryFloat, Convert.ToDouble(tryFloat));
 				iTest++;
-				AssertEquals("#I11", (double)23456.432, Convert.ToDouble("23456.432"));
+				string sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
+				AssertEquals("#I11", (double)23456.432, Convert.ToDouble("23456" + sep + "432"));
 				iTest++;
 				AssertEquals("#I12", (double)tryUI16, Convert.ToDouble(tryUI16));
 				iTest++;

+ 209 - 194
mcs/class/corlib/Test/System/DoubleTest.cs

@@ -1,194 +1,209 @@
-// BooleanTest.cs - NUnit Test Cases for the System.Double class
-//
-// Bob Doan <[email protected]>
-//
-// (C) Ximian, Inc.  http://www.ximian.com
-//
-
-using NUnit.Framework;
-using System;
-using System.Globalization;
-
-namespace MonoTests.System
-{
-
-public class DoubleTest : TestCase
-{
-	private const Double d_zero = 0.0;
-	private const Double d_neg = -1234.5678;
-	private const Double d_pos = 1234.9999;
-	private const Double d_pos2 = 1234.9999;
-	private const Double d_nan = Double.NaN;
-	private const Double d_pinf = Double.PositiveInfinity;
-	private const Double d_ninf = Double.NegativeInfinity;
-	private const String s = "What Ever";
-	private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
-	
-	
-	private string[] string_values = {
-		"1", ".1", "1.1", "-12", "44.444432", ".000021121", 
-		"   .00001", "  .223    ", "         -221.3233",
-		" 1.7976931348623157e308 ", "+1.7976931348623157E308", "-1.7976931348623157e308",
-		"4.9406564584124650e-324",
-		"6.28318530717958647692528676655900577",
-		"1e-05",
-	};
-	private double[] double_values = {
-		1, .1, 1.1, -12, 44.444432, .000021121,
-		.00001, .223, -221.3233,
-		1.7976931348623157e308, 1.7976931348623157e308, -1.7976931348623157e308,
-		4.9406564584124650e-324,
-		6.28318530717958647692528676655900577,
-		1e-05
-	};
-
-	public DoubleTest () {}
-	
-
-	protected override void SetUp ()
-	{
-	}
-
-	public void TestPublicFields ()
-	{												  
-		AssertEquals("Epsilon Field has wrong value", 3.9406564584124654e-324, Double.Epsilon);
-		AssertEquals("MaxValue Field has wrong value", 1.7976931348623157e+308, Double.MaxValue);
-		AssertEquals("MinValue Field has wrong value", -1.7976931348623157e+308, Double.MinValue);
-		AssertEquals("NegativeInfinity Field has wrong value",  (double)-1.0 / (double)(0.0), Double.NegativeInfinity);		
-		AssertEquals("PositiveInfinity Field has wrong value",  (double)1.0 / (double)(0.0), Double.PositiveInfinity);		
-	}
-
-	public void TestCompareTo () {
-		//If you do int foo =  d_ninf.CompareTo(d_pinf); Assert(".." foo < 0, true) this works.... WHY???
-		Assert("CompareTo Infinity failed", d_ninf.CompareTo(d_pinf) < 0);		
-
-		Assert("CompareTo Failed01", d_neg.CompareTo(d_pos) < 0);
-		Assert("CompareTo NaN Failed", d_nan.CompareTo(d_neg) < 0);				
-
-		AssertEquals("CompareTo Failed02", 0, d_pos.CompareTo(d_pos2));		
-		AssertEquals("CompareTo Failed03", 0, d_pinf.CompareTo(d_pinf));		
-		AssertEquals("CompareTo Failed04", 0, d_ninf.CompareTo(d_ninf));		
-		AssertEquals("CompareTo Failed05", 0, d_nan.CompareTo(d_nan));		
-
-		Assert("CompareTo Failed06", d_pos.CompareTo(d_neg) > 0);		
-		Assert("CompareTo Failed07", d_pos.CompareTo(d_nan) > 0);		
-		Assert("CompareTo Failed08", d_pos.CompareTo(null) > 0);		
-		
-		try {
-			d_pos.CompareTo(s);
-			Fail("CompareTo should raise a System.ArgumentException");
-		}
-		catch (Exception e) {
-			AssertEquals ("CompareTo should be a System.ArgumentException", typeof(ArgumentException), e.GetType());
-		}		
-		
-	}
-
-	public void TestEquals () {
-		AssertEquals("Equals Failed", true, d_pos.Equals(d_pos2));
-		AssertEquals("Equals Failed", false, d_pos.Equals(d_neg));
-		AssertEquals("Equals Failed", false, d_pos.Equals(s));
-		
-	}
-
-	public void TestTypeCode () {
-		AssertEquals("GetTypeCode Failed", TypeCode.Double, d_pos.GetTypeCode());		
-	}
-
-	public void TestIsInfinity() {
-		AssertEquals("IsInfinity Failed", true, Double.IsInfinity(Double.PositiveInfinity));
-		AssertEquals("IsInfinity Failed", true, Double.IsInfinity(Double.NegativeInfinity));
-		AssertEquals("IsInfinity Failed", false, Double.IsInfinity(12));		
-	}
-
-	public void TestIsNan() {
-		AssertEquals("IsNan Failed", true, Double.IsNaN(Double.NaN));
-		AssertEquals("IsNan Failed", false, Double.IsNaN(12));
-		AssertEquals("IsNan Failed", false, Double.IsNaN(Double.PositiveInfinity));
-	}
-
-	public void TestIsNegativeInfinity() {
-		AssertEquals("IsNegativeInfinity Failed", true, Double.IsNegativeInfinity(Double.NegativeInfinity));
-		AssertEquals("IsNegativeInfinity Failed", false, Double.IsNegativeInfinity(12));		
-	}
-
-	public void TestIsPositiveInfinity() {
-		AssertEquals("IsPositiveInfinity Failed", true, Double.IsPositiveInfinity(Double.PositiveInfinity));
-		AssertEquals("IsPositiveInfinity Failed", false, Double.IsPositiveInfinity(12));		
-	}
-
-	public void TestParse() {
-		int i=0;
-		try {
-			for(i=0;i<string_values.Length;i++) {			
-				AssertEquals("Parse Failed", double_values[i], Double.Parse(string_values[i]));
-			}
-		} catch (Exception e) {
-			Fail("TestParse: i=" + i + " failed with e = " + e.ToString());
-		}
-		
-		try {
-			AssertEquals("Parse Failed NumberStyles.Float", 10.1111, Double.Parse(" 10.1111 ", NumberStyles.Float, Nfi));
-		} catch (Exception e) {
-			Fail("TestParse: Parse Failed NumberStyles.Float with e = " + e.ToString());
-		}
-
-		try {
-			AssertEquals("Parse Failed NumberStyles.AllowThousands", 1234.5678, Double.Parse("1,234.5678", NumberStyles.Float | NumberStyles.AllowThousands, Nfi));
-		} catch (Exception e) {
-			Fail("TestParse: Parse Failed NumberStyles.AllowThousands with e = " + e.ToString());
-		}
-	
-		try {
-			Double.Parse(null);
-			Fail("Parse should raise a ArgumentNullException");
-		}
-		catch (Exception e) {
-			Assert("Parse should be a ArgumentNullException", typeof(ArgumentNullException) == e.GetType());
-		}		
-
-		try {
-			Double.Parse("save the elk");
-			Fail("Parse should raise a FormatException");
-		}
-		catch (Exception e) {
-			Assert("Parse should be a FormatException", typeof(FormatException) == e.GetType());
-		}		
-
-		double ovf_plus = 0;
-		try {
-			ovf_plus = Double.Parse("1.79769313486232e308");
-			Fail("Parse should have raised an OverflowException +");
-		}
-		catch (Exception e) {
-			AssertEquals("Should be an OverflowException + for " + ovf_plus, typeof(OverflowException), e.GetType());
-		}		
-
-		try {
-			Double.Parse("-1.79769313486232e308");
-			Fail("Parse should have raised an OverflowException -");
-		}
-		catch (Exception e) {
-			AssertEquals("Should be an OverflowException -", typeof(OverflowException), e.GetType());
-		}		
-
-
-	}
-
-	public void TestToString() {
-		//ToString is not yet Implemented......
-		//AssertEquals("ToString Failed", "1234.9999", d_pos.ToString());
-		double d;
-		try {
-			d = 3.1415;
-			d.ToString ("X");
-			Fail ("Should have thrown FormatException");
-		} catch (FormatException) {
-			/* do nothing, this is what we expect */
-		} catch (Exception e) {
-			Fail ("Unexpected exception e: " + e);
-		}
-	}
-
-}
-}
+// BooleanTest.cs - NUnit Test Cases for the System.Double class
+//
+// Bob Doan <[email protected]>
+//
+// (C) Ximian, Inc.  http://www.ximian.com
+//
+
+using NUnit.Framework;
+using System;
+using System.Globalization;
+
+namespace MonoTests.System
+{
+
+public class DoubleTest : TestCase
+{
+	private const Double d_zero = 0.0;
+	private const Double d_neg = -1234.5678;
+	private const Double d_pos = 1234.9999;
+	private const Double d_pos2 = 1234.9999;
+	private const Double d_nan = Double.NaN;
+	private const Double d_pinf = Double.PositiveInfinity;
+	private const Double d_ninf = Double.NegativeInfinity;
+	private const String s = "What Ever";
+	private NumberFormatInfo Nfi = NumberFormatInfo.InvariantInfo;
+	
+	
+	private string[] string_values = {
+		"1", ".1", "1.1", "-12", "44.444432", ".000021121", 
+		"   .00001", "  .223    ", "         -221.3233",
+		" 1.7976931348623157e308 ", "+1.7976931348623157E308", "-1.7976931348623157e308",
+		"4.9406564584124650e-324",
+		"6.28318530717958647692528676655900577",
+		"1e-05",
+	};
+	private double[] double_values = {
+		1, .1, 1.1, -12, 44.444432, .000021121,
+		.00001, .223, -221.3233,
+		1.7976931348623157e308, 1.7976931348623157e308, -1.7976931348623157e308,
+		4.9406564584124650e-324,
+		6.28318530717958647692528676655900577,
+		1e-05
+	};
+
+	public DoubleTest () {}
+	
+
+	protected override void SetUp ()
+	{
+		string sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
+		string_values [0] = "1";
+		string_values [1] = sep + "1";
+		string_values [2] = "1" + sep + "1";
+		string_values [3] = "-12";
+		string_values [4] = "44" + sep + "444432";
+		string_values [5] = sep + "000021121";
+		string_values [6] = "   " + sep + "00001";
+		string_values [7] = "  " + sep + "223    ";
+		string_values [8] = "         -221" + sep + "3233";
+		string_values [9] = " 1" + sep + "7976931348623157e308 ";
+		string_values [10] = "+1" + sep + "7976931348623157E308";
+		string_values [11] = "-1" + sep + "7976931348623157e308";
+		string_values [12] = "4" + sep + "9406564584124650e-324";
+		string_values [13] = "6" + sep + "28318530717958647692528676655900577";
+		string_values [14] = "1e-05";
+	}
+
+	public void TestPublicFields ()
+	{												  
+		AssertEquals("Epsilon Field has wrong value", 3.9406564584124654e-324, Double.Epsilon);
+		AssertEquals("MaxValue Field has wrong value", 1.7976931348623157e+308, Double.MaxValue);
+		AssertEquals("MinValue Field has wrong value", -1.7976931348623157e+308, Double.MinValue);
+		AssertEquals("NegativeInfinity Field has wrong value",  (double)-1.0 / (double)(0.0), Double.NegativeInfinity);		
+		AssertEquals("PositiveInfinity Field has wrong value",  (double)1.0 / (double)(0.0), Double.PositiveInfinity);		
+	}
+
+	public void TestCompareTo () {
+		//If you do int foo =  d_ninf.CompareTo(d_pinf); Assert(".." foo < 0, true) this works.... WHY???
+		Assert("CompareTo Infinity failed", d_ninf.CompareTo(d_pinf) < 0);		
+
+		Assert("CompareTo Failed01", d_neg.CompareTo(d_pos) < 0);
+		Assert("CompareTo NaN Failed", d_nan.CompareTo(d_neg) < 0);				
+
+		AssertEquals("CompareTo Failed02", 0, d_pos.CompareTo(d_pos2));		
+		AssertEquals("CompareTo Failed03", 0, d_pinf.CompareTo(d_pinf));		
+		AssertEquals("CompareTo Failed04", 0, d_ninf.CompareTo(d_ninf));		
+		AssertEquals("CompareTo Failed05", 0, d_nan.CompareTo(d_nan));		
+
+		Assert("CompareTo Failed06", d_pos.CompareTo(d_neg) > 0);		
+		Assert("CompareTo Failed07", d_pos.CompareTo(d_nan) > 0);		
+		Assert("CompareTo Failed08", d_pos.CompareTo(null) > 0);		
+		
+		try {
+			d_pos.CompareTo(s);
+			Fail("CompareTo should raise a System.ArgumentException");
+		}
+		catch (Exception e) {
+			AssertEquals ("CompareTo should be a System.ArgumentException", typeof(ArgumentException), e.GetType());
+		}		
+		
+	}
+
+	public void TestEquals () {
+		AssertEquals("Equals Failed", true, d_pos.Equals(d_pos2));
+		AssertEquals("Equals Failed", false, d_pos.Equals(d_neg));
+		AssertEquals("Equals Failed", false, d_pos.Equals(s));
+		
+	}
+
+	public void TestTypeCode () {
+		AssertEquals("GetTypeCode Failed", TypeCode.Double, d_pos.GetTypeCode());		
+	}
+
+	public void TestIsInfinity() {
+		AssertEquals("IsInfinity Failed", true, Double.IsInfinity(Double.PositiveInfinity));
+		AssertEquals("IsInfinity Failed", true, Double.IsInfinity(Double.NegativeInfinity));
+		AssertEquals("IsInfinity Failed", false, Double.IsInfinity(12));		
+	}
+
+	public void TestIsNan() {
+		AssertEquals("IsNan Failed", true, Double.IsNaN(Double.NaN));
+		AssertEquals("IsNan Failed", false, Double.IsNaN(12));
+		AssertEquals("IsNan Failed", false, Double.IsNaN(Double.PositiveInfinity));
+	}
+
+	public void TestIsNegativeInfinity() {
+		AssertEquals("IsNegativeInfinity Failed", true, Double.IsNegativeInfinity(Double.NegativeInfinity));
+		AssertEquals("IsNegativeInfinity Failed", false, Double.IsNegativeInfinity(12));		
+	}
+
+	public void TestIsPositiveInfinity() {
+		AssertEquals("IsPositiveInfinity Failed", true, Double.IsPositiveInfinity(Double.PositiveInfinity));
+		AssertEquals("IsPositiveInfinity Failed", false, Double.IsPositiveInfinity(12));		
+	}
+
+	public void TestParse() {
+		int i=0;
+		try {
+			for(i=0;i<string_values.Length;i++) {			
+				AssertEquals("Parse Failed", double_values[i], Double.Parse(string_values[i]));
+			}
+		} catch (Exception e) {
+			Fail("TestParse: i=" + i + " failed with e = " + e.ToString());
+		}
+		
+		try {
+			AssertEquals("Parse Failed NumberStyles.Float", 10.1111, Double.Parse(" 10.1111 ", NumberStyles.Float, Nfi));
+		} catch (Exception e) {
+			Fail("TestParse: Parse Failed NumberStyles.Float with e = " + e.ToString());
+		}
+
+		try {
+			AssertEquals("Parse Failed NumberStyles.AllowThousands", 1234.5678, Double.Parse("1,234.5678", NumberStyles.Float | NumberStyles.AllowThousands, Nfi));
+		} catch (Exception e) {
+			Fail("TestParse: Parse Failed NumberStyles.AllowThousands with e = " + e.ToString());
+		}
+	
+		try {
+			Double.Parse(null);
+			Fail("Parse should raise a ArgumentNullException");
+		}
+		catch (Exception e) {
+			Assert("Parse should be a ArgumentNullException", typeof(ArgumentNullException) == e.GetType());
+		}		
+
+		try {
+			Double.Parse("save the elk");
+			Fail("Parse should raise a FormatException");
+		}
+		catch (Exception e) {
+			Assert("Parse should be a FormatException", typeof(FormatException) == e.GetType());
+		}		
+
+		string sep = NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
+		double ovf_plus = 0;
+		try {
+			ovf_plus = Double.Parse("1" + sep + "79769313486232e308");
+			Fail("Parse should have raised an OverflowException +");
+		}
+		catch (Exception e) {
+			AssertEquals("Should be an OverflowException + for " + ovf_plus, typeof(OverflowException), e.GetType());
+		}		
+
+		try {
+			Double.Parse("-1" + sep + "79769313486232e308");
+			Fail("Parse should have raised an OverflowException -");
+		}
+		catch (Exception e) {
+			AssertEquals("Should be an OverflowException -", typeof(OverflowException), e.GetType());
+		}		
+	}
+
+	public void TestToString() {
+		//ToString is not yet Implemented......
+		//AssertEquals("ToString Failed", "1234.9999", d_pos.ToString());
+		double d;
+		try {
+			d = 3.1415;
+			d.ToString ("X");
+			Fail ("Should have thrown FormatException");
+		} catch (FormatException) {
+			/* do nothing, this is what we expect */
+		} catch (Exception e) {
+			Fail ("Unexpected exception e: " + e);
+		}
+	}
+
+}
+}