mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
git-svn-id: https://zxing.googlecode.com/svn/trunk@4 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
a5496d25bb
commit
47b9748d75
|
@ -1,122 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.qrcode.decoder;
|
||||
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import junit.framework.TestCase;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class DataMaskTestCase extends TestCase {
|
||||
|
||||
public void testMask0() {
|
||||
testMaskAcrossDimensions(0, new MaskCondition() {
|
||||
public boolean isMasked(int i, int j) {
|
||||
return (i + j) % 2 == 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testMask1() {
|
||||
testMaskAcrossDimensions(1, new MaskCondition() {
|
||||
public boolean isMasked(int i, int j) {
|
||||
return i % 2 == 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testMask2() {
|
||||
testMaskAcrossDimensions(2, new MaskCondition() {
|
||||
public boolean isMasked(int i, int j) {
|
||||
return j % 3 == 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testMask3() {
|
||||
testMaskAcrossDimensions(3, new MaskCondition() {
|
||||
public boolean isMasked(int i, int j) {
|
||||
return (i + j) % 3 == 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testMask4() {
|
||||
testMaskAcrossDimensions(4, new MaskCondition() {
|
||||
public boolean isMasked(int i, int j) {
|
||||
return (i/2 + j/3) % 2 == 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testMask5() {
|
||||
testMaskAcrossDimensions(5, new MaskCondition() {
|
||||
public boolean isMasked(int i, int j) {
|
||||
return (i*j) % 2 + (i*j) % 3 == 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testMask6() {
|
||||
testMaskAcrossDimensions(6, new MaskCondition() {
|
||||
public boolean isMasked(int i, int j) {
|
||||
return ((i*j) % 2 + (i*j) % 3) % 2 == 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testMask7() {
|
||||
testMaskAcrossDimensions(7, new MaskCondition() {
|
||||
public boolean isMasked(int i, int j) {
|
||||
return ((i+j) % 2 + (i*j) % 3) % 2 == 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void testMaskAcrossDimensions(int reference,
|
||||
MaskCondition condition) {
|
||||
DataMask mask = DataMask.forReference(reference);
|
||||
for (int version = 1; version <= 40; version++) {
|
||||
int dimension = 17 + 4*version;
|
||||
testMask(mask, dimension, condition);
|
||||
}
|
||||
}
|
||||
|
||||
private void testMask(DataMask mask, int dimension, MaskCondition condition) {
|
||||
BitMatrix bits = new BitMatrix(dimension);
|
||||
mask.unmaskBitMatrix(bits.getBits(), dimension);
|
||||
for (int i = 0; i < dimension; i++) {
|
||||
for (int j = 0; j < dimension; j++) {
|
||||
assertEquals(
|
||||
"(" + i + ',' + j + ')',
|
||||
condition.isMasked(i, j),
|
||||
bits.get(i, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static interface MaskCondition {
|
||||
boolean isMasked(int i, int j);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(new DataMaskTestCase());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright 2007 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.qrcode.decoder;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
/**
|
||||
* @author Sean Owen
|
||||
*/
|
||||
public final class FormatInformationTestCase extends TestCase {
|
||||
|
||||
public void testBitsDiffering() {
|
||||
assertEquals(0, FormatInformation.numBitsDiffering(1, 1));
|
||||
assertEquals(1, FormatInformation.numBitsDiffering(0, 2));
|
||||
assertEquals(2, FormatInformation.numBitsDiffering(1, 2));
|
||||
assertEquals(32, FormatInformation.numBitsDiffering(-1,0));
|
||||
}
|
||||
|
||||
public void testDecode() {
|
||||
// Normal case
|
||||
FormatInformation expected =
|
||||
FormatInformation.decodeFormatInformation(0x2BED ^ 0x5412);
|
||||
assertEquals((byte) 0x07, expected.getDataMask());
|
||||
assertEquals(ErrorCorrectionLevel.Q, expected.getErrorCorrectionLevel());
|
||||
// where the code forgot the mask!
|
||||
assertEquals(expected, FormatInformation.decodeFormatInformation(0x2BED));
|
||||
// 1,2,3,4 bits difference
|
||||
assertEquals(expected, FormatInformation.decodeFormatInformation(
|
||||
0x2BEF ^ 0x5412));
|
||||
assertEquals(expected, FormatInformation.decodeFormatInformation(
|
||||
0x2BEE ^ 0x5412));
|
||||
assertEquals(expected, FormatInformation.decodeFormatInformation(
|
||||
0x2BEA ^ 0x5412));
|
||||
assertNull(FormatInformation.decodeFormatInformation(0x2BE2 ^ 0x5412));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TestRunner.run(new DataMaskTestCase());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue