|
| 1 | +package com.github.romankh3.image.comparison; |
| 2 | + |
| 3 | +import com.github.romankh3.image.comparison.model.ImageComparisonResult; |
| 4 | +import com.github.romankh3.image.comparison.model.ImageComparisonState; |
| 5 | +import java.awt.image.BufferedImage; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.DisplayName; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 10 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 11 | + |
| 12 | +@DisplayName("Load tests for {@link simpleComparison} method") |
| 13 | +public class LoadTest { |
| 14 | + @Test |
| 15 | + @DisplayName("should result MisMatch for two images") |
| 16 | + public void simpleComparisonTest(){ |
| 17 | + //load images to be compared: |
| 18 | + BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("expected.png"); |
| 19 | + BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("actual.png"); |
| 20 | + |
| 21 | + //Create ImageComparison object and compare the images. |
| 22 | + ImageComparisonResult imageComparisonResult = new ImageComparison(expectedImage, actualImage).simpleComparison(); |
| 23 | + |
| 24 | + //Check the result |
| 25 | + assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult.getImageComparisonState()); |
| 26 | + } |
| 27 | + |
| 28 | + |
| 29 | + @Test |
| 30 | + @DisplayName("compare load differences between {@link simpleComparison} method and {@link compareImage} method") |
| 31 | + public void loadTest1(){ |
| 32 | + //load images to be compared: |
| 33 | + BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("expected.png"); |
| 34 | + BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("actual.png"); |
| 35 | + |
| 36 | + long time1 = System.currentTimeMillis(); |
| 37 | + //Create ImageComparison object and compare the images. |
| 38 | + ImageComparisonResult imageComparisonResult1 = new ImageComparison(expectedImage, actualImage).compareImages(); |
| 39 | + long etime1 = System.currentTimeMillis(); |
| 40 | + //Time for compareImage method |
| 41 | + long compareImageTime = etime1 - time1; |
| 42 | + |
| 43 | + //Check the result |
| 44 | + assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult1.getImageComparisonState()); |
| 45 | + |
| 46 | + long time2 = System.currentTimeMillis(); |
| 47 | + //Create ImageComparison2 object and compare the images. |
| 48 | + ImageComparisonResult imageComparisonResult2 = new ImageComparison(expectedImage, actualImage).simpleComparison(); |
| 49 | + long etime2 = System.currentTimeMillis(); |
| 50 | + //Time for simpleComparison method |
| 51 | + long simpleComparisonTime = etime2 - time2; |
| 52 | + |
| 53 | + //Check the result |
| 54 | + assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult2.getImageComparisonState()); |
| 55 | + //check the load differences between simpleComparison and compareImage pattern |
| 56 | + assertTrue(simpleComparisonTime < compareImageTime); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + @DisplayName("compare load differences between {@link simpleComparison} method and {@link compareImage} method") |
| 61 | + public void loadTest2(){ |
| 62 | + //load images to be compared: |
| 63 | + BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("expected#201.png"); |
| 64 | + BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("actual#201.png"); |
| 65 | + |
| 66 | + long time1 = System.currentTimeMillis(); |
| 67 | + //Create ImageComparison object and compare the images. |
| 68 | + ImageComparisonResult imageComparisonResult1 = new ImageComparison(expectedImage, actualImage).compareImages(); |
| 69 | + long etime1 = System.currentTimeMillis(); |
| 70 | + //Time for compareImage method |
| 71 | + long compareImageTime = etime1 - time1; |
| 72 | + |
| 73 | + //Check the result |
| 74 | + assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult1.getImageComparisonState()); |
| 75 | + |
| 76 | + long time2 = System.currentTimeMillis(); |
| 77 | + //Create ImageComparison2 object and compare the images. |
| 78 | + ImageComparisonResult imageComparisonResult2 = new ImageComparison(expectedImage, actualImage).simpleComparison(); |
| 79 | + long etime2 = System.currentTimeMillis(); |
| 80 | + //Time for simpleComparison method |
| 81 | + long simpleComparisonTime = etime2 - time2; |
| 82 | + |
| 83 | + //Check the result |
| 84 | + assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult2.getImageComparisonState()); |
| 85 | + //check the load differences between simpleComparison and compareImage pattern |
| 86 | + assertTrue(simpleComparisonTime < compareImageTime); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + @DisplayName("compare load differences between {@link simpleComparison} method and {@link compareImage} method") |
| 91 | + public void loadTest3(){ |
| 92 | + //load images to be compared: |
| 93 | + BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("expected#98.png"); |
| 94 | + BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("actual#98.png"); |
| 95 | + |
| 96 | + long time1 = System.currentTimeMillis(); |
| 97 | + //Create ImageComparison object and compare the images. |
| 98 | + ImageComparisonResult imageComparisonResult1 = new ImageComparison(expectedImage, actualImage).compareImages(); |
| 99 | + long etime1 = System.currentTimeMillis(); |
| 100 | + //Time for compareImage method |
| 101 | + long compareImageTime = etime1 - time1; |
| 102 | + |
| 103 | + //Check the result |
| 104 | + assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult1.getImageComparisonState()); |
| 105 | + |
| 106 | + long time2 = System.currentTimeMillis(); |
| 107 | + //Create ImageComparison2 object and compare the images. |
| 108 | + ImageComparisonResult imageComparisonResult2 = new ImageComparison(expectedImage, actualImage).simpleComparison(); |
| 109 | + long etime2 = System.currentTimeMillis(); |
| 110 | + //Time for simpleComparison method |
| 111 | + long simpleComparisonTime = etime2 - time2; |
| 112 | + |
| 113 | + //Check the result |
| 114 | + assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult2.getImageComparisonState()); |
| 115 | + //check the load differences between simpleComparison and compareImage pattern |
| 116 | + assertTrue(simpleComparisonTime < compareImageTime); |
| 117 | + } |
| 118 | + |
| 119 | +} |
0 commit comments