Debian Codegraph @

closure-library/closure/goog/testing/graphics.js

raw
1 // Copyright 2008 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 Testing utilities for DOM related tests.
17 *
18 * @author [email protected] (Robby Walker)
19 */
20
21 goog.setTestOnly('goog.testing.graphics');
22 goog.provide('goog.testing.graphics');
23
24 goog.require('goog.graphics.Path');
25 goog.require('goog.testing.asserts');
26
27
28 /**
29 * Array mapping numeric segment constant to a descriptive character.
30 * @type {Array<string>}
31 * @private
32 */
33 goog.testing.graphics.SEGMENT_NAMES_ = function() {
34 var arr = [];
35 arr[goog.graphics.Path.Segment.MOVETO] = 'M';
36 arr[goog.graphics.Path.Segment.LINETO] = 'L';
37 arr[goog.graphics.Path.Segment.CURVETO] = 'C';
38 arr[goog.graphics.Path.Segment.ARCTO] = 'A';
39 arr[goog.graphics.Path.Segment.CLOSE] = 'X';
40 return arr;
41 }();
42
43
44 /**
45 * Test if the given path matches the expected array of commands and parameters.
46 * @param {Array<string|number>} expected The expected array of commands and
47 * parameters.
48 * @param {goog.graphics.Path} path The path to test against.
49 */
50 goog.testing.graphics.assertPathEquals = function(expected, path) {
51 var actual = [];
52 path.forEachSegment(function(seg, args) {
53 actual.push(goog.testing.graphics.SEGMENT_NAMES_[seg]);
54 Array.prototype.push.apply(actual, args);
55 });
56 assertEquals(expected.length, actual.length);
57 for (var i = 0; i < expected.length; i++) {
58 if (goog.isNumber(expected[i])) {
59 assertTrue(goog.isNumber(actual[i]));
60 assertRoughlyEquals(expected[i], actual[i], 0.01);
61 } else {
62 assertEquals(expected[i], actual[i]);
63 }
64 }
65 };