Add private maxColourDistance for functional tests

Switch MSE-based tests to use it

Remove experimental MSE-based compare API
This commit is contained in:
Lovell Fuller
2015-05-19 17:57:03 +01:00
parent ef8db1eebf
commit 8832ae0bf9
16 changed files with 172 additions and 446 deletions

View File

@@ -3,10 +3,7 @@
var path = require('path');
var assert = require('assert');
var sharp = require('../../index');
// Constants
var MAX_ALLOWED_MEAN_SQUARED_ERROR = 0.0005;
var maxColourDistance = require('../../build/Release/sharp')._maxColourDistance;
// Helpers
var getPath = function(filename) {
@@ -130,29 +127,21 @@ module.exports = {
});
},
assertEqual: function(actualImagePath, expectedImagePath, callback) {
assertMaxColourDistance: function(actualImagePath, expectedImagePath, acceptedDistance) {
if (typeof actualImagePath !== 'string') {
throw new TypeError('`actualImagePath` must be a string; got ' + actualImagePath);
}
if (typeof expectedImagePath !== 'string') {
throw new TypeError('`expectedImagePath` must be a string; got ' + expectedImagePath);
}
if (typeof callback !== 'function') {
throw new TypeError('`callback` must be a function');
if (typeof acceptedDistance !== 'number') {
// Default threshold
acceptedDistance = 1;
}
var distance = maxColourDistance(actualImagePath, expectedImagePath);
if (distance > acceptedDistance) {
throw new Error('Expected maximum absolute distance of ' + acceptedDistance + ', actual ' + distance);
}
sharp.compare(actualImagePath, expectedImagePath, function (error, info) {
if (error) return callback(error);
var meanSquaredError = info.meanSquaredError;
if (typeof meanSquaredError !== 'undefined' && meanSquaredError > MAX_ALLOWED_MEAN_SQUARED_ERROR) {
return callback(new Error('Expected images be equal. Mean squared error: ' + meanSquaredError + '.'));
}
return callback(null, info);
});
}
};