You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sm...@apache.org on 2006/08/29 07:40:47 UTC
svn commit: r437974 [13/19] -
/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ShortTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ShortTest.java?rev=437974&r1=437973&r2=437974&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ShortTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ShortTest.java Mon Aug 28 22:40:44 2006
@@ -1,660 +1,660 @@
-/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class ShortTest extends TestCase {
- private Short sp = new Short((short) 18000);
- private Short sp2 = new Short((short) 18000);
- private Short sn = new Short((short) -19000);
-
- /**
- * @tests java.lang.Short#byteValue()
- */
- public void test_byteValue() {
- // Test for method byte java.lang.Short.byteValue()
- assertEquals("Returned incorrect byte value", 0, new Short(Short.MIN_VALUE)
- .byteValue());
- assertEquals("Returned incorrect byte value", -1, new Short(Short.MAX_VALUE)
- .byteValue());
- }
-
- /**
- * @tests java.lang.Short#compareTo(java.lang.Short)
- */
- public void test_compareToLjava_lang_Short() {
- // Test for method int java.lang.Short.compareTo(java.lang.Short)
- Short s = new Short((short) 1);
- Short x = new Short((short) 3);
- assertTrue(
- "Should have returned negative value when compared to greater short",
- s.compareTo(x) < 0);
- x = new Short((short) -1);
- assertTrue(
- "Should have returned positive value when compared to lesser short",
- s.compareTo(x) > 0);
- x = new Short((short) 1);
- assertEquals("Should have returned zero when compared to equal short",
- 0, s.compareTo(x));
-
- try {
- new Short((short)0).compareTo(null);
- fail("No NPE");
- } catch (NullPointerException e) {
- }
- }
-
- /**
- * @tests java.lang.Short#decode(java.lang.String)
- */
- public void test_decodeLjava_lang_String2() {
- // Test for method java.lang.Short
- // java.lang.Short.decode(java.lang.String)
- assertTrue("Did not decode -1 correctly", Short.decode("-1")
- .shortValue() == (short) -1);
- assertTrue("Did not decode -100 correctly", Short.decode("-100")
- .shortValue() == (short) -100);
- assertTrue("Did not decode 23 correctly", Short.decode("23")
- .shortValue() == (short) 23);
- assertTrue("Did not decode 0x10 correctly", Short.decode("0x10")
- .shortValue() == (short) 16);
- assertTrue("Did not decode 32767 correctly", Short.decode("32767")
- .shortValue() == (short) 32767);
- assertTrue("Did not decode -32767 correctly", Short.decode("-32767")
- .shortValue() == (short) -32767);
- assertTrue("Did not decode -32768 correctly", Short.decode("-32768")
- .shortValue() == (short) -32768);
-
- boolean exception = false;
- try {
- Short.decode("123s");
- } catch (NumberFormatException e) {
- // correct
- exception = true;
- }
- assertTrue("Did not throw NumberFormatException decoding 123s",
- exception);
-
- exception = false;
- try {
- Short.decode("32768");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Short.decode("-32769");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Short.decode("0x8000");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Short.decode("-0x8001");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MIN_VALUE - 1", exception);
- }
-
- /**
- * @tests java.lang.Short#parseShort(java.lang.String)
- */
- public void test_parseShortLjava_lang_String2() {
- // Test for method short java.lang.Short.parseShort(java.lang.String)
- short sp = Short.parseShort("32746");
- short sn = Short.parseShort("-32746");
-
- assertTrue("Incorrect parse of short", sp == (short) 32746
- && (sn == (short) -32746));
- assertEquals("Returned incorrect value for 0", 0, Short.parseShort("0"));
- assertTrue("Returned incorrect value for most negative value", Short
- .parseShort("-32768") == (short) 0x8000);
- assertTrue("Returned incorrect value for most positive value", Short
- .parseShort("32767") == 0x7fff);
-
- boolean exception = false;
- try {
- Short.parseShort("32768");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Short.parseShort("-32769");
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
- }
-
- /**
- * @tests java.lang.Short#parseShort(java.lang.String, int)
- */
- public void test_parseShortLjava_lang_StringI2() {
- // Test for method short java.lang.Short.parseShort(java.lang.String,
- // int)
- boolean aThrow = true;
- assertEquals("Incorrectly parsed hex string",
- 255, Short.parseShort("FF", 16));
- assertEquals("Incorrectly parsed oct string",
- 16, Short.parseShort("20", 8));
- assertEquals("Incorrectly parsed dec string",
- 20, Short.parseShort("20", 10));
- assertEquals("Incorrectly parsed bin string",
- 4, Short.parseShort("100", 2));
- assertEquals("Incorrectly parsed -hex string", -255, Short
- .parseShort("-FF", 16));
- assertEquals("Incorrectly parsed -oct string",
- -16, Short.parseShort("-20", 8));
- assertEquals("Incorrectly parsed -bin string", -4, Short
- .parseShort("-100", 2));
- assertEquals("Returned incorrect value for 0 hex", 0, Short.parseShort("0",
- 16));
- assertTrue("Returned incorrect value for most negative value hex",
- Short.parseShort("-8000", 16) == (short) 0x8000);
- assertTrue("Returned incorrect value for most positive value hex",
- Short.parseShort("7fff", 16) == 0x7fff);
- assertEquals("Returned incorrect value for 0 decimal", 0, Short.parseShort(
- "0", 10));
- assertTrue("Returned incorrect value for most negative value decimal",
- Short.parseShort("-32768", 10) == (short) 0x8000);
- assertTrue("Returned incorrect value for most positive value decimal",
- Short.parseShort("32767", 10) == 0x7fff);
-
- try {
- Short.parseShort("FF", 2);
- } catch (NumberFormatException e) {
- // Correct
- aThrow = false;
- }
- if (aThrow) {
- fail(
- "Failed to throw exception when passed hex string and base 2 radix");
- }
-
- boolean exception = false;
- try {
- Short.parseShort("10000000000", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue(
- "Failed to throw exception when passed string larger than 16 bits",
- exception);
-
- exception = false;
- try {
- Short.parseShort("32768", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Short.parseShort("-32769", 10);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
-
- exception = false;
- try {
- Short.parseShort("8000", 16);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
-
- exception = false;
- try {
- Short.parseShort("-8001", 16);
- } catch (NumberFormatException e) {
- // Correct
- exception = true;
- }
- assertTrue("Failed to throw exception for hex MIN_VALUE + 1", exception);
- }
-
- /**
- * @tests java.lang.Short#toString()
- */
- public void test_toString2() {
- // Test for method java.lang.String java.lang.Short.toString()
- assertTrue("Invalid string returned", sp.toString().equals("18000")
- && (sn.toString().equals("-19000")));
- assertEquals("Returned incorrect string", "32767", new Short((short) 32767)
- .toString());
- assertEquals("Returned incorrect string", "-32767", new Short((short) -32767)
- .toString());
- assertEquals("Returned incorrect string", "-32768", new Short((short) -32768)
- .toString());
- }
-
- /**
- * @tests java.lang.Short#toString(short)
- */
- public void test_toStringS2() {
- // Test for method java.lang.String java.lang.Short.toString(short)
- assertEquals("Returned incorrect string", "32767", Short.toString((short) 32767)
- );
- assertEquals("Returned incorrect string", "-32767", Short.toString((short) -32767)
- );
- assertEquals("Returned incorrect string", "-32768", Short.toString((short) -32768)
- );
- }
-
- /**
- * @tests java.lang.Short#valueOf(java.lang.String)
- */
- public void test_valueOfLjava_lang_String2() {
- // Test for method java.lang.Short
- // java.lang.Short.valueOf(java.lang.String)
- assertEquals("Returned incorrect short", -32768, Short.valueOf("-32768")
- .shortValue());
- assertEquals("Returned incorrect short", 32767, Short.valueOf("32767")
- .shortValue());
- }
-
- /**
- * @tests java.lang.Short#valueOf(java.lang.String, int)
- */
- public void test_valueOfLjava_lang_StringI2() {
- // Test for method java.lang.Short
- // java.lang.Short.valueOf(java.lang.String, int)
- boolean aThrow = true;
- assertEquals("Incorrectly parsed hex string", 255, Short.valueOf("FF", 16)
- .shortValue());
- assertEquals("Incorrectly parsed oct string", 16, Short.valueOf("20", 8)
- .shortValue());
- assertEquals("Incorrectly parsed dec string", 20, Short.valueOf("20", 10)
- .shortValue());
- assertEquals("Incorrectly parsed bin string", 4, Short.valueOf("100", 2)
- .shortValue());
- assertEquals("Incorrectly parsed -hex string", -255, Short.valueOf("-FF", 16)
- .shortValue());
- assertEquals("Incorrectly parsed -oct string", -16, Short.valueOf("-20", 8)
- .shortValue());
- assertEquals("Incorrectly parsed -bin string", -4, Short.valueOf("-100", 2)
- .shortValue());
- assertTrue("Did not decode 32767 correctly", Short.valueOf("32767", 10)
- .shortValue() == (short) 32767);
- assertTrue("Did not decode -32767 correctly", Short.valueOf("-32767",
- 10).shortValue() == (short) -32767);
- assertTrue("Did not decode -32768 correctly", Short.valueOf("-32768",
- 10).shortValue() == (short) -32768);
- try {
- Short.valueOf("FF", 2);
- } catch (NumberFormatException e) {
- // Correct
- aThrow = false;
- }
- if (aThrow) {
- fail(
- "Failed to throw exception when passed hex string and base 2 radix");
- }
- try {
- Short.valueOf("10000000000", 10);
- } catch (NumberFormatException e) {
- // Correct
- return;
- }
- fail(
- "Failed to throw exception when passed string larger than 16 bits");
- }
- /**
- * @tests java.lang.Short#valueOf(byte)
- */
- public void test_valueOfS() {
- assertEquals(new Short(Short.MIN_VALUE), Short.valueOf(Short.MIN_VALUE));
- assertEquals(new Short(Short.MAX_VALUE), Short.valueOf(Short.MAX_VALUE));
- assertEquals(new Short((short) 0), Short.valueOf((short) 0));
-
- short s = -128;
- while (s < 128) {
- assertEquals(new Short(s), Short.valueOf(s));
- assertSame(Short.valueOf(s), Short.valueOf(s));
- s++;
- }
- }
-
- /**
- * @tests java.lang.Short#hashCode()
- */
- public void test_hashCode() {
- assertEquals(1, new Short((short)1).hashCode());
- assertEquals(2, new Short((short)2).hashCode());
- assertEquals(0, new Short((short)0).hashCode());
- assertEquals(-1, new Short((short)-1).hashCode());
- }
-
- /**
- * @tests java.lang.Short#Short(String)
- */
- public void test_ConstructorLjava_lang_String() {
- assertEquals(new Short((short)0), new Short("0"));
- assertEquals(new Short((short)1), new Short("1"));
- assertEquals(new Short((short)-1), new Short("-1"));
-
- try {
- new Short("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Short("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Short("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- new Short(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Short#Short(short)
- */
- public void test_ConstructorS() {
- assertEquals(1, new Short((short)1).shortValue());
- assertEquals(2, new Short((short)2).shortValue());
- assertEquals(0, new Short((short)0).shortValue());
- assertEquals(-1, new Short((short)-1).shortValue());
- }
-
- /**
- * @tests java.lang.Short#byteValue()
- */
- public void test_booleanValue() {
- assertEquals(1, new Short((short)1).byteValue());
- assertEquals(2, new Short((short)2).byteValue());
- assertEquals(0, new Short((short)0).byteValue());
- assertEquals(-1, new Short((short)-1).byteValue());
- }
-
- /**
- * @tests java.lang.Short#equals(Object)
- */
- public void test_equalsLjava_lang_Object() {
- assertEquals(new Short((short)0), Short.valueOf((short)0));
- assertEquals(new Short((short)1), Short.valueOf((short)1));
- assertEquals(new Short((short)-1), Short.valueOf((short)-1));
-
- Short fixture = new Short((short)25);
- assertEquals(fixture, fixture);
- assertFalse(fixture.equals(null));
- assertFalse(fixture.equals("Not a Short"));
- }
-
- /**
- * @tests java.lang.Short#toString()
- */
- public void test_toString() {
- assertEquals("-1", new Short((short)-1).toString());
- assertEquals("0", new Short((short)0).toString());
- assertEquals("1", new Short((short)1).toString());
- assertEquals("-1", new Short((short)0xFFFF).toString());
- }
-
- /**
- * @tests java.lang.Short#toString(short)
- */
- public void test_toStringS() {
- assertEquals("-1", Short.toString((short)-1));
- assertEquals("0", Short.toString((short)0));
- assertEquals("1", Short.toString((short)1));
- assertEquals("-1", Short.toString((short)0xFFFF));
- }
-
- /**
- * @tests java.lang.Short#valueOf(String)
- */
- public void test_valueOfLjava_lang_String() {
- assertEquals(new Short((short)0), Short.valueOf("0"));
- assertEquals(new Short((short)1), Short.valueOf("1"));
- assertEquals(new Short((short)-1), Short.valueOf("-1"));
-
- try {
- Short.valueOf("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Short#valueOf(String,int)
- */
- public void test_valueOfLjava_lang_StringI() {
- assertEquals(new Short((short)0), Short.valueOf("0", 10));
- assertEquals(new Short((short)1), Short.valueOf("1", 10));
- assertEquals(new Short((short)-1), Short.valueOf("-1", 10));
-
- //must be consistent with Character.digit()
- assertEquals(Character.digit('1', 2), Short.valueOf("1", 2).byteValue());
- assertEquals(Character.digit('F', 16), Short.valueOf("F", 16).byteValue());
-
- try {
- Short.valueOf("0x1", 10);
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf("9.2", 10);
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf("", 10);
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.valueOf(null, 10);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Short#parseShort(String)
- */
- public void test_parseShortLjava_lang_String() {
- assertEquals(0, Short.parseShort("0"));
- assertEquals(1, Short.parseShort("1"));
- assertEquals(-1, Short.parseShort("-1"));
-
- try {
- Short.parseShort("0x1");
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort(null);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Short#parseShort(String,int)
- */
- public void test_parseShortLjava_lang_StringI() {
- assertEquals(0, Short.parseShort("0", 10));
- assertEquals(1, Short.parseShort("1", 10));
- assertEquals(-1, Short.parseShort("-1", 10));
-
- //must be consistent with Character.digit()
- assertEquals(Character.digit('1', 2), Short.parseShort("1", 2));
- assertEquals(Character.digit('F', 16), Short.parseShort("F", 16));
-
- try {
- Short.parseShort("0x1", 10);
- fail("Expected NumberFormatException with hex string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort("9.2", 10);
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort("", 10);
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.parseShort(null, 10);
- fail("Expected NumberFormatException with null string.");
- } catch (NumberFormatException e) {}
- }
-
- /**
- * @tests java.lang.Short#decode(String)
- */
- public void test_decodeLjava_lang_String() {
- assertEquals(new Short((short)0), Short.decode("0"));
- assertEquals(new Short((short)1), Short.decode("1"));
- assertEquals(new Short((short)-1), Short.decode("-1"));
- assertEquals(new Short((short)0xF), Short.decode("0xF"));
- assertEquals(new Short((short)0xF), Short.decode("#F"));
- assertEquals(new Short((short)0xF), Short.decode("0XF"));
- assertEquals(new Short((short)07), Short.decode("07"));
-
- try {
- Short.decode("9.2");
- fail("Expected NumberFormatException with floating point string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.decode("");
- fail("Expected NumberFormatException with empty string.");
- } catch (NumberFormatException e) {}
-
- try {
- Short.decode(null);
- //undocumented NPE, but seems consistent across JREs
- fail("Expected NullPointerException with null string.");
- } catch (NullPointerException e) {}
- }
-
- /**
- * @tests java.lang.Short#doubleValue()
- */
- public void test_doubleValue() {
- assertEquals(-1D, new Short((short)-1).doubleValue(), 0D);
- assertEquals(0D, new Short((short)0).doubleValue(), 0D);
- assertEquals(1D, new Short((short)1).doubleValue(), 0D);
- }
-
- /**
- * @tests java.lang.Short#floatValue()
- */
- public void test_floatValue() {
- assertEquals(-1F, new Short((short)-1).floatValue(), 0F);
- assertEquals(0F, new Short((short)0).floatValue(), 0F);
- assertEquals(1F, new Short((short)1).floatValue(), 0F);
- }
-
- /**
- * @tests java.lang.Short#intValue()
- */
- public void test_intValue() {
- assertEquals(-1, new Short((short)-1).intValue());
- assertEquals(0, new Short((short)0).intValue());
- assertEquals(1, new Short((short)1).intValue());
- }
-
- /**
- * @tests java.lang.Short#longValue()
- */
- public void test_longValue() {
- assertEquals(-1L, new Short((short)-1).longValue());
- assertEquals(0L, new Short((short)0).longValue());
- assertEquals(1L, new Short((short)1).longValue());
- }
-
- /**
- * @tests java.lang.Short#shortValue()
- */
- public void test_shortValue() {
- assertEquals(-1, new Short((short)-1).shortValue());
- assertEquals(0, new Short((short)0).shortValue());
- assertEquals(1, new Short((short)1).shortValue());
- }
-
- /**
- * @tests java.lang.Short#reverseBytes(short)
- */
- public void test_reverseBytesS() {
- assertEquals((short)0xABCD, Short.reverseBytes((short)0xCDAB));
- assertEquals((short)0x1234, Short.reverseBytes((short)0x3412));
- assertEquals((short)0x0011, Short.reverseBytes((short)0x1100));
- assertEquals((short)0x2002, Short.reverseBytes((short)0x0220));
- }
-
-}
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.java.lang;
+
+import junit.framework.TestCase;
+
+public class ShortTest extends TestCase {
+ private Short sp = new Short((short) 18000);
+ private Short sp2 = new Short((short) 18000);
+ private Short sn = new Short((short) -19000);
+
+ /**
+ * @tests java.lang.Short#byteValue()
+ */
+ public void test_byteValue() {
+ // Test for method byte java.lang.Short.byteValue()
+ assertEquals("Returned incorrect byte value", 0, new Short(Short.MIN_VALUE)
+ .byteValue());
+ assertEquals("Returned incorrect byte value", -1, new Short(Short.MAX_VALUE)
+ .byteValue());
+ }
+
+ /**
+ * @tests java.lang.Short#compareTo(java.lang.Short)
+ */
+ public void test_compareToLjava_lang_Short() {
+ // Test for method int java.lang.Short.compareTo(java.lang.Short)
+ Short s = new Short((short) 1);
+ Short x = new Short((short) 3);
+ assertTrue(
+ "Should have returned negative value when compared to greater short",
+ s.compareTo(x) < 0);
+ x = new Short((short) -1);
+ assertTrue(
+ "Should have returned positive value when compared to lesser short",
+ s.compareTo(x) > 0);
+ x = new Short((short) 1);
+ assertEquals("Should have returned zero when compared to equal short",
+ 0, s.compareTo(x));
+
+ try {
+ new Short((short)0).compareTo(null);
+ fail("No NPE");
+ } catch (NullPointerException e) {
+ }
+ }
+
+ /**
+ * @tests java.lang.Short#decode(java.lang.String)
+ */
+ public void test_decodeLjava_lang_String2() {
+ // Test for method java.lang.Short
+ // java.lang.Short.decode(java.lang.String)
+ assertTrue("Did not decode -1 correctly", Short.decode("-1")
+ .shortValue() == (short) -1);
+ assertTrue("Did not decode -100 correctly", Short.decode("-100")
+ .shortValue() == (short) -100);
+ assertTrue("Did not decode 23 correctly", Short.decode("23")
+ .shortValue() == (short) 23);
+ assertTrue("Did not decode 0x10 correctly", Short.decode("0x10")
+ .shortValue() == (short) 16);
+ assertTrue("Did not decode 32767 correctly", Short.decode("32767")
+ .shortValue() == (short) 32767);
+ assertTrue("Did not decode -32767 correctly", Short.decode("-32767")
+ .shortValue() == (short) -32767);
+ assertTrue("Did not decode -32768 correctly", Short.decode("-32768")
+ .shortValue() == (short) -32768);
+
+ boolean exception = false;
+ try {
+ Short.decode("123s");
+ } catch (NumberFormatException e) {
+ // correct
+ exception = true;
+ }
+ assertTrue("Did not throw NumberFormatException decoding 123s",
+ exception);
+
+ exception = false;
+ try {
+ Short.decode("32768");
+ } catch (NumberFormatException e) {
+ // Correct
+ exception = true;
+ }
+ assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
+
+ exception = false;
+ try {
+ Short.decode("-32769");
+ } catch (NumberFormatException e) {
+ // Correct
+ exception = true;
+ }
+ assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
+
+ exception = false;
+ try {
+ Short.decode("0x8000");
+ } catch (NumberFormatException e) {
+ // Correct
+ exception = true;
+ }
+ assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
+
+ exception = false;
+ try {
+ Short.decode("-0x8001");
+ } catch (NumberFormatException e) {
+ // Correct
+ exception = true;
+ }
+ assertTrue("Failed to throw exception for hex MIN_VALUE - 1", exception);
+ }
+
+ /**
+ * @tests java.lang.Short#parseShort(java.lang.String)
+ */
+ public void test_parseShortLjava_lang_String2() {
+ // Test for method short java.lang.Short.parseShort(java.lang.String)
+ short sp = Short.parseShort("32746");
+ short sn = Short.parseShort("-32746");
+
+ assertTrue("Incorrect parse of short", sp == (short) 32746
+ && (sn == (short) -32746));
+ assertEquals("Returned incorrect value for 0", 0, Short.parseShort("0"));
+ assertTrue("Returned incorrect value for most negative value", Short
+ .parseShort("-32768") == (short) 0x8000);
+ assertTrue("Returned incorrect value for most positive value", Short
+ .parseShort("32767") == 0x7fff);
+
+ boolean exception = false;
+ try {
+ Short.parseShort("32768");
+ } catch (NumberFormatException e) {
+ // Correct
+ exception = true;
+ }
+ assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
+
+ exception = false;
+ try {
+ Short.parseShort("-32769");
+ } catch (NumberFormatException e) {
+ // Correct
+ exception = true;
+ }
+ assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
+ }
+
+ /**
+ * @tests java.lang.Short#parseShort(java.lang.String, int)
+ */
+ public void test_parseShortLjava_lang_StringI2() {
+ // Test for method short java.lang.Short.parseShort(java.lang.String,
+ // int)
+ boolean aThrow = true;
+ assertEquals("Incorrectly parsed hex string",
+ 255, Short.parseShort("FF", 16));
+ assertEquals("Incorrectly parsed oct string",
+ 16, Short.parseShort("20", 8));
+ assertEquals("Incorrectly parsed dec string",
+ 20, Short.parseShort("20", 10));
+ assertEquals("Incorrectly parsed bin string",
+ 4, Short.parseShort("100", 2));
+ assertEquals("Incorrectly parsed -hex string", -255, Short
+ .parseShort("-FF", 16));
+ assertEquals("Incorrectly parsed -oct string",
+ -16, Short.parseShort("-20", 8));
+ assertEquals("Incorrectly parsed -bin string", -4, Short
+ .parseShort("-100", 2));
+ assertEquals("Returned incorrect value for 0 hex", 0, Short.parseShort("0",
+ 16));
+ assertTrue("Returned incorrect value for most negative value hex",
+ Short.parseShort("-8000", 16) == (short) 0x8000);
+ assertTrue("Returned incorrect value for most positive value hex",
+ Short.parseShort("7fff", 16) == 0x7fff);
+ assertEquals("Returned incorrect value for 0 decimal", 0, Short.parseShort(
+ "0", 10));
+ assertTrue("Returned incorrect value for most negative value decimal",
+ Short.parseShort("-32768", 10) == (short) 0x8000);
+ assertTrue("Returned incorrect value for most positive value decimal",
+ Short.parseShort("32767", 10) == 0x7fff);
+
+ try {
+ Short.parseShort("FF", 2);
+ } catch (NumberFormatException e) {
+ // Correct
+ aThrow = false;
+ }
+ if (aThrow) {
+ fail(
+ "Failed to throw exception when passed hex string and base 2 radix");
+ }
+
+ boolean exception = false;
+ try {
+ Short.parseShort("10000000000", 10);
+ } catch (NumberFormatException e) {
+ // Correct
+ exception = true;
+ }
+ assertTrue(
+ "Failed to throw exception when passed string larger than 16 bits",
+ exception);
+
+ exception = false;
+ try {
+ Short.parseShort("32768", 10);
+ } catch (NumberFormatException e) {
+ // Correct
+ exception = true;
+ }
+ assertTrue("Failed to throw exception for MAX_VALUE + 1", exception);
+
+ exception = false;
+ try {
+ Short.parseShort("-32769", 10);
+ } catch (NumberFormatException e) {
+ // Correct
+ exception = true;
+ }
+ assertTrue("Failed to throw exception for MIN_VALUE - 1", exception);
+
+ exception = false;
+ try {
+ Short.parseShort("8000", 16);
+ } catch (NumberFormatException e) {
+ // Correct
+ exception = true;
+ }
+ assertTrue("Failed to throw exception for hex MAX_VALUE + 1", exception);
+
+ exception = false;
+ try {
+ Short.parseShort("-8001", 16);
+ } catch (NumberFormatException e) {
+ // Correct
+ exception = true;
+ }
+ assertTrue("Failed to throw exception for hex MIN_VALUE + 1", exception);
+ }
+
+ /**
+ * @tests java.lang.Short#toString()
+ */
+ public void test_toString2() {
+ // Test for method java.lang.String java.lang.Short.toString()
+ assertTrue("Invalid string returned", sp.toString().equals("18000")
+ && (sn.toString().equals("-19000")));
+ assertEquals("Returned incorrect string", "32767", new Short((short) 32767)
+ .toString());
+ assertEquals("Returned incorrect string", "-32767", new Short((short) -32767)
+ .toString());
+ assertEquals("Returned incorrect string", "-32768", new Short((short) -32768)
+ .toString());
+ }
+
+ /**
+ * @tests java.lang.Short#toString(short)
+ */
+ public void test_toStringS2() {
+ // Test for method java.lang.String java.lang.Short.toString(short)
+ assertEquals("Returned incorrect string", "32767", Short.toString((short) 32767)
+ );
+ assertEquals("Returned incorrect string", "-32767", Short.toString((short) -32767)
+ );
+ assertEquals("Returned incorrect string", "-32768", Short.toString((short) -32768)
+ );
+ }
+
+ /**
+ * @tests java.lang.Short#valueOf(java.lang.String)
+ */
+ public void test_valueOfLjava_lang_String2() {
+ // Test for method java.lang.Short
+ // java.lang.Short.valueOf(java.lang.String)
+ assertEquals("Returned incorrect short", -32768, Short.valueOf("-32768")
+ .shortValue());
+ assertEquals("Returned incorrect short", 32767, Short.valueOf("32767")
+ .shortValue());
+ }
+
+ /**
+ * @tests java.lang.Short#valueOf(java.lang.String, int)
+ */
+ public void test_valueOfLjava_lang_StringI2() {
+ // Test for method java.lang.Short
+ // java.lang.Short.valueOf(java.lang.String, int)
+ boolean aThrow = true;
+ assertEquals("Incorrectly parsed hex string", 255, Short.valueOf("FF", 16)
+ .shortValue());
+ assertEquals("Incorrectly parsed oct string", 16, Short.valueOf("20", 8)
+ .shortValue());
+ assertEquals("Incorrectly parsed dec string", 20, Short.valueOf("20", 10)
+ .shortValue());
+ assertEquals("Incorrectly parsed bin string", 4, Short.valueOf("100", 2)
+ .shortValue());
+ assertEquals("Incorrectly parsed -hex string", -255, Short.valueOf("-FF", 16)
+ .shortValue());
+ assertEquals("Incorrectly parsed -oct string", -16, Short.valueOf("-20", 8)
+ .shortValue());
+ assertEquals("Incorrectly parsed -bin string", -4, Short.valueOf("-100", 2)
+ .shortValue());
+ assertTrue("Did not decode 32767 correctly", Short.valueOf("32767", 10)
+ .shortValue() == (short) 32767);
+ assertTrue("Did not decode -32767 correctly", Short.valueOf("-32767",
+ 10).shortValue() == (short) -32767);
+ assertTrue("Did not decode -32768 correctly", Short.valueOf("-32768",
+ 10).shortValue() == (short) -32768);
+ try {
+ Short.valueOf("FF", 2);
+ } catch (NumberFormatException e) {
+ // Correct
+ aThrow = false;
+ }
+ if (aThrow) {
+ fail(
+ "Failed to throw exception when passed hex string and base 2 radix");
+ }
+ try {
+ Short.valueOf("10000000000", 10);
+ } catch (NumberFormatException e) {
+ // Correct
+ return;
+ }
+ fail(
+ "Failed to throw exception when passed string larger than 16 bits");
+ }
+ /**
+ * @tests java.lang.Short#valueOf(byte)
+ */
+ public void test_valueOfS() {
+ assertEquals(new Short(Short.MIN_VALUE), Short.valueOf(Short.MIN_VALUE));
+ assertEquals(new Short(Short.MAX_VALUE), Short.valueOf(Short.MAX_VALUE));
+ assertEquals(new Short((short) 0), Short.valueOf((short) 0));
+
+ short s = -128;
+ while (s < 128) {
+ assertEquals(new Short(s), Short.valueOf(s));
+ assertSame(Short.valueOf(s), Short.valueOf(s));
+ s++;
+ }
+ }
+
+ /**
+ * @tests java.lang.Short#hashCode()
+ */
+ public void test_hashCode() {
+ assertEquals(1, new Short((short)1).hashCode());
+ assertEquals(2, new Short((short)2).hashCode());
+ assertEquals(0, new Short((short)0).hashCode());
+ assertEquals(-1, new Short((short)-1).hashCode());
+ }
+
+ /**
+ * @tests java.lang.Short#Short(String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ assertEquals(new Short((short)0), new Short("0"));
+ assertEquals(new Short((short)1), new Short("1"));
+ assertEquals(new Short((short)-1), new Short("-1"));
+
+ try {
+ new Short("0x1");
+ fail("Expected NumberFormatException with hex string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ new Short("9.2");
+ fail("Expected NumberFormatException with floating point string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ new Short("");
+ fail("Expected NumberFormatException with empty string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ new Short(null);
+ fail("Expected NumberFormatException with null string.");
+ } catch (NumberFormatException e) {}
+ }
+
+ /**
+ * @tests java.lang.Short#Short(short)
+ */
+ public void test_ConstructorS() {
+ assertEquals(1, new Short((short)1).shortValue());
+ assertEquals(2, new Short((short)2).shortValue());
+ assertEquals(0, new Short((short)0).shortValue());
+ assertEquals(-1, new Short((short)-1).shortValue());
+ }
+
+ /**
+ * @tests java.lang.Short#byteValue()
+ */
+ public void test_booleanValue() {
+ assertEquals(1, new Short((short)1).byteValue());
+ assertEquals(2, new Short((short)2).byteValue());
+ assertEquals(0, new Short((short)0).byteValue());
+ assertEquals(-1, new Short((short)-1).byteValue());
+ }
+
+ /**
+ * @tests java.lang.Short#equals(Object)
+ */
+ public void test_equalsLjava_lang_Object() {
+ assertEquals(new Short((short)0), Short.valueOf((short)0));
+ assertEquals(new Short((short)1), Short.valueOf((short)1));
+ assertEquals(new Short((short)-1), Short.valueOf((short)-1));
+
+ Short fixture = new Short((short)25);
+ assertEquals(fixture, fixture);
+ assertFalse(fixture.equals(null));
+ assertFalse(fixture.equals("Not a Short"));
+ }
+
+ /**
+ * @tests java.lang.Short#toString()
+ */
+ public void test_toString() {
+ assertEquals("-1", new Short((short)-1).toString());
+ assertEquals("0", new Short((short)0).toString());
+ assertEquals("1", new Short((short)1).toString());
+ assertEquals("-1", new Short((short)0xFFFF).toString());
+ }
+
+ /**
+ * @tests java.lang.Short#toString(short)
+ */
+ public void test_toStringS() {
+ assertEquals("-1", Short.toString((short)-1));
+ assertEquals("0", Short.toString((short)0));
+ assertEquals("1", Short.toString((short)1));
+ assertEquals("-1", Short.toString((short)0xFFFF));
+ }
+
+ /**
+ * @tests java.lang.Short#valueOf(String)
+ */
+ public void test_valueOfLjava_lang_String() {
+ assertEquals(new Short((short)0), Short.valueOf("0"));
+ assertEquals(new Short((short)1), Short.valueOf("1"));
+ assertEquals(new Short((short)-1), Short.valueOf("-1"));
+
+ try {
+ Short.valueOf("0x1");
+ fail("Expected NumberFormatException with hex string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.valueOf("9.2");
+ fail("Expected NumberFormatException with floating point string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.valueOf("");
+ fail("Expected NumberFormatException with empty string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.valueOf(null);
+ fail("Expected NumberFormatException with null string.");
+ } catch (NumberFormatException e) {}
+ }
+
+ /**
+ * @tests java.lang.Short#valueOf(String,int)
+ */
+ public void test_valueOfLjava_lang_StringI() {
+ assertEquals(new Short((short)0), Short.valueOf("0", 10));
+ assertEquals(new Short((short)1), Short.valueOf("1", 10));
+ assertEquals(new Short((short)-1), Short.valueOf("-1", 10));
+
+ //must be consistent with Character.digit()
+ assertEquals(Character.digit('1', 2), Short.valueOf("1", 2).byteValue());
+ assertEquals(Character.digit('F', 16), Short.valueOf("F", 16).byteValue());
+
+ try {
+ Short.valueOf("0x1", 10);
+ fail("Expected NumberFormatException with hex string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.valueOf("9.2", 10);
+ fail("Expected NumberFormatException with floating point string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.valueOf("", 10);
+ fail("Expected NumberFormatException with empty string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.valueOf(null, 10);
+ fail("Expected NumberFormatException with null string.");
+ } catch (NumberFormatException e) {}
+ }
+
+ /**
+ * @tests java.lang.Short#parseShort(String)
+ */
+ public void test_parseShortLjava_lang_String() {
+ assertEquals(0, Short.parseShort("0"));
+ assertEquals(1, Short.parseShort("1"));
+ assertEquals(-1, Short.parseShort("-1"));
+
+ try {
+ Short.parseShort("0x1");
+ fail("Expected NumberFormatException with hex string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.parseShort("9.2");
+ fail("Expected NumberFormatException with floating point string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.parseShort("");
+ fail("Expected NumberFormatException with empty string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.parseShort(null);
+ fail("Expected NumberFormatException with null string.");
+ } catch (NumberFormatException e) {}
+ }
+
+ /**
+ * @tests java.lang.Short#parseShort(String,int)
+ */
+ public void test_parseShortLjava_lang_StringI() {
+ assertEquals(0, Short.parseShort("0", 10));
+ assertEquals(1, Short.parseShort("1", 10));
+ assertEquals(-1, Short.parseShort("-1", 10));
+
+ //must be consistent with Character.digit()
+ assertEquals(Character.digit('1', 2), Short.parseShort("1", 2));
+ assertEquals(Character.digit('F', 16), Short.parseShort("F", 16));
+
+ try {
+ Short.parseShort("0x1", 10);
+ fail("Expected NumberFormatException with hex string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.parseShort("9.2", 10);
+ fail("Expected NumberFormatException with floating point string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.parseShort("", 10);
+ fail("Expected NumberFormatException with empty string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.parseShort(null, 10);
+ fail("Expected NumberFormatException with null string.");
+ } catch (NumberFormatException e) {}
+ }
+
+ /**
+ * @tests java.lang.Short#decode(String)
+ */
+ public void test_decodeLjava_lang_String() {
+ assertEquals(new Short((short)0), Short.decode("0"));
+ assertEquals(new Short((short)1), Short.decode("1"));
+ assertEquals(new Short((short)-1), Short.decode("-1"));
+ assertEquals(new Short((short)0xF), Short.decode("0xF"));
+ assertEquals(new Short((short)0xF), Short.decode("#F"));
+ assertEquals(new Short((short)0xF), Short.decode("0XF"));
+ assertEquals(new Short((short)07), Short.decode("07"));
+
+ try {
+ Short.decode("9.2");
+ fail("Expected NumberFormatException with floating point string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.decode("");
+ fail("Expected NumberFormatException with empty string.");
+ } catch (NumberFormatException e) {}
+
+ try {
+ Short.decode(null);
+ //undocumented NPE, but seems consistent across JREs
+ fail("Expected NullPointerException with null string.");
+ } catch (NullPointerException e) {}
+ }
+
+ /**
+ * @tests java.lang.Short#doubleValue()
+ */
+ public void test_doubleValue() {
+ assertEquals(-1D, new Short((short)-1).doubleValue(), 0D);
+ assertEquals(0D, new Short((short)0).doubleValue(), 0D);
+ assertEquals(1D, new Short((short)1).doubleValue(), 0D);
+ }
+
+ /**
+ * @tests java.lang.Short#floatValue()
+ */
+ public void test_floatValue() {
+ assertEquals(-1F, new Short((short)-1).floatValue(), 0F);
+ assertEquals(0F, new Short((short)0).floatValue(), 0F);
+ assertEquals(1F, new Short((short)1).floatValue(), 0F);
+ }
+
+ /**
+ * @tests java.lang.Short#intValue()
+ */
+ public void test_intValue() {
+ assertEquals(-1, new Short((short)-1).intValue());
+ assertEquals(0, new Short((short)0).intValue());
+ assertEquals(1, new Short((short)1).intValue());
+ }
+
+ /**
+ * @tests java.lang.Short#longValue()
+ */
+ public void test_longValue() {
+ assertEquals(-1L, new Short((short)-1).longValue());
+ assertEquals(0L, new Short((short)0).longValue());
+ assertEquals(1L, new Short((short)1).longValue());
+ }
+
+ /**
+ * @tests java.lang.Short#shortValue()
+ */
+ public void test_shortValue() {
+ assertEquals(-1, new Short((short)-1).shortValue());
+ assertEquals(0, new Short((short)0).shortValue());
+ assertEquals(1, new Short((short)1).shortValue());
+ }
+
+ /**
+ * @tests java.lang.Short#reverseBytes(short)
+ */
+ public void test_reverseBytesS() {
+ assertEquals((short)0xABCD, Short.reverseBytes((short)0xCDAB));
+ assertEquals((short)0x1234, Short.reverseBytes((short)0x3412));
+ assertEquals((short)0x0011, Short.reverseBytes((short)0x1100));
+ assertEquals((short)0x2002, Short.reverseBytes((short)0x0220));
+ }
+
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ShortTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackOverflowErrorTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackOverflowErrorTest.java?rev=437974&r1=437973&r2=437974&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackOverflowErrorTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackOverflowErrorTest.java Mon Aug 28 22:40:44 2006
@@ -1,40 +1,40 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-import junit.framework.TestCase;
-
-public class StackOverflowErrorTest extends TestCase {
-
- /**
- * @tests java.lang.StackOverflowError#StackOverflowError()
- */
- public void test_Constructor() {
- StackOverflowError e = new StackOverflowError();
- assertNull(e.getMessage());
- assertNull(e.getLocalizedMessage());
- assertNull(e.getCause());
- }
-
- /**
- * @tests java.lang.StackOverflowError#StackOverflowError(java.lang.String)
- */
- public void test_ConstructorLjava_lang_String() {
- StackOverflowError e = new StackOverflowError("fixture");
- assertEquals("fixture", e.getMessage());
- assertNull(e.getCause());
- }
-}
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.java.lang;
+
+import junit.framework.TestCase;
+
+public class StackOverflowErrorTest extends TestCase {
+
+ /**
+ * @tests java.lang.StackOverflowError#StackOverflowError()
+ */
+ public void test_Constructor() {
+ StackOverflowError e = new StackOverflowError();
+ assertNull(e.getMessage());
+ assertNull(e.getLocalizedMessage());
+ assertNull(e.getCause());
+ }
+
+ /**
+ * @tests java.lang.StackOverflowError#StackOverflowError(java.lang.String)
+ */
+ public void test_ConstructorLjava_lang_String() {
+ StackOverflowError e = new StackOverflowError("fixture");
+ assertEquals("fixture", e.getMessage());
+ assertNull(e.getCause());
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StackOverflowErrorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java?rev=437974&r1=437973&r2=437974&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java Mon Aug 28 22:40:44 2006
@@ -1,416 +1,416 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.luni.tests.java.lang;
-
-public class StrictMathTest extends junit.framework.TestCase {
-
- double HYP = StrictMath.sqrt(2.0);
-
- double OPP = 1.0;
-
- double ADJ = 1.0;
-
- /* Required to make previous preprocessor flags work - do not remove */
- int unused = 0;
-
- /**
- * @tests java.lang.StrictMath#abs(double)
- */
- public void test_absD() {
- // Test for method double java.lang.StrictMath.abs(double)
-
- assertTrue("Incorrect double abs value",
- (StrictMath.abs(-1908.8976) == 1908.8976));
- assertTrue("Incorrect double abs value",
- (StrictMath.abs(1908.8976) == 1908.8976));
- }
-
- /**
- * @tests java.lang.StrictMath#abs(float)
- */
- public void test_absF() {
- // Test for method float java.lang.StrictMath.abs(float)
- assertTrue("Incorrect float abs value",
- (StrictMath.abs(-1908.8976f) == 1908.8976f));
- assertTrue("Incorrect float abs value",
- (StrictMath.abs(1908.8976f) == 1908.8976f));
- }
-
- /**
- * @tests java.lang.StrictMath#abs(int)
- */
- public void test_absI() {
- // Test for method int java.lang.StrictMath.abs(int)
- assertTrue("Incorrect int abs value",
- (StrictMath.abs(-1908897) == 1908897));
- assertTrue("Incorrect int abs value",
- (StrictMath.abs(1908897) == 1908897));
- }
-
- /**
- * @tests java.lang.StrictMath#abs(long)
- */
- public void test_absJ() {
- // Test for method long java.lang.StrictMath.abs(long)
- assertTrue("Incorrect long abs value", (StrictMath
- .abs(-19088976000089L) == 19088976000089L));
- assertTrue("Incorrect long abs value",
- (StrictMath.abs(19088976000089L) == 19088976000089L));
- }
-
- /**
- * @tests java.lang.StrictMath#acos(double)
- */
- public void test_acosD() {
- // Test for method double java.lang.StrictMath.acos(double)
- assertTrue("Returned incorrect arc cosine", StrictMath.cos(StrictMath
- .acos(ADJ / HYP)) == ADJ / HYP);
- }
-
- /**
- * @tests java.lang.StrictMath#asin(double)
- */
- public void test_asinD() {
- // Test for method double java.lang.StrictMath.asin(double)
- assertTrue("Returned incorrect arc sine", StrictMath.sin(StrictMath
- .asin(OPP / HYP)) == OPP / HYP);
- }
-
- /**
- * @tests java.lang.StrictMath#atan(double)
- */
- public void test_atanD() {
- // Test for method double java.lang.StrictMath.atan(double)
- double answer = StrictMath.tan(StrictMath.atan(1.0));
- assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
- && answer >= 9.9999999999999983E-1);
- }
-
- /**
- * @tests java.lang.StrictMath#atan2(double, double)
- */
- public void test_atan2DD() {
- // Test for method double java.lang.StrictMath.atan2(double, double)
- double answer = StrictMath.atan(StrictMath.tan(1.0));
- assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
- && answer >= 9.9999999999999983E-1);
- }
-
- /**
- * @tests java.lang.StrictMath#ceil(double)
- */
- public void test_ceilD() {
- // Test for method double java.lang.StrictMath.ceil(double)
- assertEquals("Incorrect ceiling for double",
- 79, StrictMath.ceil(78.89), 0.0);
- assertEquals("Incorrect ceiling for double",
- -78, StrictMath.ceil(-78.89), 0.0);
- }
-
- /**
- * @tests java.lang.StrictMath#cos(double)
- */
- public void test_cosD() {
- // Test for method double java.lang.StrictMath.cos(double)
-
- assertTrue("Returned incorrect cosine", StrictMath.cos(StrictMath
- .acos(ADJ / HYP)) == ADJ / HYP);
- }
-
- /**
- * @tests java.lang.StrictMath#exp(double)
- */
- public void test_expD() {
- // Test for method double java.lang.StrictMath.exp(double)
- assertTrue("Incorrect answer returned for simple power", StrictMath
- .abs(StrictMath.exp(4D) - StrictMath.E * StrictMath.E
- * StrictMath.E * StrictMath.E) < 0.1D);
- assertTrue("Incorrect answer returned for larger power", StrictMath
- .log(StrictMath.abs(StrictMath.exp(5.5D)) - 5.5D) < 10.0D);
- }
-
- /**
- * @tests java.lang.StrictMath#floor(double)
- */
- public void test_floorD() {
- // Test for method double java.lang.StrictMath.floor(double)
- assertEquals("Incorrect floor for double",
- 78, StrictMath.floor(78.89), 0.0);
- assertEquals("Incorrect floor for double",
- -79, StrictMath.floor(-78.89), 0.0);
- }
-
- /**
- * @tests java.lang.StrictMath#IEEEremainder(double, double)
- */
- public void test_IEEEremainderDD() {
- // Test for method double java.lang.StrictMath.IEEEremainder(double,
- // double)
- assertEquals("Incorrect remainder returned", 0.0, StrictMath.IEEEremainder(
- 1.0, 1.0));
- assertTrue(
- "Incorrect remainder returned",
- StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631647E-2
- || StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2);
- }
-
- /**
- * @tests java.lang.StrictMath#log(double)
- */
- public void test_logD() {
- // Test for method double java.lang.StrictMath.log(double)
- for (double d = 10; d >= -10; d -= 0.5) {
- double answer = StrictMath.log(StrictMath.exp(d));
- assertTrue("Answer does not equal expected answer for d = " + d
- + " answer = " + answer,
- StrictMath.abs(answer - d) <= StrictMath
- .abs(d * 0.00000001));
- }
- }
-
- /**
- * @tests java.lang.StrictMath#max(double, double)
- */
- public void test_maxDD() {
- // Test for method double java.lang.StrictMath.max(double, double)
- assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(
- -1908897.6000089, 1908897.6000089));
- assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(2.0,
- 1908897.6000089));
- assertEquals("Incorrect double max value", -2.0, StrictMath.max(-2.0,
- -1908897.6000089));
-
- }
-
- /**
- * @tests java.lang.StrictMath#max(float, float)
- */
- public void test_maxFF() {
- // Test for method float java.lang.StrictMath.max(float, float)
- assertTrue("Incorrect float max value", StrictMath.max(-1908897.600f,
- 1908897.600f) == 1908897.600f);
- assertTrue("Incorrect float max value", StrictMath.max(2.0f,
- 1908897.600f) == 1908897.600f);
- assertTrue("Incorrect float max value", StrictMath.max(-2.0f,
- -1908897.600f) == -2.0f);
- }
-
- /**
- * @tests java.lang.StrictMath#max(int, int)
- */
- public void test_maxII() {
- // Test for method int java.lang.StrictMath.max(int, int)
- assertEquals("Incorrect int max value", 19088976, StrictMath.max(-19088976,
- 19088976));
- assertEquals("Incorrect int max value",
- 19088976, StrictMath.max(20, 19088976));
- assertEquals("Incorrect int max value",
- -20, StrictMath.max(-20, -19088976));
- }
-
- /**
- * @tests java.lang.StrictMath#max(long, long)
- */
- public void test_maxJJ() {
- // Test for method long java.lang.StrictMath.max(long, long)
- assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(-19088976000089L,
- 19088976000089L));
- assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(20,
- 19088976000089L));
- assertEquals("Incorrect long max value", -20, StrictMath.max(-20,
- -19088976000089L));
- }
-
- /**
- * @tests java.lang.StrictMath#min(double, double)
- */
- public void test_minDD() {
- // Test for method double java.lang.StrictMath.min(double, double)
- assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(
- -1908897.6000089, 1908897.6000089));
- assertEquals("Incorrect double min value", 2.0, StrictMath.min(2.0,
- 1908897.6000089));
- assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(-2.0,
- -1908897.6000089));
- }
-
- /**
- * @tests java.lang.StrictMath#min(float, float)
- */
- public void test_minFF() {
- // Test for method float java.lang.StrictMath.min(float, float)
- assertTrue("Incorrect float min value", StrictMath.min(-1908897.600f,
- 1908897.600f) == -1908897.600f);
- assertTrue("Incorrect float min value", StrictMath.min(2.0f,
- 1908897.600f) == 2.0f);
- assertTrue("Incorrect float min value", StrictMath.min(-2.0f,
- -1908897.600f) == -1908897.600f);
- }
-
- /**
- * @tests java.lang.StrictMath#min(int, int)
- */
- public void test_minII() {
- // Test for method int java.lang.StrictMath.min(int, int)
- assertEquals("Incorrect int min value", -19088976, StrictMath.min(-19088976,
- 19088976));
- assertEquals("Incorrect int min value",
- 20, StrictMath.min(20, 19088976));
- assertEquals("Incorrect int min value",
- -19088976, StrictMath.min(-20, -19088976));
-
- }
-
- /**
- * @tests java.lang.StrictMath#min(long, long)
- */
- public void test_minJJ() {
- // Test for method long java.lang.StrictMath.min(long, long)
- assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-19088976000089L,
- 19088976000089L));
- assertEquals("Incorrect long min value", 20, StrictMath.min(20,
- 19088976000089L));
- assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-20,
- -19088976000089L));
- }
-
- /**
- * @tests java.lang.StrictMath#pow(double, double)
- */
- public void test_powDD() {
- // Test for method double java.lang.StrictMath.pow(double, double)
- assertTrue("pow returned incorrect value",
- (long) StrictMath.pow(2, 8) == 256l);
- assertTrue("pow returned incorrect value",
- StrictMath.pow(2, -8) == 0.00390625d);
- }
-
- /**
- * @tests java.lang.StrictMath#rint(double)
- */
- public void test_rintD() {
- // Test for method double java.lang.StrictMath.rint(double)
- assertEquals("Failed to round properly - up to odd",
- 3.0, StrictMath.rint(2.9));
- assertTrue("Failed to round properly - NaN", Double.isNaN(StrictMath
- .rint(Double.NaN)));
- assertEquals("Failed to round properly down to even", 2.0, StrictMath
- .rint(2.1));
- assertTrue("Failed to round properly " + 2.5 + " to even", StrictMath
- .rint(2.5) == 2.0);
- }
-
- /**
- * @tests java.lang.StrictMath#round(double)
- */
- public void test_roundD() {
- // Test for method long java.lang.StrictMath.round(double)
- assertEquals("Incorrect rounding of a float",
- -91, StrictMath.round(-90.89d));
- }
-
- /**
- * @tests java.lang.StrictMath#round(float)
- */
- public void test_roundF() {
- // Test for method int java.lang.StrictMath.round(float)
- assertEquals("Incorrect rounding of a float",
- -91, StrictMath.round(-90.89f));
- }
-
- /**
- * @tests java.lang.StrictMath#sin(double)
- */
- public void test_sinD() {
- // Test for method double java.lang.StrictMath.sin(double)
- assertTrue("Returned incorrect sine", StrictMath.sin(StrictMath
- .asin(OPP / HYP)) == OPP / HYP);
- }
-
- /**
- * @tests java.lang.StrictMath#sqrt(double)
- */
- public void test_sqrtD() {
- // Test for method double java.lang.StrictMath.sqrt(double)
- assertEquals("Incorrect root returned1",
- 2, StrictMath.sqrt(StrictMath.pow(StrictMath.sqrt(2), 4)), 0.0);
- assertEquals("Incorrect root returned2", 7, StrictMath.sqrt(49), 0.0);
- }
-
- /**
- * @tests java.lang.StrictMath#tan(double)
- */
- public void test_tanD() {
- // Test for method double java.lang.StrictMath.tan(double)
- assertTrue(
- "Returned incorrect tangent: ",
- StrictMath.tan(StrictMath.atan(1.0)) <= 1.0
- || StrictMath.tan(StrictMath.atan(1.0)) >= 9.9999999999999983E-1);
- }
-
- /**
- * @tests java.lang.StrictMath#random()
- */
- public void test_random() {
- // There isn't a place for these tests so just stick them here
- assertEquals("Wrong value E",
- 4613303445314885481L, Double.doubleToLongBits(StrictMath.E));
- assertEquals("Wrong value PI",
- 4614256656552045848L, Double.doubleToLongBits(StrictMath.PI));
-
- for (int i = 500; i >= 0; i--) {
- double d = StrictMath.random();
- assertTrue("Generated number is out of range: " + d, d >= 0.0
- && d < 1.0);
- }
- }
-
- /**
- * @tests java.lang.StrictMath#toRadians(double)
- */
- public void test_toRadiansD() {
- for (double d = 500; d >= 0; d -= 1.0) {
- double converted = StrictMath.toDegrees(StrictMath.toRadians(d));
- assertTrue("Converted number not equal to original. d = " + d,
- converted >= d * 0.99999999 && converted <= d * 1.00000001);
- }
- }
-
- /**
- * @tests java.lang.StrictMath#toDegrees(double)
- */
- public void test_toDegreesD() {
- for (double d = 500; d >= 0; d -= 1.0) {
- double converted = StrictMath.toRadians(StrictMath.toDegrees(d));
- assertTrue("Converted number not equal to original. d = " + d,
- converted >= d * 0.99999999 && converted <= d * 1.00000001);
- }
- }
-
- /**
- * Sets up the fixture, for example, open a network connection. This method
- * is called before a test is executed.
- */
- protected void setUp() {
- }
-
- /**
- * Tears down the fixture, for example, close a network connection. This
- * method is called after a test is executed.
- */
- protected void tearDown() {
- }
-}
+/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.luni.tests.java.lang;
+
+public class StrictMathTest extends junit.framework.TestCase {
+
+ double HYP = StrictMath.sqrt(2.0);
+
+ double OPP = 1.0;
+
+ double ADJ = 1.0;
+
+ /* Required to make previous preprocessor flags work - do not remove */
+ int unused = 0;
+
+ /**
+ * @tests java.lang.StrictMath#abs(double)
+ */
+ public void test_absD() {
+ // Test for method double java.lang.StrictMath.abs(double)
+
+ assertTrue("Incorrect double abs value",
+ (StrictMath.abs(-1908.8976) == 1908.8976));
+ assertTrue("Incorrect double abs value",
+ (StrictMath.abs(1908.8976) == 1908.8976));
+ }
+
+ /**
+ * @tests java.lang.StrictMath#abs(float)
+ */
+ public void test_absF() {
+ // Test for method float java.lang.StrictMath.abs(float)
+ assertTrue("Incorrect float abs value",
+ (StrictMath.abs(-1908.8976f) == 1908.8976f));
+ assertTrue("Incorrect float abs value",
+ (StrictMath.abs(1908.8976f) == 1908.8976f));
+ }
+
+ /**
+ * @tests java.lang.StrictMath#abs(int)
+ */
+ public void test_absI() {
+ // Test for method int java.lang.StrictMath.abs(int)
+ assertTrue("Incorrect int abs value",
+ (StrictMath.abs(-1908897) == 1908897));
+ assertTrue("Incorrect int abs value",
+ (StrictMath.abs(1908897) == 1908897));
+ }
+
+ /**
+ * @tests java.lang.StrictMath#abs(long)
+ */
+ public void test_absJ() {
+ // Test for method long java.lang.StrictMath.abs(long)
+ assertTrue("Incorrect long abs value", (StrictMath
+ .abs(-19088976000089L) == 19088976000089L));
+ assertTrue("Incorrect long abs value",
+ (StrictMath.abs(19088976000089L) == 19088976000089L));
+ }
+
+ /**
+ * @tests java.lang.StrictMath#acos(double)
+ */
+ public void test_acosD() {
+ // Test for method double java.lang.StrictMath.acos(double)
+ assertTrue("Returned incorrect arc cosine", StrictMath.cos(StrictMath
+ .acos(ADJ / HYP)) == ADJ / HYP);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#asin(double)
+ */
+ public void test_asinD() {
+ // Test for method double java.lang.StrictMath.asin(double)
+ assertTrue("Returned incorrect arc sine", StrictMath.sin(StrictMath
+ .asin(OPP / HYP)) == OPP / HYP);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#atan(double)
+ */
+ public void test_atanD() {
+ // Test for method double java.lang.StrictMath.atan(double)
+ double answer = StrictMath.tan(StrictMath.atan(1.0));
+ assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
+ && answer >= 9.9999999999999983E-1);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#atan2(double, double)
+ */
+ public void test_atan2DD() {
+ // Test for method double java.lang.StrictMath.atan2(double, double)
+ double answer = StrictMath.atan(StrictMath.tan(1.0));
+ assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0
+ && answer >= 9.9999999999999983E-1);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#ceil(double)
+ */
+ public void test_ceilD() {
+ // Test for method double java.lang.StrictMath.ceil(double)
+ assertEquals("Incorrect ceiling for double",
+ 79, StrictMath.ceil(78.89), 0.0);
+ assertEquals("Incorrect ceiling for double",
+ -78, StrictMath.ceil(-78.89), 0.0);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#cos(double)
+ */
+ public void test_cosD() {
+ // Test for method double java.lang.StrictMath.cos(double)
+
+ assertTrue("Returned incorrect cosine", StrictMath.cos(StrictMath
+ .acos(ADJ / HYP)) == ADJ / HYP);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#exp(double)
+ */
+ public void test_expD() {
+ // Test for method double java.lang.StrictMath.exp(double)
+ assertTrue("Incorrect answer returned for simple power", StrictMath
+ .abs(StrictMath.exp(4D) - StrictMath.E * StrictMath.E
+ * StrictMath.E * StrictMath.E) < 0.1D);
+ assertTrue("Incorrect answer returned for larger power", StrictMath
+ .log(StrictMath.abs(StrictMath.exp(5.5D)) - 5.5D) < 10.0D);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#floor(double)
+ */
+ public void test_floorD() {
+ // Test for method double java.lang.StrictMath.floor(double)
+ assertEquals("Incorrect floor for double",
+ 78, StrictMath.floor(78.89), 0.0);
+ assertEquals("Incorrect floor for double",
+ -79, StrictMath.floor(-78.89), 0.0);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#IEEEremainder(double, double)
+ */
+ public void test_IEEEremainderDD() {
+ // Test for method double java.lang.StrictMath.IEEEremainder(double,
+ // double)
+ assertEquals("Incorrect remainder returned", 0.0, StrictMath.IEEEremainder(
+ 1.0, 1.0));
+ assertTrue(
+ "Incorrect remainder returned",
+ StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631647E-2
+ || StrictMath.IEEEremainder(1.32, 89.765) >= 1.4705063220631649E-2);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#log(double)
+ */
+ public void test_logD() {
+ // Test for method double java.lang.StrictMath.log(double)
+ for (double d = 10; d >= -10; d -= 0.5) {
+ double answer = StrictMath.log(StrictMath.exp(d));
+ assertTrue("Answer does not equal expected answer for d = " + d
+ + " answer = " + answer,
+ StrictMath.abs(answer - d) <= StrictMath
+ .abs(d * 0.00000001));
+ }
+ }
+
+ /**
+ * @tests java.lang.StrictMath#max(double, double)
+ */
+ public void test_maxDD() {
+ // Test for method double java.lang.StrictMath.max(double, double)
+ assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(
+ -1908897.6000089, 1908897.6000089));
+ assertEquals("Incorrect double max value", 1908897.6000089, StrictMath.max(2.0,
+ 1908897.6000089));
+ assertEquals("Incorrect double max value", -2.0, StrictMath.max(-2.0,
+ -1908897.6000089));
+
+ }
+
+ /**
+ * @tests java.lang.StrictMath#max(float, float)
+ */
+ public void test_maxFF() {
+ // Test for method float java.lang.StrictMath.max(float, float)
+ assertTrue("Incorrect float max value", StrictMath.max(-1908897.600f,
+ 1908897.600f) == 1908897.600f);
+ assertTrue("Incorrect float max value", StrictMath.max(2.0f,
+ 1908897.600f) == 1908897.600f);
+ assertTrue("Incorrect float max value", StrictMath.max(-2.0f,
+ -1908897.600f) == -2.0f);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#max(int, int)
+ */
+ public void test_maxII() {
+ // Test for method int java.lang.StrictMath.max(int, int)
+ assertEquals("Incorrect int max value", 19088976, StrictMath.max(-19088976,
+ 19088976));
+ assertEquals("Incorrect int max value",
+ 19088976, StrictMath.max(20, 19088976));
+ assertEquals("Incorrect int max value",
+ -20, StrictMath.max(-20, -19088976));
+ }
+
+ /**
+ * @tests java.lang.StrictMath#max(long, long)
+ */
+ public void test_maxJJ() {
+ // Test for method long java.lang.StrictMath.max(long, long)
+ assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(-19088976000089L,
+ 19088976000089L));
+ assertEquals("Incorrect long max value", 19088976000089L, StrictMath.max(20,
+ 19088976000089L));
+ assertEquals("Incorrect long max value", -20, StrictMath.max(-20,
+ -19088976000089L));
+ }
+
+ /**
+ * @tests java.lang.StrictMath#min(double, double)
+ */
+ public void test_minDD() {
+ // Test for method double java.lang.StrictMath.min(double, double)
+ assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(
+ -1908897.6000089, 1908897.6000089));
+ assertEquals("Incorrect double min value", 2.0, StrictMath.min(2.0,
+ 1908897.6000089));
+ assertEquals("Incorrect double min value", -1908897.6000089, StrictMath.min(-2.0,
+ -1908897.6000089));
+ }
+
+ /**
+ * @tests java.lang.StrictMath#min(float, float)
+ */
+ public void test_minFF() {
+ // Test for method float java.lang.StrictMath.min(float, float)
+ assertTrue("Incorrect float min value", StrictMath.min(-1908897.600f,
+ 1908897.600f) == -1908897.600f);
+ assertTrue("Incorrect float min value", StrictMath.min(2.0f,
+ 1908897.600f) == 2.0f);
+ assertTrue("Incorrect float min value", StrictMath.min(-2.0f,
+ -1908897.600f) == -1908897.600f);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#min(int, int)
+ */
+ public void test_minII() {
+ // Test for method int java.lang.StrictMath.min(int, int)
+ assertEquals("Incorrect int min value", -19088976, StrictMath.min(-19088976,
+ 19088976));
+ assertEquals("Incorrect int min value",
+ 20, StrictMath.min(20, 19088976));
+ assertEquals("Incorrect int min value",
+ -19088976, StrictMath.min(-20, -19088976));
+
+ }
+
+ /**
+ * @tests java.lang.StrictMath#min(long, long)
+ */
+ public void test_minJJ() {
+ // Test for method long java.lang.StrictMath.min(long, long)
+ assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-19088976000089L,
+ 19088976000089L));
+ assertEquals("Incorrect long min value", 20, StrictMath.min(20,
+ 19088976000089L));
+ assertEquals("Incorrect long min value", -19088976000089L, StrictMath.min(-20,
+ -19088976000089L));
+ }
+
+ /**
+ * @tests java.lang.StrictMath#pow(double, double)
+ */
+ public void test_powDD() {
+ // Test for method double java.lang.StrictMath.pow(double, double)
+ assertTrue("pow returned incorrect value",
+ (long) StrictMath.pow(2, 8) == 256l);
+ assertTrue("pow returned incorrect value",
+ StrictMath.pow(2, -8) == 0.00390625d);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#rint(double)
+ */
+ public void test_rintD() {
+ // Test for method double java.lang.StrictMath.rint(double)
+ assertEquals("Failed to round properly - up to odd",
+ 3.0, StrictMath.rint(2.9));
+ assertTrue("Failed to round properly - NaN", Double.isNaN(StrictMath
+ .rint(Double.NaN)));
+ assertEquals("Failed to round properly down to even", 2.0, StrictMath
+ .rint(2.1));
+ assertTrue("Failed to round properly " + 2.5 + " to even", StrictMath
+ .rint(2.5) == 2.0);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#round(double)
+ */
+ public void test_roundD() {
+ // Test for method long java.lang.StrictMath.round(double)
+ assertEquals("Incorrect rounding of a float",
+ -91, StrictMath.round(-90.89d));
+ }
+
+ /**
+ * @tests java.lang.StrictMath#round(float)
+ */
+ public void test_roundF() {
+ // Test for method int java.lang.StrictMath.round(float)
+ assertEquals("Incorrect rounding of a float",
+ -91, StrictMath.round(-90.89f));
+ }
+
+ /**
+ * @tests java.lang.StrictMath#sin(double)
+ */
+ public void test_sinD() {
+ // Test for method double java.lang.StrictMath.sin(double)
+ assertTrue("Returned incorrect sine", StrictMath.sin(StrictMath
+ .asin(OPP / HYP)) == OPP / HYP);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#sqrt(double)
+ */
+ public void test_sqrtD() {
+ // Test for method double java.lang.StrictMath.sqrt(double)
+ assertEquals("Incorrect root returned1",
+ 2, StrictMath.sqrt(StrictMath.pow(StrictMath.sqrt(2), 4)), 0.0);
+ assertEquals("Incorrect root returned2", 7, StrictMath.sqrt(49), 0.0);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#tan(double)
+ */
+ public void test_tanD() {
+ // Test for method double java.lang.StrictMath.tan(double)
+ assertTrue(
+ "Returned incorrect tangent: ",
+ StrictMath.tan(StrictMath.atan(1.0)) <= 1.0
+ || StrictMath.tan(StrictMath.atan(1.0)) >= 9.9999999999999983E-1);
+ }
+
+ /**
+ * @tests java.lang.StrictMath#random()
+ */
+ public void test_random() {
+ // There isn't a place for these tests so just stick them here
+ assertEquals("Wrong value E",
+ 4613303445314885481L, Double.doubleToLongBits(StrictMath.E));
+ assertEquals("Wrong value PI",
+ 4614256656552045848L, Double.doubleToLongBits(StrictMath.PI));
+
+ for (int i = 500; i >= 0; i--) {
+ double d = StrictMath.random();
+ assertTrue("Generated number is out of range: " + d, d >= 0.0
+ && d < 1.0);
+ }
+ }
+
+ /**
+ * @tests java.lang.StrictMath#toRadians(double)
+ */
+ public void test_toRadiansD() {
+ for (double d = 500; d >= 0; d -= 1.0) {
+ double converted = StrictMath.toDegrees(StrictMath.toRadians(d));
+ assertTrue("Converted number not equal to original. d = " + d,
+ converted >= d * 0.99999999 && converted <= d * 1.00000001);
+ }
+ }
+
+ /**
+ * @tests java.lang.StrictMath#toDegrees(double)
+ */
+ public void test_toDegreesD() {
+ for (double d = 500; d >= 0; d -= 1.0) {
+ double converted = StrictMath.toRadians(StrictMath.toDegrees(d));
+ assertTrue("Converted number not equal to original. d = " + d,
+ converted >= d * 0.99999999 && converted <= d * 1.00000001);
+ }
+ }
+
+ /**
+ * Sets up the fixture, for example, open a network connection. This method
+ * is called before a test is executed.
+ */
+ protected void setUp() {
+ }
+
+ /**
+ * Tears down the fixture, for example, close a network connection. This
+ * method is called after a test is executed.
+ */
+ protected void tearDown() {
+ }
+}
Propchange: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/StrictMathTest.java
------------------------------------------------------------------------------
svn:eol-style = native