coordinates_test.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2007 The Closure Library Authors. All Rights Reserved.
  2. // Use of this source code is governed by the Apache License, Version 2.0.
  3. goog.provide('goog.graphics.ext.coordinatesTest');
  4. goog.setTestOnly('goog.graphics.ext.coordinatesTest');
  5. goog.require('goog.graphics');
  6. goog.require('goog.graphics.ext.coordinates');
  7. goog.require('goog.testing.jsunit');
  8. function testIsPercent() {
  9. assert('50% is a percent',
  10. goog.graphics.ext.coordinates.isPercent_('50%'));
  11. assert('50 is not a percent',
  12. !goog.graphics.ext.coordinates.isPercent_('50'));
  13. }
  14. function testIsPixels() {
  15. assert('50px is pixels', goog.graphics.ext.coordinates.isPixels_('50px'));
  16. assert('50 is not pixels', !goog.graphics.ext.coordinates.isPixels_('50'));
  17. }
  18. function testIsSpecial() {
  19. assert('50px is special', goog.graphics.ext.coordinates.isSpecial('50px'));
  20. assert('50% is special', goog.graphics.ext.coordinates.isSpecial('50%'));
  21. assert('50 is not special', !goog.graphics.ext.coordinates.isSpecial('50'));
  22. }
  23. function testComputeValue() {
  24. assertEquals('50% of 100 is 50', 50,
  25. goog.graphics.ext.coordinates.computeValue('50%', 100, null));
  26. assertEquals('50.5% of 200 is 101', 101,
  27. goog.graphics.ext.coordinates.computeValue('50.5%', 200, null));
  28. assertEquals('50px = 25 units when in 2x view', 25,
  29. goog.graphics.ext.coordinates.computeValue('50px', null, 2));
  30. }
  31. function testGenericGetValue() {
  32. var getValue = goog.graphics.ext.coordinates.getValue;
  33. var cache = {};
  34. assertEquals('Testing 50%', 50,
  35. getValue('50%', false, 100, 2, cache));
  36. var count = 0;
  37. for (var x in cache) {
  38. count++;
  39. cache[x] = 'OVERWRITE';
  40. }
  41. assertEquals('Testing cache size', 1, count);
  42. assertEquals('Testing cache usage', 'OVERWRITE',
  43. getValue('50%', false, 100, 2, cache));
  44. cache = {};
  45. assertEquals('Testing 0%', 0,
  46. getValue('0%', false, 100, 2, cache));
  47. }