From e6fa0085b6ffb1c1f68cb77e8a41ec12538abde1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 8 Apr 2013 19:51:14 -0700 Subject: [PATCH] Update all tests that depend on old Adobe Illustrator data to either use better data or more tolerance. --- test/lib/helpers.js | 5 +++-- test/tests/Group.js | 8 ++++---- test/tests/Path_Bounds.js | 16 ++++++++-------- test/tests/Path_Length.js | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/test/lib/helpers.js b/test/lib/helpers.js index 6c8dc8ec..e66c2a34 100644 --- a/test/lib/helpers.js +++ b/test/lib/helpers.js @@ -59,8 +59,9 @@ function asyncTest(testName, expected) { }); } -function compareNumbers(number1, number2, message) { - equals(Format.number(number1), Format.number(number2), message); +function compareNumbers(number1, number2, message, precision) { + equals(Format.number(number1, precision), + Format.number(number2, precision), message); } function compareArrays(array1, array2, message) { diff --git a/test/tests/Group.js b/test/tests/Group.js index e4a0b246..c29a3c13 100644 --- a/test/tests/Group.js +++ b/test/tests/Group.js @@ -66,11 +66,11 @@ test('Group bounds', function() { compareRectangles(group.strokeBounds, { x: 87.5, y: 87.5, width: 175, height: 175 }, 'group.strokeBounds'); group.rotate(20); - compareRectangles(group.bounds, { x: 89.97681, y: 82.94095, width: 170.04639, height: 177.08224 }, 'rotated group.bounds'); - compareRectangles(group.strokeBounds, { x: 87.47681, y: 80.44095, width: 175.04639, height: 182.08224 }, 'rotated group.strokeBounds'); + compareRectangles(group.bounds, { x: 89.97687, y: 82.94085, width: 170.04627, height: 177.08228 }, 'rotated group.bounds'); + compareRectangles(group.strokeBounds, { x: 87.47687, y: 80.44085, width: 175.04627, height: 182.08228 }, 'rotated group.strokeBounds'); group.rotate(20, new Point(50, 50)); - compareRectangles(group.bounds, { x: 39.70692, y: 114.99196, width: 170.00412, height: 180.22401 }, 'rotated group.bounds'); - compareRectangles(group.strokeBounds, { x: 37.20692, y: 112.49196, width: 175.00412, height: 185.22401 }, 'rotated group.strokeBounds'); + compareRectangles(group.bounds, { x: 39.70708, y: 114.9919, width: 170.00396, height: 180.22418 }, 'rotated group.bounds'); + compareRectangles(group.strokeBounds, { x: 37.20708, y: 112.4919, width: 175.00396, height: 185.22418 }, 'rotated group.strokeBounds'); }); test('group.addChildren(otherGroup.children)', function() { diff --git a/test/tests/Path_Bounds.js b/test/tests/Path_Bounds.js index 01c0d6d8..4e389932 100644 --- a/test/tests/Path_Bounds.js +++ b/test/tests/Path_Bounds.js @@ -21,31 +21,31 @@ test('path.bounds', function() { // Test both closed and open paths, as the bounds for them differ path.closed = false; compareRectangles(path.bounds, - { x: 121, y: 275.06796, width: 149.49304, height: 145.87686 }, + { x: 121, y: 275.068, width: 149.49305, height: 145.87682 }, 'open path.bounds'); comparePoints(path.position, - { x: 195.74652, y: 348.00641 }, + { x: 195.74653, y: 348.00641 }, 'open path.position'); // Test both closed and open paths, as the bounds for them differ path.closed = true; compareRectangles(path.bounds, - { x: 114.82726, y: 275.06796, width: 155.66579, height: 148.12778 }, + { x: 114.82725, y: 275.068, width: 155.6658, height: 148.12773 }, 'closed path.bounds'); comparePoints(path.position, - { x: 192.66016, y: 349.13184 }, + { x: 192.66015, y: 349.13186 }, 'closed path.position'); // Scale the path by 0.5 and check bounds path.scale(0.5); compareRectangles(path.bounds, - { x: 153.7437, y: 312.09976, width: 77.8329, height: 74.06381 }, + { x: 153.7437, y: 312.09993, width: 77.8329, height: 74.06386 }, 'scaled path.bounds'); // Move the path to another position and check bounds path.position = [100, 100]; compareRectangles(path.bounds, - { x: 61.08355, y: 62.96797, width: 77.83289, height: 74.06384 }, + { x: 61.08355, y: 62.96807, width: 77.8329, height: 74.06386 }, 'moved path.bounds'); // Set new bounds and check segment list as result of resizing / positioning @@ -57,7 +57,7 @@ test('path.bounds', function() { // Now rotate by 40 degrees and test bounds and segments again. path.rotate(40); compareRectangles(path.bounds, - { x: 92.38109, y: 106.78957, width: 191.4803, height: 203.66878 }, + { x: 92.38102, y: 106.78972, width: 191.48071, height: 203.66876 }, 'rotated path.bounds'); equals(path.segments.toString(), @@ -71,7 +71,7 @@ test('path.strokeBounds on path without stroke', function() { new Segment(new Point(248, 320), new Point(-42, -74), new Point(42, 74)), new Segment(new Point(205, 420.94482421875), new Point(66.7890625, -12.72802734375), new Point(-79, 15.05517578125)) ]); - compareRectangles(path.strokeBounds, { x: 121, y: 275.06796, width: 149.49304, height: 145.87686 }); + compareRectangles(path.strokeBounds, { x: 121, y: 275.068, width: 149.49305, height: 145.87682 }); }); test('path.bounds & path.strokeBounds with stroke styles', function() { diff --git a/test/tests/Path_Length.js b/test/tests/Path_Length.js index e4ee3e89..eb4fcdee 100644 --- a/test/tests/Path_Length.js +++ b/test/tests/Path_Length.js @@ -19,10 +19,10 @@ test('path.length', function() { ]); var length = path.length; - compareNumbers(length, 172.10122680664062); + compareNumbers(length, 172.10122680664062, 'path.length', 4); var param = path.curves[0].getParameterAt(length / 4); - compareNumbers(param, 0.2255849553116685); + compareNumbers(param, 0.2255849553116685, 'path.curves[0].getParameterAt(length / 4)', 4); }); test('curve.getParameter with straight curve', function() {