Home | History | Annotate | Download | only in math
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 /**
     18  * @author Elena Semukhina
     19  * @version $Revision$
     20  */
     21 
     22 package org.apache.harmony.math.tests.java.math;
     23 
     24 import dalvik.annotation.TestTargetClass;
     25 import dalvik.annotation.TestTargets;
     26 import dalvik.annotation.TestLevel;
     27 import dalvik.annotation.TestTargetNew;
     28 
     29 import java.math.BigInteger;
     30 
     31 import junit.framework.TestCase;
     32 @TestTargetClass(BigInteger.class)
     33 /**
     34  * Class:   java.math.BigInteger
     35  * Methods: bitLength, shiftLeft, shiftRight,
     36  * clearBit, flipBit, setBit, testBit
     37  */
     38 public class BigIntegerOperateBitsTest extends TestCase {
     39     /**
     40      * bitCount() of zero.
     41      */
     42     @TestTargetNew(
     43         level = TestLevel.PARTIAL_COMPLETE,
     44         notes = "This is a complete subset of tests for bitCount method.",
     45         method = "bitCount",
     46         args = {}
     47     )
     48     public void testBitCountZero() {
     49         BigInteger aNumber = new BigInteger("0");
     50         assertEquals(0, aNumber.bitCount());
     51     }
     52 
     53     /**
     54      * bitCount() of a negative number.
     55      */
     56     @TestTargetNew(
     57         level = TestLevel.PARTIAL_COMPLETE,
     58         notes = "This is a complete subset of tests for bitCount method.",
     59         method = "bitCount",
     60         args = {}
     61     )
     62     public void testBitCountNeg() {
     63         BigInteger aNumber = new BigInteger("-12378634756382937873487638746283767238657872368748726875");
     64         assertEquals(87, aNumber.bitCount());
     65     }
     66 
     67     /**
     68      * bitCount() of a negative number.
     69      */
     70     @TestTargetNew(
     71         level = TestLevel.PARTIAL_COMPLETE,
     72         notes = "This is a complete subset of tests for bitCount method.",
     73         method = "bitCount",
     74         args = {}
     75     )
     76     public void testBitCountPos() {
     77         BigInteger aNumber = new BigInteger("12378634756343564757582937873487638746283767238657872368748726875");
     78         assertEquals(107, aNumber.bitCount());
     79     }
     80 
     81     /**
     82      * bitLength() of zero.
     83      */
     84     @TestTargetNew(
     85         level = TestLevel.PARTIAL_COMPLETE,
     86         notes = "This is a complete subset of tests for bitLength method.",
     87         method = "bitLength",
     88         args = {}
     89     )
     90     public void testBitLengthZero() {
     91         BigInteger aNumber = new BigInteger("0");
     92         assertEquals(0, aNumber.bitLength());
     93     }
     94 
     95     /**
     96      * bitLength() of a positive number.
     97      */
     98     @TestTargetNew(
     99         level = TestLevel.PARTIAL_COMPLETE,
    100         notes = "This is a complete subset of tests for bitLength method.",
    101         method = "bitLength",
    102         args = {}
    103     )
    104     public void testBitLengthPositive1() {
    105         byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
    106         int aSign = 1;
    107         BigInteger aNumber = new BigInteger(aSign, aBytes);
    108         assertEquals(108, aNumber.bitLength());
    109     }
    110 
    111     /**
    112      * bitLength() of a positive number with the leftmost bit set
    113      */
    114     @TestTargetNew(
    115         level = TestLevel.PARTIAL_COMPLETE,
    116         notes = "This is a complete subset of tests for bitLength method.",
    117         method = "bitLength",
    118         args = {}
    119     )
    120     public void testBitLengthPositive2() {
    121         byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    122         int aSign = 1;
    123         BigInteger aNumber = new BigInteger(aSign, aBytes);
    124         assertEquals(96, aNumber.bitLength());
    125     }
    126 
    127     /**
    128      * bitLength() of a positive number which is a power of 2
    129      */
    130     @TestTargetNew(
    131         level = TestLevel.PARTIAL_COMPLETE,
    132         notes = "This is a complete subset of tests for bitLength method.",
    133         method = "bitLength",
    134         args = {}
    135     )
    136     public void testBitLengthPositive3() {
    137         byte aBytes[] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    138         int aSign = 1;
    139         BigInteger aNumber = new BigInteger(aSign, aBytes);
    140         assertEquals(81, aNumber.bitLength());
    141     }
    142 
    143     /**
    144      * bitLength() of a negative number.
    145      */
    146     @TestTargetNew(
    147         level = TestLevel.PARTIAL_COMPLETE,
    148         notes = "This is a complete subset of tests for bitLength method.",
    149         method = "bitLength",
    150         args = {}
    151     )
    152     public void testBitLengthNegative1() {
    153         byte aBytes[] = {12, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26, 3, 91};
    154         int aSign = -1;
    155         BigInteger aNumber = new BigInteger(aSign, aBytes);
    156         assertEquals(108, aNumber.bitLength());
    157     }
    158 
    159     /**
    160      * bitLength() of a negative number with the leftmost bit set
    161      */
    162     @TestTargetNew(
    163         level = TestLevel.PARTIAL_COMPLETE,
    164         notes = "This is a complete subset of tests for bitLength method.",
    165         method = "bitLength",
    166         args = {}
    167     )
    168     public void testBitLengthNegative2() {
    169         byte aBytes[] = {-128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    170         int aSign = -1;
    171         BigInteger aNumber = new BigInteger(aSign, aBytes);
    172         assertEquals(96, aNumber.bitLength());
    173     }
    174 
    175     /**
    176      * bitLength() of a negative number which is a power of 2
    177      */
    178     @TestTargetNew(
    179         level = TestLevel.PARTIAL_COMPLETE,
    180         notes = "This is a complete subset of tests for bitLength method.",
    181         method = "bitLength",
    182         args = {}
    183     )
    184     public void testBitLengthNegative3() {
    185         byte aBytes[] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    186         int aSign = -1;
    187         BigInteger aNumber = new BigInteger(aSign, aBytes);
    188         assertEquals(80, aNumber.bitLength());
    189     }
    190 
    191     /**
    192      * clearBit(int n) of a negative n
    193      */
    194     @TestTargetNew(
    195         level = TestLevel.PARTIAL_COMPLETE,
    196         notes = "This is a complete subset of tests for clearBit method.",
    197         method = "clearBit",
    198         args = {int.class}
    199     )
    200     public void testClearBitException() {
    201         byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    202         int aSign = 1;
    203         int number = -7;
    204         BigInteger aNumber = new BigInteger(aSign, aBytes);
    205         try {
    206             aNumber.clearBit(number);
    207             fail("ArithmeticException has not been caught");
    208         } catch (ArithmeticException e) {
    209             assertEquals("Improper exception message", "Negative bit address", e.getMessage());
    210         }
    211     }
    212 
    213     /**
    214      * clearBit(int n) outside zero
    215      */
    216     @TestTargetNew(
    217         level = TestLevel.PARTIAL_COMPLETE,
    218         notes = "This is a complete subset of tests for clearBit method.",
    219         method = "clearBit",
    220         args = {int.class}
    221     )
    222     public void testClearBitZero() {
    223         byte aBytes[] = {0};
    224         int aSign = 0;
    225         int number = 0;
    226         byte rBytes[] = {0};
    227         BigInteger aNumber = new BigInteger(aSign, aBytes);
    228         BigInteger result = aNumber.clearBit(number);
    229         byte resBytes[] = new byte[rBytes.length];
    230         resBytes = result.toByteArray();
    231         for(int i = 0; i < resBytes.length; i++) {
    232             assertTrue(resBytes[i] == rBytes[i]);
    233         }
    234         assertEquals("incorrect sign", 0, result.signum());
    235     }
    236 
    237     /**
    238      * clearBit(int n) outside zero
    239      */
    240     @TestTargetNew(
    241         level = TestLevel.PARTIAL_COMPLETE,
    242         notes = "This is a complete subset of tests for clearBit method.",
    243         method = "clearBit",
    244         args = {int.class}
    245     )
    246     public void testClearBitZeroOutside1() {
    247         byte aBytes[] = {0};
    248         int aSign = 0;
    249         int number = 95;
    250         byte rBytes[] = {0};
    251         BigInteger aNumber = new BigInteger(aSign, aBytes);
    252         BigInteger result = aNumber.clearBit(number);
    253         byte resBytes[] = new byte[rBytes.length];
    254         resBytes = result.toByteArray();
    255         for(int i = 0; i < resBytes.length; i++) {
    256             assertTrue(resBytes[i] == rBytes[i]);
    257         }
    258         assertEquals("incorrect sign", 0, result.signum());
    259     }
    260 
    261     /**
    262      * clearBit(int n) inside a negative number
    263      */
    264     @TestTargetNew(
    265         level = TestLevel.PARTIAL_COMPLETE,
    266         notes = "This is a complete subset of tests for clearBit method.",
    267         method = "clearBit",
    268         args = {int.class}
    269     )
    270     public void testClearBitNegativeInside1() {
    271         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    272         int aSign = -1;
    273         int number = 15;
    274         byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, 92, -26};
    275         BigInteger aNumber = new BigInteger(aSign, aBytes);
    276         BigInteger result = aNumber.clearBit(number);
    277         byte resBytes[] = new byte[rBytes.length];
    278         resBytes = result.toByteArray();
    279         for(int i = 0; i < resBytes.length; i++) {
    280             assertTrue(resBytes[i] == rBytes[i]);
    281         }
    282         assertEquals("incorrect sign", -1, result.signum());
    283     }
    284 
    285     /**
    286      * clearBit(int n) inside a negative number
    287      */
    288     @TestTargetNew(
    289         level = TestLevel.PARTIAL_COMPLETE,
    290         notes = "This is a complete subset of tests for clearBit method.",
    291         method = "clearBit",
    292         args = {int.class}
    293     )
    294     public void testClearBitNegativeInside2() {
    295         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    296         int aSign = -1;
    297         int number = 44;
    298         byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -62, -92, -4, 14, -36, -26};
    299         BigInteger aNumber = new BigInteger(aSign, aBytes);
    300         BigInteger result = aNumber.clearBit(number);
    301         byte resBytes[] = new byte[rBytes.length];
    302         resBytes = result.toByteArray();
    303         for(int i = 0; i < resBytes.length; i++) {
    304             assertTrue(resBytes[i] == rBytes[i]);
    305         }
    306         assertEquals("incorrect sign", -1, result.signum());
    307     }
    308 
    309     /**
    310      * clearBit(2) in the negative number with all ones in bit representation
    311      */
    312     @TestTargetNew(
    313         level = TestLevel.PARTIAL_COMPLETE,
    314         notes = "This is a complete subset of tests for clearBit method.",
    315         method = "clearBit",
    316         args = {int.class}
    317     )
    318     public void testClearBitNegativeInside3() {
    319         String as = "-18446744073709551615";
    320         int number = 2;
    321         BigInteger aNumber = new BigInteger(as);
    322         BigInteger result = aNumber.clearBit(number);
    323         assertEquals(as, result.toString());
    324     }
    325 
    326     /**
    327      * clearBit(0) in the negative number of length 1
    328      * with all ones in bit representation.
    329      * the resulting number's length is 2.
    330      */
    331     @TestTargetNew(
    332         level = TestLevel.PARTIAL_COMPLETE,
    333         notes = "This is a complete subset of tests for clearBit method.",
    334         method = "clearBit",
    335         args = {int.class}
    336     )
    337     public void testClearBitNegativeInside4() {
    338         String as = "-4294967295";
    339         String res = "-4294967296";
    340         int number = 0;
    341         BigInteger aNumber = new BigInteger(as);
    342         BigInteger result = aNumber.clearBit(number);
    343         assertEquals(res, result.toString());
    344     }
    345 
    346     /**
    347      * clearBit(0) in the negative number of length 2
    348      * with all ones in bit representation.
    349      * the resulting number's length is 3.
    350      */
    351     @TestTargetNew(
    352         level = TestLevel.PARTIAL_COMPLETE,
    353         notes = "This is a complete subset of tests for clearBit method.",
    354         method = "clearBit",
    355         args = {int.class}
    356     )
    357     public void testClearBitNegativeInside5() {
    358         String as = "-18446744073709551615";
    359         String res = "-18446744073709551616";
    360         int number = 0;
    361         BigInteger aNumber = new BigInteger(as);
    362         BigInteger result = aNumber.clearBit(number);
    363         assertEquals(res, result.toString());
    364     }
    365 
    366     /**
    367      * clearBit(int n) outside a negative number
    368      */
    369     @TestTargetNew(
    370         level = TestLevel.PARTIAL_COMPLETE,
    371         notes = "This is a complete subset of tests for clearBit method.",
    372         method = "clearBit",
    373         args = {int.class}
    374     )
    375     public void testClearBitNegativeOutside1() {
    376         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    377         int aSign = -1;
    378         int number = 150;
    379         byte rBytes[] = {-65, -1, -1, -1, -1, -1, -2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
    380         BigInteger aNumber = new BigInteger(aSign, aBytes);
    381         BigInteger result = aNumber.clearBit(number);
    382         byte resBytes[] = new byte[rBytes.length];
    383         resBytes = result.toByteArray();
    384         for(int i = 0; i < resBytes.length; i++) {
    385             assertTrue(resBytes[i] == rBytes[i]);
    386         }
    387         assertEquals("incorrect sign", -1, result.signum());
    388     }
    389 
    390     /**
    391      * clearBit(int n) outside a negative number
    392      */
    393     @TestTargetNew(
    394         level = TestLevel.PARTIAL_COMPLETE,
    395         notes = "This is a complete subset of tests for clearBit method.",
    396         method = "clearBit",
    397         args = {int.class}
    398     )
    399     public void testClearBitNegativeOutside2() {
    400         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    401         int aSign = -1;
    402         int number = 165;
    403         byte rBytes[] = {-33, -1, -1, -1, -1, -1, -1, -1, -2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
    404         BigInteger aNumber = new BigInteger(aSign, aBytes);
    405         BigInteger result = aNumber.clearBit(number);
    406         byte resBytes[] = new byte[rBytes.length];
    407         resBytes = result.toByteArray();
    408         for(int i = 0; i < resBytes.length; i++) {
    409             assertTrue(resBytes[i] == rBytes[i]);
    410         }
    411         assertEquals("incorrect sign", -1, result.signum());
    412     }
    413 
    414     /**
    415      * clearBit(int n) inside a positive number
    416      */
    417     @TestTargetNew(
    418         level = TestLevel.PARTIAL_COMPLETE,
    419         notes = "This is a complete subset of tests for clearBit method.",
    420         method = "clearBit",
    421         args = {int.class}
    422     )
    423     public void testClearBitPositiveInside1() {
    424         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    425         int aSign = 1;
    426         int number = 20;
    427         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -31, 35, 26};
    428         BigInteger aNumber = new BigInteger(aSign, aBytes);
    429         BigInteger result = aNumber.clearBit(number);
    430         byte resBytes[] = new byte[rBytes.length];
    431         resBytes = result.toByteArray();
    432         for(int i = 0; i < resBytes.length; i++) {
    433             assertTrue(resBytes[i] == rBytes[i]);
    434         }
    435         assertEquals("incorrect sign", 1, result.signum());
    436     }
    437 
    438     /**
    439      * clearBit(int n) inside a positive number
    440      */
    441     @TestTargetNew(
    442         level = TestLevel.PARTIAL_COMPLETE,
    443         notes = "This is a complete subset of tests for clearBit method.",
    444         method = "clearBit",
    445         args = {int.class}
    446     )
    447     public void testClearBitPositiveInside2() {
    448         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    449         int aSign = 1;
    450         int number = 17;
    451         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    452         BigInteger aNumber = new BigInteger(aSign, aBytes);
    453         BigInteger result = aNumber.clearBit(number);
    454         byte resBytes[] = new byte[rBytes.length];
    455         resBytes = result.toByteArray();
    456         for(int i = 0; i < resBytes.length; i++) {
    457             assertTrue(resBytes[i] == rBytes[i]);
    458         }
    459         assertEquals("incorrect sign", 1, result.signum());
    460     }
    461 
    462     /**
    463      * clearBit(int n) inside a positive number
    464      */
    465     @TestTargetNew(
    466         level = TestLevel.PARTIAL_COMPLETE,
    467         notes = "This is a complete subset of tests for clearBit method.",
    468         method = "clearBit",
    469         args = {int.class}
    470     )
    471     public void testClearBitPositiveInside3() {
    472         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    473         int aSign = 1;
    474         int number = 45;
    475         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 13, 91, 3, -15, 35, 26};
    476         BigInteger aNumber = new BigInteger(aSign, aBytes);
    477         BigInteger result = aNumber.clearBit(number);
    478         byte resBytes[] = new byte[rBytes.length];
    479         resBytes = result.toByteArray();
    480         for(int i = 0; i < resBytes.length; i++) {
    481             assertTrue(resBytes[i] == rBytes[i]);
    482         }
    483         assertEquals("incorrect sign", 1, result.signum());
    484     }
    485 
    486     /**
    487      * clearBit(int n) inside a positive number
    488      */
    489     @TestTargetNew(
    490         level = TestLevel.PARTIAL_COMPLETE,
    491         notes = "This is a complete subset of tests for clearBit method.",
    492         method = "clearBit",
    493         args = {int.class}
    494     )
    495     public void testClearBitPositiveInside4 () {
    496         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    497         int aSign = 1;
    498         int number = 50;
    499         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    500         BigInteger aNumber = new BigInteger(aSign, aBytes);
    501         BigInteger result = aNumber.clearBit(number);
    502         byte resBytes[] = new byte[rBytes.length];
    503         resBytes = result.toByteArray();
    504         for(int i = 0; i < resBytes.length; i++) {
    505             assertTrue(resBytes[i] == rBytes[i]);
    506         }
    507         assertEquals("incorrect sign", 1, result.signum());
    508     }
    509 
    510     /**
    511      * clearBit(int n) inside a positive number
    512      */
    513     @TestTargetNew(
    514         level = TestLevel.PARTIAL_COMPLETE,
    515         notes = "This is a complete subset of tests for clearBit method.",
    516         method = "clearBit",
    517         args = {int.class}
    518     )
    519     public void testClearBitPositiveInside5 () {
    520         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    521         int aSign = 1;
    522         int number = 63;
    523         byte rBytes[] = {1, -128, 56, 100, -2, 52, 89, 45, 91, 3, -15, 35, 26};
    524         BigInteger aNumber = new BigInteger(aSign, aBytes);
    525         BigInteger result = aNumber.clearBit(number);
    526         byte resBytes[] = new byte[rBytes.length];
    527         resBytes = result.toByteArray();
    528         for(int i = 0; i < resBytes.length; i++) {
    529             assertTrue(resBytes[i] == rBytes[i]);
    530         }
    531         assertEquals("incorrect sign", 1, result.signum());
    532     }
    533 
    534     /**
    535      * clearBit(int n) outside a positive number
    536      */
    537     @TestTargetNew(
    538         level = TestLevel.PARTIAL_COMPLETE,
    539         notes = "This is a complete subset of tests for clearBit method.",
    540         method = "clearBit",
    541         args = {int.class}
    542     )
    543     public void testClearBitPositiveOutside1() {
    544         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    545         int aSign = 1;
    546         int number = 150;
    547         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    548         BigInteger aNumber = new BigInteger(aSign, aBytes);
    549         BigInteger result = aNumber.clearBit(number);
    550         byte resBytes[] = new byte[rBytes.length];
    551         resBytes = result.toByteArray();
    552         for(int i = 0; i < resBytes.length; i++) {
    553             assertTrue(resBytes[i] == rBytes[i]);
    554         }
    555         assertEquals("incorrect sign", 1, result.signum());
    556     }
    557 
    558     /**
    559      * clearBit(int n) outside a positive number
    560      */
    561     @TestTargetNew(
    562         level = TestLevel.PARTIAL_COMPLETE,
    563         notes = "This is a complete subset of tests for clearBit method.",
    564         method = "clearBit",
    565         args = {int.class}
    566     )
    567     public void testClearBitPositiveOutside2() {
    568         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    569         int aSign = 1;
    570         int number = 191;
    571         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    572         BigInteger aNumber = new BigInteger(aSign, aBytes);
    573         BigInteger result = aNumber.clearBit(number);
    574         byte resBytes[] = new byte[rBytes.length];
    575         resBytes = result.toByteArray();
    576         for(int i = 0; i < resBytes.length; i++) {
    577             assertTrue(resBytes[i] == rBytes[i]);
    578         }
    579         assertEquals("incorrect sign", 1, result.signum());
    580     }
    581 
    582     /**
    583      * clearBit(int n) the leftmost bit in a negative number
    584      */
    585     @TestTargetNew(
    586         level = TestLevel.PARTIAL_COMPLETE,
    587         notes = "This is a complete subset of tests for clearBit method.",
    588         method = "clearBit",
    589         args = {int.class}
    590     )
    591     public void testClearBitTopNegative() {
    592         byte aBytes[] = {1, -128, 56, 100, -15, 35, 26};
    593         int aSign = -1;
    594         int number = 63;
    595         byte rBytes[] = {-1, 127, -2, 127, -57, -101, 14, -36, -26};
    596         BigInteger aNumber = new BigInteger(aSign, aBytes);
    597         BigInteger result = aNumber.clearBit(number);
    598         byte resBytes[] = new byte[rBytes.length];
    599         resBytes = result.toByteArray();
    600         for(int i = 0; i < resBytes.length; i++) {
    601             assertTrue(resBytes[i] == rBytes[i]);
    602         }
    603         assertEquals("incorrect sign", -1, result.signum());
    604     }
    605 
    606     /**
    607      * flipBit(int n) of a negative n
    608      */
    609     @TestTargetNew(
    610         level = TestLevel.PARTIAL_COMPLETE,
    611         notes = "This is a complete subset of tests for flipBit method.",
    612         method = "flipBit",
    613         args = {int.class}
    614     )
    615     public void testFlipBitException() {
    616         byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    617         int aSign = 1;
    618         int number = -7;
    619         BigInteger aNumber = new BigInteger(aSign, aBytes);
    620         try {
    621             aNumber.flipBit(number);
    622             fail("ArithmeticException has not been caught");
    623         } catch (ArithmeticException e) {
    624             assertEquals("Improper exception message", "Negative bit address", e.getMessage());
    625         }
    626     }
    627 
    628     /**
    629      * flipBit(int n) zero
    630      */
    631     @TestTargetNew(
    632         level = TestLevel.PARTIAL_COMPLETE,
    633         notes = "This is a complete subset of tests for flipBit method.",
    634         method = "flipBit",
    635         args = {int.class}
    636     )
    637     public void testFlipBitZero() {
    638         byte aBytes[] = {0};
    639         int aSign = 0;
    640         int number = 0;
    641         byte rBytes[] = {1};
    642         BigInteger aNumber = new BigInteger(aSign, aBytes);
    643         BigInteger result = aNumber.flipBit(number);
    644         byte resBytes[] = new byte[rBytes.length];
    645         resBytes = result.toByteArray();
    646         for(int i = 0; i < resBytes.length; i++) {
    647             assertTrue(resBytes[i] == rBytes[i]);
    648         }
    649         assertEquals("incorrect sign", 1, result.signum());
    650     }
    651 
    652     /**
    653      * flipBit(int n) outside zero
    654      */
    655     @TestTargetNew(
    656         level = TestLevel.PARTIAL_COMPLETE,
    657         notes = "This is a complete subset of tests for flipBit method.",
    658         method = "flipBit",
    659         args = {int.class}
    660     )
    661     public void testFlipBitZeroOutside1() {
    662         byte aBytes[] = {0};
    663         int aSign = 0;
    664         int number = 62;
    665         byte rBytes[] = {64, 0, 0, 0, 0, 0, 0, 0};
    666         BigInteger aNumber = new BigInteger(aSign, aBytes);
    667         BigInteger result = aNumber.flipBit(number);
    668         byte resBytes[] = new byte[rBytes.length];
    669         resBytes = result.toByteArray();
    670         for(int i = 0; i < resBytes.length; i++) {
    671             assertTrue("incorrect value", resBytes[i] == rBytes[i]);
    672         }
    673         assertEquals("incorrect sign", 1, result.signum());
    674     }
    675 
    676     /**
    677      * flipBit(int n) outside zero
    678      */
    679     @TestTargetNew(
    680         level = TestLevel.PARTIAL_COMPLETE,
    681         notes = "This is a complete subset of tests for flipBit method.",
    682         method = "flipBit",
    683         args = {int.class}
    684     )
    685     public void testFlipBitZeroOutside2() {
    686         byte aBytes[] = {0};
    687         int aSign = 0;
    688         int number = 63;
    689         byte rBytes[] = {0, -128, 0, 0, 0, 0, 0, 0, 0};
    690         BigInteger aNumber = new BigInteger(aSign, aBytes);
    691         BigInteger result = aNumber.flipBit(number);
    692         byte resBytes[] = new byte[rBytes.length];
    693         resBytes = result.toByteArray();
    694         for(int i = 0; i < resBytes.length; i++) {
    695             assertTrue("incorrect value", resBytes[i] == rBytes[i]);
    696         }
    697         assertEquals("incorrect sign", 1, result.signum());
    698     }
    699 
    700     /**
    701      * flipBit(int n) the leftmost bit in a negative number
    702      */
    703     @TestTargetNew(
    704         level = TestLevel.PARTIAL_COMPLETE,
    705         notes = "This is a complete subset of tests for flipBit method.",
    706         method = "flipBit",
    707         args = {int.class}
    708     )
    709     public void testFlipBitLeftmostNegative() {
    710         byte aBytes[] = {1, -128, 56, 100, -15, 35, 26};
    711         int aSign = -1;
    712         int number = 48;
    713         byte rBytes[] = {-1, 127, -57, -101, 14, -36, -26, 49};
    714         BigInteger aNumber = new BigInteger(aSign, aBytes);
    715         BigInteger result = aNumber.flipBit(number);
    716         byte resBytes[] = new byte[rBytes.length];
    717         resBytes = result.toByteArray();
    718         for(int i = 0; i < resBytes.length; i++) {
    719             assertTrue(resBytes[i] == rBytes[i]);
    720         }
    721         assertEquals("incorrect sign", -1, result.signum());
    722     }
    723 
    724     /**
    725      * flipBit(int n) the leftmost bit in a positive number
    726      */
    727     @TestTargetNew(
    728         level = TestLevel.PARTIAL_COMPLETE,
    729         notes = "This is a complete subset of tests for flipBit method.",
    730         method = "flipBit",
    731         args = {int.class}
    732     )
    733     public void testFlipBitLeftmostPositive() {
    734         byte aBytes[] = {1, -128, 56, 100, -15, 35, 26};
    735         int aSign = 1;
    736         int number = 48;
    737         byte rBytes[] = {0, -128, 56, 100, -15, 35, 26};
    738         BigInteger aNumber = new BigInteger(aSign, aBytes);
    739         BigInteger result = aNumber.flipBit(number);
    740         byte resBytes[] = new byte[rBytes.length];
    741         resBytes = result.toByteArray();
    742         for(int i = 0; i < resBytes.length; i++) {
    743             assertTrue(resBytes[i] == rBytes[i]);
    744         }
    745         assertEquals("incorrect sign", 1, result.signum());
    746     }
    747 
    748     /**
    749      * flipBit(int n) inside a negative number
    750      */
    751     @TestTargetNew(
    752         level = TestLevel.PARTIAL_COMPLETE,
    753         notes = "This is a complete subset of tests for flipBit method.",
    754         method = "flipBit",
    755         args = {int.class}
    756     )
    757     public void testFlipBitNegativeInside1() {
    758         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    759         int aSign = -1;
    760         int number = 15;
    761         byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, 92, -26};
    762         BigInteger aNumber = new BigInteger(aSign, aBytes);
    763         BigInteger result = aNumber.flipBit(number);
    764         byte resBytes[] = new byte[rBytes.length];
    765         resBytes = result.toByteArray();
    766         for(int i = 0; i < resBytes.length; i++) {
    767             assertTrue(resBytes[i] == rBytes[i]);
    768         }
    769         assertEquals("incorrect sign", -1, result.signum());
    770     }
    771 
    772     /**
    773      * flipBit(int n) inside a negative number
    774      */
    775     @TestTargetNew(
    776         level = TestLevel.PARTIAL_COMPLETE,
    777         notes = "This is a complete subset of tests for flipBit method.",
    778         method = "flipBit",
    779         args = {int.class}
    780     )
    781     public void testFlipBitNegativeInside2() {
    782         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    783         int aSign = -1;
    784         int number = 45;
    785         byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -14, -92, -4, 14, -36, -26};
    786         BigInteger aNumber = new BigInteger(aSign, aBytes);
    787         BigInteger result = aNumber.flipBit(number);
    788         byte resBytes[] = new byte[rBytes.length];
    789         resBytes = result.toByteArray();
    790         for(int i = 0; i < resBytes.length; i++) {
    791             assertTrue(resBytes[i] == rBytes[i]);
    792         }
    793         assertEquals("incorrect sign", -1, result.signum());
    794     }
    795 
    796     /**
    797      * flipBit(int n) inside a negative number with all ones in bit representation
    798      */
    799     @TestTargetNew(
    800         level = TestLevel.PARTIAL_COMPLETE,
    801         notes = "This is a complete subset of tests for flipBit method.",
    802         method = "flipBit",
    803         args = {int.class}
    804     )
    805     public void testFlipBitNegativeInside3() {
    806         String as = "-18446744073709551615";
    807         String res = "-18446744073709551611";
    808         int number = 2;
    809         BigInteger aNumber = new BigInteger(as);
    810         BigInteger result = aNumber.flipBit(number);
    811         assertEquals(res, result.toString());
    812     }
    813 
    814     /**
    815      * flipBit(0) in the negative number of length 1
    816      * with all ones in bit representation.
    817      * the resulting number's length is 2.
    818      */
    819     @TestTargetNew(
    820         level = TestLevel.PARTIAL_COMPLETE,
    821         notes = "This is a complete subset of tests for flipBit method.",
    822         method = "flipBit",
    823         args = {int.class}
    824     )
    825     public void testFlipBitNegativeInside4() {
    826         String as = "-4294967295";
    827         String res = "-4294967296";
    828         int number = 0;
    829         BigInteger aNumber = new BigInteger(as);
    830         BigInteger result = aNumber.flipBit(number);
    831         assertEquals(res, result.toString());
    832     }
    833 
    834     /**
    835      * flipBit(0) in the negative number of length 2
    836      * with all ones in bit representation.
    837      * the resulting number's length is 3.
    838      */
    839     @TestTargetNew(
    840         level = TestLevel.PARTIAL_COMPLETE,
    841         notes = "This is a complete subset of tests for flipBit method.",
    842         method = "flipBit",
    843         args = {int.class}
    844     )
    845     public void testFlipBitNegativeInside5() {
    846         String as = "-18446744073709551615";
    847         String res = "-18446744073709551616";
    848         int number = 0;
    849         BigInteger aNumber = new BigInteger(as);
    850         BigInteger result = aNumber.flipBit(number);
    851         assertEquals(res, result.toString());
    852     }
    853 
    854     /**
    855      * flipBit(int n) outside a negative number
    856      */
    857     @TestTargetNew(
    858         level = TestLevel.PARTIAL_COMPLETE,
    859         notes = "This is a complete subset of tests for flipBit method.",
    860         method = "flipBit",
    861         args = {int.class}
    862     )
    863     public void testFlipBitNegativeOutside1() {
    864         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    865         int aSign = -1;
    866         int number = 150;
    867         byte rBytes[] = {-65, -1, -1, -1, -1, -1, -2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
    868         BigInteger aNumber = new BigInteger(aSign, aBytes);
    869         BigInteger result = aNumber.flipBit(number);
    870         byte resBytes[] = new byte[rBytes.length];
    871         resBytes = result.toByteArray();
    872         for(int i = 0; i < resBytes.length; i++) {
    873             assertTrue(resBytes[i] == rBytes[i]);
    874         }
    875         assertEquals("incorrect sign", -1, result.signum());
    876     }
    877 
    878     /**
    879      * flipBit(int n) outside a negative number
    880      */
    881     @TestTargetNew(
    882         level = TestLevel.PARTIAL_COMPLETE,
    883         notes = "This is a complete subset of tests for flipBit method.",
    884         method = "flipBit",
    885         args = {int.class}
    886     )
    887     public void testFlipBitNegativeOutside2() {
    888         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    889         int aSign = -1;
    890         int number = 191;
    891         byte rBytes[] = {-1, 127, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
    892         BigInteger aNumber = new BigInteger(aSign, aBytes);
    893         BigInteger result = aNumber.flipBit(number);
    894         byte resBytes[] = new byte[rBytes.length];
    895         resBytes = result.toByteArray();
    896         for(int i = 0; i < resBytes.length; i++) {
    897             assertTrue(resBytes[i] == rBytes[i]);
    898         }
    899         assertEquals("incorrect sign", -1, result.signum());
    900     }
    901 
    902     /**
    903      * flipBit(int n) inside a positive number
    904      */
    905     @TestTargetNew(
    906         level = TestLevel.PARTIAL_COMPLETE,
    907         notes = "This is a complete subset of tests for flipBit method.",
    908         method = "flipBit",
    909         args = {int.class}
    910     )
    911     public void testFlipBitPositiveInside1() {
    912         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    913         int aSign = 1;
    914         int number = 15;
    915         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, -93, 26};
    916         BigInteger aNumber = new BigInteger(aSign, aBytes);
    917         BigInteger result = aNumber.flipBit(number);
    918         byte resBytes[] = new byte[rBytes.length];
    919         resBytes = result.toByteArray();
    920         for(int i = 0; i < resBytes.length; i++) {
    921             assertTrue(resBytes[i] == rBytes[i]);
    922         }
    923         assertEquals("incorrect sign", 1, result.signum());
    924     }
    925 
    926     /**
    927      * flipBit(int n) inside a positive number
    928      */
    929     @TestTargetNew(
    930         level = TestLevel.PARTIAL_COMPLETE,
    931         notes = "This is a complete subset of tests for flipBit method.",
    932         method = "flipBit",
    933         args = {int.class}
    934     )
    935     public void testFlipBitPositiveInside2() {
    936         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    937         int aSign = 1;
    938         int number = 45;
    939         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 13, 91, 3, -15, 35, 26};
    940         BigInteger aNumber = new BigInteger(aSign, aBytes);
    941         BigInteger result = aNumber.flipBit(number);
    942         byte resBytes[] = new byte[rBytes.length];
    943         resBytes = result.toByteArray();
    944         for(int i = 0; i < resBytes.length; i++) {
    945             assertTrue(resBytes[i] == rBytes[i]);
    946         }
    947         assertEquals("incorrect sign", 1, result.signum());
    948     }
    949 
    950     /**
    951      * flipBit(int n) outside a positive number
    952      */
    953     @TestTargetNew(
    954         level = TestLevel.PARTIAL_COMPLETE,
    955         notes = "This is a complete subset of tests for flipBit method.",
    956         method = "flipBit",
    957         args = {int.class}
    958     )
    959     public void testFlipBitPositiveOutside1() {
    960         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    961         int aSign = 1;
    962         int number = 150;
    963         byte rBytes[] = {64, 0, 0, 0, 0, 0, 1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    964         BigInteger aNumber = new BigInteger(aSign, aBytes);
    965         BigInteger result = aNumber.flipBit(number);
    966         byte resBytes[] = new byte[rBytes.length];
    967         resBytes = result.toByteArray();
    968         for(int i = 0; i < resBytes.length; i++) {
    969             assertTrue(resBytes[i] == rBytes[i]);
    970         }
    971         assertEquals("incorrect sign", 1, result.signum());
    972     }
    973 
    974     /**
    975      * flipBit(int n) outside a positive number
    976      */
    977     @TestTargetNew(
    978         level = TestLevel.PARTIAL_COMPLETE,
    979         notes = "This is a complete subset of tests for flipBit method.",
    980         method = "flipBit",
    981         args = {int.class}
    982     )
    983     public void testFlipBitPositiveOutside2() {
    984         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    985         int aSign = 1;
    986         int number = 191;
    987         byte rBytes[] = {0, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
    988         BigInteger aNumber = new BigInteger(aSign, aBytes);
    989         BigInteger result = aNumber.flipBit(number);
    990         byte resBytes[] = new byte[rBytes.length];
    991         resBytes = result.toByteArray();
    992         for(int i = 0; i < resBytes.length; i++) {
    993             assertTrue(resBytes[i] == rBytes[i]);
    994         }
    995         assertEquals("incorrect sign", 1, result.signum());
    996     }
    997 
    998     /**
    999      * setBit(int n) of a negative n
   1000      */
   1001     @TestTargetNew(
   1002         level = TestLevel.PARTIAL_COMPLETE,
   1003         notes = "This is a complete subset of tests for setBit method.",
   1004         method = "setBit",
   1005         args = {int.class}
   1006     )
   1007     public void testSetBitException() {
   1008         byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1009         int aSign = 1;
   1010         int number = -7;
   1011         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1012         try {
   1013             aNumber.setBit(number);
   1014             fail("ArithmeticException has not been caught");
   1015         } catch (ArithmeticException e) {
   1016             assertEquals("Improper exception message", "Negative bit address", e.getMessage());
   1017         }
   1018     }
   1019 
   1020     /**
   1021      * setBit(int n) outside zero
   1022      */
   1023     @TestTargetNew(
   1024         level = TestLevel.PARTIAL_COMPLETE,
   1025         notes = "This is a complete subset of tests for setBit method.",
   1026         method = "setBit",
   1027         args = {int.class}
   1028     )
   1029     public void testSetBitZero() {
   1030         byte aBytes[] = {0};
   1031         int aSign = 0;
   1032         int number = 0;
   1033         byte rBytes[] = {1};
   1034         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1035         BigInteger result = aNumber.setBit(number);
   1036         byte resBytes[] = new byte[rBytes.length];
   1037         resBytes = result.toByteArray();
   1038         for(int i = 0; i < resBytes.length; i++) {
   1039             assertTrue(resBytes[i] == rBytes[i]);
   1040         }
   1041         assertEquals("incorrect sign", 1, result.signum());
   1042     }
   1043 
   1044     /**
   1045      * setBit(int n) outside zero
   1046      */
   1047     @TestTargetNew(
   1048         level = TestLevel.PARTIAL_COMPLETE,
   1049         notes = "This is a complete subset of tests for setBit method.",
   1050         method = "setBit",
   1051         args = {int.class}
   1052     )
   1053     public void testSetBitZeroOutside1() {
   1054         byte aBytes[] = {0};
   1055         int aSign = 0;
   1056         int number = 95;
   1057         byte rBytes[] = {0, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
   1058         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1059         BigInteger result = aNumber.setBit(number);
   1060         byte resBytes[] = new byte[rBytes.length];
   1061         resBytes = result.toByteArray();
   1062         for(int i = 0; i < resBytes.length; i++) {
   1063             assertTrue(resBytes[i] == rBytes[i]);
   1064         }
   1065         assertEquals("incorrect sign", 1, result.signum());
   1066     }
   1067 
   1068     /**
   1069      * setBit(int n) inside a positive number
   1070      */
   1071     @TestTargetNew(
   1072         level = TestLevel.PARTIAL_COMPLETE,
   1073         notes = "This is a complete subset of tests for setBit method.",
   1074         method = "setBit",
   1075         args = {int.class}
   1076     )
   1077     public void testSetBitPositiveInside1() {
   1078         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1079         int aSign = 1;
   1080         int number = 20;
   1081         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1082         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1083         BigInteger result = aNumber.setBit(number);
   1084         byte resBytes[] = new byte[rBytes.length];
   1085         resBytes = result.toByteArray();
   1086         for(int i = 0; i < resBytes.length; i++) {
   1087             assertTrue(resBytes[i] == rBytes[i]);
   1088         }
   1089         assertEquals("incorrect sign", 1, result.signum());
   1090     }
   1091 
   1092     /**
   1093      * setBit(int n) inside a positive number
   1094      */
   1095     @TestTargetNew(
   1096         level = TestLevel.PARTIAL_COMPLETE,
   1097         notes = "This is a complete subset of tests for setBit method.",
   1098         method = "setBit",
   1099         args = {int.class}
   1100     )
   1101     public void testSetBitPositiveInside2() {
   1102         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1103         int aSign = 1;
   1104         int number = 17;
   1105         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -13, 35, 26};
   1106         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1107         BigInteger result = aNumber.setBit(number);
   1108         byte resBytes[] = new byte[rBytes.length];
   1109         resBytes = result.toByteArray();
   1110         for(int i = 0; i < resBytes.length; i++) {
   1111             assertTrue(resBytes[i] == rBytes[i]);
   1112         }
   1113         assertEquals("incorrect sign", 1, result.signum());
   1114     }
   1115 
   1116     /**
   1117      * setBit(int n) inside a positive number
   1118      */
   1119     @TestTargetNew(
   1120         level = TestLevel.PARTIAL_COMPLETE,
   1121         notes = "This is a complete subset of tests for setBit method.",
   1122         method = "setBit",
   1123         args = {int.class}
   1124     )
   1125     public void testSetBitPositiveInside3() {
   1126         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1127         int aSign = 1;
   1128         int number = 45;
   1129         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1130         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1131         BigInteger result = aNumber.setBit(number);
   1132         byte resBytes[] = new byte[rBytes.length];
   1133         resBytes = result.toByteArray();
   1134         for(int i = 0; i < resBytes.length; i++) {
   1135             assertTrue(resBytes[i] == rBytes[i]);
   1136         }
   1137         assertEquals("incorrect sign", 1, result.signum());
   1138     }
   1139 
   1140     /**
   1141      * setBit(int n) inside a positive number
   1142      */
   1143     @TestTargetNew(
   1144         level = TestLevel.PARTIAL_COMPLETE,
   1145         notes = "This is a complete subset of tests for setBit method.",
   1146         method = "setBit",
   1147         args = {int.class}
   1148     )
   1149     public void testSetBitPositiveInside4 () {
   1150         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1151         int aSign = 1;
   1152         int number = 50;
   1153         byte rBytes[] = {1, -128, 56, 100, -2, -76, 93, 45, 91, 3, -15, 35, 26};
   1154         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1155         BigInteger result = aNumber.setBit(number);
   1156         byte resBytes[] = new byte[rBytes.length];
   1157         resBytes = result.toByteArray();
   1158         for(int i = 0; i < resBytes.length; i++) {
   1159             assertTrue(resBytes[i] == rBytes[i]);
   1160         }
   1161         assertEquals("incorrect sign", 1, result.signum());
   1162     }
   1163 
   1164     /**
   1165      * setBit(int n) outside a positive number
   1166      */
   1167     @TestTargetNew(
   1168         level = TestLevel.PARTIAL_COMPLETE,
   1169         notes = "This is a complete subset of tests for setBit method.",
   1170         method = "setBit",
   1171         args = {int.class}
   1172     )
   1173     public void testSetBitPositiveOutside1() {
   1174         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1175         int aSign = 1;
   1176         int number = 150;
   1177         byte rBytes[] = {64, 0, 0, 0, 0, 0, 1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1178         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1179         BigInteger result = aNumber.setBit(number);
   1180         byte resBytes[] = new byte[rBytes.length];
   1181         resBytes = result.toByteArray();
   1182         for(int i = 0; i < resBytes.length; i++) {
   1183             assertTrue(resBytes[i] == rBytes[i]);
   1184         }
   1185         assertEquals("incorrect sign", 1, result.signum());
   1186     }
   1187 
   1188     /**
   1189      * setBit(int n) outside a positive number
   1190      */
   1191     @TestTargetNew(
   1192         level = TestLevel.PARTIAL_COMPLETE,
   1193         notes = "This is a complete subset of tests for setBit method.",
   1194         method = "setBit",
   1195         args = {int.class}
   1196     )
   1197     public void testSetBitPositiveOutside2() {
   1198         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1199         int aSign = 1;
   1200         int number = 223;
   1201         byte rBytes[] = {0, -128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1202         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1203         BigInteger result = aNumber.setBit(number);
   1204         byte resBytes[] = new byte[rBytes.length];
   1205         resBytes = result.toByteArray();
   1206         for(int i = 0; i < resBytes.length; i++) {
   1207             assertTrue(resBytes[i] == rBytes[i]);
   1208         }
   1209         assertEquals("incorrect sign", 1, result.signum());
   1210     }
   1211 
   1212     /**
   1213      * setBit(int n) the leftmost bit in a positive number
   1214      */
   1215     @TestTargetNew(
   1216         level = TestLevel.PARTIAL_COMPLETE,
   1217         notes = "This is a complete subset of tests for setBit method.",
   1218         method = "setBit",
   1219         args = {int.class}
   1220     )
   1221     public void testSetBitTopPositive() {
   1222         byte aBytes[] = {1, -128, 56, 100, -15, 35, 26};
   1223         int aSign = 1;
   1224         int number = 63;
   1225         byte rBytes[] = {0, -128, 1, -128, 56, 100, -15, 35, 26};
   1226         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1227         BigInteger result = aNumber.setBit(number);
   1228         byte resBytes[] = new byte[rBytes.length];
   1229         resBytes = result.toByteArray();
   1230         for(int i = 0; i < resBytes.length; i++) {
   1231             assertTrue(resBytes[i] == rBytes[i]);
   1232         }
   1233         assertEquals("incorrect sign", 1, result.signum());
   1234     }
   1235 
   1236     /**
   1237      * setBit(int n) the leftmost bit in a negative number
   1238      */
   1239     @TestTargetNew(
   1240         level = TestLevel.PARTIAL_COMPLETE,
   1241         notes = "This is a complete subset of tests for setBit method.",
   1242         method = "setBit",
   1243         args = {int.class}
   1244     )
   1245     public void testSetBitLeftmostNegative() {
   1246         byte aBytes[] = {1, -128, 56, 100, -15, 35, 26};
   1247         int aSign = -1;
   1248         int number = 48;
   1249         byte rBytes[] = {-1, 127, -57, -101, 14, -36, -26, 49};
   1250         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1251         BigInteger result = aNumber.setBit(number);
   1252         byte resBytes[] = new byte[rBytes.length];
   1253         resBytes = result.toByteArray();
   1254         for(int i = 0; i < resBytes.length; i++) {
   1255             assertTrue(resBytes[i] == rBytes[i]);
   1256         }
   1257         assertEquals("incorrect sign", -1, result.signum());
   1258     }
   1259 
   1260     /**
   1261      * setBit(int n) inside a negative number
   1262      */
   1263     @TestTargetNew(
   1264         level = TestLevel.PARTIAL_COMPLETE,
   1265         notes = "This is a complete subset of tests for setBit method.",
   1266         method = "setBit",
   1267         args = {int.class}
   1268     )
   1269     public void testSetBitNegativeInside1() {
   1270         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1271         int aSign = -1;
   1272         int number = 15;
   1273         byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
   1274         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1275         BigInteger result = aNumber.setBit(number);
   1276         byte resBytes[] = new byte[rBytes.length];
   1277         resBytes = result.toByteArray();
   1278         for(int i = 0; i < resBytes.length; i++) {
   1279             assertTrue(resBytes[i] == rBytes[i]);
   1280         }
   1281         assertEquals("incorrect sign", -1, result.signum());
   1282     }
   1283 
   1284     /**
   1285      * setBit(int n) inside a negative number
   1286      */
   1287     @TestTargetNew(
   1288         level = TestLevel.PARTIAL_COMPLETE,
   1289         notes = "This is a complete subset of tests for setBit method.",
   1290         method = "setBit",
   1291         args = {int.class}
   1292     )
   1293     public void testSetBitNegativeInside2() {
   1294         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1295         int aSign = -1;
   1296         int number = 44;
   1297         byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
   1298         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1299         BigInteger result = aNumber.setBit(number);
   1300         byte resBytes[] = new byte[rBytes.length];
   1301         resBytes = result.toByteArray();
   1302         for(int i = 0; i < resBytes.length; i++) {
   1303             assertTrue(resBytes[i] == rBytes[i]);
   1304         }
   1305         assertEquals("incorrect sign", -1, result.signum());
   1306     }
   1307 
   1308     /**
   1309      * setBit(int n) inside a negative number with all ones in bit representation
   1310      */
   1311     @TestTargetNew(
   1312         level = TestLevel.PARTIAL_COMPLETE,
   1313         notes = "This is a complete subset of tests for setBit method.",
   1314         method = "setBit",
   1315         args = {int.class}
   1316     )
   1317     public void testSetBitNegativeInside3() {
   1318         String as = "-18446744073709551615";
   1319         String res = "-18446744073709551611";
   1320         int number = 2;
   1321         BigInteger aNumber = new BigInteger(as);
   1322         BigInteger result = aNumber.setBit(number);
   1323         assertEquals(res, result.toString());
   1324     }
   1325 
   1326     /**
   1327      * setBit(0) in the negative number of length 1
   1328      * with all ones in bit representation.
   1329      * the resulting number's length is 2.
   1330      */
   1331     @TestTargetNew(
   1332         level = TestLevel.PARTIAL_COMPLETE,
   1333         notes = "This is a complete subset of tests for setBit method.",
   1334         method = "setBit",
   1335         args = {int.class}
   1336     )
   1337     public void testSetBitNegativeInside4() {
   1338         String as = "-4294967295";
   1339         int number = 0;
   1340         BigInteger aNumber = new BigInteger(as);
   1341         BigInteger result = aNumber.setBit(number);
   1342         assertEquals(as, result.toString());
   1343     }
   1344 
   1345     /**
   1346      * setBit(0) in the negative number of length 2
   1347      * with all ones in bit representation.
   1348      * the resulting number's length is 3.
   1349      */
   1350     @TestTargetNew(
   1351         level = TestLevel.PARTIAL_COMPLETE,
   1352         notes = "This is a complete subset of tests for setBit method.",
   1353         method = "setBit",
   1354         args = {int.class}
   1355     )
   1356     public void testSetBitNegativeInside5() {
   1357         String as = "-18446744073709551615";
   1358         int number = 0;
   1359         BigInteger aNumber = new BigInteger(as);
   1360         BigInteger result = aNumber.setBit(number);
   1361         assertEquals(as, result.toString());
   1362     }
   1363 
   1364     /**
   1365      * setBit(int n) outside a negative number
   1366      */
   1367     @TestTargetNew(
   1368         level = TestLevel.PARTIAL_COMPLETE,
   1369         notes = "This is a complete subset of tests for setBit method.",
   1370         method = "setBit",
   1371         args = {int.class}
   1372     )
   1373     public void testSetBitNegativeOutside1() {
   1374         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1375         int aSign = -1;
   1376         int number = 150;
   1377         byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
   1378         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1379         BigInteger result = aNumber.setBit(number);
   1380         byte resBytes[] = new byte[rBytes.length];
   1381         resBytes = result.toByteArray();
   1382         for(int i = 0; i < resBytes.length; i++) {
   1383             assertTrue(resBytes[i] == rBytes[i]);
   1384         }
   1385         assertEquals("incorrect sign", -1, result.signum());
   1386     }
   1387 
   1388     /**
   1389      * setBit(int n) outside a negative number
   1390      */
   1391     @TestTargetNew(
   1392         level = TestLevel.PARTIAL_COMPLETE,
   1393         notes = "This is a complete subset of tests for setBit method.",
   1394         method = "setBit",
   1395         args = {int.class}
   1396     )
   1397     public void testSetBitNegativeOutside2() {
   1398         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1399         int aSign = -1;
   1400         int number = 191;
   1401         byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92, -4, 14, -36, -26};
   1402         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1403         BigInteger result = aNumber.setBit(number);
   1404         byte resBytes[] = new byte[rBytes.length];
   1405         resBytes = result.toByteArray();
   1406         for(int i = 0; i < resBytes.length; i++) {
   1407             assertTrue(resBytes[i] == rBytes[i]);
   1408         }
   1409         assertEquals("incorrect sign", -1, result.signum());
   1410     }
   1411 
   1412     /**
   1413      * setBit: check the case when the number of bit to be set can be
   1414      * represented as n * 32 + 31, where n is an arbitrary integer.
   1415      * Here 191 = 5 * 32 + 31
   1416      */
   1417     @TestTargetNew(
   1418         level = TestLevel.PARTIAL_COMPLETE,
   1419         notes = "This is a complete subset of tests for setBit method.",
   1420         method = "setBit",
   1421         args = {int.class}
   1422     )
   1423     public void testSetBitBug1331() {
   1424         BigInteger result = BigInteger.valueOf(0L).setBit(191);
   1425         assertEquals("incorrect value", "3138550867693340381917894711603833208051177722232017256448", result.toString());
   1426         assertEquals("incorrect sign", 1, result.signum());
   1427     }
   1428 
   1429     /**
   1430      * shiftLeft(int n), n = 0
   1431      */
   1432     @TestTargetNew(
   1433         level = TestLevel.PARTIAL_COMPLETE,
   1434         notes = "This is a complete subset of tests for shiftLeft method.",
   1435         method = "shiftLeft",
   1436         args = {int.class}
   1437     )
   1438     public void testShiftLeft1() {
   1439         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1440         int aSign = 1;
   1441         int number = 0;
   1442         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1443         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1444         BigInteger result = aNumber.shiftLeft(number);
   1445         byte resBytes[] = new byte[rBytes.length];
   1446         resBytes = result.toByteArray();
   1447         for(int i = 0; i < resBytes.length; i++) {
   1448             assertTrue(resBytes[i] == rBytes[i]);
   1449         }
   1450         assertEquals("incorrect sign", 1, result.signum());
   1451     }
   1452 
   1453     /**
   1454      * shiftLeft(int n), n < 0
   1455      */
   1456     @TestTargetNew(
   1457         level = TestLevel.PARTIAL_COMPLETE,
   1458         notes = "This is a complete subset of tests for shiftLeft method.",
   1459         method = "shiftLeft",
   1460         args = {int.class}
   1461     )
   1462     public void testShiftLeft2() {
   1463         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1464         int aSign = 1;
   1465         int number = -27;
   1466         byte rBytes[] = {48, 7, 12, -97, -42, -117, 37, -85, 96};
   1467         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1468         BigInteger result = aNumber.shiftLeft(number);
   1469         byte resBytes[] = new byte[rBytes.length];
   1470         resBytes = result.toByteArray();
   1471         for(int i = 0; i < resBytes.length; i++) {
   1472             assertTrue(resBytes[i] == rBytes[i]);
   1473         }
   1474         assertEquals("incorrect sign", 1, result.signum());
   1475     }
   1476 
   1477     /**
   1478      * shiftLeft(int n) a positive number, n > 0
   1479      */
   1480     @TestTargetNew(
   1481         level = TestLevel.PARTIAL_COMPLETE,
   1482         notes = "This is a complete subset of tests for shiftLeft method.",
   1483         method = "shiftLeft",
   1484         args = {int.class}
   1485     )
   1486     public void testShiftLeft3() {
   1487         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1488         int aSign = 1;
   1489         int number = 27;
   1490         byte rBytes[] = {12, 1, -61, 39, -11, -94, -55, 106, -40, 31, -119, 24, -48, 0, 0, 0};
   1491         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1492         BigInteger result = aNumber.shiftLeft(number);
   1493         byte resBytes[] = new byte[rBytes.length];
   1494         resBytes = result.toByteArray();
   1495         for(int i = 0; i < resBytes.length; i++) {
   1496             assertTrue(resBytes[i] == rBytes[i]);
   1497         }
   1498         assertEquals("incorrect sign", 1, result.signum());
   1499     }
   1500 
   1501     /**
   1502      * shiftLeft(int n) a positive number, n > 0
   1503      */
   1504     @TestTargetNew(
   1505         level = TestLevel.PARTIAL_COMPLETE,
   1506         notes = "This is a complete subset of tests for shiftLeft method.",
   1507         method = "shiftLeft",
   1508         args = {int.class}
   1509     )
   1510     public void testShiftLeft4() {
   1511         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1512         int aSign = 1;
   1513         int number = 45;
   1514         byte rBytes[] = {48, 7, 12, -97, -42, -117, 37, -85, 96, 126, 36, 99, 64, 0, 0, 0, 0, 0};
   1515         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1516         BigInteger result = aNumber.shiftLeft(number);
   1517         byte resBytes[] = new byte[rBytes.length];
   1518         resBytes = result.toByteArray();
   1519         for(int i = 0; i < resBytes.length; i++) {
   1520             assertTrue(resBytes[i] == rBytes[i]);
   1521         }
   1522         assertEquals("incorrect sign", 1, result.signum());
   1523     }
   1524 
   1525     /**
   1526      * shiftLeft(int n) a negative number, n > 0
   1527      */
   1528     @TestTargetNew(
   1529         level = TestLevel.PARTIAL_COMPLETE,
   1530         notes = "This is a complete subset of tests for shiftLeft method.",
   1531         method = "shiftLeft",
   1532         args = {int.class}
   1533     )
   1534     public void testShiftLeft5() {
   1535         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1536         int aSign = -1;
   1537         int number = 45;
   1538         byte rBytes[] = {-49, -8, -13, 96, 41, 116, -38, 84, -97, -127, -37, -100, -64, 0, 0, 0, 0, 0};
   1539         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1540         BigInteger result = aNumber.shiftLeft(number);
   1541         byte resBytes[] = new byte[rBytes.length];
   1542         resBytes = result.toByteArray();
   1543         for(int i = 0; i < resBytes.length; i++) {
   1544             assertTrue(resBytes[i] == rBytes[i]);
   1545         }
   1546         assertEquals("incorrect sign", -1, result.signum());
   1547     }
   1548 
   1549     /**
   1550      * shiftRight(int n), n = 0
   1551      */
   1552     @TestTargetNew(
   1553         level = TestLevel.PARTIAL_COMPLETE,
   1554         notes = "This is a complete subset of tests for shiftRight method.",
   1555         method = "shiftRight",
   1556         args = {int.class}
   1557     )
   1558     public void testShiftRight1() {
   1559         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1560         int aSign = 1;
   1561         int number = 0;
   1562         byte rBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1563         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1564         BigInteger result = aNumber.shiftRight(number);
   1565         byte resBytes[] = new byte[rBytes.length];
   1566         resBytes = result.toByteArray();
   1567         for(int i = 0; i < resBytes.length; i++) {
   1568             assertTrue(resBytes[i] == rBytes[i]);
   1569         }
   1570         assertEquals("incorrect sign", 1, result.signum());
   1571     }
   1572 
   1573     /**
   1574      * shiftRight(int n), n < 0
   1575      */
   1576     @TestTargetNew(
   1577         level = TestLevel.PARTIAL_COMPLETE,
   1578         notes = "This is a complete subset of tests for shiftRight method.",
   1579         method = "shiftRight",
   1580         args = {int.class}
   1581     )
   1582     public void testShiftRight2() {
   1583         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1584         int aSign = 1;
   1585         int number = -27;
   1586         byte rBytes[] = {12, 1, -61, 39, -11, -94, -55, 106, -40, 31, -119, 24, -48, 0, 0, 0};
   1587         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1588         BigInteger result = aNumber.shiftRight(number);
   1589         byte resBytes[] = new byte[rBytes.length];
   1590         resBytes = result.toByteArray();
   1591         for(int i = 0; i < resBytes.length; i++) {
   1592             assertTrue(resBytes[i] == rBytes[i]);
   1593         }
   1594         assertEquals("incorrect sign", 1, result.signum());
   1595     }
   1596 
   1597     /**
   1598      * shiftRight(int n), 0 < n < 32
   1599      */
   1600     @TestTargetNew(
   1601         level = TestLevel.PARTIAL_COMPLETE,
   1602         notes = "This is a complete subset of tests for shiftRight method.",
   1603         method = "shiftRight",
   1604         args = {int.class}
   1605     )
   1606     public void testShiftRight3() {
   1607         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1608         int aSign = 1;
   1609         int number = 27;
   1610         byte rBytes[] = {48, 7, 12, -97, -42, -117, 37, -85, 96};
   1611         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1612         BigInteger result = aNumber.shiftRight(number);
   1613         byte resBytes[] = new byte[rBytes.length];
   1614         resBytes = result.toByteArray();
   1615         for(int i = 0; i < resBytes.length; i++) {
   1616             assertTrue(resBytes[i] == rBytes[i]);
   1617         }
   1618         assertEquals("incorrect sign", 1, result.signum());
   1619     }
   1620 
   1621     /**
   1622      * shiftRight(int n), n > 32
   1623      */
   1624     @TestTargetNew(
   1625         level = TestLevel.PARTIAL_COMPLETE,
   1626         notes = "This is a complete subset of tests for shiftRight method.",
   1627         method = "shiftRight",
   1628         args = {int.class}
   1629     )
   1630     public void testShiftRight4() {
   1631         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1632         int aSign = 1;
   1633         int number = 45;
   1634         byte rBytes[] = {12, 1, -61, 39, -11, -94, -55};
   1635         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1636         BigInteger result = aNumber.shiftRight(number);
   1637         byte resBytes[] = new byte[rBytes.length];
   1638         resBytes = result.toByteArray();
   1639         for(int i = 0; i < resBytes.length; i++) {
   1640             assertTrue(resBytes[i] == rBytes[i]);
   1641         }
   1642         assertEquals("incorrect sign", 1, result.signum());
   1643     }
   1644 
   1645     /**
   1646      * shiftRight(int n), n is greater than bitLength()
   1647      */
   1648     @TestTargetNew(
   1649         level = TestLevel.PARTIAL_COMPLETE,
   1650         notes = "This is a complete subset of tests for shiftRight method.",
   1651         method = "shiftRight",
   1652         args = {int.class}
   1653     )
   1654     public void testShiftRight5() {
   1655         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1656         int aSign = 1;
   1657         int number = 300;
   1658         byte rBytes[] = {0};
   1659         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1660         BigInteger result = aNumber.shiftRight(number);
   1661         byte resBytes[] = new byte[rBytes.length];
   1662         resBytes = result.toByteArray();
   1663         for(int i = 0; i < resBytes.length; i++) {
   1664             assertTrue(resBytes[i] == rBytes[i]);
   1665         }
   1666         assertEquals("incorrect sign", 0, result.signum());
   1667     }
   1668 
   1669     /**
   1670      * shiftRight a negative number;
   1671      * shift distance is multiple of 32;
   1672      * shifted bits are NOT zeroes.
   1673      */
   1674     @TestTargetNew(
   1675         level = TestLevel.PARTIAL_COMPLETE,
   1676         notes = "This is a complete subset of tests for shiftRight method.",
   1677         method = "shiftRight",
   1678         args = {int.class}
   1679     )
   1680     public void testShiftRightNegNonZeroesMul32() {
   1681         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 1, 0, 0, 0, 0, 0, 0, 0};
   1682         int aSign = -1;
   1683         int number = 64;
   1684         byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -92};
   1685         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1686         BigInteger result = aNumber.shiftRight(number);
   1687         byte resBytes[] = new byte[rBytes.length];
   1688         resBytes = result.toByteArray();
   1689         for(int i = 0; i < resBytes.length; i++) {
   1690             assertTrue(resBytes[i] == rBytes[i]);
   1691         }
   1692         assertEquals("incorrect sign", -1, result.signum());
   1693     }
   1694 
   1695     /**
   1696      * shiftRight a negative number;
   1697      * shift distance is NOT multiple of 32;
   1698      * shifted bits are NOT zeroes.
   1699      */
   1700     @TestTargetNew(
   1701         level = TestLevel.PARTIAL_COMPLETE,
   1702         notes = "This is a complete subset of tests for shiftRight method.",
   1703         method = "shiftRight",
   1704         args = {int.class}
   1705     )
   1706     public void testShiftRightNegNonZeroes() {
   1707         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 0, 0, 0, 0, 0, 0, 0, 0};
   1708         int aSign = -1;
   1709         int number = 68;
   1710         byte rBytes[] = {-25, -4, 121, -80, 20, -70, 109, 42};
   1711         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1712         BigInteger result = aNumber.shiftRight(number);
   1713         byte resBytes[] = new byte[rBytes.length];
   1714         resBytes = result.toByteArray();
   1715         for(int i = 0; i < resBytes.length; i++) {
   1716             assertTrue(resBytes[i] == rBytes[i]);
   1717         }
   1718         assertEquals("incorrect sign", -1, result.signum());
   1719     }
   1720 
   1721     /**
   1722      * shiftRight a negative number;
   1723      * shift distance is NOT multiple of 32;
   1724      * shifted bits are zeroes.
   1725      */
   1726     @TestTargetNew(
   1727         level = TestLevel.PARTIAL_COMPLETE,
   1728         notes = "This is a complete subset of tests for shiftRight method.",
   1729         method = "shiftRight",
   1730         args = {int.class}
   1731     )
   1732     public void testShiftRightNegZeroes() {
   1733         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 0, 0, 0, 0, 0, 0, 0, 0, 0};
   1734         int aSign = -1;
   1735         int number = 68;
   1736         byte rBytes[] = {-25, -4, 121, -80, 20, -70, 109, 48};
   1737         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1738         BigInteger result = aNumber.shiftRight(number);
   1739         byte resBytes[] = new byte[rBytes.length];
   1740         resBytes = result.toByteArray();
   1741         for(int i = 0; i < resBytes.length; i++) {
   1742             assertTrue(resBytes[i] == rBytes[i]);
   1743         }
   1744         assertEquals("incorrect sign", -1, result.signum());
   1745     }
   1746 
   1747     /**
   1748      * shiftRight a negative number;
   1749      * shift distance is multiple of 32;
   1750      * shifted bits are zeroes.
   1751      */
   1752     @TestTargetNew(
   1753         level = TestLevel.PARTIAL_COMPLETE,
   1754         notes = "This is a complete subset of tests for shiftRight method.",
   1755         method = "shiftRight",
   1756         args = {int.class}
   1757     )
   1758     public void testShiftRightNegZeroesMul32() {
   1759         byte aBytes[] = {1, -128, 56, 100, -2, -76, 89, 45, 91, 0, 0, 0, 0, 0, 0, 0, 0};
   1760         int aSign = -1;
   1761         int number = 64;
   1762         byte rBytes[] = {-2, 127, -57, -101, 1, 75, -90, -46, -91};
   1763         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1764         BigInteger result = aNumber.shiftRight(number);
   1765         byte resBytes[] = new byte[rBytes.length];
   1766         resBytes = result.toByteArray();
   1767         for(int i = 0; i < resBytes.length; i++) {
   1768             assertTrue(resBytes[i] == rBytes[i]);
   1769         }
   1770         assertEquals("incorrect sign", -1, result.signum());
   1771     }
   1772 
   1773     /**
   1774      * testBit(int n) of a negative n
   1775      */
   1776     @TestTargetNew(
   1777         level = TestLevel.PARTIAL_COMPLETE,
   1778         notes = "This is a complete subset of tests for shiftRight method.",
   1779         method = "testBit",
   1780         args = {int.class}
   1781     )
   1782     public void testTestBitException() {
   1783         byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1784         int aSign = 1;
   1785         int number = -7;
   1786         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1787         try {
   1788             aNumber.testBit(number);
   1789             fail("ArithmeticException has not been caught");
   1790         } catch (ArithmeticException e) {
   1791             assertEquals("Improper exception message", "Negative bit address", e.getMessage());
   1792         }
   1793     }
   1794 
   1795     /**
   1796      * testBit(int n) of a positive number
   1797      */
   1798     @TestTargetNew(
   1799         level = TestLevel.PARTIAL_COMPLETE,
   1800         notes = "This is a complete subset of tests for shiftRight method.",
   1801         method = "testBit",
   1802         args = {int.class}
   1803     )
   1804     public void testTestBitPositive1() {
   1805         byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1806         int aSign = 1;
   1807         int number = 7;
   1808         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1809         assertTrue(!aNumber.testBit(number));
   1810     }
   1811 
   1812     /**
   1813      * testBit(int n) of a positive number
   1814      */
   1815     @TestTargetNew(
   1816         level = TestLevel.PARTIAL_COMPLETE,
   1817         notes = "This is a complete subset of tests for shiftRight method.",
   1818         method = "testBit",
   1819         args = {int.class}
   1820     )
   1821     public void testTestBitPositive2() {
   1822         byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1823         int aSign = 1;
   1824         int number = 45;
   1825         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1826         assertTrue(aNumber.testBit(number));
   1827     }
   1828 
   1829     /**
   1830      * testBit(int n) of a positive number, n > bitLength()
   1831      */
   1832     @TestTargetNew(
   1833         level = TestLevel.PARTIAL_COMPLETE,
   1834         notes = "This is a complete subset of tests for shiftRight method.",
   1835         method = "testBit",
   1836         args = {int.class}
   1837     )
   1838     public void testTestBitPositive3() {
   1839         byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1840         int aSign = 1;
   1841         int number = 300;
   1842         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1843         assertTrue(!aNumber.testBit(number));
   1844     }
   1845 
   1846     /**
   1847      * testBit(int n) of a negative number
   1848      */
   1849     @TestTargetNew(
   1850         level = TestLevel.PARTIAL_COMPLETE,
   1851         notes = "This is a complete subset of tests for shiftRight method.",
   1852         method = "testBit",
   1853         args = {int.class}
   1854     )
   1855     public void testTestBitNegative1() {
   1856         byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1857         int aSign = -1;
   1858         int number = 7;
   1859         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1860         assertTrue(aNumber.testBit(number));
   1861     }
   1862 
   1863     /**
   1864      * testBit(int n) of a positive n
   1865      */
   1866     @TestTargetNew(
   1867         level = TestLevel.PARTIAL_COMPLETE,
   1868         notes = "This is a complete subset of tests for shiftRight method.",
   1869         method = "testBit",
   1870         args = {int.class}
   1871     )
   1872     public void testTestBitNegative2() {
   1873         byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1874         int aSign = -1;
   1875         int number = 45;
   1876         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1877         assertTrue(!aNumber.testBit(number));
   1878     }
   1879 
   1880     /**
   1881      * testBit(int n) of a positive n, n > bitLength()
   1882      */
   1883     @TestTargetNew(
   1884         level = TestLevel.PARTIAL_COMPLETE,
   1885         notes = "This is a complete subset of tests for shiftRight method.",
   1886         method = "testBit",
   1887         args = {int.class}
   1888     )
   1889     public void testTestBitNegative3() {
   1890         byte aBytes[] = {-1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26};
   1891         int aSign = -1;
   1892         int number = 300;
   1893         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1894         assertTrue(aNumber.testBit(number));
   1895     }
   1896 
   1897 // ANDROID ADDED
   1898 
   1899     /**
   1900      * @tests java.math.BigInteger#getLowestSetBit() getLowestSetBit for
   1901      *        negative BigInteger
   1902      */
   1903     @TestTargetNew(
   1904         level = TestLevel.PARTIAL_COMPLETE,
   1905         notes = "This is a complete subset of tests for getLowestSetBit method.",
   1906         method = "getLowestSetBit",
   1907         args = {}
   1908     )
   1909     public void test_getLowestSetBitNeg() {
   1910         byte aBytes[] = {
   1911                 -1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26
   1912         };
   1913         int aSign = -1;
   1914         int iNumber = 1;
   1915         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1916         int result = aNumber.getLowestSetBit();
   1917         assertTrue("incorrect value", result == iNumber);
   1918     }
   1919 
   1920     /**
   1921      * @tests java.math.BigInteger#getLowestSetBit() getLowestSetBit for
   1922      *        positive BigInteger
   1923      */
   1924     @TestTargetNew(
   1925         level = TestLevel.PARTIAL_COMPLETE,
   1926         notes = "This is a complete subset of tests for getLowestSetBit method.",
   1927         method = "getLowestSetBit",
   1928         args = {}
   1929     )
   1930     public void test_getLowestSetBitPos() {
   1931         byte aBytes[] = {
   1932                 -1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26
   1933         };
   1934         int aSign = 1;
   1935         int iNumber = 1;
   1936         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1937         int result = aNumber.getLowestSetBit();
   1938         assertTrue("incorrect value", result == iNumber);
   1939 
   1940         byte[] aBytes_ = {
   1941                 127, 0, 3
   1942         };
   1943         iNumber = 0;
   1944         aNumber = new BigInteger(aSign, aBytes_);
   1945         result = aNumber.getLowestSetBit();
   1946         assertTrue("incorrect value", result == iNumber);
   1947 
   1948         byte[] aBytes__ = {
   1949                 -128, 0, 0
   1950         };
   1951         iNumber = 23;
   1952         aNumber = new BigInteger(aSign, aBytes__);
   1953         result = aNumber.getLowestSetBit();
   1954         assertTrue("incorrect value", result == iNumber);
   1955     }
   1956 
   1957     /**
   1958      * @tests java.math.BigInteger#getLowestSetBit() getLowestSetBit for zero
   1959      *        BigInteger
   1960      */
   1961     @TestTargetNew(
   1962         level = TestLevel.PARTIAL_COMPLETE,
   1963         notes = "This is a complete subset of tests for getLowestSetBit method.",
   1964         method = "getLowestSetBit",
   1965         args = {}
   1966     )
   1967     public void test_getLowestSetBitZero() {
   1968         byte[] aBytes = {
   1969             0
   1970         };
   1971         int aSign = 0;
   1972         int iNumber = -1;
   1973         BigInteger aNumber = new BigInteger(aSign, aBytes);
   1974         int result = aNumber.getLowestSetBit();
   1975         assertTrue("incorrect value", result == iNumber);
   1976 
   1977         byte[] aBytes_ = {
   1978                 0, 0, 0
   1979         };
   1980         iNumber = -1;
   1981         aNumber = new BigInteger(aSign, aBytes_);
   1982         result = aNumber.getLowestSetBit();
   1983         assertTrue("incorrect value", result == iNumber);
   1984     }
   1985 
   1986 }
   1987