deno.land / x / linq@4.0.2 / test / dictionary.js

نووسراو ببینە
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { test, testModule, equal, ok } from './testutils.js'import Enumerable from '../linq.js'
testModule("Dictionary");
var aComparer = function (x) { return x.a }var obj1 = { a: 1 }var obj1_ = { a: 1 }var obj2 = { a: 2 }var obj2_ = { a: 2 }
test("AddGetCountRemoveClear", function (){ var dict = Enumerable.empty().toDictionary(); dict.add("a", 1); dict.add("b", 2); dict.add("c", 3); dict.add("c", 100); equal(1, dict.get("a")); equal(2, dict.get("b")); equal(100, dict.get("c"));
dict.add(obj1, 1); dict.add(obj1_, 2); dict.add(obj2, 3); dict.add(obj2_, 4); equal(1, dict.get(obj1)); equal(2, dict.get(obj1_)); equal(3, dict.get(obj2)); equal(4, dict.get(obj2_));
equal(7, dict.count());
dict.remove("a"); dict.remove(obj1); dict.remove(obj1_); dict.remove(obj2_); equal(undefined, dict.get("a")); equal(undefined, dict.get(obj1)); equal(undefined, dict.get(obj1_)); equal(undefined, dict.get(obj2_));
equal(3, dict.count()); dict.clear(); equal(undefined, dict.get("b")); equal(undefined, dict.get(obj2)); equal(0, dict.count());
dict = Enumerable.empty().toDictionary("", "", aComparer);
dict.add(obj1, 1); dict.add(obj1_, 2); dict.add(obj2, 3); dict.add(obj2_, 4); equal(2, dict.get(obj1)); equal(2, dict.get(obj1_)); equal(4, dict.get(obj2)); equal(4, dict.get(obj2_));
equal(2, dict.count());
dict.remove(obj1); equal(undefined, dict.get(obj1)); equal(undefined, dict.get(obj1_));
equal(1, dict.count()); dict.clear(); equal(undefined, dict.get(obj2)); equal(undefined, dict.get(obj2_)); equal(0, dict.count());});
test("SetContains", function (){ var dict = Enumerable.empty().toDictionary(); dict.add("a", 1); dict.add("b", 2); dict.add(obj1, 1); dict.add(obj1_, 2); dict.set("a", 1000); dict.set("b", 2000); dict.set(obj1, 10000); dict.set(obj1_, 20000); equal(1000, dict.get("a")); equal(2000, dict.get("b")); equal(10000, dict.get(obj1)); equal(20000, dict.get(obj1_)); ok(dict.contains("a")); ok(dict.contains("b")); ok(dict.contains(obj1)); ok(dict.contains(obj1_)); ok(!dict.contains("c")); ok(!dict.contains(obj2));
dict = Enumerable.empty().toDictionary("", "", aComparer); dict.add(obj1, 1); dict.add(obj1_, 2); dict.add(obj2, 3); dict.add(obj2_, 4); dict.set(obj1, 10000); dict.set(obj1_, 20000); dict.set(obj2, 30000); dict.set(obj2_, 40000); equal(20000, dict.get(obj1)); equal(20000, dict.get(obj1_)); equal(40000, dict.get(obj2)); equal(40000, dict.get(obj2_)); ok(dict.contains(obj1)); ok(dict.contains(obj1_)); ok(!dict.contains({ a: 3 }));});
test("toEnumerable", function (){ var dict = Enumerable.empty().toDictionary(); dict.add("a", 1); dict.add("b", 2); dict.add("c", 3);
var ar = dict.toEnumerable().orderBy("$.key").toArray(); equal("a", ar[0].key); equal(1, ar[0].value); equal("b", ar[1].key); equal(2, ar[1].value); equal("c", ar[2].key); equal(3, ar[2].value);
dict.clear(); dict.add(obj1, 1); dict.add(obj1_, 2); dict.add(obj2, 3); dict.add(obj2_, 4);
ar = dict.toEnumerable().orderBy("$.key.a").toArray(); equal(obj1, ar[0].key); equal(1, ar[0].value); equal(obj1_, ar[1].key); equal(2, ar[1].value); equal(obj2, ar[2].key); equal(3, ar[2].value); equal(obj2_, ar[3].key); equal(4, ar[3].value);
dict = Enumerable.empty().toDictionary("", "", aComparer); dict.add(obj1, 1); dict.add(obj1_, 2); dict.add(obj2, 3); dict.add(obj2_, 4); ar = dict.toEnumerable().orderBy("$.key.a").toArray(); equal(obj1_, ar[0].key); equal(2, ar[0].value); equal(obj2_, ar[1].key); equal(4, ar[1].value);});
linq

Version Info

Tagged at
7 months ago