Permalink
Browse files

TMI-43: Made tests a little more robust to void false positives.

  • Loading branch information...
1 parent aacad8a commit c3c23d052356b730ff8be488e51596be56a20b74 @haraldk haraldk committed Mar 3, 2014
@@ -513,9 +513,7 @@ public void testInvertedColors() throws IOException {
// Validate strip colors
for (int i = 0; i < strip.getWidth() / 128; i++) {
int actualRGB = strip.getRGB(i * 128, 4);
- assertEquals((actualRGB >> 16) & 0xff, (expectedRGB[i] >> 16) & 0xff, 5);
- assertEquals((actualRGB >> 8) & 0xff, (expectedRGB[i] >> 8) & 0xff, 5);
- assertEquals((actualRGB) & 0xff, (expectedRGB[i]) & 0xff, 5);
+ assertRGBEquals(expectedRGB[i], actualRGB);
}
}
@@ -543,9 +541,7 @@ public void testThumbnailInvertedColors() throws IOException {
// Validate strip colors
for (int i = 0; i < thumbnail.getWidth() / 8; i++) {
int actualRGB = thumbnail.getRGB(i * 8, 4);
- assertEquals((actualRGB >> 16) & 0xff, (expectedRGB[i] >> 16) & 0xff, 5);
- assertEquals((actualRGB >> 8) & 0xff, (expectedRGB[i] >> 8) & 0xff, 5);
- assertEquals((actualRGB) & 0xff, (expectedRGB[i]) & 0xff, 5);
+ assertRGBEquals(expectedRGB[i], actualRGB);
}
}
@@ -680,12 +676,19 @@ public void testReadNoJFIFYCbCr() throws IOException {
// Validate strip colors
for (int i = 0; i < image.getWidth() / 10; i++) {
int actualRGB = image.getRGB(i * 10, 7);
- assertEquals((actualRGB >> 16) & 0xff, (expectedRGB[i] >> 16) & 0xff, 5);
- assertEquals((actualRGB >> 8) & 0xff, (expectedRGB[i] >> 8) & 0xff, 5);
- assertEquals((actualRGB ) & 0xff, (expectedRGB[i] ) & 0xff, 5);
+ assertRGBEquals(expectedRGB[i], actualRGB);
}
}
+ /**
+ * Slightly fuzzy RGB equals method. Tolerance +/-5 steps.
+ */
+ private void assertRGBEquals(int expectedRGB, int actualRGB) {
+ assertEquals((expectedRGB >> 16) & 0xff, (actualRGB >> 16) & 0xff, 5);
+ assertEquals((expectedRGB >> 8) & 0xff, (actualRGB >> 8) & 0xff, 5);
+ assertEquals((expectedRGB ) & 0xff, (actualRGB ) & 0xff, 5);
+ }
+
// Regression: Test subsampling offset within of bounds
// NOTE: These tests assumes the reader will read at least 1024 scanlines (if available) each iteration,
// this might change in the future. If so, the tests will no longer test what tey are supposed to....
@@ -716,8 +719,8 @@ public void testReadSubsamplingNotSkippingLines1028() throws IOException {
assertNotNull(image);
// Make sure correct color is actually read, not just left empty
- assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2) & 0xffffff);
- assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1) & 0xffffff);
+ assertRGBEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2));
+ assertRGBEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1));
}
@Test
@@ -733,8 +736,8 @@ public void testReadSubsamplingBounds1027() throws IOException {
assertNotNull(image);
// Make sure correct color is actually read, not just left empty
- assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2) & 0xffffff);
- assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1) & 0xffffff);
+ assertRGBEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2));
+ assertRGBEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1));
}
@Test
@@ -750,8 +753,8 @@ public void testReadSubsamplingBounds1026() throws IOException {
assertNotNull(image);
// Make sure correct color is actually read, not just left empty
- assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2) & 0xffffff);
- assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1) & 0xffffff);
+ assertRGBEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2));
+ assertRGBEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1));
}
@Test
@@ -781,8 +784,8 @@ public void testReadSubsamplingNotSkippingLines1025() throws IOException {
assertNotNull(image);
// Make sure correct color is actually read, not just left empty
- assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2) & 0xffffff);
- assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1) & 0xffffff);
+ assertRGBEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2));
+ assertRGBEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1));
}
@Test
@@ -798,8 +801,8 @@ public void testReadSubsamplingBounds1024() throws IOException {
assertNotNull(image);
// Make sure correct color is actually read, not just left empty
- assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2) & 0xffffff);
- assertEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1) & 0xffffff);
+ assertRGBEquals(0xfefefd, image.getRGB(0, image.getHeight() - 2));
+ assertRGBEquals(0xfefefd, image.getRGB(0, image.getHeight() - 1));
}
@Test

0 comments on commit c3c23d0

Please sign in to comment.