From fb6955e50948070c58d4ff270071e79b5dcaa24d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 4 May 2011 19:40:52 +0100 Subject: [PATCH] Replace compareSegments() / compareSegmentLists() calls with straight toString() compares. --- test/lib/helpers.js | 22 ---------------------- test/tests/Path.js | 25 +++++++------------------ test/tests/Path_Bounds.js | 4 ++-- test/tests/Path_Curves.js | 24 ++++++++++++------------ test/tests/Path_Drawing_Commands.js | 6 ++---- test/tests/Path_Shapes.js | 21 ++++++++++----------- test/tests/Segment.js | 24 ++++++++---------------- 7 files changed, 41 insertions(+), 85 deletions(-) diff --git a/test/lib/helpers.js b/test/lib/helpers.js index 1f42b806..ca204c62 100644 --- a/test/lib/helpers.js +++ b/test/lib/helpers.js @@ -1,25 +1,3 @@ -function compareSegmentLists(list1, list2) { - equals(list1.length, list2.length, 'segment count'); - if (list1.length == list2.length) { - for (var i = 0, l = list1.length; i < l; i++) { - compareSegments(list1[i], list2[i]); - } - } -} - -function compareSegments(segment1, segment2) { - // Convert comparison value through Segment.read, to not have to provide - // all handles all the time. - segment2 = Segment.read([segment2]); - var points = ['point', 'handleIn', 'handleOut']; - for (var i = 0; i < 3; i++) { - equals(!!segment1[points[i]], !!segment2[points[i]], - 'have ' + points[i]); - if (segment1[points[i]] && segment2[points[i]]) - comparePoints(segment1[points[i]], segment2[points[i]], points[i]); - } -} - function compareNumbers(number1, number2, message) { if (number1 !== 0) number1 = Math.round(number1 * 100) / 100; diff --git a/test/tests/Path.js b/test/tests/Path.js index c2079c9a..6a621506 100644 --- a/test/tests/Path.js +++ b/test/tests/Path.js @@ -11,8 +11,7 @@ test('path.join(path)', function() { path2.add([20, 10]); path.join(path2); - compareSegmentLists(path.segments, [new Segment(new Point(0, 0)), - new Segment(new Point(10, 0)), new Segment(new Point(20, 10))]); + equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }'); equals(doc.activeLayer.children.length, 1); var path = new Path(); @@ -23,8 +22,7 @@ test('path.join(path)', function() { path2.add([20, 10]); path2.add([10, 0]); path.join(path2); - compareSegmentLists(path.segments, [new Segment(new Point(0, 0)), - new Segment(new Point(10, 0)), new Segment(new Point(20, 10))]); + equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } }'); var path = new Path(); path.add([0, 0]); @@ -34,10 +32,8 @@ test('path.join(path)', function() { path2.add([30, 10]); path2.add([40, 0]); path.join(path2); - compareSegmentLists(path.segments, [new Segment(new Point(0, 0)), - new Segment(new Point(10, 0)), new Segment(new Point(30, 10)), - new Segment(new Point(40, 0))]); - + equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 30, y: 10 } },{ point: { x: 40, y: 0 } }'); + var path = new Path(); path.add([0, 0]); path.add([10, 0]); @@ -49,9 +45,8 @@ test('path.join(path)', function() { path2.add([20, 10]); path.join(path2); - compareSegmentLists(path.segments, [new Segment(new Point(0, 0)), - new Segment(new Point(10, 0)), new Segment(new Point(20, 10)), - new Segment(new Point(10, 5))]); + + equals(path.segments.toString(), '{ point: { x: 0, y: 0 } },{ point: { x: 10, y: 0 } },{ point: { x: 20, y: 10 } },{ point: { x: 10, y: 5 } }'); equals(path.closed, true); }); @@ -94,12 +89,6 @@ test('Path#reverse', function() { var doc = new Document(); var path = new Path.Circle([100, 100], 30); path.reverse(); - compareSegmentLists(path.segments, [new Segment(new Point(100, 130), - new Point(-16.568359375, 0), new Point(16.568359375, 0)), - new Segment(new Point(130, 100), new Point(0, 16.568359375), - new Point(0, -16.568359375)), new Segment(new Point(100, 70), - new Point(16.568359375, 0), new Point(-16.568359375, 0)), - new Segment(new Point(70, 100), new Point(0, -16.568359375), - new Point(0, 16.568359375))]); + equals(path.segments.toString(), '{ point: { x: 100, y: 130 }, handleIn: { x: -16.56854, y: 0 }, handleOut: { x: 16.56854, y: 0 } },{ point: { x: 130, y: 100 }, handleIn: { x: 0, y: 16.56854 }, handleOut: { x: 0, y: -16.56854 } },{ point: { x: 100, y: 70 }, handleIn: { x: 16.56854, y: 0 }, handleOut: { x: -16.56854, y: 0 } },{ point: { x: 70, y: 100 }, handleIn: { x: 0, y: -16.56854 }, handleOut: { x: 0, y: 16.56854 } }'); }); diff --git a/test/tests/Path_Bounds.js b/test/tests/Path_Bounds.js index 493dec51..b03cda90 100644 --- a/test/tests/Path_Bounds.js +++ b/test/tests/Path_Bounds.js @@ -27,11 +27,11 @@ test('path.bounds', function() { // Set new bounds and check segment list as result of resizing / positioning path.bounds = { x: 100, y: 100, width: 200, height: 200 }; - compareSegmentLists(path.segments, [{ point: { x: 107.93066, y: 179.56982 }, handleIn: { x: -24.41211, y: 51.30664 }, handleOut: { x: 39.52734, y: -83.08447 } }, { point: { x: 271.10107, y: 160.66553 }, handleIn: { x: -53.96289, y: -99.9126 }, handleOut: { x: 53.96143, y: 99.91406 } }, { point: { x: 215.85303, y: 296.96045 }, handleIn: { x: 85.81299, y: -17.18555 }, handleOut: { x: -101.49854, y: 20.32861 } }]) + equals(path.segments.toString(), '{ point: { x: 107.93077, y: 179.56917 }, handleIn: { x: -24.41127, y: 51.30707 }, handleOut: { x: 39.52904, y: -83.08194 } },{ point: { x: 271.10084, y: 160.66656 }, handleIn: { x: -53.96176, y: -99.91377 }, handleOut: { x: 53.96176, y: 99.91377 } },{ point: { x: 215.85428, y: 296.96086 }, handleIn: { x: 85.81084, y: -17.18521 }, handleOut: { x: -101.49949, y: 20.32729 } }'); // 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 }); - compareSegmentLists(path.segments, [{ point: { x: 142.60352, y: 125.16797 }, handleIn: { x: -51.67969, y: 23.6123 }, handleOut: { x: 83.68555, y: -38.23584 } }, { point: { x: 279.74902, y: 215.57178 }, handleIn: { x: 22.88672, y: -111.22461 }, handleOut: { x: -22.88623, y: 111.22412 } }, { point: { x: 149.82031, y: 284.4668 }, handleIn: { x: 76.78076, y: 41.99414 }, handleOut: { x: -90.81982, y: -49.66992 } }]); + equals(path.segments.toString(), '{ point: { x: 142.60356, y: 125.16811 }, handleIn: { x: -51.67967, y: 23.61224 }, handleOut: { x: 83.68504, y: -38.23568 } },{ point: { x: 279.74945, y: 215.57158 }, handleIn: { x: 22.88623, y: -111.22434 }, handleOut: { x: -22.88623, y: 111.22434 } },{ point: { x: 149.81984, y: 284.46726 }, handleIn: { x: 76.78135, y: 41.99351 }, handleOut: { x: -90.81925, y: -49.67101 } }'); }); \ No newline at end of file diff --git a/test/tests/Path_Curves.js b/test/tests/Path_Curves.js index 4b933548..be1129ab 100644 --- a/test/tests/Path_Curves.js +++ b/test/tests/Path_Curves.js @@ -6,22 +6,22 @@ test('path.curves Synchronisation', function() { var path = new Path(); path.add(new Point(0, 100)); - equals(path.segments.toString(), '{ point: { x: 0, y: 100 } }', 'path.segments: path.add(new Point(0, 100));'); - equals(path.curves.toString(), '', 'path.curves: path.add(new Point(0, 100));'); + equals(path.segments.toString(), "{ point: { x: 0, y: 100 } }", "path.segments: path.add(new Point(0, 100));"); + equals(path.curves.toString(), "", "path.curves: path.add(new Point(0, 100));"); path.add(new Point(100, 100)); - equals(path.segments.toString(), '{ point: { x: 0, y: 100 } },{ point: { x: 100, y: 100 } }', 'path.segments: path.add(new Point(100, 100));'); - equals(path.curves.toString(), '{ point1: { x: 0, y: 100 }, point2: { x: 100, y: 100 } }', 'path.curves: path.add(new Point(100, 100));'); + equals(path.segments.toString(), "{ point: { x: 0, y: 100 } },{ point: { x: 100, y: 100 } }", "path.segments: path.add(new Point(100, 100));"); + equals(path.curves.toString(), "{ point1: { x: 0, y: 100 }, point2: { x: 100, y: 100 } }", "path.curves: path.add(new Point(100, 100));"); path.insert(1, {point:[50, 0], handleIn:[-25, 0], handleOut:[25, 0]}); - equals(path.segments.toString(), '{ point: { x: 0, y: 100 } },{ point: { x: 50, y: 0 }, handleIn: { x: -25, y: 0 }, handleOut: { x: 25, y: 0 } },{ point: { x: 100, y: 100 } }', 'path.segments: path.insert(1, {point:[50, 0], handleIn:[-25, 0], handleOut:[25, 0]});'); - equals(path.curves.toString(), '{ point1: { x: 0, y: 100 }, handle2: { x: -25, y: 0 }, point2: { x: 50, y: 0 } },{ point1: { x: 50, y: 0 }, handle1: { x: 25, y: 0 }, point2: { x: 100, y: 100 } }', 'path.curves: path.insert(1, {point:[50, 0], handleIn:[-25, 0], handleOut:[25, 0]});'); + equals(path.segments.toString(), "{ point: { x: 0, y: 100 } },{ point: { x: 50, y: 0 }, handleIn: { x: -25, y: 0 }, handleOut: { x: 25, y: 0 } },{ point: { x: 100, y: 100 } }", "path.segments: path.insert(1, {point:[50, 0], handleIn:[-25, 0], handleOut:[25, 0]});"); + equals(path.curves.toString(), "{ point1: { x: 0, y: 100 }, handle2: { x: -25, y: 0 }, point2: { x: 50, y: 0 } },{ point1: { x: 50, y: 0 }, handle1: { x: 25, y: 0 }, point2: { x: 100, y: 100 } }", "path.curves: path.insert(1, {point:[50, 0], handleIn:[-25, 0], handleOut:[25, 0]});"); path.closed = true; - equals(path.segments.toString(), '{ point: { x: 0, y: 100 } },{ point: { x: 50, y: 0 }, handleIn: { x: -25, y: 0 }, handleOut: { x: 25, y: 0 } },{ point: { x: 100, y: 100 } }', 'path.segments: path.closed = true;'); - equals(path.curves.toString(), '{ point1: { x: 0, y: 100 }, handle2: { x: -25, y: 0 }, point2: { x: 50, y: 0 } },{ point1: { x: 50, y: 0 }, handle1: { x: 25, y: 0 }, point2: { x: 100, y: 100 } },{ point1: { x: 100, y: 100 }, point2: { x: 0, y: 100 } }', 'path.curves: path.closed = true;'); + equals(path.segments.toString(), "{ point: { x: 0, y: 100 } },{ point: { x: 50, y: 0 }, handleIn: { x: -25, y: 0 }, handleOut: { x: 25, y: 0 } },{ point: { x: 100, y: 100 } }", "path.segments: path.closed = true;"); + equals(path.curves.toString(), "{ point1: { x: 0, y: 100 }, handle2: { x: -25, y: 0 }, point2: { x: 50, y: 0 } },{ point1: { x: 50, y: 0 }, handle1: { x: 25, y: 0 }, point2: { x: 100, y: 100 } },{ point1: { x: 100, y: 100 }, point2: { x: 0, y: 100 } }", "path.curves: path.closed = true;"); path.removeSegments(2, 3); - equals(path.segments.toString(), '{ point: { x: 0, y: 100 } },{ point: { x: 50, y: 0 }, handleIn: { x: -25, y: 0 }, handleOut: { x: 25, y: 0 } }', 'path.segments: path.removeSegments(2, 3);'); - equals(path.curves.toString(), '{ point1: { x: 0, y: 100 }, handle2: { x: -25, y: 0 }, point2: { x: 50, y: 0 } },{ point1: { x: 50, y: 0 }, handle1: { x: 25, y: 0 }, point2: { x: 0, y: 100 } }', 'path.curves: path.removeSegments(2, 3);'); + equals(path.segments.toString(), "{ point: { x: 0, y: 100 } },{ point: { x: 50, y: 0 }, handleIn: { x: -25, y: 0 }, handleOut: { x: 25, y: 0 } }", "path.segments: path.removeSegments(2, 3);"); + equals(path.curves.toString(), "{ point1: { x: 0, y: 100 }, handle2: { x: -25, y: 0 }, point2: { x: 50, y: 0 } },{ point1: { x: 50, y: 0 }, handle1: { x: 25, y: 0 }, point2: { x: 0, y: 100 } }", "path.curves: path.removeSegments(2, 3);"); path.add(new Point(100, 100)); path.removeSegments(1, 2); - equals(path.segments.toString(), '{ point: { x: 0, y: 100 } },{ point: { x: 100, y: 100 } }', 'path.segments: path.add(new Point(100, 100));\n path.removeSegments(1, 2);'); - equals(path.curves.toString(), '{ point1: { x: 0, y: 100 }, point2: { x: 100, y: 100 } },{ point1: { x: 100, y: 100 }, point2: { x: 0, y: 100 } }', 'path.curves: path.add(new Point(100, 100));\n path.removeSegments(1, 2);'); + equals(path.segments.toString(), "{ point: { x: 0, y: 100 } },{ point: { x: 100, y: 100 } }", "path.segments: path.add(new Point(100, 100));\npath.removeSegments(1, 2);"); + equals(path.curves.toString(), "{ point1: { x: 0, y: 100 }, point2: { x: 100, y: 100 } },{ point1: { x: 100, y: 100 }, point2: { x: 0, y: 100 } }", "path.curves: path.add(new Point(100, 100));\npath.removeSegments(1, 2);"); }); diff --git a/test/tests/Path_Drawing_Commands.js b/test/tests/Path_Drawing_Commands.js index 9b4df79b..1f21c0e2 100644 --- a/test/tests/Path_Drawing_Commands.js +++ b/test/tests/Path_Drawing_Commands.js @@ -4,14 +4,12 @@ test('path.lineTo(point);', function() { var path = new Path(); path.moveTo([50, 50]); path.lineTo([100, 100]); - var expectedSegments = [{ point: { x: 50, y: 50 } }, { point: { x: 100, y: 100 } }]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 50, y: 50 } },{ point: { x: 100, y: 100 } }'); }); test('path.arcTo(from, through, to);', function() { var path = new Path(); path.moveTo([50, 50]); path.arcTo([100, 100], [75, 75]); - var expectedSegments = [{ point: { x: 50, y: 50 }, handleOut: { x: 10.11156, y: -10.11156 } }, { point: { x: 88.5299, y: 42.33593 }, handleIn: { x: -13.21138, y: -5.47233 }, handleOut: { x: 13.21138, y: 5.47233 } }, { point: { x: 110.35534, y: 75 }, handleIn: { x: 0, y: -14.2999 } }]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 50, y: 50 }, handleOut: { x: 10.11156, y: -10.11156 } },{ point: { x: 88.5299, y: 42.33593 }, handleIn: { x: -13.21138, y: -5.47233 }, handleOut: { x: 13.21138, y: 5.47233 } },{ point: { x: 110.35534, y: 75 }, handleIn: { x: 0, y: -14.2999 } }'); }); \ No newline at end of file diff --git a/test/tests/Path_Shapes.js b/test/tests/Path_Shapes.js index 7eca7db1..2b5f0cf6 100644 --- a/test/tests/Path_Shapes.js +++ b/test/tests/Path_Shapes.js @@ -2,62 +2,61 @@ module('Predefined Path Shapes'); test('new Path.Rectangle([50, 50], [100, 100])', function() { var path = new Path.Rectangle([50, 50], [100, 100]); - var expectedSegments = [new Segment(new Point(50, 150)), new Segment(new Point(50, 50)), new Segment(new Point(150, 50)), new Segment(new Point(150, 150))]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 50, y: 150 } },{ point: { x: 50, y: 50 } },{ point: { x: 150, y: 50 } },{ point: { x: 150, y: 150 } }'); }); test('new Path.Circle([100, 100], 50)', function() { var path = new Path.Circle([100, 100], 50); var expectedSegments = [new Segment(new Point(50, 100), new Point(0, 27.6142578125), new Point(0, -27.6142578125)), new Segment(new Point(100, 50), new Point(-27.6142578125, 0), new Point(27.6142578125, 0)), new Segment(new Point(150, 100), new Point(0, -27.6142578125), new Point(0, 27.6142578125)), new Segment(new Point(100, 150), new Point(27.6142578125, 0), new Point(-27.6142578125, 0))]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 50, y: 100 }, handleIn: { x: 0, y: 27.61424 }, handleOut: { x: 0, y: -27.61424 } },{ point: { x: 100, y: 50 }, handleIn: { x: -27.61424, y: 0 }, handleOut: { x: 27.61424, y: 0 } },{ point: { x: 150, y: 100 }, handleIn: { x: 0, y: -27.61424 }, handleOut: { x: 0, y: 27.61424 } },{ point: { x: 100, y: 150 }, handleIn: { x: 27.61424, y: 0 }, handleOut: { x: -27.61424, y: 0 } }'); }); test('new Path.Oval(rect)', function() { var rect = new Rectangle([500, 500], [1000, 750]) var path = new Path.Oval(rect); var expectedSegments = [{ point: { x: 500, y: 875 }, handleIn: { x: 0, y: 207.10645 }, handleOut: { x: 0, y: -207.10645 } }, { point: { x: 1000, y: 500 }, handleIn: { x: -276.14258, y: 0 }, handleOut: { x: 276.14258, y: 0 } }, { point: { x: 1500, y: 875 }, handleIn: { x: 0, y: -207.10645 }, handleOut: { x: 0, y: 207.10645 } }, { point: { x: 1000, y: 1250 }, handleIn: { x: 276.14258, y: 0 }, handleOut: { x: -276.14258, y: 0 } }]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 500, y: 875 }, handleIn: { x: 0, y: 207.10678 }, handleOut: { x: 0, y: -207.10678 } },{ point: { x: 1000, y: 500 }, handleIn: { x: -276.14237, y: 0 }, handleOut: { x: 276.14237, y: 0 } },{ point: { x: 1500, y: 875 }, handleIn: { x: 0, y: -207.10678 }, handleOut: { x: 0, y: 207.10678 } },{ point: { x: 1000, y: 1250 }, handleIn: { x: 276.14237, y: 0 }, handleOut: { x: -276.14237, y: 0 } }'); }); test('new Path.RoundRectangle(rect, size)', function() { var rect = new Rectangle([50, 50], [200, 100]) var path = new Path.RoundRectangle(rect, 20); var expectedSegments = [{ point: { x: 70, y: 150 }, handleOut: { x: -11.0459, y: 0 } }, { point: { x: 50, y: 130 }, handleIn: { x: 0, y: 11.0459 } }, { point: { x: 50, y: 70 }, handleOut: { x: 0, y: -11.0459 } }, { point: { x: 70, y: 50 }, handleIn: { x: -11.0459, y: 0 } }, { point: { x: 230, y: 50 }, handleOut: { x: 11.0459, y: 0 } }, { point: { x: 250, y: 70 }, handleIn: { x: 0, y: -11.0459 } }, { point: { x: 250, y: 130 }, handleOut: { x: 0, y: 11.0459 } }, { point: { x: 230, y: 150 }, handleIn: { x: 11.0459, y: 0 } }]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 70, y: 150 }, handleOut: { x: -11.04569, y: 0 } },{ point: { x: 50, y: 130 }, handleIn: { x: 0, y: 11.04569 } },{ point: { x: 50, y: 70 }, handleOut: { x: 0, y: -11.04569 } },{ point: { x: 70, y: 50 }, handleIn: { x: -11.04569, y: 0 } },{ point: { x: 230, y: 50 }, handleOut: { x: 11.04569, y: 0 } },{ point: { x: 250, y: 70 }, handleIn: { x: 0, y: -11.04569 } },{ point: { x: 250, y: 130 }, handleOut: { x: 0, y: 11.04569 } },{ point: { x: 230, y: 150 }, handleIn: { x: 11.04569, y: 0 } }'); }); test('new Path.RoundRectangle(rect, size) - too large size', function() { var rect = new Rectangle([50, 50], [200, 100]) var path = new Path.RoundRectangle(rect, 200); var expectedSegments = [{ point: { x: 150, y: 150 }, handleOut: { x: -55.22852, y: 0 } }, { point: { x: 50, y: 100 }, handleIn: { x: 0, y: 27.61426 } }, { point: { x: 50, y: 100 }, handleOut: { x: 0, y: -27.61426 } }, { point: { x: 150, y: 50 }, handleIn: { x: -55.22852, y: 0 } }, { point: { x: 150, y: 50 }, handleOut: { x: 55.22852, y: 0 } }, { point: { x: 250, y: 100 }, handleIn: { x: 0, y: -27.61426 } }, { point: { x: 250, y: 100 }, handleOut: { x: 0, y: 27.61426 } }, { point: { x: 150, y: 150 }, handleIn: { x: 55.22852, y: 0 } }]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 150, y: 150 }, handleOut: { x: -55.22847, y: 0 } },{ point: { x: 50, y: 100 }, handleIn: { x: 0, y: 27.61424 } },{ point: { x: 50, y: 100 }, handleOut: { x: 0, y: -27.61424 } },{ point: { x: 150, y: 50 }, handleIn: { x: -55.22847, y: 0 } },{ point: { x: 150, y: 50 }, handleOut: { x: 55.22847, y: 0 } },{ point: { x: 250, y: 100 }, handleIn: { x: 0, y: -27.61424 } },{ point: { x: 250, y: 100 }, handleOut: { x: 0, y: 27.61424 } },{ point: { x: 150, y: 150 }, handleIn: { x: 55.22847, y: 0 } }'); }); test('new Path.Arc(from, through, to)', function() { var path = new Path.Arc([50, 50], [100, 100], [75, 75]); var expectedSegments = [{ point: { x: 50, y: 50 }, handleOut: { x: 10.11156, y: -10.11156 } }, { point: { x: 88.5299, y: 42.33593 }, handleIn: { x: -13.21138, y: -5.47233 }, handleOut: { x: 13.21138, y: 5.47233 } }, { point: { x: 110.35534, y: 75 }, handleIn: { x: 0, y: -14.2999 } }]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 50, y: 50 }, handleOut: { x: 10.11156, y: -10.11156 } },{ point: { x: 88.5299, y: 42.33593 }, handleIn: { x: -13.21138, y: -5.47233 }, handleOut: { x: 13.21138, y: 5.47233 } },{ point: { x: 110.35534, y: 75 }, handleIn: { x: 0, y: -14.2999 } }'); }); test('new Path.RegularPolygon(center, numSides, radius)', function() { var doc = new Document(); var path = new Path.RegularPolygon(new Point(50, 50), 3, 10); var expectedSegments = [{ point: { x: 41.33984, y: 55 } }, { point: { x: 50, y: 40 } }, { point: { x: 58.66016, y: 55 } }]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 41.33975, y: 55 } },{ point: { x: 50, y: 40 } },{ point: { x: 58.66025, y: 55 } }'); var path = new Path.RegularPolygon(new Point(250, 250), 10, 100); var expectedSegments = [{ point: { x: 219.09814, y: 345.10547 } }, { point: { x: 169.09814, y: 308.77832 } }, { point: { x: 150, y: 250 } }, { point: { x: 169.09814, y: 191.22168 } }, { point: { x: 219.09814, y: 154.89453 } }, { point: { x: 280.90186, y: 154.89453 } }, { point: { x: 330.90186, y: 191.22168 } }, { point: { x: 350, y: 250 } }, { point: { x: 330.90186, y: 308.77832 } }, { point: { x: 280.90186, y: 345.10547 } }]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 219.0983, y: 345.10565 } },{ point: { x: 169.0983, y: 308.77853 } },{ point: { x: 150, y: 250 } },{ point: { x: 169.0983, y: 191.22147 } },{ point: { x: 219.0983, y: 154.89435 } },{ point: { x: 280.9017, y: 154.89435 } },{ point: { x: 330.9017, y: 191.22147 } },{ point: { x: 350, y: 250 } },{ point: { x: 330.9017, y: 308.77853 } },{ point: { x: 280.9017, y: 345.10565 } }'); }); test('new Path.Star(center, numSides, radius1, radius2)', function() { var doc = new Document(); var path = new Path.Star(new Point(100, 100), 10, 10, 20); var expectedSegments = [new Segment(new Point(100, 90)), new Segment(new Point(106.18017578125, 80.97900390625)), new Segment(new Point(105.8779296875, 91.90966796875)), new Segment(new Point(116.18017578125, 88.244140625)), new Segment(new Point(109.5107421875, 96.90966796875)), new Segment(new Point(120, 100)), new Segment(new Point(109.5107421875, 103.09033203125)), new Segment(new Point(116.18017578125, 111.755859375)), new Segment(new Point(105.8779296875, 108.09033203125)), new Segment(new Point(106.18017578125, 119.02099609375)), new Segment(new Point(100, 110)), new Segment(new Point(93.81982421875, 119.02099609375)), new Segment(new Point(94.1220703125, 108.09033203125)), new Segment(new Point(83.81982421875, 111.755859375)), new Segment(new Point(90.4892578125, 103.09033203125)), new Segment(new Point(80, 100)), new Segment(new Point(90.4892578125, 96.90966796875)), new Segment(new Point(83.81982421875, 88.244140625)), new Segment(new Point(94.1220703125, 91.90966796875)), new Segment(new Point(93.81982421875, 80.97900390625))]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 100, y: 90 } },{ point: { x: 106.18034, y: 80.97887 } },{ point: { x: 105.87785, y: 91.90983 } },{ point: { x: 116.18034, y: 88.24429 } },{ point: { x: 109.51057, y: 96.90983 } },{ point: { x: 120, y: 100 } },{ point: { x: 109.51057, y: 103.09017 } },{ point: { x: 116.18034, y: 111.75571 } },{ point: { x: 105.87785, y: 108.09017 } },{ point: { x: 106.18034, y: 119.02113 } },{ point: { x: 100, y: 110 } },{ point: { x: 93.81966, y: 119.02113 } },{ point: { x: 94.12215, y: 108.09017 } },{ point: { x: 83.81966, y: 111.75571 } },{ point: { x: 90.48943, y: 103.09017 } },{ point: { x: 80, y: 100 } },{ point: { x: 90.48943, y: 96.90983 } },{ point: { x: 83.81966, y: 88.24429 } },{ point: { x: 94.12215, y: 91.90983 } },{ point: { x: 93.81966, y: 80.97887 } }'); var doc = new Document(); var path = new Path.Star(new Point(100, 100), 5, 20, 10); var expectedSegments = [new Segment(new Point(100, 80)), new Segment(new Point(105.8779296875, 91.90966796875)), new Segment(new Point(119.02099609375, 93.81982421875)), new Segment(new Point(109.5107421875, 103.09033203125)), new Segment(new Point(111.755859375, 116.18017578125)), new Segment(new Point(100, 110)), new Segment(new Point(88.244140625, 116.18017578125)), new Segment(new Point(90.4892578125, 103.09033203125)), new Segment(new Point(80.97900390625, 93.81982421875)), new Segment(new Point(94.1220703125, 91.90966796875))]; - compareSegmentLists(path.segments, expectedSegments); + equals(path.segments.toString(), '{ point: { x: 100, y: 80 } },{ point: { x: 105.87785, y: 91.90983 } },{ point: { x: 119.02113, y: 93.81966 } },{ point: { x: 109.51057, y: 103.09017 } },{ point: { x: 111.75571, y: 116.18034 } },{ point: { x: 100, y: 110 } },{ point: { x: 88.24429, y: 116.18034 } },{ point: { x: 90.48943, y: 103.09017 } },{ point: { x: 80.97887, y: 93.81966 } },{ point: { x: 94.12215, y: 91.90983 } }'); }); \ No newline at end of file diff --git a/test/tests/Segment.js b/test/tests/Segment.js index b4124911..149fd1e9 100644 --- a/test/tests/Segment.js +++ b/test/tests/Segment.js @@ -1,57 +1,49 @@ module('Segment'); test('new Segment(point)', function() { var segment = new Segment(new Point(10, 10)); - var expected = { point: { x: 10, y: 10 } }; - compareSegments(segment, expected); + equals(segment.toString(), '{ point: { x: 10, y: 10 } }'); }); test('new Segment(x, y)', function() { var segment = new Segment(10, 10); - var expected = { point: { x: 10, y: 10 } }; - compareSegments(segment, expected); + equals(segment.toString(), '{ point: { x: 10, y: 10 } }'); }); test('new Segment(object)', function() { var segment = new Segment({ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }); - var expected = { point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }; - compareSegments(segment, expected); + equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }'); }); test('new Segment(point, handleIn, handleOut)', function() { var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15)); - var expected = { point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }; - compareSegments(segment, expected); + equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }'); }); test('new Segment(x, y, inX, inY, outX, outY)', function() { var segment = new Segment(10, 10, 5, 5, 15, 15); - var expected = { point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }; - compareSegments(segment, expected); + equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 5, y: 5 }, handleOut: { x: 15, y: 15 } }'); }); test('segment.reverse()', function() { var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15)); segment = segment.reverse(); - var expected = { point: { x: 10, y: 10 }, handleIn: { x: 15, y: 15 }, handleOut: { x: 5, y: 5 } }; - compareSegments(segment, expected); + equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 15, y: 15 }, handleOut: { x: 5, y: 5 } }'); }); test('segment.clone()', function() { var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15)); var clone = segment.clone(); equals(segment == clone, false); - compareSegments(segment, clone); + equals(segment.toString(), clone.toString()); }); test('segment.remove()', function() { - var doc = new Document(); var path = new Path([10, 10], [5, 5], [10, 10]); path.segments[1].remove(); - equals(path.segments.length, 2); + equals(path.segments.toString(), '{ point: { x: 10, y: 10 } },{ point: { x: 10, y: 10 } }'); }); test('segment.selected', function() { - var doc = new Document(); var path = new Path([10, 20], [50, 100]); path.segments[0].point.selected = true; equals(path.segments[0].point.selected, true);