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 org.junit.Assert;
20 import org.junit.Test;
25 public final class BitArrayTestCase extends Assert {
28 public void testGetSet() {
29 BitArray array = new BitArray(33);
30 for (int i = 0; i < 33; i++) {
31 assertFalse(array.get(i));
33 assertTrue(array.get(i));
38 public void testSetBulk() {
39 BitArray array = new BitArray(64);
40 array.setBulk(32, 0xFFFF0000);
41 for (int i = 0; i < 48; i++) {
42 assertFalse(array.get(i));
44 for (int i = 48; i < 64; i++) {
45 assertTrue(array.get(i));
50 public void testClear() {
51 BitArray array = new BitArray(32);
52 for (int i = 0; i < 32; i++) {
56 for (int i = 0; i < 32; i++) {
57 assertFalse(array.get(i));
62 public void testGetArray() {
63 BitArray array = new BitArray(64);
66 int[] ints = array.getBitArray();
67 assertEquals(1, ints[0]);
68 assertEquals(Integer.MIN_VALUE, ints[1]);
72 public void testIsRange() {
73 BitArray array = new BitArray(64);
74 assertTrue(array.isRange(0, 64, false));
75 assertFalse(array.isRange(0, 64, true));
77 assertTrue(array.isRange(32, 33, true));
79 assertTrue(array.isRange(31, 33, true));
81 assertFalse(array.isRange(31, 35, true));
82 for (int i = 0; i < 31; i++) {
85 assertTrue(array.isRange(0, 33, true));
86 for (int i = 33; i < 64; i++) {
89 assertTrue(array.isRange(0, 64, true));
90 assertFalse(array.isRange(0, 64, false));