Source Code Cross Referenced for IntegerTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » luni » tests » java » lang » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.luni.tests.java.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /* Licensed to the Apache Software Foundation (ASF) under one or more
0002:         * contributor license agreements.  See the NOTICE file distributed with
0003:         * this work for additional information regarding copyright ownership.
0004:         * The ASF licenses this file to You under the Apache License, Version 2.0
0005:         * (the "License"); you may not use this file except in compliance with
0006:         * the License.  You may obtain a copy of the License at
0007:         * 
0008:         *     http://www.apache.org/licenses/LICENSE-2.0
0009:         * 
0010:         * Unless required by applicable law or agreed to in writing, software
0011:         * distributed under the License is distributed on an "AS IS" BASIS,
0012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0013:         * See the License for the specific language governing permissions and
0014:         * limitations under the License.
0015:         */
0016:
0017:        package org.apache.harmony.luni.tests.java.lang;
0018:
0019:        import java.util.Properties;
0020:
0021:        import junit.framework.TestCase;
0022:
0023:        public class IntegerTest extends TestCase {
0024:            private Properties orgProps;
0025:
0026:            @Override
0027:            protected void setUp() {
0028:                orgProps = System.getProperties();
0029:            }
0030:
0031:            @Override
0032:            protected void tearDown() {
0033:                System.setProperties(orgProps);
0034:            }
0035:
0036:            /**
0037:             * @tests java.lang.Integer#byteValue()
0038:             */
0039:            public void test_byteValue() {
0040:                // Test for method byte java.lang.Integer.byteValue()
0041:                assertEquals("Returned incorrect byte value", -1, new Integer(
0042:                        65535).byteValue());
0043:                assertEquals("Returned incorrect byte value", 127, new Integer(
0044:                        127).byteValue());
0045:            }
0046:
0047:            /**
0048:             * @tests java.lang.Integer#compareTo(java.lang.Integer)
0049:             */
0050:            public void test_compareToLjava_lang_Integer() {
0051:                // Test for method int java.lang.Integer.compareTo(java.lang.Integer)
0052:                assertTrue("-2 compared to 1 gave non-negative answer",
0053:                        new Integer(-2).compareTo(new Integer(1)) < 0);
0054:                assertEquals("-2 compared to -2 gave non-zero answer", 0,
0055:                        new Integer(-2).compareTo(new Integer(-2)));
0056:                assertTrue("3 compared to 2 gave non-positive answer",
0057:                        new Integer(3).compareTo(new Integer(2)) > 0);
0058:
0059:                try {
0060:                    new Integer(0).compareTo(null);
0061:                    fail("No NPE");
0062:                } catch (NullPointerException e) {
0063:                }
0064:            }
0065:
0066:            /**
0067:             * @tests java.lang.Integer#decode(java.lang.String)
0068:             */
0069:            public void test_decodeLjava_lang_String2() {
0070:                // Test for method java.lang.Integer
0071:                // java.lang.Integer.decode(java.lang.String)
0072:                assertEquals("Failed for 132233", 132233, Integer.decode(
0073:                        "132233").intValue());
0074:                assertEquals("Failed for 07654321", 07654321, Integer.decode(
0075:                        "07654321").intValue());
0076:                assertTrue("Failed for #1234567", Integer.decode("#1234567")
0077:                        .intValue() == 0x1234567);
0078:                assertTrue("Failed for 0xdAd", Integer.decode("0xdAd")
0079:                        .intValue() == 0xdad);
0080:                assertEquals("Failed for -23", -23, Integer.decode("-23")
0081:                        .intValue());
0082:                assertEquals("Returned incorrect value for 0 decimal", 0,
0083:                        Integer.decode("0").intValue());
0084:                assertEquals("Returned incorrect value for 0 hex", 0, Integer
0085:                        .decode("0x0").intValue());
0086:                assertTrue(
0087:                        "Returned incorrect value for most negative value decimal",
0088:                        Integer.decode("-2147483648").intValue() == 0x80000000);
0089:                assertTrue(
0090:                        "Returned incorrect value for most negative value hex",
0091:                        Integer.decode("-0x80000000").intValue() == 0x80000000);
0092:                assertTrue(
0093:                        "Returned incorrect value for most positive value decimal",
0094:                        Integer.decode("2147483647").intValue() == 0x7fffffff);
0095:                assertTrue(
0096:                        "Returned incorrect value for most positive value hex",
0097:                        Integer.decode("0x7fffffff").intValue() == 0x7fffffff);
0098:
0099:                boolean exception = false;
0100:                try {
0101:                    Integer.decode("0a");
0102:                } catch (NumberFormatException e) {
0103:                    // correct
0104:                    exception = true;
0105:                }
0106:                assertTrue("Failed to throw NumberFormatException for \"Oa\"",
0107:                        exception);
0108:
0109:                exception = false;
0110:                try {
0111:                    Integer.decode("2147483648");
0112:                } catch (NumberFormatException e) {
0113:                    // Correct
0114:                    exception = true;
0115:                }
0116:                assertTrue("Failed to throw exception for MAX_VALUE + 1",
0117:                        exception);
0118:
0119:                exception = false;
0120:                try {
0121:                    Integer.decode("-2147483649");
0122:                } catch (NumberFormatException e) {
0123:                    // Correct
0124:                    exception = true;
0125:                }
0126:                assertTrue("Failed to throw exception for MIN_VALUE - 1",
0127:                        exception);
0128:
0129:                exception = false;
0130:                try {
0131:                    Integer.decode("0x80000000");
0132:                } catch (NumberFormatException e) {
0133:                    // Correct
0134:                    exception = true;
0135:                }
0136:                assertTrue("Failed to throw exception for hex MAX_VALUE + 1",
0137:                        exception);
0138:
0139:                exception = false;
0140:                try {
0141:                    Integer.decode("-0x80000001");
0142:                } catch (NumberFormatException e) {
0143:                    // Correct
0144:                    exception = true;
0145:                }
0146:                assertTrue("Failed to throw exception for hex MIN_VALUE - 1",
0147:                        exception);
0148:
0149:                exception = false;
0150:                try {
0151:                    Integer.decode("9999999999");
0152:                } catch (NumberFormatException e) {
0153:                    // Correct
0154:                    exception = true;
0155:                }
0156:                assertTrue("Failed to throw exception for 9999999999",
0157:                        exception);
0158:
0159:                try {
0160:                    Integer.decode("-");
0161:                    fail("Expected exception for -");
0162:                } catch (NumberFormatException e) {
0163:                    // Expected
0164:                }
0165:
0166:                try {
0167:                    Integer.decode("0x");
0168:                    fail("Expected exception for 0x");
0169:                } catch (NumberFormatException e) {
0170:                    // Expected
0171:                }
0172:
0173:                try {
0174:                    Integer.decode("#");
0175:                    fail("Expected exception for #");
0176:                } catch (NumberFormatException e) {
0177:                    // Expected
0178:                }
0179:
0180:                try {
0181:                    Integer.decode("x123");
0182:                    fail("Expected exception for x123");
0183:                } catch (NumberFormatException e) {
0184:                    // Expected
0185:                }
0186:
0187:                try {
0188:                    Integer.decode(null);
0189:                    fail("Expected exception for null");
0190:                } catch (NullPointerException e) {
0191:                    // Expected
0192:                }
0193:
0194:                try {
0195:                    Integer.decode("");
0196:                    fail("Expected exception for empty string");
0197:                } catch (NumberFormatException ex) {
0198:                    // Expected
0199:                }
0200:
0201:                try {
0202:                    Integer.decode(" ");
0203:                    fail("Expected exception for single space");
0204:                } catch (NumberFormatException ex) {
0205:                    // Expected
0206:                }
0207:
0208:            }
0209:
0210:            /**
0211:             * @tests java.lang.Integer#doubleValue()
0212:             */
0213:            public void test_doubleValue2() {
0214:                // Test for method double java.lang.Integer.doubleValue()
0215:                assertEquals("Returned incorrect double value", 2147483647.0,
0216:                        new Integer(2147483647).doubleValue(), 0.0D);
0217:                assertEquals("Returned incorrect double value", -2147483647.0,
0218:                        new Integer(-2147483647).doubleValue(), 0.0D);
0219:            }
0220:
0221:            /**
0222:             * @tests java.lang.Integer#equals(java.lang.Object)
0223:             */
0224:            public void test_equalsLjava_lang_Object2() {
0225:                // Test for method boolean java.lang.Integer.equals(java.lang.Object)
0226:                Integer i1 = new Integer(1000);
0227:                Integer i2 = new Integer(1000);
0228:                Integer i3 = new Integer(-1000);
0229:                assertTrue("Equality test failed", i1.equals(i2)
0230:                        && !(i1.equals(i3)));
0231:            }
0232:
0233:            /**
0234:             * @tests java.lang.Integer#floatValue()
0235:             */
0236:            public void test_floatValue2() {
0237:                // Test for method float java.lang.Integer.floatValue()
0238:                assertTrue("Returned incorrect float value", new Integer(65535)
0239:                        .floatValue() == 65535.0f);
0240:                assertTrue("Returned incorrect float value",
0241:                        new Integer(-65535).floatValue() == -65535.0f);
0242:            }
0243:
0244:            /**
0245:             * @tests java.lang.Integer#getInteger(java.lang.String)
0246:             */
0247:            public void test_getIntegerLjava_lang_String() {
0248:                // Test for method java.lang.Integer
0249:                // java.lang.Integer.getInteger(java.lang.String)
0250:                Properties tProps = new Properties();
0251:                tProps.put("testInt", "99");
0252:                System.setProperties(tProps);
0253:                assertTrue("returned incorrect Integer", Integer.getInteger(
0254:                        "testInt").equals(new Integer(99)));
0255:                assertNull("returned incorrect default Integer", Integer
0256:                        .getInteger("ff"));
0257:            }
0258:
0259:            /**
0260:             * @tests java.lang.Integer#getInteger(java.lang.String, int)
0261:             */
0262:            public void test_getIntegerLjava_lang_StringI() {
0263:                // Test for method java.lang.Integer
0264:                // java.lang.Integer.getInteger(java.lang.String, int)
0265:                Properties tProps = new Properties();
0266:                tProps.put("testInt", "99");
0267:                System.setProperties(tProps);
0268:                assertTrue("returned incorrect Integer", Integer.getInteger(
0269:                        "testInt", 4).equals(new Integer(99)));
0270:                assertTrue("returned incorrect default Integer", Integer
0271:                        .getInteger("ff", 4).equals(new Integer(4)));
0272:            }
0273:
0274:            /**
0275:             * @tests java.lang.Integer#getInteger(java.lang.String, java.lang.Integer)
0276:             */
0277:            public void test_getIntegerLjava_lang_StringLjava_lang_Integer() {
0278:                // Test for method java.lang.Integer
0279:                // java.lang.Integer.getInteger(java.lang.String, java.lang.Integer)
0280:                Properties tProps = new Properties();
0281:                tProps.put("testInt", "99");
0282:                System.setProperties(tProps);
0283:                assertTrue("returned incorrect Integer", Integer.getInteger(
0284:                        "testInt", new Integer(4)).equals(new Integer(99)));
0285:                assertTrue("returned incorrect default Integer", Integer
0286:                        .getInteger("ff", new Integer(4))
0287:                        .equals(new Integer(4)));
0288:            }
0289:
0290:            /**
0291:             * @tests java.lang.Integer#hashCode()
0292:             */
0293:            public void test_hashCode2() {
0294:                // Test for method int java.lang.Integer.hashCode()
0295:
0296:                Integer i1 = new Integer(1000);
0297:                Integer i2 = new Integer(-1000);
0298:                assertTrue("Returned incorrect hashcode", i1.hashCode() == 1000
0299:                        && (i2.hashCode() == -1000));
0300:            }
0301:
0302:            /**
0303:             * @tests java.lang.Integer#intValue()
0304:             */
0305:            public void test_intValue2() {
0306:                // Test for method int java.lang.Integer.intValue()
0307:
0308:                Integer i = new Integer(8900);
0309:                assertEquals("Returned incorrect int value", 8900, i.intValue());
0310:            }
0311:
0312:            /**
0313:             * @tests java.lang.Integer#longValue()
0314:             */
0315:            public void test_longValue2() {
0316:                // Test for method long java.lang.Integer.longValue()
0317:                Integer i = new Integer(8900);
0318:                assertEquals("Returned incorrect long value", 8900L, i
0319:                        .longValue());
0320:            }
0321:
0322:            /**
0323:             * @tests java.lang.Integer#parseInt(java.lang.String)
0324:             */
0325:            public void test_parseIntLjava_lang_String2() {
0326:                // Test for method int java.lang.Integer.parseInt(java.lang.String)
0327:
0328:                int i = Integer.parseInt("-8900");
0329:                assertEquals("Returned incorrect int", -8900, i);
0330:                assertEquals("Returned incorrect value for 0", 0, Integer
0331:                        .parseInt("0"));
0332:                assertTrue("Returned incorrect value for most negative value",
0333:                        Integer.parseInt("-2147483648") == 0x80000000);
0334:                assertTrue("Returned incorrect value for most positive value",
0335:                        Integer.parseInt("2147483647") == 0x7fffffff);
0336:
0337:                boolean exception = false;
0338:                try {
0339:                    Integer.parseInt("999999999999");
0340:                } catch (NumberFormatException e) {
0341:                    // Correct
0342:                    exception = true;
0343:                }
0344:                assertTrue("Failed to throw exception for value > int",
0345:                        exception);
0346:
0347:                exception = false;
0348:                try {
0349:                    Integer.parseInt("2147483648");
0350:                } catch (NumberFormatException e) {
0351:                    // Correct
0352:                    exception = true;
0353:                }
0354:                assertTrue("Failed to throw exception for MAX_VALUE + 1",
0355:                        exception);
0356:
0357:                exception = false;
0358:                try {
0359:                    Integer.parseInt("-2147483649");
0360:                } catch (NumberFormatException e) {
0361:                    // Correct
0362:                    exception = true;
0363:                }
0364:                assertTrue("Failed to throw exception for MIN_VALUE - 1",
0365:                        exception);
0366:            }
0367:
0368:            /**
0369:             * @tests java.lang.Integer#parseInt(java.lang.String, int)
0370:             */
0371:            public void test_parseIntLjava_lang_StringI2() {
0372:                // Test for method int java.lang.Integer.parseInt(java.lang.String, int)
0373:                assertEquals("Parsed dec val incorrectly", -8000, Integer
0374:                        .parseInt("-8000", 10));
0375:                assertEquals("Parsed hex val incorrectly", 255, Integer
0376:                        .parseInt("FF", 16));
0377:                assertEquals("Parsed oct val incorrectly", 16, Integer
0378:                        .parseInt("20", 8));
0379:                assertEquals("Returned incorrect value for 0 hex", 0, Integer
0380:                        .parseInt("0", 16));
0381:                assertTrue(
0382:                        "Returned incorrect value for most negative value hex",
0383:                        Integer.parseInt("-80000000", 16) == 0x80000000);
0384:                assertTrue(
0385:                        "Returned incorrect value for most positive value hex",
0386:                        Integer.parseInt("7fffffff", 16) == 0x7fffffff);
0387:                assertEquals("Returned incorrect value for 0 decimal", 0,
0388:                        Integer.parseInt("0", 10));
0389:                assertTrue(
0390:                        "Returned incorrect value for most negative value decimal",
0391:                        Integer.parseInt("-2147483648", 10) == 0x80000000);
0392:                assertTrue(
0393:                        "Returned incorrect value for most positive value decimal",
0394:                        Integer.parseInt("2147483647", 10) == 0x7fffffff);
0395:
0396:                boolean exception = false;
0397:                try {
0398:                    Integer.parseInt("FFFF", 10);
0399:                } catch (NumberFormatException e) {
0400:                    // Correct
0401:                    exception = true;
0402:                }
0403:                assertTrue(
0404:                        "Failed to throw exception when passes hex string and dec parm",
0405:                        exception);
0406:
0407:                exception = false;
0408:                try {
0409:                    Integer.parseInt("2147483648", 10);
0410:                } catch (NumberFormatException e) {
0411:                    // Correct
0412:                    exception = true;
0413:                }
0414:                assertTrue("Failed to throw exception for MAX_VALUE + 1",
0415:                        exception);
0416:
0417:                exception = false;
0418:                try {
0419:                    Integer.parseInt("-2147483649", 10);
0420:                } catch (NumberFormatException e) {
0421:                    // Correct
0422:                    exception = true;
0423:                }
0424:                assertTrue("Failed to throw exception for MIN_VALUE - 1",
0425:                        exception);
0426:
0427:                exception = false;
0428:                try {
0429:                    Integer.parseInt("80000000", 16);
0430:                } catch (NumberFormatException e) {
0431:                    // Correct
0432:                    exception = true;
0433:                }
0434:                assertTrue("Failed to throw exception for hex MAX_VALUE + 1",
0435:                        exception);
0436:
0437:                exception = false;
0438:                try {
0439:                    Integer.parseInt("-80000001", 16);
0440:                } catch (NumberFormatException e) {
0441:                    // Correct
0442:                    exception = true;
0443:                }
0444:                assertTrue("Failed to throw exception for hex MIN_VALUE + 1",
0445:                        exception);
0446:
0447:                exception = false;
0448:                try {
0449:                    Integer.parseInt("9999999999", 10);
0450:                } catch (NumberFormatException e) {
0451:                    // Correct
0452:                    exception = true;
0453:                }
0454:                assertTrue("Failed to throw exception for 9999999999",
0455:                        exception);
0456:            }
0457:
0458:            /**
0459:             * @tests java.lang.Integer#shortValue()
0460:             */
0461:            public void test_shortValue2() {
0462:                // Test for method short java.lang.Integer.shortValue()
0463:                Integer i = new Integer(2147450880);
0464:                assertEquals("Returned incorrect long value", -32768, i
0465:                        .shortValue());
0466:            }
0467:
0468:            /**
0469:             * @tests java.lang.Integer#toBinaryString(int)
0470:             */
0471:            public void test_toBinaryStringI() {
0472:                // Test for method java.lang.String
0473:                // java.lang.Integer.toBinaryString(int)
0474:                assertEquals("Incorrect string returned",
0475:                        "1111111111111111111111111111111", Integer
0476:                                .toBinaryString(Integer.MAX_VALUE));
0477:                assertEquals("Incorrect string returned",
0478:                        "10000000000000000000000000000000", Integer
0479:                                .toBinaryString(Integer.MIN_VALUE));
0480:            }
0481:
0482:            /**
0483:             * @tests java.lang.Integer#toHexString(int)
0484:             */
0485:            public void test_toHexStringI() {
0486:                // Test for method java.lang.String java.lang.Integer.toHexString(int)
0487:
0488:                String[] hexvals = { "0", "1", "2", "3", "4", "5", "6", "7",
0489:                        "8", "9", "a", "b", "c", "d", "e", "f" };
0490:
0491:                for (int i = 0; i < 16; i++) {
0492:                    assertTrue("Incorrect string returned " + hexvals[i],
0493:                            Integer.toHexString(i).equals(hexvals[i]));
0494:                }
0495:
0496:                assertTrue("Returned incorrect hex string: "
0497:                        + Integer.toHexString(Integer.MAX_VALUE), Integer
0498:                        .toHexString(Integer.MAX_VALUE).equals("7fffffff"));
0499:                assertTrue("Returned incorrect hex string: "
0500:                        + Integer.toHexString(Integer.MIN_VALUE), Integer
0501:                        .toHexString(Integer.MIN_VALUE).equals("80000000"));
0502:            }
0503:
0504:            /**
0505:             * @tests java.lang.Integer#toOctalString(int)
0506:             */
0507:            public void test_toOctalStringI() {
0508:                // Test for method java.lang.String java.lang.Integer.toOctalString(int)
0509:                // Spec states that the int arg is treated as unsigned
0510:                assertEquals("Returned incorrect octal string", "17777777777",
0511:                        Integer.toOctalString(Integer.MAX_VALUE));
0512:                assertEquals("Returned incorrect octal string", "20000000000",
0513:                        Integer.toOctalString(Integer.MIN_VALUE));
0514:            }
0515:
0516:            /**
0517:             * @tests java.lang.Integer#toString()
0518:             */
0519:            public void test_toString2() {
0520:                // Test for method java.lang.String java.lang.Integer.toString()
0521:
0522:                Integer i = new Integer(-80001);
0523:
0524:                assertEquals("Returned incorrect String", "-80001", i
0525:                        .toString());
0526:            }
0527:
0528:            /**
0529:             * @tests java.lang.Integer#toString(int)
0530:             */
0531:            public void test_toStringI2() {
0532:                // Test for method java.lang.String java.lang.Integer.toString(int)
0533:
0534:                assertEquals("Returned incorrect String", "-80765", Integer
0535:                        .toString(-80765));
0536:                assertEquals("Returned incorrect octal string", "2147483647",
0537:                        Integer.toString(Integer.MAX_VALUE));
0538:                assertEquals("Returned incorrect octal string", "-2147483647",
0539:                        Integer.toString(-Integer.MAX_VALUE));
0540:                assertEquals("Returned incorrect octal string", "-2147483648",
0541:                        Integer.toString(Integer.MIN_VALUE));
0542:            }
0543:
0544:            /**
0545:             * @tests java.lang.Integer#toString(int, int)
0546:             */
0547:            public void test_toStringII() {
0548:                // Test for method java.lang.String java.lang.Integer.toString(int, int)
0549:                assertEquals("Returned incorrect octal string", "17777777777",
0550:                        Integer.toString(2147483647, 8));
0551:                assertTrue(
0552:                        "Returned incorrect hex string--wanted 7fffffff but got: "
0553:                                + Integer.toString(2147483647, 16), Integer
0554:                                .toString(2147483647, 16).equals("7fffffff"));
0555:                assertEquals("Incorrect string returned",
0556:                        "1111111111111111111111111111111", Integer.toString(
0557:                                2147483647, 2));
0558:                assertEquals("Incorrect string returned", "2147483647", Integer
0559:                        .toString(2147483647, 10));
0560:
0561:                assertEquals("Returned incorrect octal string", "-17777777777",
0562:                        Integer.toString(-2147483647, 8));
0563:                assertTrue(
0564:                        "Returned incorrect hex string--wanted -7fffffff but got: "
0565:                                + Integer.toString(-2147483647, 16), Integer
0566:                                .toString(-2147483647, 16).equals("-7fffffff"));
0567:                assertEquals("Incorrect string returned",
0568:                        "-1111111111111111111111111111111", Integer.toString(
0569:                                -2147483647, 2));
0570:                assertEquals("Incorrect string returned", "-2147483647",
0571:                        Integer.toString(-2147483647, 10));
0572:
0573:                assertEquals("Returned incorrect octal string", "-20000000000",
0574:                        Integer.toString(-2147483648, 8));
0575:                assertTrue(
0576:                        "Returned incorrect hex string--wanted -80000000 but got: "
0577:                                + Integer.toString(-2147483648, 16), Integer
0578:                                .toString(-2147483648, 16).equals("-80000000"));
0579:                assertEquals("Incorrect string returned",
0580:                        "-10000000000000000000000000000000", Integer.toString(
0581:                                -2147483648, 2));
0582:                assertEquals("Incorrect string returned", "-2147483648",
0583:                        Integer.toString(-2147483648, 10));
0584:            }
0585:
0586:            /**
0587:             * @tests java.lang.Integer#valueOf(java.lang.String)
0588:             */
0589:            public void test_valueOfLjava_lang_String2() {
0590:                // Test for method java.lang.Integer
0591:                // java.lang.Integer.valueOf(java.lang.String)
0592:                assertEquals("Returned incorrect int", 8888888, Integer
0593:                        .valueOf("8888888").intValue());
0594:                assertTrue("Returned incorrect int", Integer.valueOf(
0595:                        "2147483647").intValue() == Integer.MAX_VALUE);
0596:                assertTrue("Returned incorrect int", Integer.valueOf(
0597:                        "-2147483648").intValue() == Integer.MIN_VALUE);
0598:
0599:                boolean exception = false;
0600:                try {
0601:                    Integer.valueOf("2147483648");
0602:                } catch (NumberFormatException e) {
0603:                    // Correct
0604:                    exception = true;
0605:                }
0606:                assertTrue("Failed to throw exception with MAX_VALUE + 1",
0607:                        exception);
0608:
0609:                exception = false;
0610:                try {
0611:                    Integer.valueOf("-2147483649");
0612:                } catch (NumberFormatException e) {
0613:                    // Correct
0614:                    exception = true;
0615:                }
0616:                assertTrue("Failed to throw exception with MIN_VALUE - 1",
0617:                        exception);
0618:            }
0619:
0620:            /**
0621:             * @tests java.lang.Integer#valueOf(java.lang.String, int)
0622:             */
0623:            public void test_valueOfLjava_lang_StringI2() {
0624:                // Test for method java.lang.Integer
0625:                // java.lang.Integer.valueOf(java.lang.String, int)
0626:                assertEquals("Returned incorrect int for hex string", 255,
0627:                        Integer.valueOf("FF", 16).intValue());
0628:                assertEquals("Returned incorrect int for oct string", 16,
0629:                        Integer.valueOf("20", 8).intValue());
0630:                assertEquals("Returned incorrect int for bin string", 4,
0631:                        Integer.valueOf("100", 2).intValue());
0632:
0633:                assertEquals("Returned incorrect int for - hex string", -255,
0634:                        Integer.valueOf("-FF", 16).intValue());
0635:                assertEquals("Returned incorrect int for - oct string", -16,
0636:                        Integer.valueOf("-20", 8).intValue());
0637:                assertEquals("Returned incorrect int for - bin string", -4,
0638:                        Integer.valueOf("-100", 2).intValue());
0639:                assertTrue("Returned incorrect int", Integer.valueOf(
0640:                        "2147483647", 10).intValue() == Integer.MAX_VALUE);
0641:                assertTrue("Returned incorrect int", Integer.valueOf(
0642:                        "-2147483648", 10).intValue() == Integer.MIN_VALUE);
0643:                assertTrue("Returned incorrect int", Integer.valueOf(
0644:                        "7fffffff", 16).intValue() == Integer.MAX_VALUE);
0645:                assertTrue("Returned incorrect int", Integer.valueOf(
0646:                        "-80000000", 16).intValue() == Integer.MIN_VALUE);
0647:
0648:                boolean exception = false;
0649:                try {
0650:                    Integer.valueOf("FF", 2);
0651:                } catch (NumberFormatException e) {
0652:                    // Correct
0653:                    exception = true;
0654:                }
0655:                assertTrue(
0656:                        "Failed to throw exception with hex string and base 2 radix",
0657:                        exception);
0658:
0659:                exception = false;
0660:                try {
0661:                    Integer.valueOf("2147483648", 10);
0662:                } catch (NumberFormatException e) {
0663:                    // Correct
0664:                    exception = true;
0665:                }
0666:                assertTrue("Failed to throw exception with MAX_VALUE + 1",
0667:                        exception);
0668:
0669:                exception = false;
0670:                try {
0671:                    Integer.valueOf("-2147483649", 10);
0672:                } catch (NumberFormatException e) {
0673:                    // Correct
0674:                    exception = true;
0675:                }
0676:                assertTrue("Failed to throw exception with MIN_VALUE - 1",
0677:                        exception);
0678:
0679:                exception = false;
0680:                try {
0681:                    Integer.valueOf("80000000", 16);
0682:                } catch (NumberFormatException e) {
0683:                    // Correct
0684:                    exception = true;
0685:                }
0686:                assertTrue("Failed to throw exception with hex MAX_VALUE + 1",
0687:                        exception);
0688:
0689:                exception = false;
0690:                try {
0691:                    Integer.valueOf("-80000001", 16);
0692:                } catch (NumberFormatException e) {
0693:                    // Correct
0694:                    exception = true;
0695:                }
0696:                assertTrue("Failed to throw exception with hex MIN_VALUE - 1",
0697:                        exception);
0698:            }
0699:
0700:            /**
0701:             * @tests java.lang.Integer#valueOf(byte)
0702:             */
0703:            public void test_valueOfI() {
0704:                assertEquals(new Integer(Integer.MIN_VALUE), Integer
0705:                        .valueOf(Integer.MIN_VALUE));
0706:                assertEquals(new Integer(Integer.MAX_VALUE), Integer
0707:                        .valueOf(Integer.MAX_VALUE));
0708:                assertEquals(new Integer(0), Integer.valueOf(0));
0709:
0710:                short s = -128;
0711:                while (s < 128) {
0712:                    assertEquals(new Integer(s), Integer.valueOf(s));
0713:                    assertSame(Integer.valueOf(s), Integer.valueOf(s));
0714:                    s++;
0715:                }
0716:            }
0717:
0718:            /**
0719:             * @tests java.lang.Integer#hashCode()
0720:             */
0721:            public void test_hashCode() {
0722:                assertEquals(1, new Integer(1).hashCode());
0723:                assertEquals(2, new Integer(2).hashCode());
0724:                assertEquals(0, new Integer(0).hashCode());
0725:                assertEquals(-1, new Integer(-1).hashCode());
0726:            }
0727:
0728:            /**
0729:             * @tests java.lang.Integer#Integer(String)
0730:             */
0731:            public void test_ConstructorLjava_lang_String() {
0732:                assertEquals(new Integer(0), new Integer("0"));
0733:                assertEquals(new Integer(1), new Integer("1"));
0734:                assertEquals(new Integer(-1), new Integer("-1"));
0735:
0736:                try {
0737:                    new Integer("0x1");
0738:                    fail("Expected NumberFormatException with hex string.");
0739:                } catch (NumberFormatException e) {
0740:                }
0741:
0742:                try {
0743:                    new Integer("9.2");
0744:                    fail("Expected NumberFormatException with floating point string.");
0745:                } catch (NumberFormatException e) {
0746:                }
0747:
0748:                try {
0749:                    new Integer("");
0750:                    fail("Expected NumberFormatException with empty string.");
0751:                } catch (NumberFormatException e) {
0752:                }
0753:
0754:                try {
0755:                    new Integer(null);
0756:                    fail("Expected NumberFormatException with null string.");
0757:                } catch (NumberFormatException e) {
0758:                }
0759:            }
0760:
0761:            /**
0762:             * @tests java.lang.Integer#Integer
0763:             */
0764:            public void test_ConstructorI() {
0765:                assertEquals(1, new Integer(1).intValue());
0766:                assertEquals(2, new Integer(2).intValue());
0767:                assertEquals(0, new Integer(0).intValue());
0768:                assertEquals(-1, new Integer(-1).intValue());
0769:
0770:                Integer i = new Integer(-89000);
0771:                assertEquals("Incorrect Integer created", -89000, i.intValue());
0772:            }
0773:
0774:            /**
0775:             * @tests java.lang.Integer#byteValue()
0776:             */
0777:            public void test_booleanValue() {
0778:                assertEquals(1, new Integer(1).byteValue());
0779:                assertEquals(2, new Integer(2).byteValue());
0780:                assertEquals(0, new Integer(0).byteValue());
0781:                assertEquals(-1, new Integer(-1).byteValue());
0782:            }
0783:
0784:            /**
0785:             * @tests java.lang.Integer#equals(Object)
0786:             */
0787:            public void test_equalsLjava_lang_Object() {
0788:                assertEquals(new Integer(0), Integer.valueOf(0));
0789:                assertEquals(new Integer(1), Integer.valueOf(1));
0790:                assertEquals(new Integer(-1), Integer.valueOf(-1));
0791:
0792:                Integer fixture = new Integer(25);
0793:                assertEquals(fixture, fixture);
0794:                assertFalse(fixture.equals(null));
0795:                assertFalse(fixture.equals("Not a Integer"));
0796:            }
0797:
0798:            /**
0799:             * @tests java.lang.Integer#toString()
0800:             */
0801:            public void test_toString() {
0802:                assertEquals("-1", new Integer(-1).toString());
0803:                assertEquals("0", new Integer(0).toString());
0804:                assertEquals("1", new Integer(1).toString());
0805:                assertEquals("-1", new Integer(0xFFFFFFFF).toString());
0806:            }
0807:
0808:            /**
0809:             * @tests java.lang.Integer#toString
0810:             */
0811:            public void test_toStringI() {
0812:                assertEquals("-1", Integer.toString(-1));
0813:                assertEquals("0", Integer.toString(0));
0814:                assertEquals("1", Integer.toString(1));
0815:                assertEquals("-1", Integer.toString(0xFFFFFFFF));
0816:            }
0817:
0818:            /**
0819:             * @tests java.lang.Integer#valueOf(String)
0820:             */
0821:            public void test_valueOfLjava_lang_String() {
0822:                assertEquals(new Integer(0), Integer.valueOf("0"));
0823:                assertEquals(new Integer(1), Integer.valueOf("1"));
0824:                assertEquals(new Integer(-1), Integer.valueOf("-1"));
0825:
0826:                try {
0827:                    Integer.valueOf("0x1");
0828:                    fail("Expected NumberFormatException with hex string.");
0829:                } catch (NumberFormatException e) {
0830:                }
0831:
0832:                try {
0833:                    Integer.valueOf("9.2");
0834:                    fail("Expected NumberFormatException with floating point string.");
0835:                } catch (NumberFormatException e) {
0836:                }
0837:
0838:                try {
0839:                    Integer.valueOf("");
0840:                    fail("Expected NumberFormatException with empty string.");
0841:                } catch (NumberFormatException e) {
0842:                }
0843:
0844:                try {
0845:                    Integer.valueOf(null);
0846:                    fail("Expected NumberFormatException with null string.");
0847:                } catch (NumberFormatException e) {
0848:                }
0849:            }
0850:
0851:            /**
0852:             * @tests java.lang.Integer#valueOf(String,int)
0853:             */
0854:            public void test_valueOfLjava_lang_StringI() {
0855:                assertEquals(new Integer(0), Integer.valueOf("0", 10));
0856:                assertEquals(new Integer(1), Integer.valueOf("1", 10));
0857:                assertEquals(new Integer(-1), Integer.valueOf("-1", 10));
0858:
0859:                //must be consistent with Character.digit()
0860:                assertEquals(Character.digit('1', 2), Integer.valueOf("1", 2)
0861:                        .byteValue());
0862:                assertEquals(Character.digit('F', 16), Integer.valueOf("F", 16)
0863:                        .byteValue());
0864:
0865:                try {
0866:                    Integer.valueOf("0x1", 10);
0867:                    fail("Expected NumberFormatException with hex string.");
0868:                } catch (NumberFormatException e) {
0869:                }
0870:
0871:                try {
0872:                    Integer.valueOf("9.2", 10);
0873:                    fail("Expected NumberFormatException with floating point string.");
0874:                } catch (NumberFormatException e) {
0875:                }
0876:
0877:                try {
0878:                    Integer.valueOf("", 10);
0879:                    fail("Expected NumberFormatException with empty string.");
0880:                } catch (NumberFormatException e) {
0881:                }
0882:
0883:                try {
0884:                    Integer.valueOf(null, 10);
0885:                    fail("Expected NumberFormatException with null string.");
0886:                } catch (NumberFormatException e) {
0887:                }
0888:            }
0889:
0890:            /**
0891:             * @tests java.lang.Integer#parseInt(String)
0892:             */
0893:            public void test_parseIntLjava_lang_String() {
0894:                assertEquals(0, Integer.parseInt("0"));
0895:                assertEquals(1, Integer.parseInt("1"));
0896:                assertEquals(-1, Integer.parseInt("-1"));
0897:
0898:                try {
0899:                    Integer.parseInt("0x1");
0900:                    fail("Expected NumberFormatException with hex string.");
0901:                } catch (NumberFormatException e) {
0902:                }
0903:
0904:                try {
0905:                    Integer.parseInt("9.2");
0906:                    fail("Expected NumberFormatException with floating point string.");
0907:                } catch (NumberFormatException e) {
0908:                }
0909:
0910:                try {
0911:                    Integer.parseInt("");
0912:                    fail("Expected NumberFormatException with empty string.");
0913:                } catch (NumberFormatException e) {
0914:                }
0915:
0916:                try {
0917:                    Integer.parseInt(null);
0918:                    fail("Expected NumberFormatException with null string.");
0919:                } catch (NumberFormatException e) {
0920:                }
0921:            }
0922:
0923:            /**
0924:             * @tests java.lang.Integer#parseInt(String,int)
0925:             */
0926:            public void test_parseIntLjava_lang_StringI() {
0927:                assertEquals(0, Integer.parseInt("0", 10));
0928:                assertEquals(1, Integer.parseInt("1", 10));
0929:                assertEquals(-1, Integer.parseInt("-1", 10));
0930:
0931:                //must be consistent with Character.digit()
0932:                assertEquals(Character.digit('1', 2), Integer.parseInt("1", 2));
0933:                assertEquals(Character.digit('F', 16), Integer
0934:                        .parseInt("F", 16));
0935:
0936:                try {
0937:                    Integer.parseInt("0x1", 10);
0938:                    fail("Expected NumberFormatException with hex string.");
0939:                } catch (NumberFormatException e) {
0940:                }
0941:
0942:                try {
0943:                    Integer.parseInt("9.2", 10);
0944:                    fail("Expected NumberFormatException with floating point string.");
0945:                } catch (NumberFormatException e) {
0946:                }
0947:
0948:                try {
0949:                    Integer.parseInt("", 10);
0950:                    fail("Expected NumberFormatException with empty string.");
0951:                } catch (NumberFormatException e) {
0952:                }
0953:
0954:                try {
0955:                    Integer.parseInt(null, 10);
0956:                    fail("Expected NumberFormatException with null string.");
0957:                } catch (NumberFormatException e) {
0958:                }
0959:            }
0960:
0961:            /**
0962:             * @tests java.lang.Integer#decode(String)
0963:             */
0964:            public void test_decodeLjava_lang_String() {
0965:                assertEquals(new Integer(0), Integer.decode("0"));
0966:                assertEquals(new Integer(1), Integer.decode("1"));
0967:                assertEquals(new Integer(-1), Integer.decode("-1"));
0968:                assertEquals(new Integer(0xF), Integer.decode("0xF"));
0969:                assertEquals(new Integer(0xF), Integer.decode("#F"));
0970:                assertEquals(new Integer(0xF), Integer.decode("0XF"));
0971:                assertEquals(new Integer(07), Integer.decode("07"));
0972:
0973:                try {
0974:                    Integer.decode("9.2");
0975:                    fail("Expected NumberFormatException with floating point string.");
0976:                } catch (NumberFormatException e) {
0977:                }
0978:
0979:                try {
0980:                    Integer.decode("");
0981:                    fail("Expected NumberFormatException with empty string.");
0982:                } catch (NumberFormatException e) {
0983:                }
0984:
0985:                try {
0986:                    Integer.decode(null);
0987:                    //undocumented NPE, but seems consistent across JREs
0988:                    fail("Expected NullPointerException with null string.");
0989:                } catch (NullPointerException e) {
0990:                }
0991:            }
0992:
0993:            /**
0994:             * @tests java.lang.Integer#doubleValue()
0995:             */
0996:            public void test_doubleValue() {
0997:                assertEquals(-1D, new Integer(-1).doubleValue(), 0D);
0998:                assertEquals(0D, new Integer(0).doubleValue(), 0D);
0999:                assertEquals(1D, new Integer(1).doubleValue(), 0D);
1000:            }
1001:
1002:            /**
1003:             * @tests java.lang.Integer#floatValue()
1004:             */
1005:            public void test_floatValue() {
1006:                assertEquals(-1F, new Integer(-1).floatValue(), 0F);
1007:                assertEquals(0F, new Integer(0).floatValue(), 0F);
1008:                assertEquals(1F, new Integer(1).floatValue(), 0F);
1009:            }
1010:
1011:            /**
1012:             * @tests java.lang.Integer#intValue()
1013:             */
1014:            public void test_intValue() {
1015:                assertEquals(-1, new Integer(-1).intValue());
1016:                assertEquals(0, new Integer(0).intValue());
1017:                assertEquals(1, new Integer(1).intValue());
1018:            }
1019:
1020:            /**
1021:             * @tests java.lang.Integer#longValue()
1022:             */
1023:            public void test_longValue() {
1024:                assertEquals(-1L, new Integer(-1).longValue());
1025:                assertEquals(0L, new Integer(0).longValue());
1026:                assertEquals(1L, new Integer(1).longValue());
1027:            }
1028:
1029:            /**
1030:             * @tests java.lang.Integer#shortValue()
1031:             */
1032:            public void test_shortValue() {
1033:                assertEquals(-1, new Integer(-1).shortValue());
1034:                assertEquals(0, new Integer(0).shortValue());
1035:                assertEquals(1, new Integer(1).shortValue());
1036:            }
1037:
1038:            /**
1039:             * @tests java.lang.Integer#highestOneBit(int)
1040:             */
1041:            public void test_highestOneBitI() {
1042:                assertEquals(0x08, Integer.highestOneBit(0x0A));
1043:                assertEquals(0x08, Integer.highestOneBit(0x0B));
1044:                assertEquals(0x08, Integer.highestOneBit(0x0C));
1045:                assertEquals(0x08, Integer.highestOneBit(0x0F));
1046:                assertEquals(0x80, Integer.highestOneBit(0xFF));
1047:
1048:                assertEquals(0x080000, Integer.highestOneBit(0x0F1234));
1049:                assertEquals(0x800000, Integer.highestOneBit(0xFF9977));
1050:
1051:                assertEquals(0x80000000, Integer.highestOneBit(0xFFFFFFFF));
1052:
1053:                assertEquals(0, Integer.highestOneBit(0));
1054:                assertEquals(1, Integer.highestOneBit(1));
1055:                assertEquals(0x80000000, Integer.highestOneBit(-1));
1056:            }
1057:
1058:            /**
1059:             * @tests java.lang.Integer#lowestOneBit(int)
1060:             */
1061:            public void test_lowestOneBitI() {
1062:                assertEquals(0x10, Integer.lowestOneBit(0xF0));
1063:
1064:                assertEquals(0x10, Integer.lowestOneBit(0x90));
1065:                assertEquals(0x10, Integer.lowestOneBit(0xD0));
1066:
1067:                assertEquals(0x10, Integer.lowestOneBit(0x123490));
1068:                assertEquals(0x10, Integer.lowestOneBit(0x1234D0));
1069:
1070:                assertEquals(0x100000, Integer.lowestOneBit(0x900000));
1071:                assertEquals(0x100000, Integer.lowestOneBit(0xD00000));
1072:
1073:                assertEquals(0x40, Integer.lowestOneBit(0x40));
1074:                assertEquals(0x40, Integer.lowestOneBit(0xC0));
1075:
1076:                assertEquals(0x4000, Integer.lowestOneBit(0x4000));
1077:                assertEquals(0x4000, Integer.lowestOneBit(0xC000));
1078:
1079:                assertEquals(0x4000, Integer.lowestOneBit(0x99994000));
1080:                assertEquals(0x4000, Integer.lowestOneBit(0x9999C000));
1081:
1082:                assertEquals(0, Integer.lowestOneBit(0));
1083:                assertEquals(1, Integer.lowestOneBit(1));
1084:                assertEquals(1, Integer.lowestOneBit(-1));
1085:            }
1086:
1087:            /**
1088:             * @tests java.lang.Integer#numberOfLeadingZeros(int)
1089:             */
1090:            public void test_numberOfLeadingZerosI() {
1091:                assertEquals(32, Integer.numberOfLeadingZeros(0x0));
1092:                assertEquals(31, Integer.numberOfLeadingZeros(0x1));
1093:                assertEquals(30, Integer.numberOfLeadingZeros(0x2));
1094:                assertEquals(30, Integer.numberOfLeadingZeros(0x3));
1095:                assertEquals(29, Integer.numberOfLeadingZeros(0x4));
1096:                assertEquals(29, Integer.numberOfLeadingZeros(0x5));
1097:                assertEquals(29, Integer.numberOfLeadingZeros(0x6));
1098:                assertEquals(29, Integer.numberOfLeadingZeros(0x7));
1099:                assertEquals(28, Integer.numberOfLeadingZeros(0x8));
1100:                assertEquals(28, Integer.numberOfLeadingZeros(0x9));
1101:                assertEquals(28, Integer.numberOfLeadingZeros(0xA));
1102:                assertEquals(28, Integer.numberOfLeadingZeros(0xB));
1103:                assertEquals(28, Integer.numberOfLeadingZeros(0xC));
1104:                assertEquals(28, Integer.numberOfLeadingZeros(0xD));
1105:                assertEquals(28, Integer.numberOfLeadingZeros(0xE));
1106:                assertEquals(28, Integer.numberOfLeadingZeros(0xF));
1107:                assertEquals(27, Integer.numberOfLeadingZeros(0x10));
1108:                assertEquals(24, Integer.numberOfLeadingZeros(0x80));
1109:                assertEquals(24, Integer.numberOfLeadingZeros(0xF0));
1110:                assertEquals(23, Integer.numberOfLeadingZeros(0x100));
1111:                assertEquals(20, Integer.numberOfLeadingZeros(0x800));
1112:                assertEquals(20, Integer.numberOfLeadingZeros(0xF00));
1113:                assertEquals(19, Integer.numberOfLeadingZeros(0x1000));
1114:                assertEquals(16, Integer.numberOfLeadingZeros(0x8000));
1115:                assertEquals(16, Integer.numberOfLeadingZeros(0xF000));
1116:                assertEquals(15, Integer.numberOfLeadingZeros(0x10000));
1117:                assertEquals(12, Integer.numberOfLeadingZeros(0x80000));
1118:                assertEquals(12, Integer.numberOfLeadingZeros(0xF0000));
1119:                assertEquals(11, Integer.numberOfLeadingZeros(0x100000));
1120:                assertEquals(8, Integer.numberOfLeadingZeros(0x800000));
1121:                assertEquals(8, Integer.numberOfLeadingZeros(0xF00000));
1122:                assertEquals(7, Integer.numberOfLeadingZeros(0x1000000));
1123:                assertEquals(4, Integer.numberOfLeadingZeros(0x8000000));
1124:                assertEquals(4, Integer.numberOfLeadingZeros(0xF000000));
1125:                assertEquals(3, Integer.numberOfLeadingZeros(0x10000000));
1126:                assertEquals(0, Integer.numberOfLeadingZeros(0x80000000));
1127:                assertEquals(0, Integer.numberOfLeadingZeros(0xF0000000));
1128:
1129:                assertEquals(1, Integer.numberOfLeadingZeros(Integer.MAX_VALUE));
1130:                assertEquals(0, Integer.numberOfLeadingZeros(Integer.MIN_VALUE));
1131:            }
1132:
1133:            /**
1134:             * @tests java.lang.Integer#numberOfTrailingZeros(int)
1135:             */
1136:            public void test_numberOfTrailingZerosI() {
1137:                assertEquals(32, Integer.numberOfTrailingZeros(0x0));
1138:                assertEquals(31, Integer
1139:                        .numberOfTrailingZeros(Integer.MIN_VALUE));
1140:                assertEquals(0, Integer
1141:                        .numberOfTrailingZeros(Integer.MAX_VALUE));
1142:
1143:                assertEquals(0, Integer.numberOfTrailingZeros(0x1));
1144:                assertEquals(3, Integer.numberOfTrailingZeros(0x8));
1145:                assertEquals(0, Integer.numberOfTrailingZeros(0xF));
1146:
1147:                assertEquals(4, Integer.numberOfTrailingZeros(0x10));
1148:                assertEquals(7, Integer.numberOfTrailingZeros(0x80));
1149:                assertEquals(4, Integer.numberOfTrailingZeros(0xF0));
1150:
1151:                assertEquals(8, Integer.numberOfTrailingZeros(0x100));
1152:                assertEquals(11, Integer.numberOfTrailingZeros(0x800));
1153:                assertEquals(8, Integer.numberOfTrailingZeros(0xF00));
1154:
1155:                assertEquals(12, Integer.numberOfTrailingZeros(0x1000));
1156:                assertEquals(15, Integer.numberOfTrailingZeros(0x8000));
1157:                assertEquals(12, Integer.numberOfTrailingZeros(0xF000));
1158:
1159:                assertEquals(16, Integer.numberOfTrailingZeros(0x10000));
1160:                assertEquals(19, Integer.numberOfTrailingZeros(0x80000));
1161:                assertEquals(16, Integer.numberOfTrailingZeros(0xF0000));
1162:
1163:                assertEquals(20, Integer.numberOfTrailingZeros(0x100000));
1164:                assertEquals(23, Integer.numberOfTrailingZeros(0x800000));
1165:                assertEquals(20, Integer.numberOfTrailingZeros(0xF00000));
1166:
1167:                assertEquals(24, Integer.numberOfTrailingZeros(0x1000000));
1168:                assertEquals(27, Integer.numberOfTrailingZeros(0x8000000));
1169:                assertEquals(24, Integer.numberOfTrailingZeros(0xF000000));
1170:
1171:                assertEquals(28, Integer.numberOfTrailingZeros(0x10000000));
1172:                assertEquals(31, Integer.numberOfTrailingZeros(0x80000000));
1173:                assertEquals(28, Integer.numberOfTrailingZeros(0xF0000000));
1174:            }
1175:
1176:            /**
1177:             * @tests java.lang.Integer#bitCount(int)
1178:             */
1179:            public void test_bitCountI() {
1180:                assertEquals(0, Integer.bitCount(0x0));
1181:                assertEquals(1, Integer.bitCount(0x1));
1182:                assertEquals(1, Integer.bitCount(0x2));
1183:                assertEquals(2, Integer.bitCount(0x3));
1184:                assertEquals(1, Integer.bitCount(0x4));
1185:                assertEquals(2, Integer.bitCount(0x5));
1186:                assertEquals(2, Integer.bitCount(0x6));
1187:                assertEquals(3, Integer.bitCount(0x7));
1188:                assertEquals(1, Integer.bitCount(0x8));
1189:                assertEquals(2, Integer.bitCount(0x9));
1190:                assertEquals(2, Integer.bitCount(0xA));
1191:                assertEquals(3, Integer.bitCount(0xB));
1192:                assertEquals(2, Integer.bitCount(0xC));
1193:                assertEquals(3, Integer.bitCount(0xD));
1194:                assertEquals(3, Integer.bitCount(0xE));
1195:                assertEquals(4, Integer.bitCount(0xF));
1196:
1197:                assertEquals(8, Integer.bitCount(0xFF));
1198:                assertEquals(12, Integer.bitCount(0xFFF));
1199:                assertEquals(16, Integer.bitCount(0xFFFF));
1200:                assertEquals(20, Integer.bitCount(0xFFFFF));
1201:                assertEquals(24, Integer.bitCount(0xFFFFFF));
1202:                assertEquals(28, Integer.bitCount(0xFFFFFFF));
1203:                assertEquals(32, Integer.bitCount(0xFFFFFFFF));
1204:            }
1205:
1206:            /**
1207:             * @tests java.lang.Integer#rotateLeft(int,int)
1208:             */
1209:            public void test_rotateLeftII() {
1210:                assertEquals(0xF, Integer.rotateLeft(0xF, 0));
1211:                assertEquals(0xF0, Integer.rotateLeft(0xF, 4));
1212:                assertEquals(0xF00, Integer.rotateLeft(0xF, 8));
1213:                assertEquals(0xF000, Integer.rotateLeft(0xF, 12));
1214:                assertEquals(0xF0000, Integer.rotateLeft(0xF, 16));
1215:                assertEquals(0xF00000, Integer.rotateLeft(0xF, 20));
1216:                assertEquals(0xF000000, Integer.rotateLeft(0xF, 24));
1217:                assertEquals(0xF0000000, Integer.rotateLeft(0xF, 28));
1218:                assertEquals(0xF0000000, Integer.rotateLeft(0xF0000000, 32));
1219:            }
1220:
1221:            /**
1222:             * @tests java.lang.Integer#rotateRight(int,int)
1223:             */
1224:            public void test_rotateRightII() {
1225:                assertEquals(0xF, Integer.rotateRight(0xF0, 4));
1226:                assertEquals(0xF, Integer.rotateRight(0xF00, 8));
1227:                assertEquals(0xF, Integer.rotateRight(0xF000, 12));
1228:                assertEquals(0xF, Integer.rotateRight(0xF0000, 16));
1229:                assertEquals(0xF, Integer.rotateRight(0xF00000, 20));
1230:                assertEquals(0xF, Integer.rotateRight(0xF000000, 24));
1231:                assertEquals(0xF, Integer.rotateRight(0xF0000000, 28));
1232:                assertEquals(0xF0000000, Integer.rotateRight(0xF0000000, 32));
1233:                assertEquals(0xF0000000, Integer.rotateRight(0xF0000000, 0));
1234:
1235:            }
1236:
1237:            /**
1238:             * @tests java.lang.Integer#reverseBytes(int)
1239:             */
1240:            public void test_reverseBytesI() {
1241:                assertEquals(0xAABBCCDD, Integer.reverseBytes(0xDDCCBBAA));
1242:                assertEquals(0x11223344, Integer.reverseBytes(0x44332211));
1243:                assertEquals(0x00112233, Integer.reverseBytes(0x33221100));
1244:                assertEquals(0x20000002, Integer.reverseBytes(0x02000020));
1245:            }
1246:
1247:            /**
1248:             * @tests java.lang.Integer#reverse(int)
1249:             */
1250:            public void test_reverseI() {
1251:                assertEquals(-1, Integer.reverse(-1));
1252:                assertEquals(0x80000000, Integer.reverse(1));
1253:            }
1254:
1255:            /**
1256:             * @tests java.lang.Integer#signum(int)
1257:             */
1258:            public void test_signumI() {
1259:                for (int i = -128; i < 0; i++) {
1260:                    assertEquals(-1, Integer.signum(i));
1261:                }
1262:                assertEquals(0, Integer.signum(0));
1263:                for (int i = 1; i <= 127; i++) {
1264:                    assertEquals(1, Integer.signum(i));
1265:                }
1266:            }
1267:        }
w___ww_.__ja_v__a___2s.__c__o___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.