image.compare returns the % difference against the reference image
As canvas can differ from one implementation to another make tests to have a tolerance to differences.
This commit is contained in:
parent
ddffe412c6
commit
916871365f
@ -3,6 +3,8 @@ var image = require('../../support/image');
|
||||
|
||||
QUnit.module('renderer/point');
|
||||
|
||||
var IMAGE_DIFF_TOLERANCE = 4 / 100;
|
||||
|
||||
asyncTest('navy example', function(assert) {
|
||||
var cartocss = [
|
||||
'Map {',
|
||||
@ -33,7 +35,7 @@ asyncTest('navy example', function(assert) {
|
||||
pointRenderer.getTile('default_navy_3-3-2.torque.json', cartocss, 3, 3, 2, step, function(err, canvas) {
|
||||
assert.ok(!err, 'no error while getting tile');
|
||||
var imageDiff = image.compare(canvas.toBuffer(), 'default_navy_3-3-2.png');
|
||||
assert.equal(imageDiff, 0, 'navy tile is ok');
|
||||
assert.ok(imageDiff < IMAGE_DIFF_TOLERANCE, 'navy tile is ok');
|
||||
QUnit.start();
|
||||
});
|
||||
});
|
||||
@ -58,7 +60,7 @@ asyncTest('basic heatmap', function(assert) {
|
||||
pointRenderer.getTile('heatmap_navy_3-2-3.torque.json', cartocss, 3, 2, 3, step, function(err, canvas) {
|
||||
assert.ok(!err, 'no error while getting tile');
|
||||
var imageDiff = image.compare(canvas.toBuffer(), 'heatmap_navy_3-2-3.png');
|
||||
assert.equal(imageDiff, 0, 'heatmap tile is ok');
|
||||
assert.ok(imageDiff < IMAGE_DIFF_TOLERANCE, 'heatmap tile is ok');
|
||||
QUnit.start();
|
||||
});
|
||||
});
|
@ -5,7 +5,7 @@ function compare(buffer, fixtureRelPath) {
|
||||
|
||||
var img = new mapnik.Image.fromBytesSync(buffer);
|
||||
var reference = new mapnik.Image.openSync(__dirname + '/../fixtures/image/' + fixtureRelPath);
|
||||
return img.compare(reference);
|
||||
return img.compare(reference) / (reference.width() * reference.height());
|
||||
}
|
||||
|
||||
function save(path, buffer) {
|
||||
|
Loading…
Reference in New Issue
Block a user