Issue 563: Support non-rectangular Data Matrix
[zxing.git] / core / test / src / com / google / zxing / common / BitArrayTestCase.java
1 /*
2  * Copyright 2007 ZXing authors
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.google.zxing.common;
18
19 import org.junit.Assert;
20 import org.junit.Test;
21
22 /**
23  * @author Sean Owen
24  */
25 public final class BitArrayTestCase extends Assert {
26
27   @Test
28   public void testGetSet() {
29     BitArray array = new BitArray(33);
30     for (int i = 0; i < 33; i++) {
31       assertFalse(array.get(i));
32       array.set(i);
33       assertTrue(array.get(i));
34     }
35   }
36
37   @Test
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));
43     }
44     for (int i = 48; i < 64; i++) {
45       assertTrue(array.get(i));
46     }
47   }
48
49   @Test
50   public void testClear() {
51     BitArray array = new BitArray(32);
52     for (int i = 0; i < 32; i++) {
53       array.set(i);
54     }
55     array.clear();
56     for (int i = 0; i < 32; i++) {
57       assertFalse(array.get(i));
58     }
59   }
60
61   @Test
62   public void testGetArray() {
63     BitArray array = new BitArray(64);
64     array.set(0);
65     array.set(63);
66     int[] ints = array.getBitArray();
67     assertEquals(1, ints[0]);
68     assertEquals(Integer.MIN_VALUE, ints[1]);
69   }
70
71   @Test
72   public void testIsRange() {
73     BitArray array = new BitArray(64);
74     assertTrue(array.isRange(0, 64, false));
75     assertFalse(array.isRange(0, 64, true));
76     array.set(32);
77     assertTrue(array.isRange(32, 33, true));
78     array.set(31);
79     assertTrue(array.isRange(31, 33, true));
80     array.set(34);
81     assertFalse(array.isRange(31, 35, true));
82     for (int i = 0; i < 31; i++) {
83       array.set(i);
84     }
85     assertTrue(array.isRange(0, 33, true));
86     for (int i = 33; i < 64; i++) {
87       array.set(i);
88     }
89     assertTrue(array.isRange(0, 64, true));
90     assertFalse(array.isRange(0, 64, false));
91   }
92
93 }