aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/graphics/paths_test.html
diff options
context:
space:
mode:
authorGravatar Rogan Creswick <creswick@galois.com>2012-03-30 17:07:02 -0700
committerGravatar Rogan Creswick <creswick@galois.com>2012-03-30 17:07:02 -0700
commitf6ab6622aab00fe7c2f4c3dc41f786ebbe0f0d73 (patch)
tree870111038542cd27153e1396ebdc063573249689 /contexts/data/lib/closure-library/closure/goog/graphics/paths_test.html
initial revision
Diffstat (limited to 'contexts/data/lib/closure-library/closure/goog/graphics/paths_test.html')
-rw-r--r--contexts/data/lib/closure-library/closure/goog/graphics/paths_test.html98
1 files changed, 98 insertions, 0 deletions
diff --git a/contexts/data/lib/closure-library/closure/goog/graphics/paths_test.html b/contexts/data/lib/closure-library/closure/goog/graphics/paths_test.html
new file mode 100644
index 0000000..e6e062b
--- /dev/null
+++ b/contexts/data/lib/closure-library/closure/goog/graphics/paths_test.html
@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<html>
+<!--
+Copyright 2010 The Closure Library Authors. All Rights Reserved.
+
+Use of this source code is governed by the Apache License, Version 2.0.
+See the COPYING file for details.
+
+Author: nicksantos@google.com (Nick Santos)
+-->
+<head>
+<meta http-equiv="X-UA-Compatible" content="IE=edge">
+<title>JsUnit tests for goog.graphics.paths</title>
+<script src="../base.js"></script>
+<script>
+
+goog.require('goog.dom');
+goog.require('goog.graphics');
+goog.require('goog.graphics.paths');
+goog.require('goog.testing.jsunit');
+
+
+</script>
+</head>
+<body>
+
+<div id="root"></div>
+
+<script type='text/javascript'>
+
+// The purpose of this test is less about the actual unit test, and
+// more for drawing demos of shapes.
+var regularNGon = goog.graphics.paths.createRegularNGon;
+var arrow = goog.graphics.paths.createArrow;
+
+function setUp() {
+ goog.dom.removeChildren(goog.dom.getElement('root'));
+}
+
+function testSquare() {
+ var square = regularNGon(
+ $coord(10, 10), $coord(0, 10), 4);
+ assertArrayRoughlyEquals(
+ [0, 10, 10, 0, 20, 10, 10, 20], square.arguments_, 0.05);
+}
+
+function assertArrayRoughlyEquals(expected, actual, delta) {
+ var message = 'Expected: ' + expected + ', Actual: ' + actual;
+ assertEquals('Wrong length. ' + message, expected.length, actual.length);
+ for (var i = 0; i < expected.length; i++) {
+ assertRoughlyEquals(
+ 'Wrong item at ' + i + '. ' + message,
+ expected[i], actual[i], delta);
+ }
+}
+
+function tearDownPage() {
+ var root = goog.dom.getElement('root');
+ var graphics = goog.graphics.createGraphics(800, 600);
+
+ var blueFill = new goog.graphics.SolidFill('blue');
+ var blackStroke = new goog.graphics.Stroke(1, 'black');
+ graphics.drawPath(
+ regularNGon($coord(20, 50), $coord(0, 20), 3),
+ blackStroke, blueFill);
+ graphics.drawPath(
+ regularNGon($coord(120, 50), $coord(100, 20), 4),
+ blackStroke, blueFill);
+ graphics.drawPath(
+ regularNGon($coord(220, 50), $coord(200, 20), 5),
+ blackStroke, blueFill);
+ graphics.drawPath(
+ regularNGon($coord(320, 50), $coord(300, 20), 6),
+ blackStroke, blueFill);
+
+ graphics.drawPath(
+ arrow($coord(0, 300), $coord(100, 400), 0, 0),
+ blackStroke, blueFill);
+ graphics.drawPath(
+ arrow($coord(120, 400), $coord(200, 300), 0, 10),
+ blackStroke, blueFill);
+ graphics.drawPath(
+ arrow($coord(220, 300), $coord(300, 400), 10, 0),
+ blackStroke, blueFill);
+ graphics.drawPath(
+ arrow($coord(320, 400), $coord(400, 300), 10, 10),
+ blackStroke, blueFill);
+
+ root.appendChild(graphics.getElement());
+}
+
+function $coord(x, y) {
+ return new goog.math.Coordinate(x, y);
+}
+
+</script>
+</body>
+</html>