harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r396842 - in /incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math: BigDecimalTest.java BigIntegerTest.java
Date Tue, 25 Apr 2006 11:16:40 GMT
Author: mloenko
Date: Tue Apr 25 04:16:37 2006
New Revision: 396842

URL: http://svn.apache.org/viewcvs?rev=396842&view=rev
Log:
Let JUnit handle the "unexpected exception" cases

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java
    incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigIntegerTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java?rev=396842&r1=396841&r2=396842&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigDecimalTest.java
Tue Apr 25 04:16:37 2006
@@ -78,7 +78,7 @@
 	/**
 	 * @tests java.math.BigDecimal#BigDecimal(java.lang.String)
 	 */
-	public void test_ConstructorLjava_lang_String() {
+	public void test_ConstructorLjava_lang_String() throws NumberFormatException {
 		BigDecimal big = new BigDecimal("345.23499600293850");
 		assertTrue("the BigDecimal value is not initialized properly", big
 				.toString().equals("345.23499600293850")
@@ -91,15 +91,8 @@
 		assertTrue("the BigDecimal value is not initialized properly", big
 				.toString().equals("123")
 				&& big.scale() == 0);
-		int r = 0;
-		try {
-			new BigDecimal("1.234E02");
-		} catch (NumberFormatException e) {
-			r = 1;
-		}
-		assertTrue(
-				"constructor failed to catch invalid character in BigDecimal(string)",
-				r == 0);
+
+		new BigDecimal("1.234E02");
 	}
 
 	/**
@@ -110,18 +103,8 @@
 		 * BigDecimal does not support a + sign in the exponent when converting
 		 * from a String
 		 */
-		try {
-			new BigDecimal(+23e-0);
-		} catch (Throwable e) {
-			fail("Unexpected Exception when constructing BigDecimal  +23e-0 : "
-					+ e);
-		}
-		try {
-			new BigDecimal(-23e+0);
-		} catch (Throwable e) {
-			fail("Unexpected Exception when constructing BigDecimal  -23e+0 : "
-					+ e);
-		}
+		new BigDecimal(+23e-0);
+		new BigDecimal(-23e+0);
 	}
 
 	/**
@@ -131,13 +114,8 @@
 		boolean gotNFE = false;
 		try {
 			new BigDecimal("");			
+            fail("NumberFormatException expected");
 		} catch (NumberFormatException e) {
-			gotNFE = true;
-		} catch (Throwable e) {
-			fail("Unexpected exception for new BigDecimal(\"\") " + e);
-		}
-		if (!gotNFE) { 
-			fail("Expected NumberFormatException for new BigDecimal(\"\")");
 		}
 	}
 	
@@ -145,29 +123,16 @@
 	 * @tests java.math.BigDecimal#BigDecimal(java.lang.String)
 	 */
 	public void test_constructor_String_plus_minus_exp() {
-		boolean gotNFE = false;
 		try {
 			new BigDecimal("+35e+-2");			
+            fail("NumberFormatException expected");
 		} catch (NumberFormatException e) {
-			gotNFE = true;
-		} catch (Throwable e) {
-			fail("Unexpected exception for new BigDecimal(\"+35e+-2\") " + e);
 		}
 		
-		if (!gotNFE) {
-			fail("Expected NumberFormatException for new BigDecimal(\"+35e+-2\")");
-		}
-		gotNFE = false;
-
 		try {
 			new BigDecimal("-35e-+2");			
+            fail("NumberFormatException expected");
 		} catch (NumberFormatException e) {
-			gotNFE = true;
-		} catch (Throwable e) {
-			fail("Unexpected exception for new BigDecimal(\"-35e-+2\") " + e);
-		}
-		if (!gotNFE) {
-			fail("Expected NumberFormatException for new BigDecimal(\"-35e-+2\")");
 		}
 	}
 
@@ -237,13 +202,12 @@
 				"1000.47")
 				&& divd3.scale() == 2);
 		divd2 = new BigDecimal(000D);
-		int r = 0;
+
 		try {
-			divd3 = divd1.divide(divd2, BigDecimal.ROUND_DOWN);
+			divd1.divide(divd2, BigDecimal.ROUND_DOWN);
+            fail("divide by zero is not caught");
 		} catch (ArithmeticException e) {
-			r = 1;
 		}
-		assertTrue("divide by zero is not caught", r == 1);
 	}
 
 	/**
@@ -262,13 +226,12 @@
 				"1233456/13.455 is not correct or does not have the correct scale",
 				divd3.toString().equals("91672") && divd3.scale() == 0);
 		divd2 = new BigDecimal(0000D);
-		int r = 0;
+
 		try {
-			divd3 = divd1.divide(divd2, 4, BigDecimal.ROUND_DOWN);
+			divd1.divide(divd2, 4, BigDecimal.ROUND_DOWN);
+            fail("divide by zero is not caught");
 		} catch (ArithmeticException e) {
-			r = 1;
 		}
-		assertTrue("divide by zero is not caught", r == 1);
 	}
 
 	/**
@@ -590,15 +553,12 @@
 		assertTrue("the number 12345.908 after setting scale is wrong",
 				setScale2.unscaledValue().equals(setresult)
 						&& setScale2.scale() == 5);
-		int r = 0;
+
 		try {
 			setScale2 = setScale1.setScale(2, BigDecimal.ROUND_UNNECESSARY);
+            fail("arithmetic Exception not caught as a result of loosing precision");
 		} catch (ArithmeticException e) {
-			r = 1;
 		}
-		assertTrue(
-				"arithmetic Exception not caught as a result of loosing precision",
-				r == 1);
 	}
 
 	/**
@@ -708,14 +668,11 @@
 				setScale2.toString().equals("-1234") && setScale2.scale() == 0);
 
 		// testing rounding Mode ROUND_UNNECESSARY
-		int r = 0;
 		try {
-			setScale2 = setScale1.setScale(3, BigDecimal.ROUND_UNNECESSARY);
+			setScale1.setScale(3, BigDecimal.ROUND_UNNECESSARY);
+            fail("arithmetic Exception not caught for round unnecessary");
 		} catch (ArithmeticException e) {
-			r = 1;
 		}
-		assertTrue("arithmetic Exception not caught for round unnecessary",
-				r == 1);
 
 		// testing rounding Mode ROUND_UP
 		setScale1 = new BigDecimal("100000.374");
@@ -731,15 +688,11 @@
 				setScale2.doubleValue() == -134.35D && setScale2.scale() == 2);
 
 		// testing invalid rounding modes
-		r = 0;
 		try {
 			setScale2 = setScale1.setScale(0, -123);
+            fail("IllegalArgumentException is not caught for wrong rounding mode");
 		} catch (IllegalArgumentException e) {
-			r = 1;
 		}
-		assertTrue(
-				"IllegalArgumentException is not caught for wrong rounding mode",
-				r == 1);
 	}
 
 	/**
@@ -896,11 +849,5 @@
 				"the toString representation of 9223372036854775806 is wrong",
 				valueOfJI.toString().equals("0.000"));
 
-	}
-
-	protected void setUp() {
-	}
-
-	protected void tearDown() {
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigIntegerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigIntegerTest.java?rev=396842&r1=396841&r2=396842&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigIntegerTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/math/src/test/java/tests/api/java/math/BigIntegerTest.java
Tue Apr 25 04:16:37 2006
@@ -145,28 +145,21 @@
 		assertTrue("Incorrect value for zero", bi.equals(zero));
 		myByteArray = new byte[] { (byte) 1 };
 		try {
-			bi = new BigInteger(0, myByteArray);
+			new BigInteger(0, myByteArray);
+            fail("Failed to throw NumberFormatException");
 		} catch (NumberFormatException e) {
 			// correct
-			return;
 		}
-		fail("Failed to throw NumberFormatException");
 	}
 	
 	/**
 	 * @tests java.math.BigInteger#BigInteger(java.lang.String)
 	 */
 	public void test_constructor_String_empty() {
-		boolean gotNFE = false;
 		try {
 			new BigInteger("");			
+            fail("Expected NumberFormatException for new BigInteger(\"\")");
 		} catch (NumberFormatException e) {
-			gotNFE = true;
-		} catch (Throwable e) {
-			fail("Unexpected exception for new BigInteger(\"\") " + e);
-		}
-		if (!gotNFE) { 
-			fail("Expected NumberFormatException for new BigInteger(\"\")");
 		}
 	}
 
@@ -581,136 +574,117 @@
 		testDivRanges(new BigInteger("62EB40FEF85AA9EB", 16));
 		testAllDivs(BigInteger.valueOf(0xCC0225953CL), BigInteger
 				.valueOf(0x1B937B765L));
-		boolean thr = false;
+
 		try {
 			largePos.divide(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on div by zero", thr);
-		thr = false;
+
 		try {
 			bi1.divide(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on div by zero", thr);
-		thr = false;
+
 		try {
 			bi3.negate().divide(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on div by zero", thr);
-		thr = false;
+
 		try {
 			zero.divide(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on div by zero", thr);
 	}
 
 	/**
 	 * @tests java.math.BigInteger#remainder(java.math.BigInteger)
 	 */
 	public void test_remainderLjava_math_BigInteger() {
-		boolean thr = false;
 		try {
 			largePos.remainder(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on remainder by zero", thr);
-		thr = false;
+
 		try {
 			bi1.remainder(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on remainder by zero", thr);
-		thr = false;
+
 		try {
 			bi3.negate().remainder(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on remainder by zero", thr);
-		thr = false;
+
 		try {
 			zero.remainder(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on remainder by zero", thr);
 	}
 
 	/**
 	 * @tests java.math.BigInteger#mod(java.math.BigInteger)
 	 */
 	public void test_modLjava_math_BigInteger() {
-		boolean thr = false;
 		try {
 			largePos.mod(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on mod by zero", thr);
-		thr = false;
+
 		try {
 			bi1.mod(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on mod by zero", thr);
-		thr = false;
+
 		try {
 			bi3.negate().mod(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on mod by zero", thr);
-		thr = false;
+
 		try {
 			zero.mod(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on mod by zero", thr);
 	}
 
 	/**
 	 * @tests java.math.BigInteger#divideAndRemainder(java.math.BigInteger)
 	 */
 	public void test_divideAndRemainderLjava_math_BigInteger() {
-		boolean thr = false;
 		try {
 			largePos.divideAndRemainder(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on divAndRem by zero", thr);
-		thr = false;
+
 		try {
 			bi1.divideAndRemainder(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on divAndRem by zero", thr);
-		thr = false;
+
 		try {
 			bi3.negate().divideAndRemainder(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on divAndRem by zero", thr);
-		thr = false;
+
 		try {
 			zero.divideAndRemainder(zero);
+            fail("ArithmeticException expected");
 		} catch (ArithmeticException e) {
-			thr = true;
 		}
-		assertTrue("exception on divAndRem by zero", thr);
 	}
 
 	/**
@@ -895,9 +869,6 @@
 		booleanPairs = new BigInteger[][] { { largePos, smallPos },
 				{ largePos, smallNeg }, { largeNeg, smallPos },
 				{ largeNeg, smallNeg } };
-	}
-
-	protected void tearDown() {
 	}
 
 	private void testDiv(BigInteger i1, BigInteger i2) {



Mime
View raw message