Source Code Cross Referenced for BigIntegerAddTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » tests » java » math » 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.tests.java.math 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Elena Semukhina
019:         * @version $Revision$
020:         */package org.apache.harmony.tests.java.math;
021:
022:        import junit.framework.TestCase;
023:        import java.math.BigInteger;
024:
025:        /**
026:         * Class:  java.math.BigInteger
027:         * Method: add 
028:         */
029:        public class BigIntegerAddTest extends TestCase {
030:            /**
031:             * Add two positive numbers of the same length
032:             */
033:            public void testCase1() {
034:                byte aBytes[] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3 };
035:                byte bBytes[] = { 10, 20, 30, 40, 50, 60, 70, 10, 20, 30 };
036:                int aSign = 1;
037:                int bSign = 1;
038:                byte rBytes[] = { 11, 22, 33, 44, 55, 66, 77, 11, 22, 33 };
039:                BigInteger aNumber = new BigInteger(aSign, aBytes);
040:                BigInteger bNumber = new BigInteger(bSign, bBytes);
041:                BigInteger result = aNumber.add(bNumber);
042:                byte resBytes[] = new byte[rBytes.length];
043:                resBytes = result.toByteArray();
044:                for (int i = 0; i < resBytes.length; i++) {
045:                    assertTrue(resBytes[i] == rBytes[i]);
046:                }
047:                assertEquals("incorrect sign", 1, result.signum());
048:            }
049:
050:            /**
051:             * Add two negative numbers of the same length
052:             */
053:            public void testCase2() {
054:                byte aBytes[] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3 };
055:                byte bBytes[] = { 10, 20, 30, 40, 50, 60, 70, 10, 20, 30 };
056:                int aSign = -1;
057:                int bSign = -1;
058:                byte rBytes[] = { -12, -23, -34, -45, -56, -67, -78, -12, -23,
059:                        -33 };
060:                BigInteger aNumber = new BigInteger(aSign, aBytes);
061:                BigInteger bNumber = new BigInteger(bSign, bBytes);
062:                BigInteger result = aNumber.add(bNumber);
063:                byte resBytes[] = new byte[rBytes.length];
064:                resBytes = result.toByteArray();
065:                for (int i = 0; i < resBytes.length; i++) {
066:                    assertTrue(resBytes[i] == rBytes[i]);
067:                }
068:                assertEquals("incorrect sign", -1, result.signum());
069:            }
070:
071:            /**
072:             * Add two numbers of the same length.
073:             * The first one is positive and the second is negative.
074:             * The first one is greater in absolute value.
075:             */
076:            public void testCase3() {
077:                byte aBytes[] = { 3, 4, 5, 6, 7, 8, 9 };
078:                byte bBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
079:                byte rBytes[] = { 2, 2, 2, 2, 2, 2, 2 };
080:                int aSign = 1;
081:                int bSign = -1;
082:                BigInteger aNumber = new BigInteger(aSign, aBytes);
083:                BigInteger bNumber = new BigInteger(bSign, bBytes);
084:                BigInteger result = aNumber.add(bNumber);
085:                byte resBytes[] = new byte[rBytes.length];
086:                resBytes = result.toByteArray();
087:                for (int i = 0; i < resBytes.length; i++) {
088:                    assertTrue(resBytes[i] == rBytes[i]);
089:                }
090:                assertEquals("incorrect sign", 1, result.signum());
091:            }
092:
093:            /**
094:             * Add two numbers of the same length.
095:             * The first one is negative and the second is positive.
096:             * The first one is greater in absolute value.
097:             */
098:            public void testCase4() {
099:                byte aBytes[] = { 3, 4, 5, 6, 7, 8, 9 };
100:                byte bBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
101:                byte rBytes[] = { -3, -3, -3, -3, -3, -3, -2 };
102:                int aSign = -1;
103:                int bSign = 1;
104:                BigInteger aNumber = new BigInteger(aSign, aBytes);
105:                BigInteger bNumber = new BigInteger(bSign, bBytes);
106:                BigInteger result = aNumber.add(bNumber);
107:                byte resBytes[] = new byte[rBytes.length];
108:                resBytes = result.toByteArray();
109:                for (int i = 0; i < resBytes.length; i++) {
110:                    assertTrue(resBytes[i] == rBytes[i]);
111:                }
112:                assertEquals("incorrect sign", -1, result.signum());
113:            }
114:
115:            /**
116:             * Add two numbers of the same length.
117:             * The first is positive and the second is negative.
118:             * The first is less in absolute value.
119:             */
120:            public void testCase5() {
121:                byte aBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
122:                byte bBytes[] = { 3, 4, 5, 6, 7, 8, 9 };
123:                byte rBytes[] = { -3, -3, -3, -3, -3, -3, -2 };
124:                int aSign = 1;
125:                int bSign = -1;
126:                BigInteger aNumber = new BigInteger(aSign, aBytes);
127:                BigInteger bNumber = new BigInteger(bSign, bBytes);
128:                BigInteger result = aNumber.add(bNumber);
129:                byte resBytes[] = new byte[rBytes.length];
130:                resBytes = result.toByteArray();
131:                for (int i = 0; i < resBytes.length; i++) {
132:                    assertTrue(resBytes[i] == rBytes[i]);
133:                }
134:                assertEquals("incorrect sign", -1, result.signum());
135:            }
136:
137:            /**
138:             * Add two numbers of the same length.
139:             * The first one is negative and the second is positive.
140:             * The first one is less in absolute value.
141:             */
142:            public void testCase6() {
143:                byte aBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
144:                byte bBytes[] = { 3, 4, 5, 6, 7, 8, 9 };
145:                byte rBytes[] = { 2, 2, 2, 2, 2, 2, 2 };
146:                int aSign = -1;
147:                int bSign = 1;
148:                BigInteger aNumber = new BigInteger(aSign, aBytes);
149:                BigInteger bNumber = new BigInteger(bSign, bBytes);
150:                BigInteger result = aNumber.add(bNumber);
151:                byte resBytes[] = new byte[rBytes.length];
152:                resBytes = result.toByteArray();
153:                for (int i = 0; i < resBytes.length; i++) {
154:                    assertTrue(resBytes[i] == rBytes[i]);
155:                }
156:                assertEquals("incorrect sign", 1, result.signum());
157:            }
158:
159:            /**
160:             * Add two positive numbers of different length.
161:             * The first is longer.
162:             */
163:            public void testCase7() {
164:                byte aBytes[] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7 };
165:                byte bBytes[] = { 10, 20, 30, 40, 50, 60, 70, 10, 20, 30 };
166:                int aSign = 1;
167:                int bSign = 1;
168:                byte rBytes[] = { 1, 2, 3, 4, 15, 26, 37, 41, 52, 63, 74, 15,
169:                        26, 37 };
170:                BigInteger aNumber = new BigInteger(aSign, aBytes);
171:                BigInteger bNumber = new BigInteger(bSign, bBytes);
172:                BigInteger result = aNumber.add(bNumber);
173:                byte resBytes[] = new byte[rBytes.length];
174:                resBytes = result.toByteArray();
175:                for (int i = 0; i < resBytes.length; i++) {
176:                    assertTrue(resBytes[i] == rBytes[i]);
177:                }
178:                assertEquals("incorrect sign", 1, result.signum());
179:            }
180:
181:            /**
182:             * Add two positive numbers of different length.
183:             * The second is longer.
184:             */
185:            public void testCase8() {
186:                byte aBytes[] = { 10, 20, 30, 40, 50, 60, 70, 10, 20, 30 };
187:                byte bBytes[] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7 };
188:                byte rBytes[] = { 1, 2, 3, 4, 15, 26, 37, 41, 52, 63, 74, 15,
189:                        26, 37 };
190:                BigInteger aNumber = new BigInteger(aBytes);
191:                BigInteger bNumber = new BigInteger(bBytes);
192:                BigInteger result = aNumber.add(bNumber);
193:                byte resBytes[] = new byte[rBytes.length];
194:                resBytes = result.toByteArray();
195:                for (int i = 0; i < resBytes.length; i++) {
196:                    assertTrue(resBytes[i] == rBytes[i]);
197:                }
198:                assertEquals("incorrect sign", 1, result.signum());
199:            }
200:
201:            /**
202:             * Add two negative numbers of different length.
203:             * The first is longer.
204:             */
205:            public void testCase9() {
206:                byte aBytes[] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7 };
207:                byte bBytes[] = { 10, 20, 30, 40, 50, 60, 70, 10, 20, 30 };
208:                int aSign = -1;
209:                int bSign = -1;
210:                byte rBytes[] = { -2, -3, -4, -5, -16, -27, -38, -42, -53, -64,
211:                        -75, -16, -27, -37 };
212:                BigInteger aNumber = new BigInteger(aSign, aBytes);
213:                BigInteger bNumber = new BigInteger(bSign, bBytes);
214:                BigInteger result = aNumber.add(bNumber);
215:                byte resBytes[] = new byte[rBytes.length];
216:                resBytes = result.toByteArray();
217:                for (int i = 0; i < resBytes.length; i++) {
218:                    assertTrue(resBytes[i] == rBytes[i]);
219:                }
220:                assertEquals("incorrect sign", -1, result.signum());
221:            }
222:
223:            /**
224:             * Add two negative numbers of different length.
225:             * The second is longer.
226:             */
227:            public void testCase10() {
228:                byte aBytes[] = { 10, 20, 30, 40, 50, 60, 70, 10, 20, 30 };
229:                byte bBytes[] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7 };
230:                int aSign = -1;
231:                int bSign = -1;
232:                byte rBytes[] = { -2, -3, -4, -5, -16, -27, -38, -42, -53, -64,
233:                        -75, -16, -27, -37 };
234:                BigInteger aNumber = new BigInteger(aSign, aBytes);
235:                BigInteger bNumber = new BigInteger(bSign, bBytes);
236:                BigInteger result = aNumber.add(bNumber);
237:                byte resBytes[] = new byte[rBytes.length];
238:                resBytes = result.toByteArray();
239:                for (int i = 0; i < resBytes.length; i++) {
240:                    assertTrue(resBytes[i] == rBytes[i]);
241:                }
242:                assertEquals("incorrect sign", -1, result.signum());
243:            }
244:
245:            /**
246:             * Add two numbers of different length and sign.
247:             * The first is positive.
248:             * The first is longer.
249:             */
250:            public void testCase11() {
251:                byte aBytes[] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7 };
252:                byte bBytes[] = { 10, 20, 30, 40, 50, 60, 70, 10, 20, 30 };
253:                int aSign = 1;
254:                int bSign = -1;
255:                byte rBytes[] = { 1, 2, 3, 3, -6, -15, -24, -40, -49, -58, -67,
256:                        -6, -15, -23 };
257:                BigInteger aNumber = new BigInteger(aSign, aBytes);
258:                BigInteger bNumber = new BigInteger(bSign, bBytes);
259:                BigInteger result = aNumber.add(bNumber);
260:                byte resBytes[] = new byte[rBytes.length];
261:                resBytes = result.toByteArray();
262:                for (int i = 0; i < resBytes.length; i++) {
263:                    assertTrue(resBytes[i] == rBytes[i]);
264:                }
265:                assertEquals("incorrect sign", 1, result.signum());
266:            }
267:
268:            /**
269:             * Add two numbers of different length and sign.
270:             * The first is positive.
271:             * The second is longer.
272:             */
273:            public void testCase12() {
274:                byte aBytes[] = { 10, 20, 30, 40, 50, 60, 70, 10, 20, 30 };
275:                byte bBytes[] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7 };
276:                int aSign = 1;
277:                int bSign = -1;
278:                byte rBytes[] = { -2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5,
279:                        14, 23 };
280:                BigInteger aNumber = new BigInteger(aSign, aBytes);
281:                BigInteger bNumber = new BigInteger(bSign, bBytes);
282:                BigInteger result = aNumber.add(bNumber);
283:                byte resBytes[] = new byte[rBytes.length];
284:                resBytes = result.toByteArray();
285:                for (int i = 0; i < resBytes.length; i++) {
286:                    assertTrue(resBytes[i] == rBytes[i]);
287:                }
288:                assertEquals("incorrect sign", -1, result.signum());
289:            }
290:
291:            /**
292:             * Add two numbers of different length and sign.
293:             * The first is negative.
294:             * The first is longer.
295:             */
296:            public void testCase13() {
297:                byte aBytes[] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7 };
298:                byte bBytes[] = { 10, 20, 30, 40, 50, 60, 70, 10, 20, 30 };
299:                int aSign = -1;
300:                int bSign = 1;
301:                byte rBytes[] = { -2, -3, -4, -4, 5, 14, 23, 39, 48, 57, 66, 5,
302:                        14, 23 };
303:                BigInteger aNumber = new BigInteger(aSign, aBytes);
304:                BigInteger bNumber = new BigInteger(bSign, bBytes);
305:                BigInteger result = aNumber.add(bNumber);
306:                byte resBytes[] = new byte[rBytes.length];
307:                resBytes = result.toByteArray();
308:                for (int i = 0; i < resBytes.length; i++) {
309:                    assertTrue(resBytes[i] == rBytes[i]);
310:                }
311:                assertEquals("incorrect sign", -1, result.signum());
312:            }
313:
314:            /**
315:             * Add two numbers of different length and sign.
316:             * The first is negative.
317:             * The second is longer.
318:             */
319:            public void testCase14() {
320:                byte aBytes[] = { 10, 20, 30, 40, 50, 60, 70, 10, 20, 30 };
321:                byte bBytes[] = { 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7 };
322:                int aSign = -1;
323:                int bSign = 1;
324:                byte rBytes[] = { 1, 2, 3, 3, -6, -15, -24, -40, -49, -58, -67,
325:                        -6, -15, -23 };
326:                BigInteger aNumber = new BigInteger(aSign, aBytes);
327:                BigInteger bNumber = new BigInteger(bSign, bBytes);
328:                BigInteger result = aNumber.add(bNumber);
329:                byte resBytes[] = new byte[rBytes.length];
330:                resBytes = result.toByteArray();
331:                for (int i = 0; i < resBytes.length; i++) {
332:                    assertTrue(resBytes[i] == rBytes[i]);
333:                }
334:                assertEquals("incorrect sign", 1, result.signum());
335:            }
336:
337:            /**
338:             * Add two equal numbers of different signs
339:             */
340:            public void testCase15() {
341:                byte aBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
342:                byte bBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
343:                byte rBytes[] = { 0 };
344:                int aSign = -1;
345:                int bSign = 1;
346:                BigInteger aNumber = new BigInteger(aSign, aBytes);
347:                BigInteger bNumber = new BigInteger(bSign, bBytes);
348:                BigInteger result = aNumber.add(bNumber);
349:                byte resBytes[] = new byte[rBytes.length];
350:                for (int i = 0; i < resBytes.length; i++) {
351:                    assertTrue(resBytes[i] == rBytes[i]);
352:                }
353:                assertEquals("incorrect sign", 0, result.signum());
354:            }
355:
356:            /**
357:             * Add zero to a number
358:             */
359:            public void testCase16() {
360:                byte aBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
361:                byte bBytes[] = { 0 };
362:                byte rBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
363:                int aSign = 1;
364:                int bSign = 1;
365:                BigInteger aNumber = new BigInteger(aSign, aBytes);
366:                BigInteger bNumber = new BigInteger(bSign, bBytes);
367:                BigInteger result = aNumber.add(bNumber);
368:                byte resBytes[] = new byte[rBytes.length];
369:                resBytes = result.toByteArray();
370:                for (int i = 0; i < resBytes.length; i++) {
371:                    assertTrue(resBytes[i] == rBytes[i]);
372:                }
373:                assertEquals("incorrect sign", 1, result.signum());
374:            }
375:
376:            /**
377:             * Add a number to zero
378:             */
379:            public void testCase17() {
380:                byte aBytes[] = { 0 };
381:                byte bBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
382:                byte rBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
383:                int aSign = 1;
384:                int bSign = 1;
385:                BigInteger aNumber = new BigInteger(aSign, aBytes);
386:                BigInteger bNumber = new BigInteger(bSign, bBytes);
387:                BigInteger result = aNumber.add(bNumber);
388:                byte resBytes[] = new byte[rBytes.length];
389:                resBytes = result.toByteArray();
390:                for (int i = 0; i < resBytes.length; i++) {
391:                    assertTrue(resBytes[i] == rBytes[i]);
392:                }
393:                assertEquals("incorrect sign", 1, result.signum());
394:            }
395:
396:            /**
397:             * Add zero to zero
398:             */
399:            public void testCase18() {
400:                byte aBytes[] = { 0 };
401:                byte bBytes[] = { 0 };
402:                byte rBytes[] = { 0 };
403:                int aSign = 1;
404:                int bSign = 1;
405:                BigInteger aNumber = new BigInteger(aSign, aBytes);
406:                BigInteger bNumber = new BigInteger(bSign, bBytes);
407:                BigInteger result = aNumber.add(bNumber);
408:                byte resBytes[] = new byte[rBytes.length];
409:                resBytes = result.toByteArray();
410:                for (int i = 0; i < resBytes.length; i++) {
411:                    assertTrue(resBytes[i] == rBytes[i]);
412:                }
413:                assertEquals("incorrect sign", 0, result.signum());
414:            }
415:
416:            /**
417:             * Add ZERO to a number
418:             */
419:            public void testCase19() {
420:                byte aBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
421:                byte rBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
422:                int aSign = 1;
423:                BigInteger aNumber = new BigInteger(aSign, aBytes);
424:                BigInteger bNumber = BigInteger.ZERO;
425:                BigInteger result = aNumber.add(bNumber);
426:                byte resBytes[] = new byte[rBytes.length];
427:                resBytes = result.toByteArray();
428:                for (int i = 0; i < resBytes.length; i++) {
429:                    assertTrue(resBytes[i] == rBytes[i]);
430:                }
431:                assertEquals("incorrect sign", 1, result.signum());
432:            }
433:
434:            /**
435:             * Add a number to zero
436:             */
437:            public void testCase20() {
438:                byte bBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
439:                byte rBytes[] = { 1, 2, 3, 4, 5, 6, 7 };
440:                int bSign = 1;
441:                BigInteger aNumber = BigInteger.ZERO;
442:                BigInteger bNumber = new BigInteger(bSign, bBytes);
443:                BigInteger result = aNumber.add(bNumber);
444:                byte resBytes[] = new byte[rBytes.length];
445:                resBytes = result.toByteArray();
446:                for (int i = 0; i < resBytes.length; i++) {
447:                    assertTrue(resBytes[i] == rBytes[i]);
448:                }
449:                assertEquals("incorrect sign", 1, result.signum());
450:            }
451:
452:            /**
453:             * Add ZERO to ZERO
454:             */
455:            public void testCase21() {
456:                byte rBytes[] = { 0 };
457:                BigInteger aNumber = BigInteger.ZERO;
458:                BigInteger bNumber = BigInteger.ZERO;
459:                BigInteger result = aNumber.add(bNumber);
460:                byte resBytes[] = new byte[rBytes.length];
461:                resBytes = result.toByteArray();
462:                for (int i = 0; i < resBytes.length; i++) {
463:                    assertTrue(resBytes[i] == rBytes[i]);
464:                }
465:                assertEquals("incorrect sign", 0, result.signum());
466:            }
467:
468:            /**
469:             * Add ONE to ONE
470:             */
471:            public void testCase22() {
472:                byte rBytes[] = { 2 };
473:                BigInteger aNumber = BigInteger.ONE;
474:                BigInteger bNumber = BigInteger.ONE;
475:                BigInteger result = aNumber.add(bNumber);
476:                byte resBytes[] = new byte[rBytes.length];
477:                resBytes = result.toByteArray();
478:                for (int i = 0; i < resBytes.length; i++) {
479:                    assertTrue(resBytes[i] == rBytes[i]);
480:                }
481:                assertEquals("incorrect sign", 1, result.signum());
482:            }
483:
484:            /**
485:             * Add two numbers so that carry is 1
486:             */
487:            public void testCase23() {
488:                byte aBytes[] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
489:                        -1, -1, -1 };
490:                byte bBytes[] = { -1, -1, -1, -1, -1, -1, -1, -1 };
491:                int aSign = 1;
492:                int bSign = 1;
493:                byte rBytes[] = { 1, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1,
494:                        -1, -2 };
495:                BigInteger aNumber = new BigInteger(aSign, aBytes);
496:                BigInteger bNumber = new BigInteger(bSign, bBytes);
497:                BigInteger result = aNumber.add(bNumber);
498:                byte resBytes[] = new byte[rBytes.length];
499:                resBytes = result.toByteArray();
500:                for (int i = 0; i < resBytes.length; i++) {
501:                    assertTrue(resBytes[i] == rBytes[i]);
502:                }
503:                assertEquals("incorrect sign", 1, result.signum());
504:            }
505:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.