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.qrcode.decoder;
19 import com.google.zxing.common.BitMatrix;
20 import org.junit.Assert;
21 import org.junit.Test;
26 public final class DataMaskTestCase extends Assert {
29 public void testMask0() {
30 testMaskAcrossDimensions(0, new MaskCondition() {
31 public boolean isMasked(int i, int j) {
32 return (i + j) % 2 == 0;
38 public void testMask1() {
39 testMaskAcrossDimensions(1, new MaskCondition() {
40 public boolean isMasked(int i, int j) {
47 public void testMask2() {
48 testMaskAcrossDimensions(2, new MaskCondition() {
49 public boolean isMasked(int i, int j) {
56 public void testMask3() {
57 testMaskAcrossDimensions(3, new MaskCondition() {
58 public boolean isMasked(int i, int j) {
59 return (i + j) % 3 == 0;
65 public void testMask4() {
66 testMaskAcrossDimensions(4, new MaskCondition() {
67 public boolean isMasked(int i, int j) {
68 return (i / 2 + j / 3) % 2 == 0;
74 public void testMask5() {
75 testMaskAcrossDimensions(5, new MaskCondition() {
76 public boolean isMasked(int i, int j) {
77 return (i * j) % 2 + (i * j) % 3 == 0;
83 public void testMask6() {
84 testMaskAcrossDimensions(6, new MaskCondition() {
85 public boolean isMasked(int i, int j) {
86 return ((i * j) % 2 + (i * j) % 3) % 2 == 0;
92 public void testMask7() {
93 testMaskAcrossDimensions(7, new MaskCondition() {
94 public boolean isMasked(int i, int j) {
95 return ((i + j) % 2 + (i * j) % 3) % 2 == 0;
100 private static void testMaskAcrossDimensions(int reference, MaskCondition condition) {
101 DataMask mask = DataMask.forReference(reference);
102 for (int version = 1; version <= 40; version++) {
103 int dimension = 17 + 4 * version;
104 testMask(mask, dimension, condition);
108 private static void testMask(DataMask mask, int dimension, MaskCondition condition) {
109 BitMatrix bits = new BitMatrix(dimension);
110 mask.unmaskBitMatrix(bits, dimension);
111 for (int i = 0; i < dimension; i++) {
112 for (int j = 0; j < dimension; j++) {
114 "(" + i + ',' + j + ')',
115 condition.isMasked(i, j),
121 private interface MaskCondition {
122 boolean isMasked(int i, int j);