-
-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement simpleComparison() and create load tests for issue #119 and #174 #220
Merged
romankh3
merged 3 commits into
romankh3:master
from
Hannnnnnn404:feature/simplecomparison
Jun 17, 2024
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/test/java/com/github/romankh3/image/comparison/LoadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.github.romankh3.image.comparison; | ||
|
||
import com.github.romankh3.image.comparison.model.ImageComparisonResult; | ||
import com.github.romankh3.image.comparison.model.ImageComparisonState; | ||
import java.awt.image.BufferedImage; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@DisplayName("Load tests for {@link simpleComparison} method") | ||
public class LoadTest { | ||
@Test | ||
@DisplayName("should result MisMatch for two images") | ||
public void simpleComparisonTest(){ | ||
//load images to be compared: | ||
BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("expected.png"); | ||
BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("actual.png"); | ||
|
||
//Create ImageComparison object and compare the images. | ||
ImageComparisonResult imageComparisonResult = new ImageComparison(expectedImage, actualImage).simpleComparison(); | ||
|
||
//Check the result | ||
assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult.getImageComparisonState()); | ||
} | ||
|
||
|
||
@Test | ||
@DisplayName("compare load differences between {@link simpleComparison} method and {@link compareImage} method") | ||
public void loadTest1(){ | ||
//load images to be compared: | ||
BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("expected.png"); | ||
BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("actual.png"); | ||
|
||
long time1 = System.currentTimeMillis(); | ||
//Create ImageComparison object and compare the images. | ||
ImageComparisonResult imageComparisonResult1 = new ImageComparison(expectedImage, actualImage).compareImages(); | ||
long etime1 = System.currentTimeMillis(); | ||
//Time for compareImage method | ||
long compareImageTime = etime1 - time1; | ||
|
||
//Check the result | ||
assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult1.getImageComparisonState()); | ||
|
||
long time2 = System.currentTimeMillis(); | ||
//Create ImageComparison2 object and compare the images. | ||
ImageComparisonResult imageComparisonResult2 = new ImageComparison(expectedImage, actualImage).simpleComparison(); | ||
long etime2 = System.currentTimeMillis(); | ||
//Time for simpleComparison method | ||
long simpleComparisonTime = etime2 - time2; | ||
|
||
//Check the result | ||
assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult2.getImageComparisonState()); | ||
//check the load differences between simpleComparison and compareImage pattern | ||
assertTrue(simpleComparisonTime < compareImageTime); | ||
} | ||
|
||
@Test | ||
@DisplayName("compare load differences between {@link simpleComparison} method and {@link compareImage} method") | ||
public void loadTest2(){ | ||
//load images to be compared: | ||
BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("expected#201.png"); | ||
BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("actual#201.png"); | ||
|
||
long time1 = System.currentTimeMillis(); | ||
//Create ImageComparison object and compare the images. | ||
ImageComparisonResult imageComparisonResult1 = new ImageComparison(expectedImage, actualImage).compareImages(); | ||
long etime1 = System.currentTimeMillis(); | ||
//Time for compareImage method | ||
long compareImageTime = etime1 - time1; | ||
|
||
//Check the result | ||
assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult1.getImageComparisonState()); | ||
|
||
long time2 = System.currentTimeMillis(); | ||
//Create ImageComparison2 object and compare the images. | ||
ImageComparisonResult imageComparisonResult2 = new ImageComparison(expectedImage, actualImage).simpleComparison(); | ||
long etime2 = System.currentTimeMillis(); | ||
//Time for simpleComparison method | ||
long simpleComparisonTime = etime2 - time2; | ||
|
||
//Check the result | ||
assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult2.getImageComparisonState()); | ||
//check the load differences between simpleComparison and compareImage pattern | ||
assertTrue(simpleComparisonTime < compareImageTime); | ||
} | ||
|
||
@Test | ||
@DisplayName("compare load differences between {@link simpleComparison} method and {@link compareImage} method") | ||
public void loadTest3(){ | ||
//load images to be compared: | ||
BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("expected#98.png"); | ||
BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("actual#98.png"); | ||
|
||
long time1 = System.currentTimeMillis(); | ||
//Create ImageComparison object and compare the images. | ||
ImageComparisonResult imageComparisonResult1 = new ImageComparison(expectedImage, actualImage).compareImages(); | ||
long etime1 = System.currentTimeMillis(); | ||
//Time for compareImage method | ||
long compareImageTime = etime1 - time1; | ||
|
||
//Check the result | ||
assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult1.getImageComparisonState()); | ||
|
||
long time2 = System.currentTimeMillis(); | ||
//Create ImageComparison2 object and compare the images. | ||
ImageComparisonResult imageComparisonResult2 = new ImageComparison(expectedImage, actualImage).simpleComparison(); | ||
long etime2 = System.currentTimeMillis(); | ||
//Time for simpleComparison method | ||
long simpleComparisonTime = etime2 - time2; | ||
|
||
//Check the result | ||
assertEquals(ImageComparisonState.MISMATCH, imageComparisonResult2.getImageComparisonState()); | ||
//check the load differences between simpleComparison and compareImage pattern | ||
assertTrue(simpleComparisonTime < compareImageTime); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, follow general way for creating tests with BDD blocks:
//given
//when
//then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that I should code tests following the BDD style? I‘m trying to modified my tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.