Added more test cases
[zxing.git] / core / test / src / com / google / zxing / common / BitMatrixTestCase.java
1 /*
2  * Copyright 2007 Google Inc.
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 junit.framework.TestCase;
20
21 /**
22  * @author srowen@google.com (Sean Owen)
23  */
24 public final class BitMatrixTestCase extends TestCase {
25
26   public void testGetSet() {
27     BitMatrix matrix = new BitMatrix(33);
28     assertEquals(33, matrix.getDimension());
29     for (int i = 0; i < 33; i++) {
30       for (int j = 0; j < 33; j++) {
31         if (i * j % 3 == 0) {
32           matrix.set(i, j);
33         }
34       }
35     }
36     for (int i = 0; i < 33; i++) {
37       for (int j = 0; j < 33; j++) {
38         assertEquals(i * j % 3 == 0, matrix.get(i, j));
39       }
40     }
41   }
42
43   public void testSetRegion() {
44     BitMatrix matrix = new BitMatrix(5);
45     matrix.setRegion(1, 1, 3, 3);
46     for (int i = 0; i < 5; i++) {
47       for (int j = 0; j < 5; j++) {
48         assertEquals(i >= 1 && i <= 3 && j >= 1 && j <= 3, matrix.get(i, j));
49       }
50     }
51   }
52
53   public void testGetBits() {
54     BitMatrix matrix = new BitMatrix(6);
55     matrix.set(0, 0);
56     matrix.set(5, 5);
57     int[] bits = matrix.getBits();
58     assertEquals(1, bits[0]);
59     assertEquals(8, bits[1]);
60   }
61
62 }