aboutsummaryrefslogtreecommitdiff
path: root/contexts/data/lib/closure-library/closure/goog/structs/linkedmap_test.html
diff options
context:
space:
mode:
Diffstat (limited to 'contexts/data/lib/closure-library/closure/goog/structs/linkedmap_test.html')
-rw-r--r--contexts/data/lib/closure-library/closure/goog/structs/linkedmap_test.html300
1 files changed, 0 insertions, 300 deletions
diff --git a/contexts/data/lib/closure-library/closure/goog/structs/linkedmap_test.html b/contexts/data/lib/closure-library/closure/goog/structs/linkedmap_test.html
deleted file mode 100644
index d20faac..0000000
--- a/contexts/data/lib/closure-library/closure/goog/structs/linkedmap_test.html
+++ /dev/null
@@ -1,300 +0,0 @@
-<!DOCTYPE html>
-<html>
-<!--
-Copyright 2006 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.structs.LinkedMap</title>
-<script src="../base.js"></script>
-<script>
- goog.require('goog.structs.LinkedMap');
- goog.require('goog.testing.jsunit');
- goog.require('goog.testing.recordFunction');
-</script>
-</head>
-<body>
-<script>
-
-function fillLinkedMap(m) {
- m.set('a', 0);
- m.set('b', 1);
- m.set('c', 2);
- m.set('d', 3);
-}
-
-var someObj = {};
-
-function testLinkedMap() {
- var m = new goog.structs.LinkedMap();
- fillLinkedMap(m);
-
- assertArrayEquals(['a', 'b', 'c', 'd'], m.getKeys());
- assertArrayEquals([0, 1, 2, 3], m.getValues());
-}
-
-function testMaxSizeLinkedMap() {
- var m = new goog.structs.LinkedMap(3);
- fillLinkedMap(m);
-
- assertArrayEquals(['b', 'c', 'd'], m.getKeys());
- assertArrayEquals([1, 2, 3], m.getValues());
-}
-
-function testLruLinkedMap() {
- var m = new goog.structs.LinkedMap(undefined, true);
- fillLinkedMap(m);
-
- assertArrayEquals(['d', 'c', 'b', 'a'], m.getKeys());
- assertArrayEquals([3, 2, 1, 0], m.getValues());
-
- m.get('a');
- assertArrayEquals(['a', 'd', 'c', 'b'], m.getKeys());
- assertArrayEquals([0, 3, 2, 1], m.getValues());
-
- m.set('b', 4);
- assertArrayEquals(['b', 'a', 'd', 'c'], m.getKeys());
- assertArrayEquals([4, 0, 3, 2], m.getValues());
-}
-
-function testMaxSizeLruLinkedMap() {
- var m = new goog.structs.LinkedMap(3, true);
- fillLinkedMap(m);
-
- assertArrayEquals(['d', 'c', 'b'], m.getKeys());
- assertArrayEquals([3, 2, 1], m.getValues());
-
- m.get('c');
- assertArrayEquals(['c', 'd', 'b'], m.getKeys());
- assertArrayEquals([2, 3, 1], m.getValues());
-
- m.set('d', 4);
- assertArrayEquals(['d', 'c', 'b'], m.getKeys());
- assertArrayEquals([4, 2, 1], m.getValues());
-}
-
-function testGetCount() {
- var m = new goog.structs.LinkedMap();
- assertEquals(0, m.getCount());
- m.set('a', 0);
- assertEquals(1, m.getCount());
- m.set('a', 1);
- assertEquals(1, m.getCount());
- m.set('b', 2);
- assertEquals(2, m.getCount());
- m.remove('a');
- assertEquals(1, m.getCount());
-}
-
-function testIsEmpty() {
- var m = new goog.structs.LinkedMap();
- assertTrue(m.isEmpty());
- m.set('a', 0);
- assertFalse(m.isEmpty());
- m.remove('a');
- assertTrue(m.isEmpty());
-}
-
-function testSetMaxCount() {
- var m = new goog.structs.LinkedMap(3);
- fillLinkedMap(m);
- assertEquals(3, m.getCount());
-
- m.setMaxCount(5);
- m.set('e', 5);
- m.set('f', 6);
- m.set('g', 7);
- assertEquals(5, m.getCount());
-
- m.setMaxCount(4);
- assertEquals(4, m.getCount());
-
- m.setMaxCount(0);
- m.set('h', 8);
- m.set('i', 9);
- m.set('j', 10);
- assertEquals(7, m.getCount());
-}
-
-function testClear() {
- var m = new goog.structs.LinkedMap();
- fillLinkedMap(m);
- m.clear();
- assertTrue(m.isEmpty());
-}
-
-function testForEach() {
- var m = new goog.structs.LinkedMap();
- fillLinkedMap(m);
-
- m.forEach(function(val, key, linkedMap) {
- linkedMap.set(key, val * 2);
- assertEquals('forEach should run in provided context.', someObj, this);
- }, someObj);
-
- assertArrayEquals(['a', 'b', 'c', 'd'], m.getKeys());
- assertArrayEquals([0, 2, 4, 6], m.getValues());
-}
-
-function testMap() {
- var m = new goog.structs.LinkedMap();
- fillLinkedMap(m);
-
- var result = m.map(function(val, key, linkedMap) {
- assertEquals('The LinkedMap object should get passed in', m, linkedMap);
- assertEquals('map should run in provided context', someObj, this);
- return key + val;
- }, someObj);
-
- assertArrayEquals(['a0', 'b1', 'c2', 'd3'], result);
-}
-
-function testSome() {
- var m = new goog.structs.LinkedMap();
- fillLinkedMap(m);
-
- var result = m.some(function(val, key, linkedMap) {
- assertEquals('The LinkedMap object should get passed in', m, linkedMap);
- assertEquals('map should run in provided context', someObj, this);
- return val > 2;
- }, someObj);
-
- assertTrue(result);
- assertFalse(m.some(function(val) {return val > 3}));
-
- assertTrue(m.some(function(val, key) {return key == 'c';}));
- assertFalse(m.some(function(val, key) {return key == 'e';}));
-}
-
-function testEvery() {
- var m = new goog.structs.LinkedMap();
- fillLinkedMap(m);
-
- var result = m.every(function(val, key, linkedMap) {
- assertEquals('The LinkedMap object should get passed in', m, linkedMap);
- assertEquals('map should run in provided context', someObj, this);
- return val < 5;
- }, someObj);
-
- assertTrue(result);
- assertFalse(m.every(function(val) {return val < 2}));
-
- assertTrue(m.every(function(val, key) {return key.length == 1;}));
- assertFalse(m.every(function(val, key) {return key == 'b';}));
-}
-
-function testPeek() {
- var m = new goog.structs.LinkedMap();
- assertEquals(undefined, m.peek());
- assertEquals(undefined, m.peekLast());
-
- fillLinkedMap(m);
- assertEquals(0, m.peek());
-
- m.remove('a');
- assertEquals(1, m.peek());
-
- assertEquals(3, m.peekLast());
-
- assertEquals(3, m.peekValue('d'));
- assertEquals(1, m.peek());
-
- m.remove('d');
- assertEquals(2, m.peekLast());
-}
-
-function testPop() {
- var m = new goog.structs.LinkedMap();
- assertEquals(undefined, m.shift());
- assertEquals(undefined, m.pop());
-
- fillLinkedMap(m);
- assertEquals(4, m.getCount());
-
- assertEquals(0, m.shift());
- assertEquals(1, m.peek());
-
- assertEquals(3, m.pop());
- assertEquals(2, m.peekLast());
-
- assertEquals(2, m.getCount());
-}
-
-function testContains() {
- var m = new goog.structs.LinkedMap();
- fillLinkedMap(m);
-
- assertTrue(m.contains(2));
- assertFalse(m.contains(4));
-}
-
-function testContainsKey() {
- var m = new goog.structs.LinkedMap();
- fillLinkedMap(m);
-
- assertTrue(m.containsKey('b'));
- assertFalse(m.containsKey('elephant'));
- assertFalse(m.containsKey('undefined'));
-}
-
-function testRemoveNodeCalls() {
- var m = new goog.structs.LinkedMap(1);
- m.removeNode = goog.testing.recordFunction(m.removeNode);
-
- m.set('1', 1);
- assertEquals('removeNode not called after adding an element', 0,
- m.removeNode.getCallCount());
- m.set('1', 2);
- assertEquals('removeNode not called after updating an element', 0,
- m.removeNode.getCallCount());
- m.set('2', 2);
- assertEquals('removeNode called after adding an overflowing element', 1,
- m.removeNode.getCallCount());
-
- m.remove('3');
- assertEquals('removeNode not called after removing a non-existing element', 1,
- m.removeNode.getCallCount());
- m.remove('2');
- assertEquals('removeNode called after removing an existing element', 2,
- m.removeNode.getCallCount());
-
- m.set('1', 1);
- m.clear();
- assertEquals('removeNode called after clearing the map', 3,
- m.removeNode.getCallCount());
- m.clear();
- assertEquals('removeNode not called after clearing an empty map', 3,
- m.removeNode.getCallCount());
-
- m.set('1', 1);
- m.pop();
- assertEquals('removeNode called after calling pop', 4,
- m.removeNode.getCallCount());
- m.pop();
- assertEquals('removeNode not called after calling pop on an empty map', 4,
- m.removeNode.getCallCount());
-
- m.set('1', 1);
- m.shift();
- assertEquals('removeNode called after calling shift', 5,
- m.removeNode.getCallCount());
- m.shift();
- assertEquals('removeNode not called after calling shift on an empty map', 5,
- m.removeNode.getCallCount());
-
- m.setMaxCount(2);
- m.set('1', 1);
- m.set('2', 2);
- assertEquals('removeNode not called after increasing the maximum map size', 5,
- m.removeNode.getCallCount());
- m.setMaxCount(1);
- assertEquals('removeNode called after decreasing the maximum map size', 6,
- m.removeNode.getCallCount());
-}
-
-</script>
-</body>
-</html>