paths_test.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. * @fileoverview Unit tests for goog.math.paths.
  16. */
  17. goog.provide('goog.math.pathsTest');
  18. goog.require('goog.math.Coordinate');
  19. goog.require('goog.math.paths');
  20. goog.require('goog.testing.jsunit');
  21. goog.setTestOnly('goog.math.pathsTest');
  22. var regularNGon = goog.math.paths.createRegularNGon;
  23. var arrow = goog.math.paths.createArrow;
  24. function testSquare() {
  25. var square = regularNGon($coord(10, 10), $coord(0, 10), 4);
  26. assertArrayRoughlyEquals(
  27. [0, 10, 10, 0, 20, 10, 10, 20], square.arguments_, 0.05);
  28. }
  29. function assertArrayRoughlyEquals(expected, actual, delta) {
  30. var message = 'Expected: ' + expected + ', Actual: ' + actual;
  31. assertEquals('Wrong length. ' + message, expected.length, actual.length);
  32. for (var i = 0; i < expected.length; i++) {
  33. assertRoughlyEquals(
  34. 'Wrong item at ' + i + '. ' + message, expected[i], actual[i], delta);
  35. }
  36. }
  37. function $coord(x, y) {
  38. return new goog.math.Coordinate(x, y);
  39. }