Debian Codegraph @

closure-library/closure/goog/math/paths_test.js

raw
1 // Copyright 2006 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 /**
16 * @fileoverview Unit tests for goog.math.paths.
17 */
18
19 goog.provide('goog.math.pathsTest');
20
21 goog.require('goog.math.Coordinate');
22 goog.require('goog.math.paths');
23 goog.require('goog.testing.jsunit');
24
25 goog.setTestOnly('goog.math.pathsTest');
26
27
28 var regularNGon = goog.math.paths.createRegularNGon;
29 var arrow = goog.math.paths.createArrow;
30
31 function testSquare() {
32 var square = regularNGon($coord(10, 10), $coord(0, 10), 4);
33 assertArrayRoughlyEquals(
34 [0, 10, 10, 0, 20, 10, 10, 20], square.arguments_, 0.05);
35 }
36
37 function assertArrayRoughlyEquals(expected, actual, delta) {
38 var message = 'Expected: ' + expected + ', Actual: ' + actual;
39 assertEquals('Wrong length. ' + message, expected.length, actual.length);
40 for (var i = 0; i < expected.length; i++) {
41 assertRoughlyEquals(
42 'Wrong item at ' + i + '. ' + message, expected[i], actual[i], delta);
43 }
44 }
45
46 function $coord(x, y) {
47 return new goog.math.Coordinate(x, y);
48 }