-
-
Notifications
You must be signed in to change notification settings - Fork 666
/
map.ts
74 lines (66 loc) · 1.64 KB
/
map.ts
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
function testNumeric<K extends number,V extends number>(): void {
var map = new Map<K,V>();
// insert new
for (let k: K = 0; k < 100; ++k) {
assert(!map.has(k));
map.set(k, 10 + <V>k);
assert(map.has(k));
assert(map.get(k) == 10 + <V>k);
}
assert(map.size == 100);
// insert duplicate
for (let k: K = 0; k < 100; ++k) {
assert(map.has(k));
assert(map.get(k) == 10 + <V>k);
map.set(k, 20 + <V>k);
assert(map.has(k));
assert(map.get(k) == 20 + <V>k);
}
assert(map.size == 100);
// keys and values
let keys = map.keys();
let vals = map.values();
let keyMap = new Map<K, K>();
let valMap = new Map<V, V>();
for (let index = 0; index < keys.length; ++index) {
let key = keys[index];
let value = vals[index];
assert(map.has(key));
assert(map.has(<K>(value - 20)));
keyMap.set(key, key);
valMap.set(<V>(value - 20), <V>(value - 20));
}
assert(keyMap.size == 100);
assert(valMap.size == 100);
// delete
for (let k: K = 0; k < 50; ++k) {
assert(map.has(k));
assert(map.get(k) == 20 + <V>k);
map.delete(k);
assert(!map.has(k));
}
assert(map.size == 50);
// insert + delete
for (let k: K = 0; k < 50; ++k) {
assert(!map.has(k));
map.set(k, 10 + <V>k);
assert(map.has(k));
map.delete(k);
assert(!map.has(k));
}
assert(map.size == 50);
// clear
map.clear();
assert(map.size == 0);
}
testNumeric<i8,i32>();
testNumeric<u8,i32>();
testNumeric<i16,i32>();
testNumeric<u16,i32>();
testNumeric<i32,i32>();
testNumeric<u32,i32>();
testNumeric<i64,i32>();
testNumeric<u64,i32>();
testNumeric<f32,i32>();
testNumeric<f64,i32>();
__collect();