aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/graphics/ext/coordinates_test.html
blob: 14b5447677cd091ff574c14dbfa9d444666689c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<!DOCTYPE html>
<html>
<!--
Copyright 2007 The Closure Library Authors. All Rights Reserved.

Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.graphics.ext.coordinates</title>
<script src="../../base.js"></script>
<script>
  goog.require('goog.graphics');
  goog.require('goog.graphics.ext.coordinates');
  goog.require('goog.testing.jsunit');
</script>
</head>
<body>

<script>
  function testIsPercent() {
    assert('50% is a percent',
        goog.graphics.ext.coordinates.isPercent_('50%'));
    assert('50 is not a percent',
        !goog.graphics.ext.coordinates.isPercent_('50'));
  }

  function testIsPixels() {
    assert('50px is pixels', goog.graphics.ext.coordinates.isPixels_('50px'));
    assert('50 is not pixels', !goog.graphics.ext.coordinates.isPixels_('50'));
  }

  function testIsSpecial() {
    assert('50px is special', goog.graphics.ext.coordinates.isSpecial('50px'));
    assert('50% is special', goog.graphics.ext.coordinates.isSpecial('50%'));
    assert('50 is not special', !goog.graphics.ext.coordinates.isSpecial('50'));
  }

  function testComputeValue() {
    assertEquals('50% of 100 is 50', 50,
        goog.graphics.ext.coordinates.computeValue('50%', 100, null));
    assertEquals('50.5% of 200 is 101', 101,
        goog.graphics.ext.coordinates.computeValue('50.5%', 200, null));
    assertEquals('50px = 25 units when in 2x view', 25,
        goog.graphics.ext.coordinates.computeValue('50px', null, 2));
  }

  function testGenericGetValue() {
    var getValue = goog.graphics.ext.coordinates.getValue;

    var cache = {};

    assertEquals('Testing 50%', 50,
        getValue('50%', false, 100, 2, cache));

    var count = 0;
    for (var x in cache) {
      count++;
      cache[x] = 'OVERWRITE';
    }

    assertEquals('Testing cache size', 1, count);
    assertEquals('Testing cache usage', 'OVERWRITE',
        getValue('50%', false, 100, 2, cache));

    cache = {};

    assertEquals('Testing 0%', 0,
        getValue('0%', false, 100, 2, cache));
  }
</script>
</body>
</html>