Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
💚 Add test for percentage difference
Browse files Browse the repository at this point in the history
  • Loading branch information
saschagehlich committed May 16, 2017
1 parent d37c844 commit 511dddd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/image-comparator.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class ImageComparator {
const totalPixels = width * height
const percentageDifference = differences / totalPixels
if (this._options.thresholdType === Constants.THRESHOLD_PERCENT) {
threshold = threshold / totalPixels
threshold = percentageDifference
}

// Check if threshold is exceeded
Expand Down
10 changes: 6 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('Rembrandt', () => {
it('should be fulfilled with passed = true', (done) => {
rembrandt.compare()
.then((result) => {
result.passed.should.be.true
result.passed.should.equal(true)
result.threshold.should.equal(0)
done()
})
Expand Down Expand Up @@ -64,8 +64,10 @@ describe('Rembrandt', () => {
it('should be fulfilled with passed = false and thresholds = 3', (done) => {
rembrandt.compare()
.then((result) => {
result.passed.should.be.false
result.passed.should.equal(false)
result.threshold.should.equal(3)
result.differences.should.equal(3)
result.percentageDifference.should.equal(0.75)
done()
})
.catch((e) => done(e))
Expand All @@ -86,7 +88,7 @@ describe('Rembrandt', () => {
it('should be fulfilled with `compositionImage`', (done) => {
rembrandt.compare()
.then((result) => {
result.passed.should.be.false
result.passed.should.equal(false)
result.threshold.should.equal(3)
result.should.have.property('compositionImage')

Expand Down Expand Up @@ -129,7 +131,7 @@ describe('Rembrandt', () => {
it('should compare against the larger one', (done) => {
rembrandt.compare()
.then((result) => {
result.passed.should.be.false
result.passed.should.equal(false)
result.threshold.should.equal(5)
done()
})
Expand Down

0 comments on commit 511dddd

Please sign in to comment.