Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 66d6624

Browse files
committed
Introduce even more tests
1 parent c8403cd commit 66d6624

File tree

1 file changed

+65
-63
lines changed

1 file changed

+65
-63
lines changed

arrayStringMap.test.ts

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -49,53 +49,53 @@ describe("Map with one object", () => {
4949
assert(arrayStringMap.has(sampleArray1));
5050
})
5151
it ("Map entries returns array with one object", () => {
52-
assert([...arrayStringMap.entries()].length === 1);
53-
assert([...arrayStringMap.entries()][0][0] === sampleArray1);
54-
assert([...arrayStringMap.entries()][0][1] === sampleValue1);
52+
assert([...arrayStringMap.entries()].length === 1, "Array length is 1");
53+
assert([...arrayStringMap.entries()][0][0] === sampleArray1, "Array is sampleArray1");
54+
assert([...arrayStringMap.entries()][0][1] === sampleValue1, "Value is sampleValue1");
5555
})
5656
it ("Map keys returns array with one object", () => {
57-
assert([...arrayStringMap.keys()].length === 1);
58-
assert([...arrayStringMap.keys()][0] === sampleArray1);
57+
assert([...arrayStringMap.keys()].length === 1, "Array length is 1");
58+
assert([...arrayStringMap.keys()][0] === sampleArray1, "Array is sampleArray1");
5959
})
6060
it ("Map values returns array with one value", () => {
61-
assert([...arrayStringMap.values()].length === 1);
62-
assert([...arrayStringMap.values()][0] === sampleValue1);
61+
assert([...arrayStringMap.values()].length === 1, "Array length is 1");
62+
assert([...arrayStringMap.values()][0] === sampleValue1, "Value is sampleValue1");
6363
})
6464
it("Map uses proper separator underneath", () => {
6565
// @ts-ignore - this is a test, and we need to make sure the underlying map
6666
// works as expected
67-
assert([...arrayStringMap._map.keys()][0].includes("\u200b"));
67+
assert([...arrayStringMap._map.keys()][0].includes("\u200b"), "Separator is present");
6868
// @ts-ignore - this is a test, and we need to make sure the underlying encoding map
6969
// works as expected
70-
assert([...arrayStringMap._converterInfo.values()][0] === sampleArray1);
70+
assert([...arrayStringMap._converterInfo.values()][0] === sampleArray1, "Converter info is sampleArray1");
7171
})
7272
it ("Clearing map removes object", () => {
7373
const copiedMap = copyArrayStringMap(arrayStringMap);
7474
copiedMap.clear();
75-
assert(copiedMap.size === 0);
76-
assert(copiedMap.get(sampleArray1) === undefined);
77-
assert(!copiedMap.has(sampleArray1));
78-
assert([...copiedMap.entries()].length === 0);
75+
assert(copiedMap.size === 0, "Map size is 0");
76+
assert(copiedMap.get(sampleArray1) === undefined, "Map get returns undefined");
77+
assert(!copiedMap.has(sampleArray1), "Map has returns false");
78+
assert([...copiedMap.entries()].length === 0, "Map entries returns empty array");
7979
// @ts-ignore - this is a test, and we need to make sure the underlying map
8080
// works as expected
81-
assert(copiedMap._map.size === 0);
81+
assert(copiedMap._map.size === 0, "Data map size is 0");
8282
// @ts-ignore - this is a test, and we need to make sure the underlying encoding map
8383
// works as expected
84-
assert(copiedMap._converterInfo.size === 0);
84+
assert(copiedMap._converterInfo.size === 0, "Converter map size is 0");
8585
})
8686
it ("Deleting entry from map removes object", () => {
8787
const copiedMap = copyArrayStringMap(arrayStringMap);
8888
copiedMap.delete(sampleArray1);
89-
assert(copiedMap.size === 0);
90-
assert(copiedMap.get(sampleArray1) === undefined);
91-
assert(!copiedMap.has(sampleArray1));
92-
assert([...copiedMap.entries()].length === 0);
89+
assert(copiedMap.size === 0, "Map size is 0");
90+
assert(copiedMap.get(sampleArray1) === undefined, "Map get returns undefined");
91+
assert(!copiedMap.has(sampleArray1), "Map has returns false");
92+
assert([...copiedMap.entries()].length === 0, "Map entries returns empty array");
9393
// @ts-ignore - this is a test, and we need to make sure the underlying map
9494
// works as expected
95-
assert(copiedMap._map.size === 0);
95+
assert(copiedMap._map.size === 0, "Data map size is 0");
9696
// @ts-ignore - this is a test, and we need to make sure the underlying encoding map
9797
// works as expected
98-
assert(copiedMap._converterInfo.size === 0);
98+
assert(copiedMap._converterInfo.size === 0, "Converter map size is 0");
9999
})
100100
})
101101

@@ -105,7 +105,7 @@ describe("Map with one object and different separator", () => {
105105
it("Map uses proper encoding underneath", () => {
106106
// @ts-ignore - this is a test, and we need to make sure the underlying item
107107
// works as expected
108-
assert([...arrayStringMap._map.keys()][0].includes(":"));
108+
assert([...arrayStringMap._map.keys()][0].includes(":"), "Separator is present");
109109
})
110110
})
111111

@@ -126,17 +126,17 @@ describe("Map with one object and alternate array", () => {
126126
assert(arrayStringMap.has(sampleArray2));
127127
})
128128
it ("Map entries returns array with one object", () => {
129-
assert([...arrayStringMap.entries()].length === 1);
130-
assert([...arrayStringMap.entries()][0][0] === sampleArray2);
131-
assert([...arrayStringMap.entries()][0][1] === sampleValue2);
129+
assert([...arrayStringMap.entries()].length === 1, "Array length is 1");
130+
assert([...arrayStringMap.entries()][0][0] === sampleArray2, "Array is sampleArray2");
131+
assert([...arrayStringMap.entries()][0][1] === sampleValue2, "Value is sampleValue2");
132132
})
133133
it ("Map keys returns array with one object", () => {
134-
assert([...arrayStringMap.keys()].length === 1);
135-
assert([...arrayStringMap.keys()][0] === sampleArray2);
134+
assert([...arrayStringMap.keys()].length === 1, "Array length is 1");
135+
assert([...arrayStringMap.keys()][0] === sampleArray2, "Array is sampleArray2");
136136
})
137137
it ("Map values returns array with one value", () => {
138-
assert([...arrayStringMap.values()].length === 1);
139-
assert([...arrayStringMap.values()][0] === sampleValue2);
138+
assert([...arrayStringMap.values()].length === 1, "Array length is 1");
139+
assert([...arrayStringMap.values()][0] === sampleValue2, "Value is sampleValue2");
140140
})
141141
})
142142

@@ -148,75 +148,77 @@ describe("Map with two objects", () => {
148148
assert(arrayStringMap.size === 2);
149149
})
150150
it ("Map get returns value", () => {
151-
assert(arrayStringMap.get(sampleArray1) === sampleValue1);
152-
assert(arrayStringMap.get(sampleArray3) === sampleValue2);
151+
assert(arrayStringMap.get(sampleArray1) === sampleValue1, "Value is sampleValue1");
152+
assert(arrayStringMap.get(sampleArray3) === sampleValue2, "Value is sampleValue2");
153153
})
154154
it ("Alternate array with same values returns same value", () => {
155-
assert(arrayStringMap.get(sampleArray2) === sampleValue1);
156-
assert(arrayStringMap.get(sampleArray3) !== sampleValue1);
155+
assert(arrayStringMap.get(sampleArray2) === sampleValue1, "Value is sampleValue1");
156+
assert(arrayStringMap.get(sampleArray3) !== sampleValue1, "Value is not sampleValue1");
157157
})
158158
it ("Map has returns true", () => {
159-
assert(arrayStringMap.has(sampleArray1));
160-
assert(arrayStringMap.has(sampleArray2));
159+
assert(arrayStringMap.has(sampleArray1), "Has for sampleArray1 returns true");
160+
assert(arrayStringMap.has(sampleArray2), "Has for sampleArray2 returns true");
161161
})
162162
it ("Map entries returns array with two objects", () => {
163-
assert([...arrayStringMap.entries()].length === 2);
164-
assert([...arrayStringMap.entries()][0][0] === sampleArray1);
165-
assert([...arrayStringMap.entries()][0][1] === sampleValue1);
166-
assert([...arrayStringMap.entries()][1][0] === sampleArray3);
167-
assert([...arrayStringMap.entries()][1][1] === sampleValue2);
163+
assert([...arrayStringMap.entries()].length === 2, "Array length is 2");
164+
assert([...arrayStringMap.entries()][0][0] === sampleArray1, "Array is sampleArray1");
165+
assert([...arrayStringMap.entries()][0][1] === sampleValue1, "Value is sampleValue1");
166+
assert([...arrayStringMap.entries()][1][0] === sampleArray3, "Array is sampleArray3");
167+
assert([...arrayStringMap.entries()][1][1] === sampleValue2, "Value is sampleValue2");
168168
})
169169
it ("Map keys returns array with two objects", () => {
170-
assert([...arrayStringMap.keys()].length === 2);
171-
assert([...arrayStringMap.keys()][0] === sampleArray1);
172-
assert([...arrayStringMap.keys()][1] === sampleArray3);
170+
assert([...arrayStringMap.keys()].length === 2, "Array length is 2");
171+
assert([...arrayStringMap.keys()][0] === sampleArray1, "Array is sampleArray1");
172+
assert([...arrayStringMap.keys()][1] === sampleArray3, "Array is sampleArray3");
173173
})
174174
it ("Map values returns array with two values", () => {
175-
assert([...arrayStringMap.values()].length === 1);
176-
assert([...arrayStringMap.values()][0] === sampleValue1);
175+
assert([...arrayStringMap.values()].length === 1, "Array length is 1");
176+
assert([...arrayStringMap.values()][0] === sampleValue1, "Value is sampleValue1");
177177
})
178178
it("Map uses proper separator underneath", () => {
179179
// @ts-ignore - this is a test, and we need to make sure the underlying map
180180
// works as expected
181-
assert([...arrayStringMap._map.keys()][0].includes("\u200b"));
181+
assert([...arrayStringMap._map.keys()][0].includes("\u200b"), "Separator is present in item 0");
182182
// @ts-ignore - this is a test, and we need to make sure the underlying map
183183
// works as expected
184-
assert([...arrayStringMap._map.keys()][1].includes("\u200b"));
184+
assert([...arrayStringMap._map.keys()][1].includes("\u200b"), "Separator is present in item 1");
185185
// @ts-ignore - this is a test, and we need to make sure the underlying encoding map
186186
// works as expected
187-
assert([...arrayStringMap._converterInfo.values()][0] === sampleArray1);
187+
assert([...arrayStringMap._converterInfo.values()][0] === sampleArray1, "Converter info is sampleArray1 for item 0");
188188
// @ts-ignore - this is a test, and we need to make sure the underlying map
189189
// works as expected
190-
assert([...arrayStringMap._converterInfo.values()][1] === sampleArray3);
190+
assert([...arrayStringMap._converterInfo.values()][1] === sampleArray3, "Converter info is sampleArray3 for item 1");
191191
})
192192
it ("Clearing map removes all objects", () => {
193193
const copiedMap = copyArrayStringMap(arrayStringMap);
194194
copiedMap.clear();
195-
assert(copiedMap.size === 0);
196-
assert(copiedMap.get(sampleArray1) === undefined);
197-
assert(!copiedMap.has(sampleArray1));
198-
assert([...copiedMap.entries()].length === 0);
195+
assert(copiedMap.size === 0, "Map size is 0");
196+
assert(copiedMap.get(sampleArray1) === undefined, "Map get returns undefined for sampleArray1");
197+
assert(copiedMap.get(sampleArray3) === undefined, "Map get returns undefined for sampleArray3");
198+
assert(!copiedMap.has(sampleArray1), "Map has returns false for sampleArray1");
199+
assert(!copiedMap.has(sampleArray3), "Map has returns false for sampleArray3");
200+
assert([...copiedMap.entries()].length === 0, "Map entries returns empty array");
199201
// @ts-ignore - this is a test, and we need to make sure the underlying map
200202
// works as expected
201-
assert(copiedMap._map.size === 0);
203+
assert(copiedMap._map.size === 0, "Data map size is 0");
202204
// @ts-ignore - this is a test, and we need to make sure the underlying encoding map
203205
// works as expected
204-
assert(copiedMap._converterInfo.size === 0);
206+
assert(copiedMap._converterInfo.size === 0, "Converter map size is 0");
205207
})
206208
it ("Deleting entry from map removes object but keeps other object", () => {
207209
const copiedMap = copyArrayStringMap(arrayStringMap);
208210
copiedMap.delete(sampleArray1);
209-
assert(copiedMap.size === 1);
210-
assert(copiedMap.get(sampleArray1) === undefined);
211-
assert(copiedMap.get(sampleArray3) === sampleValue2);
212-
assert(!copiedMap.has(sampleArray1));
213-
assert(copiedMap.has(sampleArray3));
214-
assert([...copiedMap.entries()].length === 1);
211+
assert(copiedMap.size === 1, "Map size is 1");
212+
assert(copiedMap.get(sampleArray1) === undefined, "Map get returns undefined for sampleArray1");
213+
assert(copiedMap.get(sampleArray3) === sampleValue2, "Map get returns sampleValue2 for sampleArray3");
214+
assert(!copiedMap.has(sampleArray1), "Map has returns false for sampleArray1");
215+
assert(copiedMap.has(sampleArray3), "Map has returns true for sampleArray3");
216+
assert([...copiedMap.entries()].length === 1, "Map entries returns array with one object");
215217
// @ts-ignore - this is a test, and we need to make sure the underlying map
216218
// works as expected
217-
assert(copiedMap._map.size === 1);
219+
assert(copiedMap._map.size === 1, "Data map size is 1");
218220
// @ts-ignore - this is a test, and we need to make sure the underlying encoding map
219221
// works as expected
220-
assert(copiedMap._converterInfo.size === 1);
222+
assert(copiedMap._converterInfo.size === 1, "Converter map size is 1");
221223
})
222224
})

0 commit comments

Comments
 (0)