@everyonesoftware/common 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.c8rc.json +12 -0
- package/.github/workflows/publish.yml +38 -0
- package/.mocharc.json +9 -0
- package/README.md +9 -0
- package/package.json +36 -0
- package/sources/assertMessageParameters.ts +22 -0
- package/sources/asyncIterator.ts +437 -0
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +48 -0
- package/sources/asyncResult.ts +95 -0
- package/sources/basicDisposable.ts +57 -0
- package/sources/byteList.ts +202 -0
- package/sources/byteListStream.ts +121 -0
- package/sources/byteReadStream.ts +24 -0
- package/sources/byteWriteStream.ts +16 -0
- package/sources/bytes.ts +25 -0
- package/sources/characterList.ts +195 -0
- package/sources/characterListStream.ts +151 -0
- package/sources/characterReadStream.ts +81 -0
- package/sources/characterReadStreamIterator.ts +128 -0
- package/sources/characterWriteStream.ts +45 -0
- package/sources/commandLineParameter.ts +45 -0
- package/sources/commandLineParameters.ts +21 -0
- package/sources/comparable.ts +144 -0
- package/sources/comparer.ts +133 -0
- package/sources/comparison.ts +20 -0
- package/sources/concatenateIterable.ts +119 -0
- package/sources/concatenateIterator.ts +165 -0
- package/sources/condition.ts +329 -0
- package/sources/currentProcess.ts +158 -0
- package/sources/dateTime.ts +130 -0
- package/sources/depthFirstSearch.ts +230 -0
- package/sources/disposable.ts +31 -0
- package/sources/emptyError.ts +10 -0
- package/sources/english.ts +45 -0
- package/sources/equalFunctions.ts +123 -0
- package/sources/fetchHttpClient.ts +89 -0
- package/sources/fetchHttpResponse.ts +106 -0
- package/sources/flatMapIterable.ts +104 -0
- package/sources/flatMapIterator.ts +152 -0
- package/sources/generator.ts +251 -0
- package/sources/httpClient.ts +36 -0
- package/sources/httpHeader.ts +37 -0
- package/sources/httpHeaders.ts +216 -0
- package/sources/httpIncomingRequest.ts +30 -0
- package/sources/httpIncomingResponse.ts +19 -0
- package/sources/httpMethod.ts +164 -0
- package/sources/httpOutgoingRequest.ts +119 -0
- package/sources/httpOutgoingResponse.ts +113 -0
- package/sources/httpServer.ts +34 -0
- package/sources/inMemoryCharacterWriteStream.ts +78 -0
- package/sources/index.ts +101 -0
- package/sources/iterable.ts +345 -0
- package/sources/iterator.ts +481 -0
- package/sources/iteratorToJavascriptIteratorAdapter.ts +48 -0
- package/sources/javascript.ts +59 -0
- package/sources/javascriptArrayList.ts +175 -0
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +124 -0
- package/sources/javascriptIteratorToIteratorAdapter.ts +133 -0
- package/sources/javascriptMapMap.ts +143 -0
- package/sources/javascriptSetSet.ts +134 -0
- package/sources/list.ts +330 -0
- package/sources/listQueue.ts +62 -0
- package/sources/listStack.ts +62 -0
- package/sources/luxonDateTime.ts +109 -0
- package/sources/map.ts +302 -0
- package/sources/mapAsyncIterator.ts +141 -0
- package/sources/mapIterable.ts +105 -0
- package/sources/mapIterator.ts +145 -0
- package/sources/mutableCondition.ts +451 -0
- package/sources/mutableHttpHeaders.ts +204 -0
- package/sources/mutableMap.ts +292 -0
- package/sources/network.ts +18 -0
- package/sources/node.ts +37 -0
- package/sources/nodeJSCharacterWriteStream.ts +42 -0
- package/sources/nodeJSHttpIncomingRequest.ts +132 -0
- package/sources/nodeJSHttpServer.ts +134 -0
- package/sources/notFoundError.ts +12 -0
- package/sources/postCondition.ts +284 -0
- package/sources/postConditionError.ts +12 -0
- package/sources/preCondition.ts +284 -0
- package/sources/preConditionError.ts +12 -0
- package/sources/promiseAsyncResult.ts +174 -0
- package/sources/property.ts +63 -0
- package/sources/queue.ts +49 -0
- package/sources/realNetwork.ts +28 -0
- package/sources/recreationDotGovClient.ts +259 -0
- package/sources/searchControl.ts +42 -0
- package/sources/set.ts +244 -0
- package/sources/skipAsyncIterator.ts +145 -0
- package/sources/skipIterator.ts +155 -0
- package/sources/stack.ts +48 -0
- package/sources/stringComparer.ts +33 -0
- package/sources/stringIterator.ts +149 -0
- package/sources/strings.ts +322 -0
- package/sources/syncResult.ts +300 -0
- package/sources/takeAsyncIterator.ts +141 -0
- package/sources/takeIterator.ts +151 -0
- package/sources/toStringFunctions.ts +185 -0
- package/sources/types.ts +371 -0
- package/sources/whereAsyncIterator.ts +143 -0
- package/sources/whereIterable.ts +108 -0
- package/sources/whereIterator.ts +157 -0
- package/sources/wonderlandTrailClient.ts +1503 -0
- package/tests/assertTest.ts +113 -0
- package/tests/assertTestTests.ts +75 -0
- package/tests/basicTestSkip.ts +51 -0
- package/tests/byteListStreamTests.ts +390 -0
- package/tests/byteListTests.ts +27 -0
- package/tests/bytesTests.ts +43 -0
- package/tests/characterListStreamTests.ts +391 -0
- package/tests/characterListTests.ts +250 -0
- package/tests/characterWriteStreamTests.ts +12 -0
- package/tests/comparerTests.ts +92 -0
- package/tests/conditionTests.ts +877 -0
- package/tests/consoleTestRunner.ts +404 -0
- package/tests/consoleTestRunnerTests.ts +651 -0
- package/tests/dateTimeTests.ts +30 -0
- package/tests/depthFirstSearchTests.ts +106 -0
- package/tests/disposableTests.ts +121 -0
- package/tests/englishTests.ts +103 -0
- package/tests/equalFunctionsTests.ts +223 -0
- package/tests/failedTest.ts +43 -0
- package/tests/fetchHttpClientTests.ts +33 -0
- package/tests/generatorTests.ts +86 -0
- package/tests/httpClientTests.ts +18 -0
- package/tests/inMemoryCharacterWriteStreamTests.ts +117 -0
- package/tests/iterableTests.ts +141 -0
- package/tests/iteratorTests.ts +1086 -0
- package/tests/javascriptMapMapTests.ts +21 -0
- package/tests/listTests.ts +338 -0
- package/tests/mapIteratorTests.ts +55 -0
- package/tests/mapTests.ts +104 -0
- package/tests/mutableConditionTests.ts +273 -0
- package/tests/mutableMapTests.ts +154 -0
- package/tests/nodeJSHttpServerTests.ts +75 -0
- package/tests/notFoundErrorTests.ts +24 -0
- package/tests/postConditionErrorTests.ts +24 -0
- package/tests/preConditionErrorTests.ts +24 -0
- package/tests/promiseAsyncResultTests.ts +688 -0
- package/tests/propertyTests.ts +63 -0
- package/tests/queueTests.ts +29 -0
- package/tests/recreationDotGovClientTests.ts +191 -0
- package/tests/setTests.ts +140 -0
- package/tests/skippedTest.ts +39 -0
- package/tests/stackTests.ts +66 -0
- package/tests/stringComparerTests.ts +60 -0
- package/tests/stringIteratorTests.ts +156 -0
- package/tests/stringsTests.ts +516 -0
- package/tests/syncResultTests.ts +1251 -0
- package/tests/test.ts +228 -0
- package/tests/testAction.ts +75 -0
- package/tests/testActionTests.ts +93 -0
- package/tests/testFailureTests.ts +12 -0
- package/tests/testRunner.ts +267 -0
- package/tests/testRunnerTests.ts +895 -0
- package/tests/testSkip.ts +34 -0
- package/tests/tests.ts +103 -0
- package/tests/toStringFunctionsTests.ts +55 -0
- package/tests/typesTests.ts +257 -0
- package/tests/whereIteratorTests.ts +77 -0
- package/tests/wonderlandTrailClientTests.ts +452 -0
- package/tsconfig.json +17 -0
- package/tsup.config.ts +13 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { JavascriptMapMap } from "../sources/javascriptMapMap";
|
|
2
|
+
import { mapTests } from "./mapTests";
|
|
3
|
+
import { Test } from "./test";
|
|
4
|
+
import { TestRunner } from "./testRunner";
|
|
5
|
+
|
|
6
|
+
export function test(runner: TestRunner): void
|
|
7
|
+
{
|
|
8
|
+
runner.testFile("javascriptMapMap.ts", () =>
|
|
9
|
+
{
|
|
10
|
+
runner.testType("JavascriptMapMap<TKey,TValue>", () =>
|
|
11
|
+
{
|
|
12
|
+
runner.testFunction("create()", (test: Test) =>
|
|
13
|
+
{
|
|
14
|
+
const map: JavascriptMapMap<number,string> = JavascriptMapMap.create();
|
|
15
|
+
test.assertEqual(map.getCount().await(), 0);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
mapTests(runner, JavascriptMapMap.create);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { JavascriptIterable } from "../sources/javascript";
|
|
2
|
+
import { List } from "../sources/list";
|
|
3
|
+
import { PreConditionError } from "../sources/preConditionError";
|
|
4
|
+
import { isIterable } from "../sources/types";
|
|
5
|
+
import { Test } from "./test";
|
|
6
|
+
import { TestRunner } from "./testRunner";
|
|
7
|
+
|
|
8
|
+
export function test(runner: TestRunner): void
|
|
9
|
+
{
|
|
10
|
+
runner.testFile("list.ts", () =>
|
|
11
|
+
{
|
|
12
|
+
runner.testType("List<T>", () =>
|
|
13
|
+
{
|
|
14
|
+
runner.testFunction("create(T[]|Iterable<T>|undefined)", () =>
|
|
15
|
+
{
|
|
16
|
+
runner.test("with no arguments", (test: Test) =>
|
|
17
|
+
{
|
|
18
|
+
const list: List<number> = List.create();
|
|
19
|
+
test.assertNotUndefinedAndNotNull(list);
|
|
20
|
+
test.assertEqual(list.toArray().await(), []);
|
|
21
|
+
test.assertEqual(list.toString(), "[]");
|
|
22
|
+
test.assertEqual(list.getCount().await(), 0);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
runner.test("with undefined", (test: Test) =>
|
|
26
|
+
{
|
|
27
|
+
const list: List<number> = List.create(undefined);
|
|
28
|
+
test.assertNotUndefinedAndNotNull(list);
|
|
29
|
+
test.assertEqual(list.toArray().await(), []);
|
|
30
|
+
test.assertEqual(list.toString(), "[]");
|
|
31
|
+
test.assertEqual(list.getCount().await(), 0);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
runner.test("with empty array", (test: Test) =>
|
|
35
|
+
{
|
|
36
|
+
const list: List<number> = List.create<number>([]);
|
|
37
|
+
test.assertNotUndefinedAndNotNull(list);
|
|
38
|
+
test.assertEqual(list.toArray().await(), []);
|
|
39
|
+
test.assertSame(list.toString(), "[]");
|
|
40
|
+
test.assertSame(list.getCount().await(), 0);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
runner.test("with non-empty array", (test: Test) =>
|
|
44
|
+
{
|
|
45
|
+
const list: List<number> = List.create([1, 2, 3]);
|
|
46
|
+
test.assertNotUndefinedAndNotNull(list);
|
|
47
|
+
test.assertEqual(list.toArray().await(), [1, 2, 3]);
|
|
48
|
+
test.assertSame(list.toString(), "[1,2,3]");
|
|
49
|
+
test.assertSame(list.getCount().await(), 3);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
runner.test("with empty Iterable<T>", (test: Test) =>
|
|
53
|
+
{
|
|
54
|
+
const list: List<number> = List.create(List.create());
|
|
55
|
+
test.assertNotUndefinedAndNotNull(list);
|
|
56
|
+
test.assertEqual(list.toArray().await(), []);
|
|
57
|
+
test.assertSame(list.toString(), "[]");
|
|
58
|
+
test.assertSame(list.getCount().await(), 0);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
runner.test("with non-empty Iterable<T>", (test: Test) =>
|
|
62
|
+
{
|
|
63
|
+
const list: List<number> = List.create(List.create([1, 2, 3]));
|
|
64
|
+
test.assertNotUndefinedAndNotNull(list);
|
|
65
|
+
test.assertEqual(list.toArray().await(), [1, 2, 3]);
|
|
66
|
+
test.assertTrue(isIterable(list));
|
|
67
|
+
test.assertSame(list.toString(), "[1,2,3]");
|
|
68
|
+
test.assertSame(list.getCount().await(), 3);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
runner.testFunction("set(number,T)", () =>
|
|
73
|
+
{
|
|
74
|
+
function setErrorTest(list: List<number>, index: number, value: number, expectedError: Error): void
|
|
75
|
+
{
|
|
76
|
+
runner.test(`with ${runner.andList([list, index, value])}`, (test: Test) =>
|
|
77
|
+
{
|
|
78
|
+
const backupList: List<number> = List.create(list);
|
|
79
|
+
test.assertThrows(() => list.set(index, value), expectedError);
|
|
80
|
+
test.assertEqual(list, backupList);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
setErrorTest(List.create(), -1, 5, new PreConditionError(
|
|
85
|
+
"Expression: count",
|
|
86
|
+
"Expected: greater than or equal to 1",
|
|
87
|
+
"Actual: 0",
|
|
88
|
+
));
|
|
89
|
+
setErrorTest(List.create(), 0, 5, new PreConditionError(
|
|
90
|
+
"Expression: count",
|
|
91
|
+
"Expected: greater than or equal to 1",
|
|
92
|
+
"Actual: 0",
|
|
93
|
+
));
|
|
94
|
+
setErrorTest(List.create(), 1, 5, new PreConditionError(
|
|
95
|
+
"Expression: count",
|
|
96
|
+
"Expected: greater than or equal to 1",
|
|
97
|
+
"Actual: 0"
|
|
98
|
+
));
|
|
99
|
+
setErrorTest(List.create([1]), -1, 5, new PreConditionError(
|
|
100
|
+
"Expression: index",
|
|
101
|
+
"Expected: 0",
|
|
102
|
+
"Actual: -1"
|
|
103
|
+
));
|
|
104
|
+
setErrorTest(List.create([1]), 1, 5, new PreConditionError(
|
|
105
|
+
"Expression: index",
|
|
106
|
+
"Expected: 0",
|
|
107
|
+
"Actual: 1"
|
|
108
|
+
));
|
|
109
|
+
|
|
110
|
+
function setTest(list: List<number>, index: number, value: number, expected: number[]): void
|
|
111
|
+
{
|
|
112
|
+
runner.test(`with ${runner.andList([list, index, value])}`, (test: Test) =>
|
|
113
|
+
{
|
|
114
|
+
const setResult: List<number> = list.set(index, value);
|
|
115
|
+
test.assertSame(list, setResult);
|
|
116
|
+
test.assertEqual(list.toArray().await(), expected);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
setTest(List.create([1]), 0, 5, [5]);
|
|
121
|
+
setTest(List.create([1, 2]), 0, 5, [5, 2]);
|
|
122
|
+
setTest(List.create([1, 2]), 1, 5, [1, 5]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
runner.testFunction("get(number)", () =>
|
|
126
|
+
{
|
|
127
|
+
function getErrorTest(list: List<number>, index: number, expectedError: Error): void
|
|
128
|
+
{
|
|
129
|
+
runner.test(`with ${runner.andList([list, index])}`, (test: Test) =>
|
|
130
|
+
{
|
|
131
|
+
const backupList: List<number> = List.create(list);
|
|
132
|
+
test.assertThrows(() => list.get(index), expectedError);
|
|
133
|
+
test.assertEqual(list, backupList);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getErrorTest(List.create(), -1, new PreConditionError(
|
|
138
|
+
"Expression: count",
|
|
139
|
+
"Expected: greater than or equal to 1",
|
|
140
|
+
"Actual: 0"
|
|
141
|
+
));
|
|
142
|
+
getErrorTest(List.create(), 0, new PreConditionError(
|
|
143
|
+
"Expression: count",
|
|
144
|
+
"Expected: greater than or equal to 1",
|
|
145
|
+
"Actual: 0"
|
|
146
|
+
));
|
|
147
|
+
getErrorTest(List.create(), 1, new PreConditionError(
|
|
148
|
+
"Expression: count",
|
|
149
|
+
"Expected: greater than or equal to 1",
|
|
150
|
+
"Actual: 0"
|
|
151
|
+
));
|
|
152
|
+
getErrorTest(List.create([1]), -1, new PreConditionError(
|
|
153
|
+
"Expression: index",
|
|
154
|
+
"Expected: 0",
|
|
155
|
+
"Actual: -1"
|
|
156
|
+
));
|
|
157
|
+
getErrorTest(List.create([1]), 1, new PreConditionError(
|
|
158
|
+
"Expression: index",
|
|
159
|
+
"Expected: 0",
|
|
160
|
+
"Actual: 1"
|
|
161
|
+
));
|
|
162
|
+
|
|
163
|
+
function getTest(list: List<number>, index: number, expected: number): void
|
|
164
|
+
{
|
|
165
|
+
runner.test(`with ${runner.andList([list, index])}`, (test: Test) =>
|
|
166
|
+
{
|
|
167
|
+
test.assertSame(list.get(index).await(), expected);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
getTest(List.create([1]), 0, 1);
|
|
172
|
+
getTest(List.create([1, 2]), 0, 1);
|
|
173
|
+
getTest(List.create([1, 2]), 1, 2);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
runner.testFunction("add(T)", () =>
|
|
177
|
+
{
|
|
178
|
+
function addTest(list: List<number>, value: number, expected: number[]): void
|
|
179
|
+
{
|
|
180
|
+
runner.test(`with ${runner.andList([list, value])}`, (test: Test) =>
|
|
181
|
+
{
|
|
182
|
+
const addResult: List<number> = list.add(value);
|
|
183
|
+
test.assertSame(addResult, list);
|
|
184
|
+
test.assertEqual(list.toArray().await(), expected);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
addTest(List.create(), 1, [1]);
|
|
189
|
+
addTest(List.create([1]), 2, [1, 2]);
|
|
190
|
+
addTest(List.create([1, 2]), 3, [1, 2, 3]);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
runner.testFunction("addAll(T)", () =>
|
|
194
|
+
{
|
|
195
|
+
function addAllTest(list: List<number>, values: JavascriptIterable<number>, expected: number[]): void
|
|
196
|
+
{
|
|
197
|
+
runner.test(`with ${runner.andList([list, values])}`, (test: Test) =>
|
|
198
|
+
{
|
|
199
|
+
const addResult: List<number> = list.addAll(values);
|
|
200
|
+
test.assertSame(addResult, list);
|
|
201
|
+
test.assertEqual(list.toArray().await(), expected);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
addAllTest(List.create(), [1], [1]);
|
|
206
|
+
addAllTest(List.create([1]), [2], [1, 2]);
|
|
207
|
+
addAllTest(List.create([1, 2]), [3], [1, 2, 3]);
|
|
208
|
+
addAllTest(List.create(), [1, 2], [1, 2]);
|
|
209
|
+
addAllTest(List.create([1]), [2, 3], [1, 2, 3]);
|
|
210
|
+
addAllTest(List.create([1, 2]), [3, 4], [1, 2, 3, 4]);
|
|
211
|
+
|
|
212
|
+
addAllTest(List.create(), List.create([1]), [1]);
|
|
213
|
+
addAllTest(List.create([1]), List.create([2]), [1, 2]);
|
|
214
|
+
addAllTest(List.create([1, 2]), List.create([3]), [1, 2, 3]);
|
|
215
|
+
addAllTest(List.create(), List.create([1, 2]), [1, 2]);
|
|
216
|
+
addAllTest(List.create([1]), List.create([2, 3]), [1, 2, 3]);
|
|
217
|
+
addAllTest(List.create([1, 2]), List.create([3, 4]), [1, 2, 3, 4]);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
runner.testFunction("insert(number,T)", () =>
|
|
221
|
+
{
|
|
222
|
+
function insertErrorTest(list: List<number>, index: number, value: number, expected: Error): void
|
|
223
|
+
{
|
|
224
|
+
runner.test(`with ${runner.andList([list, index, value])}`, (test: Test) =>
|
|
225
|
+
{
|
|
226
|
+
const backupList: List<number> = List.create(list);
|
|
227
|
+
test.assertThrows(() => list.insert(index, value), expected);
|
|
228
|
+
test.assertEqual(list, backupList);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
insertErrorTest(List.create(), -1, 1, new PreConditionError(
|
|
233
|
+
"Expression: index",
|
|
234
|
+
"Expected: 0",
|
|
235
|
+
"Actual: -1"
|
|
236
|
+
));
|
|
237
|
+
insertErrorTest(List.create(), 1, 1, new PreConditionError(
|
|
238
|
+
"Expression: index",
|
|
239
|
+
"Expected: 0",
|
|
240
|
+
"Actual: 1"
|
|
241
|
+
));
|
|
242
|
+
insertErrorTest(List.create([1]), -1, 1, new PreConditionError(
|
|
243
|
+
"Expression: index",
|
|
244
|
+
"Expected: between 0 and 1",
|
|
245
|
+
"Actual: -1"
|
|
246
|
+
));
|
|
247
|
+
insertErrorTest(List.create([1]), 2, 1, new PreConditionError(
|
|
248
|
+
"Expression: index",
|
|
249
|
+
"Expected: between 0 and 1",
|
|
250
|
+
"Actual: 2"
|
|
251
|
+
));
|
|
252
|
+
|
|
253
|
+
function insertTest(list: List<number>, index: number, value: number, expected: number[]): void
|
|
254
|
+
{
|
|
255
|
+
runner.test(`with ${runner.andList([list, index, value])}`, (test: Test) =>
|
|
256
|
+
{
|
|
257
|
+
const insertResult: List<number> = list.insert(index, value);
|
|
258
|
+
test.assertSame(insertResult, list);
|
|
259
|
+
test.assertEqual(list.toArray().await(), expected);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
insertTest(List.create(), 0, 1, [1]);
|
|
264
|
+
insertTest(List.create([2]), 0, 1, [1, 2]);
|
|
265
|
+
insertTest(List.create([1]), 1, 2, [1, 2]);
|
|
266
|
+
insertTest(List.create([2, 3]), 0, 1, [1, 2, 3]);
|
|
267
|
+
insertTest(List.create([1, 3]), 1, 2, [1, 2, 3]);
|
|
268
|
+
insertTest(List.create([1, 2]), 2, 3, [1, 2, 3]);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
runner.testFunction("insertAll(number,T)", () =>
|
|
272
|
+
{
|
|
273
|
+
function insertAllErrorTest(list: List<number>, index: number, values: number[] | Iterable<number>, expected: Error): void
|
|
274
|
+
{
|
|
275
|
+
runner.test(`with ${runner.andList([list, index, values])}`, (test: Test) =>
|
|
276
|
+
{
|
|
277
|
+
const backupList: List<number> = List.create(list);
|
|
278
|
+
test.assertThrows(() => list.insertAll(index, values), expected);
|
|
279
|
+
test.assertEqual(list, backupList);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
insertAllErrorTest(List.create(), -1, [1], new PreConditionError(
|
|
284
|
+
"Expression: index",
|
|
285
|
+
"Expected: 0",
|
|
286
|
+
"Actual: -1"
|
|
287
|
+
));
|
|
288
|
+
insertAllErrorTest(List.create(), 1, [1], new PreConditionError(
|
|
289
|
+
"Expression: index",
|
|
290
|
+
"Expected: 0",
|
|
291
|
+
"Actual: 1"
|
|
292
|
+
));
|
|
293
|
+
insertAllErrorTest(List.create([1]), -1, [1], new PreConditionError(
|
|
294
|
+
"Expression: index",
|
|
295
|
+
"Expected: between 0 and 1",
|
|
296
|
+
"Actual: -1"
|
|
297
|
+
));
|
|
298
|
+
insertAllErrorTest(List.create([1]), 2, [1], new PreConditionError(
|
|
299
|
+
"Expression: index",
|
|
300
|
+
"Expected: between 0 and 1",
|
|
301
|
+
"Actual: 2",
|
|
302
|
+
));
|
|
303
|
+
|
|
304
|
+
function insertAllTest(list: List<number>, index: number, values: JavascriptIterable<number>, expected: number[]): void
|
|
305
|
+
{
|
|
306
|
+
runner.test(`with ${runner.andList([list, index, values])}`, (test: Test) =>
|
|
307
|
+
{
|
|
308
|
+
const insertResult: List<number> = list.insertAll(index, values);
|
|
309
|
+
test.assertSame(insertResult, list);
|
|
310
|
+
test.assertEqual(list.toArray().await(), expected);
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
insertAllTest(List.create(), 0, [], []);
|
|
315
|
+
insertAllTest(List.create(), 0, [1], [1]);
|
|
316
|
+
insertAllTest(List.create([2]), 0, [1], [1, 2]);
|
|
317
|
+
insertAllTest(List.create([1]), 1, [2], [1, 2]);
|
|
318
|
+
insertAllTest(List.create([2, 3]), 0, [1], [1, 2, 3]);
|
|
319
|
+
insertAllTest(List.create([1, 3]), 1, [2], [1, 2, 3]);
|
|
320
|
+
insertAllTest(List.create([1, 2]), 2, [3], [1, 2, 3]);
|
|
321
|
+
insertAllTest(List.create([3]), 0, [1, 2], [1, 2, 3]);
|
|
322
|
+
insertAllTest(List.create([1]), 1, [2, 3], [1, 2, 3]);
|
|
323
|
+
insertAllTest(List.create([1, 4]), 1, [2, 3], [1, 2, 3, 4]);
|
|
324
|
+
|
|
325
|
+
insertAllTest(List.create(), 0, List.create(), []);
|
|
326
|
+
insertAllTest(List.create(), 0, List.create([1]), [1]);
|
|
327
|
+
insertAllTest(List.create([2]), 0, List.create([1]), [1, 2]);
|
|
328
|
+
insertAllTest(List.create([1]), 1, List.create([2]), [1, 2]);
|
|
329
|
+
insertAllTest(List.create([2, 3]), 0, List.create([1]), [1, 2, 3]);
|
|
330
|
+
insertAllTest(List.create([1, 3]), 1, List.create([2]), [1, 2, 3]);
|
|
331
|
+
insertAllTest(List.create([1, 2]), 2, List.create([3]), [1, 2, 3]);
|
|
332
|
+
insertAllTest(List.create([3]), 0, List.create([1, 2]), [1, 2, 3]);
|
|
333
|
+
insertAllTest(List.create([1]), 1, List.create([2, 3]), [1, 2, 3]);
|
|
334
|
+
insertAllTest(List.create([1, 4]), 1, List.create([2, 3]), [1, 2, 3, 4]);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Iterator } from "../sources/iterator";
|
|
2
|
+
import { MapIterator } from "../sources/mapIterator";
|
|
3
|
+
import { PreConditionError } from "../sources/preConditionError";
|
|
4
|
+
import { Test } from "./test";
|
|
5
|
+
import { TestRunner } from "./testRunner";
|
|
6
|
+
|
|
7
|
+
export function test(runner: TestRunner): void
|
|
8
|
+
{
|
|
9
|
+
runner.testFile("mapIterator.ts", () =>
|
|
10
|
+
{
|
|
11
|
+
runner.testType("MapIterator<TInput,TOutput>", () =>
|
|
12
|
+
{
|
|
13
|
+
runner.testFunction("create(Iterator<TInput>,(TInput)=>TOutput)", () =>
|
|
14
|
+
{
|
|
15
|
+
function createErrorTest<TInput,TOutput>(testName: string, innerIterator: Iterator<TInput>, mapping: (value: TInput) => TOutput, expected: Error): void
|
|
16
|
+
{
|
|
17
|
+
runner.test(testName, (test: Test) =>
|
|
18
|
+
{
|
|
19
|
+
test.assertThrows(() => MapIterator.create(innerIterator, mapping), expected);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
createErrorTest(
|
|
24
|
+
"with undefined inputIterator",
|
|
25
|
+
undefined!,
|
|
26
|
+
(value: number) => value.toString(),
|
|
27
|
+
new PreConditionError(
|
|
28
|
+
"Expression: inputIterator",
|
|
29
|
+
"Expected: not undefined and not null",
|
|
30
|
+
"Actual: undefined",
|
|
31
|
+
));
|
|
32
|
+
createErrorTest(
|
|
33
|
+
"with null inputIterator",
|
|
34
|
+
null!,
|
|
35
|
+
(value: number) => value.toString(),
|
|
36
|
+
new PreConditionError(
|
|
37
|
+
"Expression: inputIterator",
|
|
38
|
+
"Expected: not undefined and not null",
|
|
39
|
+
"Actual: null",
|
|
40
|
+
));
|
|
41
|
+
|
|
42
|
+
runner.test("with valid values", (test: Test) =>
|
|
43
|
+
{
|
|
44
|
+
const inputIterator: Iterator<number> = Iterator.create([1, 2, 3]);
|
|
45
|
+
test.assertFalse(inputIterator.hasStarted());
|
|
46
|
+
test.assertFalse(inputIterator.hasCurrent());
|
|
47
|
+
|
|
48
|
+
const iterator: MapIterator<number,string> = MapIterator.create(inputIterator, (value: number) => value.toString());
|
|
49
|
+
test.assertFalse(iterator.hasStarted());
|
|
50
|
+
test.assertFalse(iterator.hasCurrent());
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Iterator } from "../sources/iterator";
|
|
2
|
+
import { JavascriptIterable } from "../sources/javascript";
|
|
3
|
+
import { isMap, Map } from "../sources/map";
|
|
4
|
+
import { MutableMap } from "../sources/mutableMap";
|
|
5
|
+
import { NotFoundError } from "../sources/notFoundError";
|
|
6
|
+
import { Test } from "./test";
|
|
7
|
+
import { TestRunner } from "./testRunner";
|
|
8
|
+
|
|
9
|
+
export function test(runner: TestRunner): void
|
|
10
|
+
{
|
|
11
|
+
runner.testFile("map.ts", () =>
|
|
12
|
+
{
|
|
13
|
+
runner.testType("Map<TKey,TValue>", () =>
|
|
14
|
+
{
|
|
15
|
+
runner.testFunction("create()", (test: Test) =>
|
|
16
|
+
{
|
|
17
|
+
const map: MutableMap<number,string> = Map.create();
|
|
18
|
+
test.assertSame(map.getCount().await(), 0);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
mapTests(runner, Map.create);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function mapTests(runner: TestRunner, creator: () => Map<number,string>): void
|
|
27
|
+
{
|
|
28
|
+
runner.testType("Map<TKey,TValue>", () =>
|
|
29
|
+
{
|
|
30
|
+
runner.testFunction("creator()", (test: Test) =>
|
|
31
|
+
{
|
|
32
|
+
test.assertNotUndefinedAndNotNull(creator);
|
|
33
|
+
|
|
34
|
+
const map: Map<number,string> = creator();
|
|
35
|
+
test.assertNotUndefinedAndNotNull(map);
|
|
36
|
+
test.assertEqual(map.getCount().await(), 0);
|
|
37
|
+
test.assertTrue(isMap(map));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
runner.testFunction("containsKey(TKey)", () =>
|
|
41
|
+
{
|
|
42
|
+
runner.test("when it doesn't contain the key", (test: Test) =>
|
|
43
|
+
{
|
|
44
|
+
const map: Map<number,string> = creator();
|
|
45
|
+
|
|
46
|
+
test.assertFalse(map.containsKey(50).await());
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
runner.testFunction("get(TKey)", () =>
|
|
51
|
+
{
|
|
52
|
+
runner.test("when it doesn't contain the key", (test: Test) =>
|
|
53
|
+
{
|
|
54
|
+
const map: Map<number,string> = creator();
|
|
55
|
+
|
|
56
|
+
test.assertThrows(() => map.get(1).await(),
|
|
57
|
+
new NotFoundError(
|
|
58
|
+
"The key 1 was not found in the map."));
|
|
59
|
+
test.assertEqual(map.getCount().await(), 0);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
runner.testFunction("toString()", () =>
|
|
64
|
+
{
|
|
65
|
+
function toStringTest(map: Map<number,string>, expected: string): void
|
|
66
|
+
{
|
|
67
|
+
runner.test(`with ${runner.toString(map)}`, (test: Test) =>
|
|
68
|
+
{
|
|
69
|
+
test.assertEqual(map.toString(), expected);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
toStringTest(creator(), "{}");
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
runner.testFunction("iterateKeys()", () =>
|
|
77
|
+
{
|
|
78
|
+
function iterateKeysTests(map: Map<number,string>, expected: JavascriptIterable<number>): void
|
|
79
|
+
{
|
|
80
|
+
runner.test(`with ${runner.toString(map)}`, async (test: Test) =>
|
|
81
|
+
{
|
|
82
|
+
const keyIterator: Iterator<number> = map.iterateKeys();
|
|
83
|
+
test.assertEqual(await keyIterator.toArray(), [...expected]);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
iterateKeysTests(creator(), []);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
runner.testFunction("iterateValues()", () =>
|
|
91
|
+
{
|
|
92
|
+
function iterateValuesTests(map: Map<number,string>, expected: JavascriptIterable<string>): void
|
|
93
|
+
{
|
|
94
|
+
runner.test(`with ${runner.toString(map)}`, async (test: Test) =>
|
|
95
|
+
{
|
|
96
|
+
const valueIterator: Iterator<string> = map.iterateValues();
|
|
97
|
+
test.assertEqual(await valueIterator.toArray(), [...expected]);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
iterateValuesTests(creator(), []);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|