diff --git a/lib/src/test/java/de/edux/augmentation/effects/BrightnessAugmentationTest.java b/lib/src/test/java/de/edux/augmentation/effects/BrightnessAugmentationTest.java index 9471a6b..6d28fe8 100644 --- a/lib/src/test/java/de/edux/augmentation/effects/BrightnessAugmentationTest.java +++ b/lib/src/test/java/de/edux/augmentation/effects/BrightnessAugmentationTest.java @@ -1,94 +1,100 @@ package de.edux.augmentation.effects; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; +import static de.edux.augmentation.AugmentationTestUtils.loadTestImage; +import static de.edux.augmentation.AugmentationTestUtils.openImageInPreview; +import static org.junit.jupiter.api.Assertions.*; -import javax.imageio.ImageIO; import java.awt.image.BufferedImage; -import static org.junit.jupiter.api.Assertions.*; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; - -import static de.edux.augmentation.AugmentationTestUtils.loadTestImage; -import static de.edux.augmentation.AugmentationTestUtils.openImageInPreview; +import javax.imageio.ImageIO; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; public class BrightnessAugmentationTest { - private BufferedImage originalImage; - private BufferedImage augmentedImage; - - - @AfterEach - public void checkConformity() throws IOException { - int[] originalPixels = - originalImage.getRGB(0, 0, originalImage.getWidth(), originalImage.getHeight(), null, 0, originalImage.getWidth()); - int[] augmentedPixels = - augmentedImage.getRGB( - 0, - 0, - augmentedImage.getWidth(), - augmentedImage.getHeight(), - null, - 0, - augmentedImage.getWidth()); - - assertNotNull(augmentedImage, "Augmented image should not be null."); - - assertEquals( - originalImage.getWidth(), - augmentedImage.getWidth(), - "Augmented image width should match the specified width."); - assertEquals( - originalImage.getHeight(), - augmentedImage.getHeight(), - "Augmented image height should match the specified height."); - assertFalse( - Arrays.equals(originalPixels, augmentedPixels), - "The augmented image should differ from the original."); - - Path outputPath = Paths.get("augmented.png"); - ImageIO.write(augmentedImage, "png", outputPath.toFile()); - - assertTrue(Files.exists(outputPath), "Output image file should exist."); - assertTrue(Files.size(outputPath) > 0, "Output image file should not be empty."); - } - @Test - public void shouldIncreaseBrightness() throws IOException, InterruptedException { - originalImage = loadTestImage("augmentation" + File.separator + "fireworks.png"); - - double testValue = 0.5; - BrightnessAugmentation augmentation = new BrightnessAugmentation(testValue); - augmentedImage = augmentation.apply(originalImage); - - for (int y = 0; y < originalImage.getHeight(); y++){ - for (int x = 0; x < originalImage.getWidth(); x++){ - assertTrue(originalImage.getRGB(x,y) <= augmentedImage.getRGB(x,y)); - } - } - - openImageInPreview(originalImage); - openImageInPreview(augmentedImage); + private BufferedImage originalImage; + private BufferedImage augmentedImage; + + @AfterEach + public void checkConformity() throws IOException { + int[] originalPixels = + originalImage.getRGB( + 0, + 0, + originalImage.getWidth(), + originalImage.getHeight(), + null, + 0, + originalImage.getWidth()); + int[] augmentedPixels = + augmentedImage.getRGB( + 0, + 0, + augmentedImage.getWidth(), + augmentedImage.getHeight(), + null, + 0, + augmentedImage.getWidth()); + + assertNotNull(augmentedImage, "Augmented image should not be null."); + + assertEquals( + originalImage.getWidth(), + augmentedImage.getWidth(), + "Augmented image width should match the specified width."); + assertEquals( + originalImage.getHeight(), + augmentedImage.getHeight(), + "Augmented image height should match the specified height."); + assertFalse( + Arrays.equals(originalPixels, augmentedPixels), + "The augmented image should differ from the original."); + + Path outputPath = Paths.get("augmented.png"); + ImageIO.write(augmentedImage, "png", outputPath.toFile()); + + assertTrue(Files.exists(outputPath), "Output image file should exist."); + assertTrue(Files.size(outputPath) > 0, "Output image file should not be empty."); + } + + @Test + public void shouldIncreaseBrightness() throws IOException, InterruptedException { + originalImage = loadTestImage("augmentation" + File.separator + "shaman-shadows.png"); + + double testValue = 0.35; + BrightnessAugmentation augmentation = new BrightnessAugmentation(testValue); + augmentedImage = augmentation.apply(originalImage); + + for (int y = 0; y < originalImage.getHeight(); y++) { + for (int x = 0; x < originalImage.getWidth(); x++) { + assertTrue(originalImage.getRGB(x, y) <= augmentedImage.getRGB(x, y)); + } } - @Test - public void shouldDecreaseBrightness() throws IOException, InterruptedException { - originalImage = loadTestImage("augmentation" + File.separator + "national-park.png"); + openImageInPreview(originalImage); + openImageInPreview(augmentedImage); + } - double testValue= -0.5; - BrightnessAugmentation augmentation = new BrightnessAugmentation(testValue); - augmentedImage = augmentation.apply(originalImage); + @Test + public void shouldDecreaseBrightness() throws IOException, InterruptedException { + originalImage = loadTestImage("augmentation" + File.separator + "shaman-shadows.png"); - for (int y = 0; y < originalImage.getHeight(); y++){ - for (int x = 0; x < originalImage.getWidth(); x++){ - assertTrue(originalImage.getRGB(x,y) >= augmentedImage.getRGB(x,y)); - } - } + double testValue = -0.5; + BrightnessAugmentation augmentation = new BrightnessAugmentation(testValue); + augmentedImage = augmentation.apply(originalImage); - openImageInPreview(originalImage); - openImageInPreview(augmentedImage); + for (int y = 0; y < originalImage.getHeight(); y++) { + for (int x = 0; x < originalImage.getWidth(); x++) { + assertTrue(originalImage.getRGB(x, y) >= augmentedImage.getRGB(x, y)); + } } + + openImageInPreview(originalImage); + openImageInPreview(augmentedImage); + } } diff --git a/lib/src/test/resources/augmentation/shaman-shadows.png b/lib/src/test/resources/augmentation/shaman-shadows.png new file mode 100644 index 0000000..87f6566 Binary files /dev/null and b/lib/src/test/resources/augmentation/shaman-shadows.png differ