Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: test/mjsunit/tools/splaytree.js

Issue 6456025: Shorten constructor names in JS tickprocessor. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: and CallTree Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/tools/profile_view.js ('k') | tools/codemap.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 12 matching lines...) Expand all
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Load the Splay tree implementation from <project root>/tools. 28 // Load the Splay tree implementation from <project root>/tools.
29 // Files: tools/splaytree.js 29 // Files: tools/splaytree.js
30 30
31 31
32 (function testIsEmpty() { 32 (function testIsEmpty() {
33 var tree = new goog.structs.SplayTree(); 33 var tree = new SplayTree();
34 assertTrue(tree.isEmpty()); 34 assertTrue(tree.isEmpty());
35 tree.insert(0, 'value'); 35 tree.insert(0, 'value');
36 assertFalse(tree.isEmpty()); 36 assertFalse(tree.isEmpty());
37 })(); 37 })();
38 38
39 39
40 (function testExportValues() { 40 (function testExportValues() {
41 var tree = new goog.structs.SplayTree(); 41 var tree = new SplayTree();
42 assertArrayEquals([], tree.exportValues()); 42 assertArrayEquals([], tree.exportValues());
43 tree.insert(0, 'value'); 43 tree.insert(0, 'value');
44 assertArrayEquals(['value'], tree.exportValues()); 44 assertArrayEquals(['value'], tree.exportValues());
45 tree.insert(0, 'value'); 45 tree.insert(0, 'value');
46 assertArrayEquals(['value'], tree.exportValues()); 46 assertArrayEquals(['value'], tree.exportValues());
47 })(); 47 })();
48 48
49 49
50 function createSampleTree() { 50 function createSampleTree() {
51 // Creates the following tree: 51 // Creates the following tree:
(...skipping 20 matching lines...) Expand all
72 right: { key: 90, value: 90, 72 right: { key: 90, value: 90,
73 left: { key: 70, value: 70, left: null, 73 left: { key: 70, value: 70, left: null,
74 right: { key: 80, value: 80, 74 right: { key: 80, value: 80,
75 left: null, right: null } }, 75 left: null, right: null } },
76 right: { key: 100, value: 100, 76 right: { key: 100, value: 100,
77 left: null, right: null } } } }; 77 left: null, right: null } } } };
78 }; 78 };
79 79
80 80
81 (function testSplay() { 81 (function testSplay() {
82 var tree = new goog.structs.SplayTree(); 82 var tree = new SplayTree();
83 tree.root_ = createSampleTree(); 83 tree.root_ = createSampleTree();
84 assertArrayEquals(['50', '30', '60', '10', '40', '90', '20', '70', '100', '15' , '80'], 84 assertArrayEquals(['50', '30', '60', '10', '40', '90', '20', '70', '100', '15' , '80'],
85 tree.exportValues()); 85 tree.exportValues());
86 tree.splay_(50); 86 tree.splay_(50);
87 assertArrayEquals(['50', '30', '60', '10', '40', '90', '20', '70', '100', '15' , '80'], 87 assertArrayEquals(['50', '30', '60', '10', '40', '90', '20', '70', '100', '15' , '80'],
88 tree.exportValues()); 88 tree.exportValues());
89 tree.splay_(80); 89 tree.splay_(80);
90 assertArrayEquals(['80', '60', '90', '50', '70', '100', '30', '10', '40', '20' , '15'], 90 assertArrayEquals(['80', '60', '90', '50', '70', '100', '30', '10', '40', '20' , '15'],
91 tree.exportValues()); 91 tree.exportValues());
92 })(); 92 })();
93 93
94 94
95 (function testInsert() { 95 (function testInsert() {
96 var tree = new goog.structs.SplayTree(); 96 var tree = new SplayTree();
97 tree.insert(5, 'root'); 97 tree.insert(5, 'root');
98 tree.insert(3, 'left'); 98 tree.insert(3, 'left');
99 assertArrayEquals(['left', 'root'], tree.exportValues()); 99 assertArrayEquals(['left', 'root'], tree.exportValues());
100 tree.insert(7, 'right'); 100 tree.insert(7, 'right');
101 assertArrayEquals(['right', 'root', 'left'], tree.exportValues()); 101 assertArrayEquals(['right', 'root', 'left'], tree.exportValues());
102 })(); 102 })();
103 103
104 104
105 (function testFind() { 105 (function testFind() {
106 var tree = new goog.structs.SplayTree(); 106 var tree = new SplayTree();
107 tree.insert(5, 'root'); 107 tree.insert(5, 'root');
108 tree.insert(3, 'left'); 108 tree.insert(3, 'left');
109 tree.insert(7, 'right'); 109 tree.insert(7, 'right');
110 assertEquals('root', tree.find(5).value); 110 assertEquals('root', tree.find(5).value);
111 assertEquals('left', tree.find(3).value); 111 assertEquals('left', tree.find(3).value);
112 assertEquals('right', tree.find(7).value); 112 assertEquals('right', tree.find(7).value);
113 assertEquals(null, tree.find(0)); 113 assertEquals(null, tree.find(0));
114 assertEquals(null, tree.find(100)); 114 assertEquals(null, tree.find(100));
115 assertEquals(null, tree.find(-100)); 115 assertEquals(null, tree.find(-100));
116 })(); 116 })();
117 117
118 118
119 (function testFindMin() { 119 (function testFindMin() {
120 var tree = new goog.structs.SplayTree(); 120 var tree = new SplayTree();
121 assertEquals(null, tree.findMin()); 121 assertEquals(null, tree.findMin());
122 tree.insert(5, 'root'); 122 tree.insert(5, 'root');
123 tree.insert(3, 'left'); 123 tree.insert(3, 'left');
124 tree.insert(7, 'right'); 124 tree.insert(7, 'right');
125 assertEquals('left', tree.findMin().value); 125 assertEquals('left', tree.findMin().value);
126 })(); 126 })();
127 127
128 128
129 (function testFindMax() { 129 (function testFindMax() {
130 var tree = new goog.structs.SplayTree(); 130 var tree = new SplayTree();
131 assertEquals(null, tree.findMax()); 131 assertEquals(null, tree.findMax());
132 tree.insert(5, 'root'); 132 tree.insert(5, 'root');
133 tree.insert(3, 'left'); 133 tree.insert(3, 'left');
134 tree.insert(7, 'right'); 134 tree.insert(7, 'right');
135 assertEquals('right', tree.findMax().value); 135 assertEquals('right', tree.findMax().value);
136 })(); 136 })();
137 137
138 138
139 (function testFindGreatestLessThan() { 139 (function testFindGreatestLessThan() {
140 var tree = new goog.structs.SplayTree(); 140 var tree = new SplayTree();
141 assertEquals(null, tree.findGreatestLessThan(10)); 141 assertEquals(null, tree.findGreatestLessThan(10));
142 tree.insert(5, 'root'); 142 tree.insert(5, 'root');
143 tree.insert(3, 'left'); 143 tree.insert(3, 'left');
144 tree.insert(7, 'right'); 144 tree.insert(7, 'right');
145 assertEquals('right', tree.findGreatestLessThan(10).value); 145 assertEquals('right', tree.findGreatestLessThan(10).value);
146 assertEquals('right', tree.findGreatestLessThan(7).value); 146 assertEquals('right', tree.findGreatestLessThan(7).value);
147 assertEquals('root', tree.findGreatestLessThan(6).value); 147 assertEquals('root', tree.findGreatestLessThan(6).value);
148 assertEquals('left', tree.findGreatestLessThan(4).value); 148 assertEquals('left', tree.findGreatestLessThan(4).value);
149 assertEquals(null, tree.findGreatestLessThan(2)); 149 assertEquals(null, tree.findGreatestLessThan(2));
150 })(); 150 })();
151 151
152 152
153 (function testRemove() { 153 (function testRemove() {
154 var tree = new goog.structs.SplayTree(); 154 var tree = new SplayTree();
155 assertThrows('tree.remove(5)'); 155 assertThrows('tree.remove(5)');
156 tree.insert(5, 'root'); 156 tree.insert(5, 'root');
157 tree.insert(3, 'left'); 157 tree.insert(3, 'left');
158 tree.insert(7, 'right'); 158 tree.insert(7, 'right');
159 assertThrows('tree.remove(1)'); 159 assertThrows('tree.remove(1)');
160 assertThrows('tree.remove(6)'); 160 assertThrows('tree.remove(6)');
161 assertThrows('tree.remove(10)'); 161 assertThrows('tree.remove(10)');
162 assertEquals('root', tree.remove(5).value); 162 assertEquals('root', tree.remove(5).value);
163 assertEquals('left', tree.remove(3).value); 163 assertEquals('left', tree.remove(3).value);
164 assertEquals('right', tree.remove(7).value); 164 assertEquals('right', tree.remove(7).value);
165 assertArrayEquals([], tree.exportValues()); 165 assertArrayEquals([], tree.exportValues());
166 })(); 166 })();
OLDNEW
« no previous file with comments | « test/mjsunit/tools/profile_view.js ('k') | tools/codemap.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698