| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 function testLRUCache() { | 5 function testLRUCache() { |
| 6 var cache = new LRUCache(3); | 6 var cache = new LRUCache(3); |
| 7 | 7 |
| 8 // Querying by non-existent key will get null. | 8 // Querying by non-existent key will get null. |
| 9 assertEquals(null, cache.get('a')); | 9 assertEquals(null, cache.get('a')); |
| 10 | 10 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 assertEquals(8, cache.size()); | 109 assertEquals(8, cache.size()); |
| 110 | 110 |
| 111 // Adding an item whose size is bigger than the max size will be ignored. | 111 // Adding an item whose size is bigger than the max size will be ignored. |
| 112 cache.put('f', 'FFF', 11); | 112 cache.put('f', 'FFF', 11); |
| 113 assertEquals(null, cache.get('f')); | 113 assertEquals(null, cache.get('f')); |
| 114 assertEquals('AAA', cache.get('a')); | 114 assertEquals('AAA', cache.get('a')); |
| 115 assertEquals('DDD', cache.get('d')); | 115 assertEquals('DDD', cache.get('d')); |
| 116 assertEquals(8, cache.size()); | 116 assertEquals(8, cache.size()); |
| 117 } | 117 } |
| 118 | 118 |
| 119 /** @constructor */ |
| 119 function RandomNumberGenerator(seed) { | 120 function RandomNumberGenerator(seed) { |
| 120 this.x = seed; | 121 this.x = seed; |
| 121 } | 122 } |
| 122 | 123 |
| 123 RandomNumberGenerator.prototype.random = function() { | 124 RandomNumberGenerator.prototype.random = function() { |
| 124 this.x = (32453 * this.x + 254119) % (1 << 24); | 125 this.x = (32453 * this.x + 254119) % (1 << 24); |
| 125 return this.x >> 4; | 126 return this.x >> 4; |
| 126 }; | 127 }; |
| 127 | 128 |
| 128 function generateRandom3letters(generator) { | 129 function generateRandom3letters(generator) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 cache.put('b', 'valueB'); | 170 cache.put('b', 'valueB'); |
| 170 cache.put('c', 'valueC'); | 171 cache.put('c', 'valueC'); |
| 171 assertEquals('valueA', cache.peek('a')); | 172 assertEquals('valueA', cache.peek('a')); |
| 172 assertEquals('valueB', cache.peek('b')); | 173 assertEquals('valueB', cache.peek('b')); |
| 173 assertEquals('valueC', cache.peek('c')); | 174 assertEquals('valueC', cache.peek('c')); |
| 174 cache.setMaxSize(1); | 175 cache.setMaxSize(1); |
| 175 assertEquals(null, cache.peek('a')); | 176 assertEquals(null, cache.peek('a')); |
| 176 assertEquals(null, cache.peek('b')); | 177 assertEquals(null, cache.peek('b')); |
| 177 assertEquals('valueC', cache.peek('c')); | 178 assertEquals('valueC', cache.peek('c')); |
| 178 } | 179 } |
| OLD | NEW |