@everyonesoftware/common 2.0.0 → 3.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/.github/workflows/publish.yml +54 -36
- package/package.json +6 -2
- package/sources/asyncIterator.ts +436 -436
- package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +47 -47
- package/sources/asyncResult.ts +95 -95
- package/sources/byteList.ts +201 -201
- package/sources/byteListStream.ts +120 -120
- package/sources/byteReadStream.ts +23 -23
- package/sources/byteWriteStream.ts +15 -15
- package/sources/characterList.ts +194 -194
- package/sources/characterListStream.ts +150 -150
- package/sources/characterReadStream.ts +80 -80
- package/sources/characterReadStreamIterator.ts +127 -127
- package/sources/concatenateIterable.ts +118 -118
- package/sources/concatenateIterator.ts +164 -164
- package/sources/currentProcess.ts +157 -157
- package/sources/dateTime.ts +129 -129
- package/sources/depthFirstSearch.ts +229 -229
- package/sources/flatMapIterable.ts +103 -103
- package/sources/flatMapIterator.ts +151 -151
- package/sources/generator.ts +250 -250
- package/sources/index.ts +1 -1
- package/sources/iterator.ts +480 -480
- package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +123 -123
- package/sources/javascriptSetSet.ts +133 -133
- package/sources/listQueue.ts +61 -61
- package/sources/listStack.ts +61 -61
- package/sources/luxonDateTime.ts +108 -108
- package/sources/mapAsyncIterator.ts +140 -140
- package/sources/mutableMap.ts +291 -291
- package/sources/node.ts +36 -36
- package/sources/promiseAsyncResult.ts +173 -173
- package/sources/queue.ts +48 -48
- package/sources/recreationDotGovClient.ts +258 -258
- package/sources/searchControl.ts +41 -41
- package/sources/set.ts +243 -243
- package/sources/skipAsyncIterator.ts +144 -144
- package/sources/stack.ts +47 -47
- package/sources/syncResult.ts +299 -299
- package/sources/takeAsyncIterator.ts +140 -140
- package/sources/whereAsyncIterator.ts +142 -142
- package/sources/wonderlandTrailClient.ts +1502 -1502
- package/tests/assertTestTests.ts +74 -74
- package/tests/byteListStreamTests.ts +389 -389
- package/tests/byteListTests.ts +26 -26
- package/tests/characterListStreamTests.ts +390 -390
- package/tests/characterListTests.ts +249 -249
- package/tests/dateTimeTests.ts +29 -29
- package/tests/depthFirstSearchTests.ts +105 -105
- package/tests/generatorTests.ts +85 -85
- package/tests/mutableMapTests.ts +153 -153
- package/tests/promiseAsyncResultTests.ts +687 -687
- package/tests/queueTests.ts +28 -28
- package/tests/recreationDotGovClientTests.ts +190 -190
- package/tests/setTests.ts +139 -139
- package/tests/stackTests.ts +65 -65
- package/tests/syncResultTests.ts +1250 -1250
- package/tests/wonderlandTrailClientTests.ts +451 -451
- package/tsup.config.ts +12 -12
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
import { depthFirstSearch } from "../sources/depthFirstSearch";
|
|
2
|
-
import { Node } from "../sources/node";
|
|
3
|
-
import { Iterator } from "../sources/iterator";
|
|
4
|
-
import { PreConditionError } from "../sources/preConditionError";
|
|
5
|
-
import { Test } from "./test";
|
|
6
|
-
import { TestRunner } from "./testRunner";
|
|
7
|
-
import { List } from "../sources/list";
|
|
8
|
-
import { SearchControl } from "../sources/searchControl";
|
|
9
|
-
|
|
10
|
-
export function test(runner: TestRunner): void
|
|
11
|
-
{
|
|
12
|
-
runner.testFile("depthFirstSearch.ts", () =>
|
|
13
|
-
{
|
|
14
|
-
runner.testFunction("depthFirstSearch()", () =>
|
|
15
|
-
{
|
|
16
|
-
runner.test("with undefined initialToVisit", (test: Test) =>
|
|
17
|
-
{
|
|
18
|
-
test.assertThrows(() => depthFirstSearch(undefined!, () => {}), new PreConditionError(
|
|
19
|
-
"Expression: parameters",
|
|
20
|
-
"Expected: not undefined and not null",
|
|
21
|
-
"Actual: undefined",
|
|
22
|
-
));
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
runner.test("with null initialToVisit", (test: Test) =>
|
|
26
|
-
{
|
|
27
|
-
test.assertThrows(() => depthFirstSearch(null!, () => {}), new PreConditionError(
|
|
28
|
-
"Expression: parameters",
|
|
29
|
-
"Expected: not undefined and not null",
|
|
30
|
-
"Actual: null",
|
|
31
|
-
));
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
runner.test("with undefined searchAction", (test: Test) =>
|
|
35
|
-
{
|
|
36
|
-
test.assertThrows(() => depthFirstSearch([], undefined!), new PreConditionError(
|
|
37
|
-
"Expression: searchAction",
|
|
38
|
-
"Expected: not undefined and not null",
|
|
39
|
-
"Actual: undefined",
|
|
40
|
-
));
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
runner.test("with null searchAction", (test: Test) =>
|
|
44
|
-
{
|
|
45
|
-
test.assertThrows(() => depthFirstSearch([], null!), new PreConditionError(
|
|
46
|
-
"Expression: searchAction",
|
|
47
|
-
"Expected: not undefined and not null",
|
|
48
|
-
"Actual: null",
|
|
49
|
-
));
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
runner.test("with empty initialToVisit", (test: Test) =>
|
|
53
|
-
{
|
|
54
|
-
const iterator: Iterator<number> = depthFirstSearch([], (searchControl: SearchControl<Node<number>,number>, current: Node<number>) =>
|
|
55
|
-
{
|
|
56
|
-
searchControl.addAllToVisit(current.iterateConnectedNodes());
|
|
57
|
-
|
|
58
|
-
const currentValue: number = current.getValue();
|
|
59
|
-
if (currentValue >= 7)
|
|
60
|
-
{
|
|
61
|
-
searchControl.addResult(currentValue);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
test.assertEqual([], iterator.toArray().await());
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
runner.test("with non-empty initialToVisit with return values", (test: Test) =>
|
|
68
|
-
{
|
|
69
|
-
const nodes: List<Node<number>> = List.create();
|
|
70
|
-
for (let i = 0; i < 10; i++)
|
|
71
|
-
{
|
|
72
|
-
nodes.add(Node.create(i));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function connectNodes(index1: number, index2: number): void
|
|
76
|
-
{
|
|
77
|
-
nodes.get(index1).await().addConnectedNode(nodes.get(index2).await());
|
|
78
|
-
}
|
|
79
|
-
connectNodes(0, 1);
|
|
80
|
-
connectNodes(0, 2);
|
|
81
|
-
connectNodes(1, 5);
|
|
82
|
-
connectNodes(2, 4);
|
|
83
|
-
connectNodes(3, 6);
|
|
84
|
-
connectNodes(4, 5);
|
|
85
|
-
connectNodes(4, 6);
|
|
86
|
-
connectNodes(5, 9);
|
|
87
|
-
connectNodes(6, 7);
|
|
88
|
-
connectNodes(7, 3);
|
|
89
|
-
connectNodes(8, 9);
|
|
90
|
-
|
|
91
|
-
const iterator: Iterator<number> = depthFirstSearch([nodes.get(0).await()], (searchControl: SearchControl<Node<number>,number>, current: Node<number>) =>
|
|
92
|
-
{
|
|
93
|
-
searchControl.addAllToVisit(current.iterateConnectedNodes());
|
|
94
|
-
|
|
95
|
-
const currentValue: number = current.getValue();
|
|
96
|
-
if (currentValue >= 7)
|
|
97
|
-
{
|
|
98
|
-
searchControl.addResult(currentValue);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test.assertEqual([7, 9], iterator.toArray().await());
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
1
|
+
import { depthFirstSearch } from "../sources/depthFirstSearch";
|
|
2
|
+
import { Node } from "../sources/node";
|
|
3
|
+
import { Iterator } from "../sources/iterator";
|
|
4
|
+
import { PreConditionError } from "../sources/preConditionError";
|
|
5
|
+
import { Test } from "./test";
|
|
6
|
+
import { TestRunner } from "./testRunner";
|
|
7
|
+
import { List } from "../sources/list";
|
|
8
|
+
import { SearchControl } from "../sources/searchControl";
|
|
9
|
+
|
|
10
|
+
export function test(runner: TestRunner): void
|
|
11
|
+
{
|
|
12
|
+
runner.testFile("depthFirstSearch.ts", () =>
|
|
13
|
+
{
|
|
14
|
+
runner.testFunction("depthFirstSearch()", () =>
|
|
15
|
+
{
|
|
16
|
+
runner.test("with undefined initialToVisit", (test: Test) =>
|
|
17
|
+
{
|
|
18
|
+
test.assertThrows(() => depthFirstSearch(undefined!, () => {}), new PreConditionError(
|
|
19
|
+
"Expression: parameters",
|
|
20
|
+
"Expected: not undefined and not null",
|
|
21
|
+
"Actual: undefined",
|
|
22
|
+
));
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
runner.test("with null initialToVisit", (test: Test) =>
|
|
26
|
+
{
|
|
27
|
+
test.assertThrows(() => depthFirstSearch(null!, () => {}), new PreConditionError(
|
|
28
|
+
"Expression: parameters",
|
|
29
|
+
"Expected: not undefined and not null",
|
|
30
|
+
"Actual: null",
|
|
31
|
+
));
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
runner.test("with undefined searchAction", (test: Test) =>
|
|
35
|
+
{
|
|
36
|
+
test.assertThrows(() => depthFirstSearch([], undefined!), new PreConditionError(
|
|
37
|
+
"Expression: searchAction",
|
|
38
|
+
"Expected: not undefined and not null",
|
|
39
|
+
"Actual: undefined",
|
|
40
|
+
));
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
runner.test("with null searchAction", (test: Test) =>
|
|
44
|
+
{
|
|
45
|
+
test.assertThrows(() => depthFirstSearch([], null!), new PreConditionError(
|
|
46
|
+
"Expression: searchAction",
|
|
47
|
+
"Expected: not undefined and not null",
|
|
48
|
+
"Actual: null",
|
|
49
|
+
));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
runner.test("with empty initialToVisit", (test: Test) =>
|
|
53
|
+
{
|
|
54
|
+
const iterator: Iterator<number> = depthFirstSearch([], (searchControl: SearchControl<Node<number>,number>, current: Node<number>) =>
|
|
55
|
+
{
|
|
56
|
+
searchControl.addAllToVisit(current.iterateConnectedNodes());
|
|
57
|
+
|
|
58
|
+
const currentValue: number = current.getValue();
|
|
59
|
+
if (currentValue >= 7)
|
|
60
|
+
{
|
|
61
|
+
searchControl.addResult(currentValue);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
test.assertEqual([], iterator.toArray().await());
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
runner.test("with non-empty initialToVisit with return values", (test: Test) =>
|
|
68
|
+
{
|
|
69
|
+
const nodes: List<Node<number>> = List.create();
|
|
70
|
+
for (let i = 0; i < 10; i++)
|
|
71
|
+
{
|
|
72
|
+
nodes.add(Node.create(i));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function connectNodes(index1: number, index2: number): void
|
|
76
|
+
{
|
|
77
|
+
nodes.get(index1).await().addConnectedNode(nodes.get(index2).await());
|
|
78
|
+
}
|
|
79
|
+
connectNodes(0, 1);
|
|
80
|
+
connectNodes(0, 2);
|
|
81
|
+
connectNodes(1, 5);
|
|
82
|
+
connectNodes(2, 4);
|
|
83
|
+
connectNodes(3, 6);
|
|
84
|
+
connectNodes(4, 5);
|
|
85
|
+
connectNodes(4, 6);
|
|
86
|
+
connectNodes(5, 9);
|
|
87
|
+
connectNodes(6, 7);
|
|
88
|
+
connectNodes(7, 3);
|
|
89
|
+
connectNodes(8, 9);
|
|
90
|
+
|
|
91
|
+
const iterator: Iterator<number> = depthFirstSearch([nodes.get(0).await()], (searchControl: SearchControl<Node<number>,number>, current: Node<number>) =>
|
|
92
|
+
{
|
|
93
|
+
searchControl.addAllToVisit(current.iterateConnectedNodes());
|
|
94
|
+
|
|
95
|
+
const currentValue: number = current.getValue();
|
|
96
|
+
if (currentValue >= 7)
|
|
97
|
+
{
|
|
98
|
+
searchControl.addResult(currentValue);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test.assertEqual([7, 9], iterator.toArray().await());
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
106
|
}
|
package/tests/generatorTests.ts
CHANGED
|
@@ -1,86 +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
|
-
});
|
|
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
86
|
}
|