| 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 |
|
| 4 |
goog.provide('goog.graphics.ext.coordinatesTest'); |
| 5 |
goog.setTestOnly('goog.graphics.ext.coordinatesTest'); |
| 6 |
|
| 7 |
goog.require('goog.graphics'); |
| 8 |
goog.require('goog.graphics.ext.coordinates'); |
| 9 |
goog.require('goog.testing.jsunit'); |
| 10 |
|
| 11 |
function testIsPercent() { |
| 12 |
assert('50% is a percent', |
| 13 |
goog.graphics.ext.coordinates.isPercent_('50%')); |
| 14 |
assert('50 is not a percent', |
| 15 |
!goog.graphics.ext.coordinates.isPercent_('50')); |
| 16 |
} |
| 17 |
|
| 18 |
function testIsPixels() { |
| 19 |
assert('50px is pixels', goog.graphics.ext.coordinates.isPixels_('50px')); |
| 20 |
assert('50 is not pixels', !goog.graphics.ext.coordinates.isPixels_('50')); |
| 21 |
} |
| 22 |
|
| 23 |
function testIsSpecial() { |
| 24 |
assert('50px is special', goog.graphics.ext.coordinates.isSpecial('50px')); |
| 25 |
assert('50% is special', goog.graphics.ext.coordinates.isSpecial('50%')); |
| 26 |
assert('50 is not special', !goog.graphics.ext.coordinates.isSpecial('50')); |
| 27 |
} |
| 28 |
|
| 29 |
function testComputeValue() { |
| 30 |
assertEquals('50% of 100 is 50', 50, |
| 31 |
goog.graphics.ext.coordinates.computeValue('50%', 100, null)); |
| 32 |
assertEquals('50.5% of 200 is 101', 101, |
| 33 |
goog.graphics.ext.coordinates.computeValue('50.5%', 200, null)); |
| 34 |
assertEquals('50px = 25 units when in 2x view', 25, |
| 35 |
goog.graphics.ext.coordinates.computeValue('50px', null, 2)); |
| 36 |
} |
| 37 |
|
| 38 |
function testGenericGetValue() { |
| 39 |
var getValue = goog.graphics.ext.coordinates.getValue; |
| 40 |
|
| 41 |
var cache = {}; |
| 42 |
|
| 43 |
assertEquals('Testing 50%', 50, |
| 44 |
getValue('50%', false, 100, 2, cache)); |
| 45 |
|
| 46 |
var count = 0; |
| 47 |
for (var x in cache) { |
| 48 |
count++; |
| 49 |
cache[x] = 'OVERWRITE'; |
| 50 |
} |
| 51 |
|
| 52 |
assertEquals('Testing cache size', 1, count); |
| 53 |
assertEquals('Testing cache usage', 'OVERWRITE', |
| 54 |
getValue('50%', false, 100, 2, cache)); |
| 55 |
|
| 56 |
cache = {}; |
| 57 |
|
| 58 |
assertEquals('Testing 0%', 0, |
| 59 |
getValue('0%', false, 100, 2, cache)); |
| 60 |
} |