2 * Copyright 2007 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.common;
19 import junit.framework.TestCase;
24 public final class BitArrayTestCase extends TestCase {
26 public void testGetSet() {
27 BitArray array = new BitArray(33);
28 for (int i = 0; i < 33; i++) {
29 assertFalse(array.get(i));
31 assertTrue(array.get(i));
35 public void testSetBulk() {
36 BitArray array = new BitArray(64);
37 array.setBulk(32, 0xFFFF0000);
38 for (int i = 0; i < 48; i++) {
39 assertFalse(array.get(i));
41 for (int i = 48; i < 64; i++) {
42 assertTrue(array.get(i));
46 public void testClear() {
47 BitArray array = new BitArray(32);
48 for (int i = 0; i < 32; i++) {
52 for (int i = 0; i < 32; i++) {
53 assertFalse(array.get(i));
57 public void testGetArray() {
58 BitArray array = new BitArray(64);
61 int[] ints = array.getBitArray();
62 assertEquals(1, ints[0]);
63 assertEquals(Integer.MIN_VALUE, ints[1]);
66 public void testIsRange() {
67 BitArray array = new BitArray(64);
68 assertTrue(array.isRange(0, 64, false));
69 assertFalse(array.isRange(0, 64, true));
71 assertTrue(array.isRange(32, 33, true));
73 assertTrue(array.isRange(31, 33, true));
75 assertFalse(array.isRange(31, 35, true));
76 for (int i = 0; i < 31; i++) {
79 assertTrue(array.isRange(0, 33, true));
80 for (int i = 33; i < 64; i++) {
83 assertTrue(array.isRange(0, 64, true));
84 assertFalse(array.isRange(0, 64, false));