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 libcore.java.math; 23 24 import java.math.BigInteger; 25 import junit.framework.TestCase; 26 27 public class OldBigIntegerOperateBitsTest extends TestCase { 28 29 30 /** 31 * java.math.BigInteger#getLowestSetBit() getLowestSetBit for 32 * negative BigInteger 33 */ 34 public void test_getLowestSetBitNeg() { 35 byte aBytes[] = { 36 -1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26 37 }; 38 int aSign = -1; 39 int iNumber = 1; 40 BigInteger aNumber = new BigInteger(aSign, aBytes); 41 int result = aNumber.getLowestSetBit(); 42 assertTrue("incorrect value", result == iNumber); 43 } 44 45 /** 46 * java.math.BigInteger#getLowestSetBit() getLowestSetBit for 47 * positive BigInteger 48 */ 49 public void test_getLowestSetBitPos() { 50 byte aBytes[] = { 51 -1, -128, 56, 100, -2, -76, 89, 45, 91, 3, -15, 35, 26 52 }; 53 int aSign = 1; 54 int iNumber = 1; 55 BigInteger aNumber = new BigInteger(aSign, aBytes); 56 int result = aNumber.getLowestSetBit(); 57 assertTrue("incorrect value", result == iNumber); 58 59 byte[] aBytes_ = { 60 127, 0, 3 61 }; 62 iNumber = 0; 63 aNumber = new BigInteger(aSign, aBytes_); 64 result = aNumber.getLowestSetBit(); 65 assertTrue("incorrect value", result == iNumber); 66 67 byte[] aBytes__ = { 68 -128, 0, 0 69 }; 70 iNumber = 23; 71 aNumber = new BigInteger(aSign, aBytes__); 72 result = aNumber.getLowestSetBit(); 73 assertTrue("incorrect value", result == iNumber); 74 } 75 76 /** 77 * java.math.BigInteger#getLowestSetBit() getLowestSetBit for zero 78 * BigInteger 79 */ 80 public void test_getLowestSetBitZero() { 81 byte[] aBytes = { 82 0 83 }; 84 int aSign = 0; 85 int iNumber = -1; 86 BigInteger aNumber = new BigInteger(aSign, aBytes); 87 int result = aNumber.getLowestSetBit(); 88 assertTrue("incorrect value", result == iNumber); 89 90 byte[] aBytes_ = { 91 0, 0, 0 92 }; 93 iNumber = -1; 94 aNumber = new BigInteger(aSign, aBytes_); 95 result = aNumber.getLowestSetBit(); 96 assertTrue("incorrect value", result == iNumber); 97 } 98 99 } 100