From 853263263ebb12f81152a513b60101c57fb489e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 28 Nov 2011 22:59:34 +0100 Subject: [PATCH] Implement tests for bounds caching. --- test/tests/Item_Bounds.js | 44 +++++++++++++++++++++++++++++++++++++++ test/tests/load.js | 1 + 2 files changed, 45 insertions(+) create mode 100644 test/tests/Item_Bounds.js diff --git a/test/tests/Item_Bounds.js b/test/tests/Item_Bounds.js new file mode 100644 index 00000000..250aa49b --- /dev/null +++ b/test/tests/Item_Bounds.js @@ -0,0 +1,44 @@ +/* + * Paper.js + * + * This file is part of Paper.js, a JavaScript Vector Graphics Library, + * based on Scriptographer.org and designed to be largely API compatible. + * http://paperjs.org/ + * http://scriptographer.org/ + * + * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey + * http://lehni.org/ & http://jonathanpuckey.com/ + * + * Distributed under the MIT license. See LICENSE file for details. + * + * All rights reserved. + */ + +module('Item Bounds'); + +test('item.bounds caching', function() { + var circle = new Path.Circle(new Point(100, 100), 50); + var rectangle = new Path.Rectangle(new Point(75, 75), new Point(175, 175)); + var group = new Group([circle, rectangle]); + compareRectangles(group.bounds, { x: 50, y: 50, width: 125, height: 125 }, 'group.bounds'); + rectangle.remove(); + equals(function() { + return group.children.length; + }, 1); + compareRectangles(group.bounds, { x: 50, y: 50, width: 100, height: 100 }, 'group.bounds without rectangle'); + group.addChild(rectangle); + equals(function() { + return group.children.length; + }, 2); + compareRectangles(group.bounds, { x: 50, y: 50, width: 125, height: 125 }, 'group.bounds with rectangle'); + circle.remove(); + equals(function() { + return group.children.length; + }, 1); + compareRectangles(group.bounds, { x: 75, y: 75, width: 100, height: 100 }, 'group.bounds without circle'); + group.addChild(circle); + equals(function() { + return group.children.length; + }, 2); + compareRectangles(group.bounds, { x: 50, y: 50, width: 125, height: 125 }, 'group.bounds with circle'); +}); diff --git a/test/tests/load.js b/test/tests/load.js index 9b38d690..f08f287a 100644 --- a/test/tests/load.js +++ b/test/tests/load.js @@ -9,6 +9,7 @@ /*#*/ include('Item.js'); /*#*/ include('Item_Cloning.js'); /*#*/ include('Item_Order.js'); +/*#*/ include('Item_Bounds.js'); /*#*/ include('Layer.js'); /*#*/ include('Group.js');