@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,86 @@
|
|
|
1
|
+
import { Generator } from "../sources/generator";
|
|
2
|
+
import { PreConditionError } from "../sources/preConditionError";
|
|
3
|
+
import { Test } from "./test";
|
|
4
|
+
import { TestRunner } from "./testRunner";
|
|
5
|
+
import { iteratorTests } from "./iteratorTests";
|
|
6
|
+
|
|
7
|
+
export function test(runner: TestRunner): void
|
|
8
|
+
{
|
|
9
|
+
runner.testFile("generator.ts", () =>
|
|
10
|
+
{
|
|
11
|
+
runner.testType("Generator<T>", () =>
|
|
12
|
+
{
|
|
13
|
+
iteratorTests(runner, () => Generator.create(() => {}));
|
|
14
|
+
|
|
15
|
+
runner.testFunction("create()", () =>
|
|
16
|
+
{
|
|
17
|
+
runner.test("with undefined", (test: Test) =>
|
|
18
|
+
{
|
|
19
|
+
test.assertThrows(() => Generator.create(undefined!), new PreConditionError(
|
|
20
|
+
"Expression: generatorAction",
|
|
21
|
+
"Expected: not undefined and not null",
|
|
22
|
+
"Actual: undefined",
|
|
23
|
+
));
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
runner.test("with null", (test: Test) =>
|
|
27
|
+
{
|
|
28
|
+
test.assertThrows(() => Generator.create(null!), new PreConditionError(
|
|
29
|
+
"Expression: generatorAction",
|
|
30
|
+
"Expected: not undefined and not null",
|
|
31
|
+
"Actual: null",
|
|
32
|
+
));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
runner.test("with function that doesn't add any return values or return a value", (test: Test) =>
|
|
36
|
+
{
|
|
37
|
+
const generator: Generator<void> = Generator.create(() => {});
|
|
38
|
+
test.assertNotUndefinedAndNotNull(generator);
|
|
39
|
+
test.assertEqual([], generator.toArray().await());
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
runner.test("with function that returns a constant value", (test: Test) =>
|
|
43
|
+
{
|
|
44
|
+
const generator: Generator<number> = Generator.create(() => 20);
|
|
45
|
+
test.assertNotUndefinedAndNotNull(generator);
|
|
46
|
+
test.assertEqual([20, 20, 20, 20], generator.take(4).toArray().await());
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
runner.test("with function that returns an incrementing value", (test: Test) =>
|
|
50
|
+
{
|
|
51
|
+
let value: number = 20;
|
|
52
|
+
const generator: Generator<number> = Generator.create(() => value++);
|
|
53
|
+
test.assertNotUndefinedAndNotNull(generator);
|
|
54
|
+
test.assertEqual([20, 21, 22, 23, 24], generator.take(5).toArray().await());
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
runner.test("with function that always adds a return value", (test: Test) =>
|
|
58
|
+
{
|
|
59
|
+
const generator: Generator<number> = Generator.create(control => control.addValue(20));
|
|
60
|
+
test.assertNotUndefinedAndNotNull(generator);
|
|
61
|
+
test.assertEqual([20, 20, 20, 20], generator.take(4).toArray().await());
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
runner.test("with function that always adds multiple return values", (test: Test) =>
|
|
65
|
+
{
|
|
66
|
+
const generator: Generator<number> = Generator.create(control => { control.addValues([20, 21, 22]); });
|
|
67
|
+
test.assertNotUndefinedAndNotNull(generator);
|
|
68
|
+
test.assertEqual([20, 21, 22, 20, 21], generator.take(5).toArray().await());
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
runner.test("with function that always adds a return value and returns a value", (test: Test) =>
|
|
72
|
+
{
|
|
73
|
+
const generator: Generator<number> = Generator.create(control =>
|
|
74
|
+
{
|
|
75
|
+
control.addValue(20);
|
|
76
|
+
test.assertTrue(control.hasCurrent());
|
|
77
|
+
test.assertEqual(20, control.getCurrent());
|
|
78
|
+
return 21;
|
|
79
|
+
});
|
|
80
|
+
test.assertNotUndefinedAndNotNull(generator);
|
|
81
|
+
test.assertEqual([20, 21, 20, 21, 20], generator.take(5).toArray().await());
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { HttpClient } from "../sources/httpClient";
|
|
2
|
+
import { Test } from "./test";
|
|
3
|
+
import { TestRunner } from "./testRunner";
|
|
4
|
+
|
|
5
|
+
export function test(runner: TestRunner): void
|
|
6
|
+
{
|
|
7
|
+
runner.testFile("httpClient.ts", () =>
|
|
8
|
+
{
|
|
9
|
+
runner.testType("HttpClient", () =>
|
|
10
|
+
{
|
|
11
|
+
runner.test("create()", (test: Test) =>
|
|
12
|
+
{
|
|
13
|
+
const client: HttpClient = HttpClient.create();
|
|
14
|
+
test.assertNotUndefinedAndNotNull(client);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { InMemoryCharacterWriteStream } from "../sources/inMemoryCharacterWriteStream";
|
|
2
|
+
import { SyncResult } from "../sources/syncResult";
|
|
3
|
+
import { isUndefined } from "../sources/types";
|
|
4
|
+
import * as characterWriteStreamTests from "./characterWriteStreamTests";
|
|
5
|
+
import { Test } from "./test";
|
|
6
|
+
import { TestRunner } from "./testRunner";
|
|
7
|
+
|
|
8
|
+
export function test(runner: TestRunner): void
|
|
9
|
+
{
|
|
10
|
+
runner.testFile("inMemoryCharacterWriteStream.ts", () =>
|
|
11
|
+
{
|
|
12
|
+
runner.testType("InMemoryCharacterWriteStream", () =>
|
|
13
|
+
{
|
|
14
|
+
characterWriteStreamTests.test(runner, InMemoryCharacterWriteStream.create);
|
|
15
|
+
|
|
16
|
+
runner.testFunction("create()", (test: Test) =>
|
|
17
|
+
{
|
|
18
|
+
const writeStream: InMemoryCharacterWriteStream = InMemoryCharacterWriteStream.create();
|
|
19
|
+
test.assertNotUndefinedAndNotNull(writeStream);
|
|
20
|
+
test.assertEqual("", writeStream.getWrittenText());
|
|
21
|
+
test.assertEqual("\n", writeStream.getNewlineSequence());
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
runner.testFunction("clearWrittenText()", (test: Test) =>
|
|
25
|
+
{
|
|
26
|
+
const writeStream = InMemoryCharacterWriteStream.create();
|
|
27
|
+
|
|
28
|
+
const result1: InMemoryCharacterWriteStream = writeStream.clearWrittenText();
|
|
29
|
+
test.assertSame(writeStream, result1);
|
|
30
|
+
test.assertEqual("", writeStream.getWrittenText());
|
|
31
|
+
|
|
32
|
+
writeStream.writeString("hello world!").await();
|
|
33
|
+
test.assertEqual("hello world!", writeStream.getWrittenText());
|
|
34
|
+
|
|
35
|
+
const result2: InMemoryCharacterWriteStream = writeStream.clearWrittenText();
|
|
36
|
+
test.assertSame(writeStream, result2);
|
|
37
|
+
test.assertEqual("", writeStream.getWrittenText());
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
runner.testFunction("setNewlineSequence()", (test: Test) =>
|
|
41
|
+
{
|
|
42
|
+
const writeStream = InMemoryCharacterWriteStream.create();
|
|
43
|
+
|
|
44
|
+
const result1: InMemoryCharacterWriteStream = writeStream.setNewlineSequence("e");
|
|
45
|
+
test.assertSame(writeStream, result1);
|
|
46
|
+
test.assertEqual("e", writeStream.getNewlineSequence());
|
|
47
|
+
test.assertEqual("", writeStream.getWrittenText());
|
|
48
|
+
|
|
49
|
+
const result2: SyncResult<number> = writeStream.writeString("ab");
|
|
50
|
+
test.assertEqual("ab", writeStream.getWrittenText());
|
|
51
|
+
for (let i = 0; i < 3; i++)
|
|
52
|
+
{
|
|
53
|
+
test.assertEqual(2, result2.await());
|
|
54
|
+
test.assertEqual("ab", writeStream.getWrittenText());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const result3: SyncResult<number> = writeStream.writeLine("cd");
|
|
58
|
+
test.assertEqual("abcde", writeStream.getWrittenText());
|
|
59
|
+
for (let i = 0; i < 3; i++)
|
|
60
|
+
{
|
|
61
|
+
test.assertEqual(3, result3.await());
|
|
62
|
+
test.assertEqual("abcde", writeStream.getWrittenText());
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
runner.testFunction("writeString()", () =>
|
|
67
|
+
{
|
|
68
|
+
function writeStringTest(text: string): void
|
|
69
|
+
{
|
|
70
|
+
runner.test(`with ${runner.toString(text)}`, (test: Test) =>
|
|
71
|
+
{
|
|
72
|
+
const expectedWrittenText: string = text || "";
|
|
73
|
+
const writeStream = InMemoryCharacterWriteStream.create();
|
|
74
|
+
const result: number = writeStream.writeString(text).await();
|
|
75
|
+
test.assertEqual(expectedWrittenText.length, result);
|
|
76
|
+
test.assertEqual(expectedWrittenText, writeStream.getWrittenText());
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
writeStringTest(undefined!);
|
|
81
|
+
writeStringTest(null!);
|
|
82
|
+
writeStringTest("");
|
|
83
|
+
writeStringTest("a");
|
|
84
|
+
writeStringTest("abc");
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
runner.testFunction("writeLine()", () =>
|
|
88
|
+
{
|
|
89
|
+
function writeLineTest(text: string, newlineSequence?: string): void
|
|
90
|
+
{
|
|
91
|
+
runner.test(`with ${runner.toString(text)}${isUndefined(newlineSequence) ? "" : ` and ${runner.toString(newlineSequence)}`}`, (test: Test) =>
|
|
92
|
+
{
|
|
93
|
+
|
|
94
|
+
const writeStream = InMemoryCharacterWriteStream.create();
|
|
95
|
+
if (!isUndefined(newlineSequence))
|
|
96
|
+
{
|
|
97
|
+
writeStream.setNewlineSequence(newlineSequence);
|
|
98
|
+
}
|
|
99
|
+
const expectedWrittenText: string = (text || "") + writeStream.getNewlineSequence();
|
|
100
|
+
|
|
101
|
+
const result: number = writeStream.writeLine(text).await();
|
|
102
|
+
test.assertEqual(expectedWrittenText.length, result);
|
|
103
|
+
test.assertEqual(expectedWrittenText, writeStream.getWrittenText());
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
writeLineTest(undefined!);
|
|
108
|
+
writeLineTest(null!);
|
|
109
|
+
writeLineTest("");
|
|
110
|
+
writeLineTest("a");
|
|
111
|
+
writeLineTest("abc");
|
|
112
|
+
writeLineTest("abc", "\r\n");
|
|
113
|
+
writeLineTest("abc", "");
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Iterable } from "../sources/iterable";
|
|
2
|
+
import { Test } from "./test";
|
|
3
|
+
import { TestRunner } from "./testRunner";
|
|
4
|
+
|
|
5
|
+
export function test(runner: TestRunner): void
|
|
6
|
+
{
|
|
7
|
+
runner.testFile("iterable.ts", () =>
|
|
8
|
+
{
|
|
9
|
+
runner.testType("Iterable<T>", () =>
|
|
10
|
+
{
|
|
11
|
+
runner.testFunction("create(JavascriptIterable<T>|undefined)", () =>
|
|
12
|
+
{
|
|
13
|
+
runner.test("with no arguments", async (test: Test) =>
|
|
14
|
+
{
|
|
15
|
+
const iterable: Iterable<number> = Iterable.create();
|
|
16
|
+
test.assertNotUndefinedAndNotNull(iterable);
|
|
17
|
+
test.assertEqual(await iterable.toArray(), []);
|
|
18
|
+
test.assertEqual(await iterable.getCount(), 0);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
runner.test("with empty array", async (test: Test) =>
|
|
22
|
+
{
|
|
23
|
+
const iterable: Iterable<number> = Iterable.create<number>([]);
|
|
24
|
+
test.assertNotUndefinedAndNotNull(iterable);
|
|
25
|
+
test.assertEqual(await iterable.toArray(), []);
|
|
26
|
+
test.assertEqual(await iterable.getCount(), 0);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
runner.test("with non-empty array", async (test: Test) =>
|
|
30
|
+
{
|
|
31
|
+
const iterable: Iterable<number> = Iterable.create([1, 2, 3]);
|
|
32
|
+
test.assertNotUndefinedAndNotNull(iterable);
|
|
33
|
+
test.assertEqual(await iterable.toArray(), [1, 2, 3]);
|
|
34
|
+
test.assertEqual(await iterable.getCount(), 3);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
runner.testGroup("concatenate()", () =>
|
|
39
|
+
{
|
|
40
|
+
runner.testGroup("empty and", () =>
|
|
41
|
+
{
|
|
42
|
+
runner.test("empty", (test: Test) =>
|
|
43
|
+
{
|
|
44
|
+
const iterable: Iterable<number> = Iterable.create([]);
|
|
45
|
+
const concatenateIterable: Iterable<number> = iterable.concatenate([]);
|
|
46
|
+
test.assertEqual(concatenateIterable.toArray().await(), []);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
runner.test("non-empty", (test: Test) =>
|
|
50
|
+
{
|
|
51
|
+
const iterable: Iterable<number> = Iterable.create([]);
|
|
52
|
+
const concatenateIterable: Iterable<number> = iterable.concatenate([5]);
|
|
53
|
+
test.assertEqual(concatenateIterable.toArray().await(), [5]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
runner.test("two non-emptys", (test: Test) =>
|
|
57
|
+
{
|
|
58
|
+
const iterable: Iterable<number> = Iterable.create([]);
|
|
59
|
+
const concatenateIterable: Iterable<number> = iterable.concatenate([5], [6, 7]);
|
|
60
|
+
test.assertEqual(concatenateIterable.toArray().await(), [5, 6, 7]);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
runner.testGroup("non-empty and", () =>
|
|
65
|
+
{
|
|
66
|
+
runner.test("empty", (test: Test) =>
|
|
67
|
+
{
|
|
68
|
+
const iterable: Iterable<number> = Iterable.create([1, 2]);
|
|
69
|
+
const concatenateIterable: Iterable<number> = iterable.concatenate([]);
|
|
70
|
+
test.assertEqual(concatenateIterable.toArray().await(), [1, 2]);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
runner.test("non-empty", (test: Test) =>
|
|
74
|
+
{
|
|
75
|
+
const iterable: Iterable<number> = Iterable.create([3]);
|
|
76
|
+
const concatenateIterable: Iterable<number> = iterable.concatenate([4, 5, 6]);
|
|
77
|
+
test.assertEqual(concatenateIterable.toArray().await(), [3, 4, 5, 6]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
runner.test("two non-emptys", (test: Test) =>
|
|
81
|
+
{
|
|
82
|
+
const iterable: Iterable<number> = Iterable.create([7, 8, 9]);
|
|
83
|
+
const concatenateIterable: Iterable<number> = iterable.concatenate([10, 11, 12], [13]);
|
|
84
|
+
test.assertEqual(concatenateIterable.toArray().await(), [7, 8, 9, 10, 11, 12, 13]);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
runner.testFunction("flatMap()", () =>
|
|
90
|
+
{
|
|
91
|
+
runner.test("with empty iterable", (test: Test) =>
|
|
92
|
+
{
|
|
93
|
+
const iterable: Iterable<number> = Iterable.create([]);
|
|
94
|
+
const flatMapIterable: Iterable<string> = iterable.flatMap((value: number) =>
|
|
95
|
+
{
|
|
96
|
+
const result: string[] = [];
|
|
97
|
+
for (let i = 0; i < value; i++)
|
|
98
|
+
{
|
|
99
|
+
result.push(value.toString());
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
});
|
|
103
|
+
test.assertEqual(flatMapIterable.toArray().await(), []);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
runner.test("with non-empty iterable", (test: Test) =>
|
|
107
|
+
{
|
|
108
|
+
const iterable: Iterable<number> = Iterable.create([1, 2, 3]);
|
|
109
|
+
const flatMapIterable: Iterable<string> = iterable.flatMap((value: number) =>
|
|
110
|
+
{
|
|
111
|
+
const result: string[] = [];
|
|
112
|
+
for (let i = 0; i < value; i++)
|
|
113
|
+
{
|
|
114
|
+
result.push(value.toString());
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
});
|
|
118
|
+
test.assertEqual(flatMapIterable.toArray().await(), ["1", "2", "2", "3", "3", "3"]);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
runner.test("with mapping that sometimes returns an empty iterable", (test: Test) =>
|
|
122
|
+
{
|
|
123
|
+
const iterable: Iterable<number> = Iterable.create([1, 2, 3, 4]);
|
|
124
|
+
const flatMapIterable: Iterable<string> = iterable.flatMap((value: number) =>
|
|
125
|
+
{
|
|
126
|
+
const result: string[] = [];
|
|
127
|
+
if (value % 2 === 1)
|
|
128
|
+
{
|
|
129
|
+
for (let i = 0; i < value; i++)
|
|
130
|
+
{
|
|
131
|
+
result.push(value.toString());
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
});
|
|
136
|
+
test.assertEqual(flatMapIterable.toArray().await(), ["1", "3", "3", "3"]);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
}
|