mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Improve code coverage in some core classes, plus fix a small BitMatrix bug
This commit is contained in:
parent
39da927362
commit
0895b3cefa
|
@ -311,7 +311,7 @@ public final class BitMatrix implements Cloneable {
|
|||
return null;
|
||||
}
|
||||
|
||||
return new int[] {left, top, right - left, bottom - top};
|
||||
return new int[] {left, top, right - left + 1, bottom - top + 1};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -201,6 +201,7 @@ final class ModulusPoly {
|
|||
return new ModulusPoly(field, product);
|
||||
}
|
||||
|
||||
/*
|
||||
ModulusPoly[] divide(ModulusPoly other) {
|
||||
if (!field.equals(other.field)) {
|
||||
throw new IllegalArgumentException("ModulusPolys do not have same ModulusGF field");
|
||||
|
@ -226,6 +227,7 @@ final class ModulusPoly {
|
|||
|
||||
return new ModulusPoly[] { quotient, remainder };
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright 2014 ZXing authors
|
||||
*
|
||||
* 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;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public final class RGBLuminanceSourceTestCase extends Assert {
|
||||
|
||||
private static final RGBLuminanceSource SOURCE = new RGBLuminanceSource(3, 3, new int[] {
|
||||
0x000000, 0x7F7F7F, 0xFFFFFF,
|
||||
0xFF0000, 0x00FF00, 0x0000FF,
|
||||
0x0000FF, 0x00FF00, 0xFF0000});
|
||||
|
||||
@Test
|
||||
public void testCrop() {
|
||||
assertTrue(SOURCE.isCropSupported());
|
||||
LuminanceSource cropped = SOURCE.crop(1, 1, 1, 1);
|
||||
assertEquals(1, cropped.getHeight());
|
||||
assertEquals(1, cropped.getWidth());
|
||||
assertArrayEquals(new byte[] { 0x7F }, cropped.getRow(0, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatrix() {
|
||||
assertArrayEquals(new byte[] { 0x00, 0x7F, (byte) 0xFF, 0x3F, 0x7F, 0x3F, 0x3F, 0x7F, 0x3F },
|
||||
SOURCE.getMatrix());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRow() {
|
||||
assertArrayEquals(new byte[] { 0x3F, 0x7F, 0x3F }, SOURCE.getRow(2, new byte[3]));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
assertEquals("#+ \n#+#\n#+#\n", SOURCE.toString());
|
||||
}
|
||||
|
||||
}
|
|
@ -133,6 +133,17 @@ public final class BitArrayTestCase extends Assert {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetRange() {
|
||||
BitArray array = new BitArray(64);
|
||||
array.setRange(28, 36);
|
||||
assertFalse(array.get(27));
|
||||
for (int i = 28; i < 36; i++) {
|
||||
assertTrue(array.get(i));
|
||||
}
|
||||
assertFalse(array.get(36));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClear() {
|
||||
BitArray array = new BitArray(32);
|
||||
|
@ -145,6 +156,16 @@ public final class BitArrayTestCase extends Assert {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFlip() {
|
||||
BitArray array = new BitArray(32);
|
||||
assertFalse(array.get(5));
|
||||
array.flip(5);
|
||||
assertTrue(array.get(5));
|
||||
array.flip(5);
|
||||
assertFalse(array.get(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetArray() {
|
||||
BitArray array = new BitArray(64);
|
||||
|
@ -189,6 +210,28 @@ public final class BitArrayTestCase extends Assert {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClone() {
|
||||
BitArray array = new BitArray(32);
|
||||
array.clone().set(0);
|
||||
assertFalse(array.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
BitArray a = new BitArray(32);
|
||||
BitArray b = new BitArray(32);
|
||||
assertEquals(a, b);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
assertNotEquals(a, new BitArray(31));
|
||||
a.set(16);
|
||||
assertNotEquals(a, new BitArray(31));
|
||||
assertNotEquals(a.hashCode(), b.hashCode());
|
||||
b.set(16);
|
||||
assertEquals(a, b);
|
||||
assertEquals(a.hashCode(), b.hashCode());
|
||||
}
|
||||
|
||||
private static int[] reverseOriginal(int[] oldBits, int size) {
|
||||
int[] newBits = new int[oldBits.length];
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
|
|
@ -56,6 +56,34 @@ public final class BitMatrixTestCase extends Assert {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnclosing() {
|
||||
BitMatrix matrix = new BitMatrix(5);
|
||||
assertNull(matrix.getEnclosingRectangle());
|
||||
matrix.setRegion(1, 1, 1, 1);
|
||||
assertArrayEquals(new int[] { 1, 1, 1, 1 }, matrix.getEnclosingRectangle());
|
||||
matrix.setRegion(1, 1, 3, 2);
|
||||
assertArrayEquals(new int[] { 1, 1, 3, 2 }, matrix.getEnclosingRectangle());
|
||||
matrix.setRegion(0, 0, 5, 5);
|
||||
assertArrayEquals(new int[] { 0, 0, 5, 5 }, matrix.getEnclosingRectangle());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnBit() {
|
||||
BitMatrix matrix = new BitMatrix(5);
|
||||
assertNull(matrix.getTopLeftOnBit());
|
||||
assertNull(matrix.getBottomRightOnBit());
|
||||
matrix.setRegion(1, 1, 1, 1);
|
||||
assertArrayEquals(new int[] { 1, 1 }, matrix.getTopLeftOnBit());
|
||||
assertArrayEquals(new int[] { 1, 1 }, matrix.getBottomRightOnBit());
|
||||
matrix.setRegion(1, 1, 3, 2);
|
||||
assertArrayEquals(new int[] { 1, 1 }, matrix.getTopLeftOnBit());
|
||||
assertArrayEquals(new int[] { 3, 2 }, matrix.getBottomRightOnBit());
|
||||
matrix.setRegion(0, 0, 5, 5);
|
||||
assertArrayEquals(new int[] { 0, 0 }, matrix.getTopLeftOnBit());
|
||||
assertArrayEquals(new int[] { 4, 4 }, matrix.getBottomRightOnBit());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRectangularMatrix() {
|
||||
BitMatrix matrix = new BitMatrix(75, 20);
|
||||
|
|
Loading…
Reference in a new issue