From 916871365fad339280f9608f804c43b941bb46d1 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Wed, 4 Mar 2015 18:53:06 +0100 Subject: [PATCH] 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. --- test/acceptance/renderer/point.js | 6 ++++-- test/support/image.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/acceptance/renderer/point.js b/test/acceptance/renderer/point.js index d1ad220..e37f576 100644 --- a/test/acceptance/renderer/point.js +++ b/test/acceptance/renderer/point.js @@ -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(); }); }); \ No newline at end of file diff --git a/test/support/image.js b/test/support/image.js index 91964e5..062508d 100644 --- a/test/support/image.js +++ b/test/support/image.js @@ -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) {