OLD | NEW |
(Empty) | |
| 1 dart_library.library('corelib/hash_map2_test', null, /* Imports */[ |
| 2 'dart_sdk', |
| 3 'expect' |
| 4 ], function load__hash_map2_test(exports, dart_sdk, expect) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const collection = dart_sdk.collection; |
| 8 const dart = dart_sdk.dart; |
| 9 const dartx = dart_sdk.dartx; |
| 10 const expect$ = expect.expect; |
| 11 const hash_map2_test = Object.create(null); |
| 12 let VoidToMap = () => (VoidToMap = dart.constFn(dart.functionType(core.Map, []
)))(); |
| 13 let MapToMap = () => (MapToMap = dart.constFn(dart.functionType(core.Map, [cor
e.Map])))(); |
| 14 let HashMapOfint$String = () => (HashMapOfint$String = dart.constFn(collection
.HashMap$(core.int, core.String)))(); |
| 15 let MapOfint$String = () => (MapOfint$String = dart.constFn(core.Map$(core.int
, core.String)))(); |
| 16 let LinkedHashMapOfint$String = () => (LinkedHashMapOfint$String = dart.constF
n(collection.LinkedHashMap$(core.int, core.String)))(); |
| 17 let HashMapOfString$int = () => (HashMapOfString$int = dart.constFn(collection
.HashMap$(core.String, core.int)))(); |
| 18 let MapOfString$int = () => (MapOfString$int = dart.constFn(core.Map$(core.Str
ing, core.int)))(); |
| 19 let LinkedHashMapOfString$int = () => (LinkedHashMapOfString$int = dart.constF
n(collection.LinkedHashMap$(core.String, core.int)))(); |
| 20 let intAndintToMap = () => (intAndintToMap = dart.constFn(dart.definiteFunctio
nType(core.Map, [core.int, core.int])))(); |
| 21 let intTobool = () => (intTobool = dart.constFn(dart.definiteFunctionType(core
.bool, [core.int])))(); |
| 22 let dynamicAnddynamicTovoid = () => (dynamicAnddynamicTovoid = dart.constFn(da
rt.definiteFunctionType(dart.void, [dart.dynamic, dart.dynamic])))(); |
| 23 let MapAndMapTovoid = () => (MapAndMapTovoid = dart.constFn(dart.definiteFunct
ionType(dart.void, [core.Map, core.Map])))(); |
| 24 let dynamicTobool = () => (dynamicTobool = dart.constFn(dart.definiteFunctionT
ype(core.bool, [dart.dynamic])))(); |
| 25 let VoidToint = () => (VoidToint = dart.constFn(dart.definiteFunctionType(core
.int, [])))(); |
| 26 let VoidTovoid = () => (VoidTovoid = dart.constFn(dart.definiteFunctionType(da
rt.void, [])))(); |
| 27 let FnAndFnTodynamic = () => (FnAndFnTodynamic = dart.constFn(dart.definiteFun
ctionType(dart.dynamic, [VoidToMap(), MapToMap()])))(); |
| 28 let VoidToHashMap = () => (VoidToHashMap = dart.constFn(dart.definiteFunctionT
ype(collection.HashMap, [])))(); |
| 29 let MapToHashMap = () => (MapToHashMap = dart.constFn(dart.definiteFunctionTyp
e(collection.HashMap, [core.Map])))(); |
| 30 let VoidToLinkedHashMap = () => (VoidToLinkedHashMap = dart.constFn(dart.defin
iteFunctionType(collection.LinkedHashMap, [])))(); |
| 31 let MapToLinkedHashMap = () => (MapToLinkedHashMap = dart.constFn(dart.definit
eFunctionType(collection.LinkedHashMap, [core.Map])))(); |
| 32 hash_map2_test.testMap = function(newMap, newMapFrom) { |
| 33 function gen(from, to) { |
| 34 let map = collection.LinkedHashMap.new(); |
| 35 for (let i = from; dart.notNull(i) < dart.notNull(to); i = dart.notNull(i)
+ 1) |
| 36 map[dartx.set](i, i); |
| 37 return map; |
| 38 } |
| 39 dart.fn(gen, intAndintToMap()); |
| 40 function odd(n) { |
| 41 return (dart.notNull(n) & 1) == 1; |
| 42 } |
| 43 dart.fn(odd, intTobool()); |
| 44 function even(n) { |
| 45 return (dart.notNull(n) & 1) == 0; |
| 46 } |
| 47 dart.fn(even, intTobool()); |
| 48 function addAll(toMap, fromMap) { |
| 49 fromMap[dartx.forEach](dart.fn((k, v) => { |
| 50 toMap[dartx.set](k, v); |
| 51 }, dynamicAnddynamicTovoid())); |
| 52 } |
| 53 dart.fn(addAll, MapAndMapTovoid()); |
| 54 { |
| 55 let map = newMap(); |
| 56 for (let i = 0; i < 256; i++) { |
| 57 map[dartx.set](i, i); |
| 58 } |
| 59 addAll(map, gen(256, 512)); |
| 60 addAll(map, newMapFrom(gen(512, 1000))); |
| 61 expect$.Expect.equals(1000, map[dartx.length]); |
| 62 for (let i = 0; i < 1000; i = i + 2) |
| 63 map[dartx.remove](i); |
| 64 expect$.Expect.equals(500, map[dartx.length]); |
| 65 expect$.Expect.isFalse(map[dartx.keys][dartx.any](even)); |
| 66 expect$.Expect.isTrue(map[dartx.keys][dartx.every](odd)); |
| 67 addAll(map, gen(0, 1000)); |
| 68 expect$.Expect.equals(1000, map[dartx.length]); |
| 69 } |
| 70 { |
| 71 let map = newMap(); |
| 72 map[dartx.set](0, 0); |
| 73 for (let i = 0; i < 1000; i++) { |
| 74 map[dartx.set](i + 1, i + 1); |
| 75 map[dartx.remove](i); |
| 76 expect$.Expect.equals(1, map[dartx.length]); |
| 77 } |
| 78 } |
| 79 { |
| 80 let map = newMap(); |
| 81 for (let i = 0; i < 1000; i++) { |
| 82 map[dartx.set](new hash_map2_test.BadHashCode(), 0); |
| 83 } |
| 84 expect$.Expect.equals(1000, map[dartx.length]); |
| 85 } |
| 86 { |
| 87 let map = newMap(); |
| 88 map[dartx.set](0, 0); |
| 89 map[dartx.set](1, 1); |
| 90 { |
| 91 let iter = map[dartx.keys][dartx.iterator]; |
| 92 iter.moveNext(); |
| 93 map[dartx.set](1, 9); |
| 94 iter.moveNext(); |
| 95 map[dartx.set](2, 2); |
| 96 expect$.Expect.throws(dart.bind(iter, 'moveNext'), dart.fn(e => core.Err
or.is(e), dynamicTobool())); |
| 97 } |
| 98 { |
| 99 let iter = map[dartx.keys][dartx.iterator]; |
| 100 expect$.Expect.equals(3, map[dartx.length]); |
| 101 iter.moveNext(); |
| 102 iter.moveNext(); |
| 103 iter.moveNext(); |
| 104 map[dartx.set](3, 3); |
| 105 expect$.Expect.throws(dart.bind(iter, 'moveNext'), dart.fn(e => core.Err
or.is(e), dynamicTobool())); |
| 106 } |
| 107 { |
| 108 let iter = map[dartx.keys][dartx.iterator]; |
| 109 iter.moveNext(); |
| 110 map[dartx.remove](1000); |
| 111 iter.moveNext(); |
| 112 let n = core.int._check(iter.current); |
| 113 map[dartx.remove](n); |
| 114 expect$.Expect.equals(n, iter.current); |
| 115 expect$.Expect.throws(dart.bind(iter, 'moveNext'), dart.fn(e => core.Err
or.is(e), dynamicTobool())); |
| 116 } |
| 117 { |
| 118 let iter = map[dartx.keys][dartx.iterator]; |
| 119 expect$.Expect.equals(3, map[dartx.length]); |
| 120 iter.moveNext(); |
| 121 iter.moveNext(); |
| 122 iter.moveNext(); |
| 123 let n = core.int._check(iter.current); |
| 124 map[dartx.remove](n); |
| 125 expect$.Expect.equals(n, iter.current); |
| 126 expect$.Expect.throws(dart.bind(iter, 'moveNext'), dart.fn(e => core.Err
or.is(e), dynamicTobool())); |
| 127 } |
| 128 { |
| 129 let iter = map[dartx.keys][dartx.iterator]; |
| 130 expect$.Expect.equals(2, map[dartx.length]); |
| 131 iter.moveNext(); |
| 132 let n = core.int._check(iter.current); |
| 133 map[dartx.set](n, dart.notNull(n) * 2); |
| 134 iter.moveNext(); |
| 135 expect$.Expect.equals(map[dartx.get](iter.current), iter.current); |
| 136 } |
| 137 { |
| 138 map[dartx.putIfAbsent](4, dart.fn(() => { |
| 139 map[dartx.set](5, 5); |
| 140 map[dartx.set](4, -1); |
| 141 return 4; |
| 142 }, VoidToint())); |
| 143 expect$.Expect.equals(4, map[dartx.get](4)); |
| 144 expect$.Expect.equals(5, map[dartx.get](5)); |
| 145 } |
| 146 { |
| 147 let map2 = newMap(); |
| 148 for (let key of map[dartx.keys]) { |
| 149 map2[dartx.set](key, dart.dsend(map[dartx.get](key), '+', 1)); |
| 150 } |
| 151 let iter = map[dartx.keys][dartx.iterator]; |
| 152 addAll(map, map2); |
| 153 iter.moveNext(); |
| 154 } |
| 155 } |
| 156 { |
| 157 let map = newMap(); |
| 158 map[dartx.putIfAbsent]("S", dart.fn(() => 0, VoidToint())); |
| 159 map[dartx.putIfAbsent]("T", dart.fn(() => 0, VoidToint())); |
| 160 map[dartx.putIfAbsent]("U", dart.fn(() => 0, VoidToint())); |
| 161 map[dartx.putIfAbsent]("C", dart.fn(() => 0, VoidToint())); |
| 162 map[dartx.putIfAbsent]("a", dart.fn(() => 0, VoidToint())); |
| 163 map[dartx.putIfAbsent]("b", dart.fn(() => 0, VoidToint())); |
| 164 map[dartx.putIfAbsent]("n", dart.fn(() => 0, VoidToint())); |
| 165 expect$.Expect.isTrue(map[dartx.containsKey]("n")); |
| 166 } |
| 167 { |
| 168 let map = newMap(); |
| 169 for (let i = 0; i < 128; i++) { |
| 170 map[dartx.putIfAbsent](i, dart.fn(() => i, VoidToint())); |
| 171 expect$.Expect.isTrue(map[dartx.containsKey](i)); |
| 172 map[dartx.putIfAbsent](i[dartx['>>']](1), dart.fn(() => -1, VoidToint())
); |
| 173 } |
| 174 for (let i = 0; i < 128; i++) { |
| 175 expect$.Expect.equals(i, map[dartx.get](i)); |
| 176 } |
| 177 } |
| 178 { |
| 179 for (let i = 1; i < 128; i++) { |
| 180 let map = newMapFrom(gen(0, i)); |
| 181 map[dartx.forEach](dart.fn((key, v) => { |
| 182 expect$.Expect.equals(key, map[dartx.get](key)); |
| 183 map[dartx.set](key, dart.dsend(key, '+', 1)); |
| 184 map[dartx.remove](1000); |
| 185 map[dartx.putIfAbsent](key, dart.fn(() => expect$.Expect.fail("SHOULD
NOT BE ABSENT"), VoidTovoid())); |
| 186 }, dynamicAnddynamicTovoid())); |
| 187 for (let key of map[dartx.keys]) { |
| 188 core.int._check(key); |
| 189 expect$.Expect.equals(dart.notNull(key) + 1, map[dartx.get](key)); |
| 190 map[dartx.set](key, dart.dsend(map[dartx.get](key), '+', 1)); |
| 191 map[dartx.remove](1000); |
| 192 map[dartx.putIfAbsent](key, dart.fn(() => expect$.Expect.fail("SHOULD
NOT BE ABSENT"), VoidTovoid())); |
| 193 } |
| 194 let iter = map[dartx.keys][dartx.iterator]; |
| 195 for (let key = 0; key < i; key++) { |
| 196 expect$.Expect.equals(key + 2, map[dartx.get](key)); |
| 197 map[dartx.set](key, key + 3); |
| 198 map[dartx.remove](1000); |
| 199 map[dartx.putIfAbsent](key, dart.fn(() => expect$.Expect.fail("SHOULD
NOT BE ABSENT"), VoidTovoid())); |
| 200 } |
| 201 iter.moveNext(); |
| 202 for (let key = 1; key < i; key++) { |
| 203 expect$.Expect.equals(key + 3, map[dartx.get](key)); |
| 204 map[dartx.remove](key); |
| 205 } |
| 206 iter = map[dartx.keys][dartx.iterator]; |
| 207 map[dartx.set](0, 2); |
| 208 iter.moveNext(); |
| 209 } |
| 210 } |
| 211 { |
| 212 let map = newMap(); |
| 213 map[dartx.set](null, 0); |
| 214 expect$.Expect.equals(1, map[dartx.length]); |
| 215 expect$.Expect.isTrue(map[dartx.containsKey](null)); |
| 216 expect$.Expect.isNull(map[dartx.keys][dartx.first]); |
| 217 expect$.Expect.isNull(map[dartx.keys][dartx.last]); |
| 218 map[dartx.set](null, 1); |
| 219 expect$.Expect.equals(1, map[dartx.length]); |
| 220 expect$.Expect.isTrue(map[dartx.containsKey](null)); |
| 221 map[dartx.remove](null); |
| 222 expect$.Expect.isTrue(map[dartx.isEmpty]); |
| 223 expect$.Expect.isFalse(map[dartx.containsKey](null)); |
| 224 map = newMapFrom((() => { |
| 225 let _ = core.Map.new(); |
| 226 _[dartx.set](null, 0); |
| 227 return _; |
| 228 })()); |
| 229 expect$.Expect.equals(1, map[dartx.length]); |
| 230 expect$.Expect.isTrue(map[dartx.containsKey](null)); |
| 231 expect$.Expect.isNull(map[dartx.keys][dartx.first]); |
| 232 expect$.Expect.isNull(map[dartx.keys][dartx.last]); |
| 233 map[dartx.set](null, 1); |
| 234 expect$.Expect.equals(1, map[dartx.length]); |
| 235 expect$.Expect.isTrue(map[dartx.containsKey](null)); |
| 236 map[dartx.remove](null); |
| 237 expect$.Expect.isTrue(map[dartx.isEmpty]); |
| 238 expect$.Expect.isFalse(map[dartx.containsKey](null)); |
| 239 let fromMap = core.Map.new(); |
| 240 fromMap[dartx.set](1, 0); |
| 241 fromMap[dartx.set](2, 0); |
| 242 fromMap[dartx.set](3, 0); |
| 243 fromMap[dartx.set](null, 0); |
| 244 fromMap[dartx.set](4, 0); |
| 245 fromMap[dartx.set](5, 0); |
| 246 fromMap[dartx.set](6, 0); |
| 247 expect$.Expect.equals(7, fromMap[dartx.length]); |
| 248 map = newMapFrom(fromMap); |
| 249 expect$.Expect.equals(7, map[dartx.length]); |
| 250 for (let i = 7; i < 128; i++) { |
| 251 map[dartx.set](i, 0); |
| 252 } |
| 253 expect$.Expect.equals(128, map[dartx.length]); |
| 254 expect$.Expect.isTrue(map[dartx.containsKey](null)); |
| 255 map[dartx.set](null, 1); |
| 256 expect$.Expect.equals(128, map[dartx.length]); |
| 257 expect$.Expect.isTrue(map[dartx.containsKey](null)); |
| 258 map[dartx.remove](null); |
| 259 expect$.Expect.equals(127, map[dartx.length]); |
| 260 expect$.Expect.isFalse(map[dartx.containsKey](null)); |
| 261 } |
| 262 }; |
| 263 dart.fn(hash_map2_test.testMap, FnAndFnTodynamic()); |
| 264 let const$; |
| 265 hash_map2_test.main = function() { |
| 266 expect$.Expect.isTrue(MapOfint$String().is(HashMapOfint$String().new())); |
| 267 expect$.Expect.isTrue(MapOfint$String().is(LinkedHashMapOfint$String().new()
)); |
| 268 expect$.Expect.isTrue(MapOfString$int().is(HashMapOfString$int().from(dart.m
ap()))); |
| 269 expect$.Expect.isTrue(MapOfString$int().is(LinkedHashMapOfString$int().from(
dart.map()))); |
| 270 expect$.Expect.isTrue(MapOfString$int().is(dart.map({}, core.String, core.in
t))); |
| 271 expect$.Expect.isTrue(MapOfString$int().is(const$ || (const$ = dart.const(da
rt.map({}, core.String, core.int))))); |
| 272 hash_map2_test.testMap(dart.fn(() => collection.HashMap.new(), VoidToHashMap
()), dart.fn(m => collection.HashMap.from(m), MapToHashMap())); |
| 273 hash_map2_test.testMap(dart.fn(() => collection.LinkedHashMap.new(), VoidToL
inkedHashMap()), dart.fn(m => collection.LinkedHashMap.from(m), MapToLinkedHashM
ap())); |
| 274 }; |
| 275 dart.fn(hash_map2_test.main, VoidTovoid()); |
| 276 hash_map2_test.BadHashCode = class BadHashCode extends core.Object { |
| 277 new() { |
| 278 this.id = (() => { |
| 279 let x = hash_map2_test.BadHashCode.idCounter; |
| 280 hash_map2_test.BadHashCode.idCounter = dart.notNull(x) + 1; |
| 281 return x; |
| 282 })(); |
| 283 } |
| 284 get hashCode() { |
| 285 return 42; |
| 286 } |
| 287 }; |
| 288 dart.setSignature(hash_map2_test.BadHashCode, { |
| 289 constructors: () => ({new: dart.definiteFunctionType(hash_map2_test.BadHashC
ode, [])}) |
| 290 }); |
| 291 hash_map2_test.BadHashCode.idCounter = 0; |
| 292 // Exports: |
| 293 exports.hash_map2_test = hash_map2_test; |
| 294 }); |
OLD | NEW |