graphics.js 2.1 KB

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