@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.
Files changed (163) hide show
  1. package/.c8rc.json +12 -0
  2. package/.github/workflows/publish.yml +38 -0
  3. package/.mocharc.json +9 -0
  4. package/README.md +9 -0
  5. package/package.json +36 -0
  6. package/sources/assertMessageParameters.ts +22 -0
  7. package/sources/asyncIterator.ts +437 -0
  8. package/sources/asyncIteratorToJavascriptAsyncIteratorAdapter.ts +48 -0
  9. package/sources/asyncResult.ts +95 -0
  10. package/sources/basicDisposable.ts +57 -0
  11. package/sources/byteList.ts +202 -0
  12. package/sources/byteListStream.ts +121 -0
  13. package/sources/byteReadStream.ts +24 -0
  14. package/sources/byteWriteStream.ts +16 -0
  15. package/sources/bytes.ts +25 -0
  16. package/sources/characterList.ts +195 -0
  17. package/sources/characterListStream.ts +151 -0
  18. package/sources/characterReadStream.ts +81 -0
  19. package/sources/characterReadStreamIterator.ts +128 -0
  20. package/sources/characterWriteStream.ts +45 -0
  21. package/sources/commandLineParameter.ts +45 -0
  22. package/sources/commandLineParameters.ts +21 -0
  23. package/sources/comparable.ts +144 -0
  24. package/sources/comparer.ts +133 -0
  25. package/sources/comparison.ts +20 -0
  26. package/sources/concatenateIterable.ts +119 -0
  27. package/sources/concatenateIterator.ts +165 -0
  28. package/sources/condition.ts +329 -0
  29. package/sources/currentProcess.ts +158 -0
  30. package/sources/dateTime.ts +130 -0
  31. package/sources/depthFirstSearch.ts +230 -0
  32. package/sources/disposable.ts +31 -0
  33. package/sources/emptyError.ts +10 -0
  34. package/sources/english.ts +45 -0
  35. package/sources/equalFunctions.ts +123 -0
  36. package/sources/fetchHttpClient.ts +89 -0
  37. package/sources/fetchHttpResponse.ts +106 -0
  38. package/sources/flatMapIterable.ts +104 -0
  39. package/sources/flatMapIterator.ts +152 -0
  40. package/sources/generator.ts +251 -0
  41. package/sources/httpClient.ts +36 -0
  42. package/sources/httpHeader.ts +37 -0
  43. package/sources/httpHeaders.ts +216 -0
  44. package/sources/httpIncomingRequest.ts +30 -0
  45. package/sources/httpIncomingResponse.ts +19 -0
  46. package/sources/httpMethod.ts +164 -0
  47. package/sources/httpOutgoingRequest.ts +119 -0
  48. package/sources/httpOutgoingResponse.ts +113 -0
  49. package/sources/httpServer.ts +34 -0
  50. package/sources/inMemoryCharacterWriteStream.ts +78 -0
  51. package/sources/index.ts +101 -0
  52. package/sources/iterable.ts +345 -0
  53. package/sources/iterator.ts +481 -0
  54. package/sources/iteratorToJavascriptIteratorAdapter.ts +48 -0
  55. package/sources/javascript.ts +59 -0
  56. package/sources/javascriptArrayList.ts +175 -0
  57. package/sources/javascriptAsyncIteratorToAsyncIteratorAdapter.ts +124 -0
  58. package/sources/javascriptIteratorToIteratorAdapter.ts +133 -0
  59. package/sources/javascriptMapMap.ts +143 -0
  60. package/sources/javascriptSetSet.ts +134 -0
  61. package/sources/list.ts +330 -0
  62. package/sources/listQueue.ts +62 -0
  63. package/sources/listStack.ts +62 -0
  64. package/sources/luxonDateTime.ts +109 -0
  65. package/sources/map.ts +302 -0
  66. package/sources/mapAsyncIterator.ts +141 -0
  67. package/sources/mapIterable.ts +105 -0
  68. package/sources/mapIterator.ts +145 -0
  69. package/sources/mutableCondition.ts +451 -0
  70. package/sources/mutableHttpHeaders.ts +204 -0
  71. package/sources/mutableMap.ts +292 -0
  72. package/sources/network.ts +18 -0
  73. package/sources/node.ts +37 -0
  74. package/sources/nodeJSCharacterWriteStream.ts +42 -0
  75. package/sources/nodeJSHttpIncomingRequest.ts +132 -0
  76. package/sources/nodeJSHttpServer.ts +134 -0
  77. package/sources/notFoundError.ts +12 -0
  78. package/sources/postCondition.ts +284 -0
  79. package/sources/postConditionError.ts +12 -0
  80. package/sources/preCondition.ts +284 -0
  81. package/sources/preConditionError.ts +12 -0
  82. package/sources/promiseAsyncResult.ts +174 -0
  83. package/sources/property.ts +63 -0
  84. package/sources/queue.ts +49 -0
  85. package/sources/realNetwork.ts +28 -0
  86. package/sources/recreationDotGovClient.ts +259 -0
  87. package/sources/searchControl.ts +42 -0
  88. package/sources/set.ts +244 -0
  89. package/sources/skipAsyncIterator.ts +145 -0
  90. package/sources/skipIterator.ts +155 -0
  91. package/sources/stack.ts +48 -0
  92. package/sources/stringComparer.ts +33 -0
  93. package/sources/stringIterator.ts +149 -0
  94. package/sources/strings.ts +322 -0
  95. package/sources/syncResult.ts +300 -0
  96. package/sources/takeAsyncIterator.ts +141 -0
  97. package/sources/takeIterator.ts +151 -0
  98. package/sources/toStringFunctions.ts +185 -0
  99. package/sources/types.ts +371 -0
  100. package/sources/whereAsyncIterator.ts +143 -0
  101. package/sources/whereIterable.ts +108 -0
  102. package/sources/whereIterator.ts +157 -0
  103. package/sources/wonderlandTrailClient.ts +1503 -0
  104. package/tests/assertTest.ts +113 -0
  105. package/tests/assertTestTests.ts +75 -0
  106. package/tests/basicTestSkip.ts +51 -0
  107. package/tests/byteListStreamTests.ts +390 -0
  108. package/tests/byteListTests.ts +27 -0
  109. package/tests/bytesTests.ts +43 -0
  110. package/tests/characterListStreamTests.ts +391 -0
  111. package/tests/characterListTests.ts +250 -0
  112. package/tests/characterWriteStreamTests.ts +12 -0
  113. package/tests/comparerTests.ts +92 -0
  114. package/tests/conditionTests.ts +877 -0
  115. package/tests/consoleTestRunner.ts +404 -0
  116. package/tests/consoleTestRunnerTests.ts +651 -0
  117. package/tests/dateTimeTests.ts +30 -0
  118. package/tests/depthFirstSearchTests.ts +106 -0
  119. package/tests/disposableTests.ts +121 -0
  120. package/tests/englishTests.ts +103 -0
  121. package/tests/equalFunctionsTests.ts +223 -0
  122. package/tests/failedTest.ts +43 -0
  123. package/tests/fetchHttpClientTests.ts +33 -0
  124. package/tests/generatorTests.ts +86 -0
  125. package/tests/httpClientTests.ts +18 -0
  126. package/tests/inMemoryCharacterWriteStreamTests.ts +117 -0
  127. package/tests/iterableTests.ts +141 -0
  128. package/tests/iteratorTests.ts +1086 -0
  129. package/tests/javascriptMapMapTests.ts +21 -0
  130. package/tests/listTests.ts +338 -0
  131. package/tests/mapIteratorTests.ts +55 -0
  132. package/tests/mapTests.ts +104 -0
  133. package/tests/mutableConditionTests.ts +273 -0
  134. package/tests/mutableMapTests.ts +154 -0
  135. package/tests/nodeJSHttpServerTests.ts +75 -0
  136. package/tests/notFoundErrorTests.ts +24 -0
  137. package/tests/postConditionErrorTests.ts +24 -0
  138. package/tests/preConditionErrorTests.ts +24 -0
  139. package/tests/promiseAsyncResultTests.ts +688 -0
  140. package/tests/propertyTests.ts +63 -0
  141. package/tests/queueTests.ts +29 -0
  142. package/tests/recreationDotGovClientTests.ts +191 -0
  143. package/tests/setTests.ts +140 -0
  144. package/tests/skippedTest.ts +39 -0
  145. package/tests/stackTests.ts +66 -0
  146. package/tests/stringComparerTests.ts +60 -0
  147. package/tests/stringIteratorTests.ts +156 -0
  148. package/tests/stringsTests.ts +516 -0
  149. package/tests/syncResultTests.ts +1251 -0
  150. package/tests/test.ts +228 -0
  151. package/tests/testAction.ts +75 -0
  152. package/tests/testActionTests.ts +93 -0
  153. package/tests/testFailureTests.ts +12 -0
  154. package/tests/testRunner.ts +267 -0
  155. package/tests/testRunnerTests.ts +895 -0
  156. package/tests/testSkip.ts +34 -0
  157. package/tests/tests.ts +103 -0
  158. package/tests/toStringFunctionsTests.ts +55 -0
  159. package/tests/typesTests.ts +257 -0
  160. package/tests/whereIteratorTests.ts +77 -0
  161. package/tests/wonderlandTrailClientTests.ts +452 -0
  162. package/tsconfig.json +17 -0
  163. package/tsup.config.ts +13 -0
@@ -0,0 +1,63 @@
1
+ import { Property } from "../sources/property";
2
+ import { Test } from "./test";
3
+ import { TestRunner } from "./testRunner";
4
+
5
+ export function test(runner: TestRunner): void
6
+ {
7
+ runner.testFile("property.ts", () =>
8
+ {
9
+ runner.testType("Property<T>", () =>
10
+ {
11
+ runner.testFunction("create()", () =>
12
+ {
13
+ runner.test("with initialValue", (test: Test) =>
14
+ {
15
+ const property: Property<number> = Property.create(5);
16
+ test.assertEqual(5, property.getValue());
17
+
18
+ const setResult: Property<number> = property.setValue(20);
19
+ test.assertSame(property, setResult);
20
+ test.assertEqual(20, property.getValue());
21
+
22
+ test.assertEqual("20", property.toString());
23
+ });
24
+
25
+ runner.test("with getter and setter functions", (test: Test) =>
26
+ {
27
+ let propertyValue: string = "hello";
28
+
29
+ const property: Property<string> = Property.create(
30
+ () => propertyValue,
31
+ (value: string) => { propertyValue = value; },
32
+ );
33
+ test.assertEqual("hello", property.getValue());
34
+
35
+ const setResult: Property<string> = property.setValue("there");
36
+ test.assertSame(property, setResult);
37
+ test.assertEqual("there", property.getValue());
38
+ test.assertEqual("there", propertyValue);
39
+
40
+ test.assertEqual("there", property.toString());
41
+ });
42
+
43
+ runner.test("with options", (test: Test) =>
44
+ {
45
+ let propertyValue: string = "hello";
46
+
47
+ const property: Property<string> = Property.create({
48
+ getter: () => propertyValue,
49
+ setter: (value: string) => { propertyValue = value; },
50
+ });
51
+ test.assertEqual("hello", property.getValue());
52
+
53
+ const setResult: Property<string> = property.setValue("there");
54
+ test.assertSame(property, setResult);
55
+ test.assertEqual("there", property.getValue());
56
+ test.assertEqual("there", propertyValue);
57
+
58
+ test.assertEqual("there", property.toString());
59
+ });
60
+ });
61
+ });
62
+ });
63
+ }
@@ -0,0 +1,29 @@
1
+ import { EmptyError } from "../sources/emptyError";
2
+ import { ListQueue } from "../sources/listQueue";
3
+ import { Queue } from "../sources/queue";
4
+ import { Test } from "./test";
5
+ import { TestRunner } from "./testRunner";
6
+
7
+ export function test(runner: TestRunner): void
8
+ {
9
+ runner.testFile("queue.ts", () =>
10
+ {
11
+ runner.testType("Queue<T>", () =>
12
+ {
13
+ runner.testFunction("create()", (test: Test) =>
14
+ {
15
+ const queue: ListQueue<number> = Queue.create();
16
+ test.assertNotUndefinedAndNotNull(queue);
17
+ test.assertFalse(queue.any().await());
18
+ test.assertThrows(() => queue.remove().await(), new EmptyError());
19
+ });
20
+
21
+ runner.testFunction("add()", (test: Test) =>
22
+ {
23
+ const queue: ListQueue<number> = Queue.create();
24
+ queue.add(20).await();
25
+ test.assertEqual(20, queue.remove().await());
26
+ });
27
+ });
28
+ });
29
+ }
@@ -0,0 +1,191 @@
1
+ import { HttpClient } from "../sources/httpClient";
2
+ import { PreConditionError } from "../sources/preConditionError";
3
+ import { RecreationDotGovClient, RecreationDotGovDivisionAvailability, RecreationDotGovDivisionAvailabilityJson, RecreationDotGovError, RecreationDotGovPermitItineraryJson } from "../sources/recreationDotGovClient";
4
+ import { WonderlandTrailClient, WonderlandTrailLocations } from "../sources/wonderlandTrailClient";
5
+ import { Test } from "./test";
6
+ import { TestRunner } from "./testRunner";
7
+ import { hasNetworkAccess } from "./tests";
8
+
9
+ export function test(runner: TestRunner): void
10
+ {
11
+ runner.testFile("recreationDotGovClient.ts", () =>
12
+ {
13
+ runner.testType("RecreationDotGovClient", () =>
14
+ {
15
+ runner.testFunction("create()", () =>
16
+ {
17
+ function createErrorTest(httpClient: HttpClient, expected: Error): void
18
+ {
19
+ runner.test(`with ${runner.toString(httpClient)}`, (test: Test) =>
20
+ {
21
+ test.assertThrows(() => RecreationDotGovClient.create(httpClient), expected);
22
+ });
23
+ }
24
+
25
+ createErrorTest(undefined!, new PreConditionError(
26
+ "Expression: httpClient",
27
+ "Expected: not undefined and not null",
28
+ "Actual: undefined",
29
+ ));
30
+ createErrorTest(null!, new PreConditionError(
31
+ "Expression: httpClient",
32
+ "Expected: not undefined and not null",
33
+ "Actual: null",
34
+ ));
35
+
36
+ runner.test("with default HttpClient", (test: Test) =>
37
+ {
38
+ const httpClient: HttpClient = HttpClient.create();
39
+ const recreationDotGovClient: RecreationDotGovClient = RecreationDotGovClient.create(httpClient);
40
+ test.assertNotUndefinedAndNotNull(recreationDotGovClient);
41
+ });
42
+ });
43
+
44
+ runner.testFunction("getPermitItinerary()", () =>
45
+ {
46
+ function getPermitItineraryErrorTest(itineraryId: string, expected: Error): void
47
+ {
48
+ runner.test(`with ${runner.toString(itineraryId)}`, async (test: Test) =>
49
+ {
50
+ const client: RecreationDotGovClient = RecreationDotGovClient.create(HttpClient.create());
51
+ await test.assertThrowsAsync(async () => await client.getPermitItinerary(itineraryId), expected);
52
+ });
53
+ }
54
+
55
+ getPermitItineraryErrorTest(undefined!, new PreConditionError(
56
+ "Expression: permitItineraryId",
57
+ "Expected: not undefined and not null",
58
+ "Actual: undefined",
59
+ ));
60
+ getPermitItineraryErrorTest(null!, new PreConditionError(
61
+ "Expression: permitItineraryId",
62
+ "Expected: not undefined and not null",
63
+ "Actual: null",
64
+ ));
65
+ getPermitItineraryErrorTest("", new PreConditionError(
66
+ "Expression: permitItineraryId",
67
+ "Expected: not empty",
68
+ "Actual: \"\"",
69
+ ));
70
+
71
+ runner.test("with invalid permit itinerary id", runner.skip(!hasNetworkAccess), async (test: Test) =>
72
+ {
73
+ const client: RecreationDotGovClient = RecreationDotGovClient.create(HttpClient.create());
74
+ await test.assertThrowsAsync(
75
+ async () => await client.getPermitItinerary("oopsie!"),
76
+ new RecreationDotGovError(
77
+ `No permit itinerary found for id: "oopsie!"`,
78
+ ),
79
+ );
80
+ });
81
+
82
+ runner.test("with valid permit itinerary id", runner.skip(!hasNetworkAccess), async (test: Test) =>
83
+ {
84
+ const client: RecreationDotGovClient = RecreationDotGovClient.create(HttpClient.create());
85
+ const result: RecreationDotGovPermitItineraryJson = await client.getPermitItinerary(WonderlandTrailClient.permitItineraryId);
86
+ test.assertNotUndefinedAndNotNull(result);
87
+ test.assertEqual(result.id, WonderlandTrailClient.permitItineraryId);
88
+ test.assertEqual(result.name, "Mount Rainier National Park Wilderness and Climbing Permits");
89
+ test.assertNotUndefinedAndNotNull(result.divisions);
90
+ test.assertTrue(Object.keys(result.divisions).length > 0);
91
+ for (const division of Object.values(result.divisions))
92
+ {
93
+ test.assertNotUndefinedAndNotNull(division.id);
94
+ test.assertNotUndefinedAndNotNull(division.district);
95
+ test.assertNotUndefinedAndNotNull(division.name);
96
+ test.assertNotUndefinedAndNotNull(division.type);
97
+ }
98
+ });
99
+ });
100
+
101
+ runner.testFunction("getDivisionAvailability()", () =>
102
+ {
103
+ function getDivisionAvailabilityErrorTest(itineraryId: string, divisionId: string, month: number, year: number, expected: Error): void
104
+ {
105
+ runner.test(`with ${runner.andList([itineraryId, divisionId, month, year])}`, async (test: Test) =>
106
+ {
107
+
108
+ });
109
+ }
110
+
111
+ getDivisionAvailabilityErrorTest(undefined!, "fake-division-id", 5, 2026, new PreConditionError(
112
+ "Expression: permitItineraryId",
113
+ "Expected: not undefined and not null",
114
+ "Actual: undefined",
115
+ ));
116
+ getDivisionAvailabilityErrorTest(null!, "fake-division-id", 5, 2026, new PreConditionError(
117
+ "Expression: permitItineraryId",
118
+ "Expected: not undefined and not null",
119
+ "Actual: null",
120
+ ));
121
+ getDivisionAvailabilityErrorTest("", "fake-division-id", 5, 2026, new PreConditionError(
122
+ "Expression: permitItineraryId",
123
+ "Expected: not empty",
124
+ "Actual: \"\"",
125
+ ));
126
+ getDivisionAvailabilityErrorTest("oopsie!", "fake-division-id", 5, 2026, new RecreationDotGovError(
127
+ `No permit itinerary found for id: "oopsie!"`,
128
+ ));
129
+
130
+ runner.test("with invalid division id", runner.skip(!hasNetworkAccess), async (test: Test) =>
131
+ {
132
+ const client: RecreationDotGovClient = RecreationDotGovClient.create(HttpClient.create());
133
+ const itineraryId: string = WonderlandTrailClient.permitItineraryId;
134
+ const divisionId: string = "fake-division-id";
135
+ const month: number = 5;
136
+ const year: number = 2026;
137
+ const earlyAccessPermitLotteryId: string = "";
138
+
139
+ const response: RecreationDotGovDivisionAvailability = await client.getDivisionAvailability(itineraryId, divisionId, month, year, earlyAccessPermitLotteryId);
140
+
141
+ test.assertNotUndefinedAndNotNull(response);
142
+ test.assertNotUndefinedAndNotNull(response.json);
143
+ test.assertNotUndefinedAndNotNull(response.dayAvailabilities);
144
+ test.assertEqual(0, response.dayAvailabilities.getCount().await());
145
+ test.assertUndefined(response.maximumGroupSize);
146
+ test.assertUndefined(response.minimumGroupSize);
147
+ });
148
+
149
+ runner.test("with Sunrise Camp division id", runner.skip(!hasNetworkAccess), async (test: Test) =>
150
+ {
151
+ const client: RecreationDotGovClient = RecreationDotGovClient.create(HttpClient.create());
152
+
153
+ const itineraryId: string = WonderlandTrailClient.permitItineraryId;
154
+ const divisionId: string = WonderlandTrailLocations.sunriseCamp.divisionId;
155
+ const month: number = 8;
156
+ const year: number = 2026;
157
+ const earlyAccessPermitLotteryId: string = "";
158
+
159
+ const response: RecreationDotGovDivisionAvailability = await client.getDivisionAvailability(itineraryId, divisionId, month, year, earlyAccessPermitLotteryId);
160
+
161
+ test.assertNotUndefinedAndNotNull(response);
162
+ test.assertNotUndefinedAndNotNull(response.json);
163
+ test.assertNotUndefinedAndNotNull(response.dayAvailabilities);
164
+ test.assertEqual(31, response.dayAvailabilities.getCount().await());
165
+ test.assertNotUndefinedAndNotNull(response.maximumGroupSize);
166
+ test.assertNotUndefinedAndNotNull(response.minimumGroupSize);
167
+ });
168
+
169
+ runner.test("with Indian Bar division id", runner.skip(!hasNetworkAccess), async (test: Test) =>
170
+ {
171
+ const client: RecreationDotGovClient = RecreationDotGovClient.create(HttpClient.create());
172
+
173
+ const itineraryId: string = WonderlandTrailClient.permitItineraryId;
174
+ const divisionId: string = WonderlandTrailLocations.indianBar.divisionId;
175
+ const month: number = 7;
176
+ const year: number = 2026;
177
+ const earlyAccessPermitLotteryId: string = "";
178
+
179
+ const response: RecreationDotGovDivisionAvailability = await client.getDivisionAvailability(itineraryId, divisionId, month, year, earlyAccessPermitLotteryId);
180
+
181
+ test.assertNotUndefinedAndNotNull(response);
182
+ test.assertNotUndefinedAndNotNull(response.json);
183
+ test.assertNotUndefinedAndNotNull(response.dayAvailabilities);
184
+ test.assertEqual(31, response.dayAvailabilities.getCount().await());
185
+ test.assertNotUndefinedAndNotNull(response.maximumGroupSize);
186
+ test.assertNotUndefinedAndNotNull(response.minimumGroupSize);
187
+ });
188
+ });
189
+ });
190
+ });
191
+ }
@@ -0,0 +1,140 @@
1
+ import { TestRunner } from "./testRunner";
2
+ import { Set } from "../sources/set";
3
+ import { Test } from "./test";
4
+ import { JavascriptSetSet } from "../sources/javascriptSetSet";
5
+ import { NotFoundError } from "../sources/notFoundError";
6
+ import { SyncResult } from "../sources/syncResult";
7
+ import { JavascriptIterable } from "../sources/javascript";
8
+ import { PreCondition } from "../sources/preCondition";
9
+ import { PreConditionError } from "../sources/preConditionError";
10
+
11
+ export function test(runner: TestRunner): void
12
+ {
13
+ runner.testFile("set.ts", () =>
14
+ {
15
+ runner.testType("Set<T>", () =>
16
+ {
17
+ runner.testFunction("create()", (test: Test) =>
18
+ {
19
+ const set: JavascriptSetSet<number> = Set.create();
20
+ test.assertNotUndefinedAndNotNull(set);
21
+ test.assertEqual(0, set.getCount().await());
22
+ test.assertEqual([], set.toArray().await());
23
+ });
24
+
25
+ runner.testFunction("add()", (test: Test) =>
26
+ {
27
+ const set: Set<number> = Set.create();
28
+ for (let i = 0; i < 3; i++)
29
+ {
30
+ const addResult: Set<number> = set.add(20);
31
+ test.assertSame(set, addResult);
32
+ test.assertTrue(set.contains(20).await());
33
+ test.assertEqual(set.getCount().await(), 1);
34
+ test.assertEqual([20], set.toArray().await());
35
+ }
36
+ });
37
+
38
+ runner.testFunction("addAll()", (test: Test) =>
39
+ {
40
+ const set: Set<number> = Set.create();
41
+ for (let i = 0; i < 3; i++)
42
+ {
43
+ const addResult: Set<number> = set.addAll([20, 20, 25, 26]);
44
+ test.assertSame(set, addResult);
45
+ test.assertTrue(set.contains(20).await());
46
+ test.assertTrue(set.contains(25).await());
47
+ test.assertTrue(set.contains(26).await());
48
+ test.assertEqual(set.getCount().await(), 3);
49
+ test.assertEqual([20, 25, 26], set.toArray().await());
50
+ }
51
+ });
52
+
53
+ runner.testFunction("remove()", (test: Test) =>
54
+ {
55
+ const set: Set<number> = Set.create();
56
+
57
+ test.assertThrows(set.remove(15), new NotFoundError("Could not find 15."));
58
+
59
+ set.add(16);
60
+ const removeResult: SyncResult<void> = set.remove(16);
61
+ test.assertNotUndefinedAndNotNull(removeResult);
62
+ test.assertFalse(set.contains(16).await());
63
+ test.assertUndefined(removeResult.await());
64
+
65
+ test.assertThrows(set.remove(16), new NotFoundError("Could not find 16."));
66
+ });
67
+
68
+ runner.testFunction("toString()", () =>
69
+ {
70
+ function toStringTest<T>(set: Set<T>, expected: string): void
71
+ {
72
+ runner.test(`with ${runner.toString(set)}`, (test: Test) =>
73
+ {
74
+ test.assertEqual(set.toString(), expected);
75
+ });
76
+ }
77
+
78
+ toStringTest(Set.create(), "{}");
79
+ toStringTest(Set.create().addAll([1]), "{1}");
80
+ toStringTest(Set.create().addAll([1, 2]), "{1,2}");
81
+ toStringTest(Set.create().addAll([3, 1, 2]), "{3,1,2}");
82
+ });
83
+
84
+ runner.testFunction("equals()", () =>
85
+ {
86
+ function equalsTest<T>(set: Set<T>, right: JavascriptIterable<T>, expected: boolean): void
87
+ {
88
+ runner.test(`with ${runner.andList([set, right])}`, (test: Test) =>
89
+ {
90
+ test.assertEqual(set.equals(right).await(), expected);
91
+ });
92
+ }
93
+
94
+ equalsTest(Set.create(), [], true);
95
+ equalsTest(Set.create(), [1], false);
96
+ equalsTest(Set.create<number>().addAll([1]), [], false);
97
+ equalsTest(Set.create<number>().addAll([1]), [1], true);
98
+ equalsTest(Set.create<number>().addAll([1]), [1, 1], false);
99
+ equalsTest(Set.create<number>().addAll([1, 2]), [1, 2], true);
100
+ equalsTest(Set.create<number>().addAll([1, 2]), [2, 1], false);
101
+ equalsTest(Set.create<number>().addAll([1, 2]), Set.create<number>().addAll([2, 1]), true);
102
+ });
103
+
104
+ runner.testFunction("union()", () =>
105
+ {
106
+ function unionErrorTest<T>(set: Set<T>, values: JavascriptIterable<T>, expected: Error): void
107
+ {
108
+ runner.test(`with ${runner.andList([set, values])}`, (test: Test) =>
109
+ {
110
+ test.assertThrows(() => set.union(values), expected);
111
+ });
112
+ }
113
+
114
+ unionErrorTest(Set.create<number>(), undefined!, new PreConditionError(
115
+ "Expression: values",
116
+ "Expected: not undefined and not null",
117
+ "Actual: undefined",
118
+ ));
119
+ unionErrorTest(Set.create<number>(), null!, new PreConditionError(
120
+ "Expression: values",
121
+ "Expected: not undefined and not null",
122
+ "Actual: null",
123
+ ));
124
+
125
+ function unionTest<T>(set: Set<T>, values: JavascriptIterable<T>, expected: JavascriptIterable<T>): void
126
+ {
127
+ runner.test(`with ${runner.andList([set, values])}`, (test: Test) =>
128
+ {
129
+ test.assertEqual(set.union(values).toArray().await(), expected);
130
+ });
131
+ }
132
+
133
+ unionTest(Set.create(), [], []);
134
+ unionTest(Set.create(), [1, 2], [1, 2]);
135
+ unionTest(Set.create([1]), [2], [1, 2]);
136
+ unionTest(Set.create([1, 2]), [1], [1, 2]);
137
+ });
138
+ });
139
+ });
140
+ }
@@ -0,0 +1,39 @@
1
+ import { JavascriptIterable } from "../sources/javascript";
2
+ import { PreCondition } from "../sources/preCondition";
3
+ import { join } from "../sources/strings";
4
+ import { TestSkip } from "./testSkip";
5
+
6
+ export class SkippedTest
7
+ {
8
+ private readonly skip: TestSkip;
9
+ private readonly fullTestNameParts: JavascriptIterable<string>;
10
+
11
+ private constructor(skip: TestSkip, fullTestNameParts: JavascriptIterable<string>)
12
+ {
13
+ PreCondition.assertNotUndefinedAndNotNull(skip, "skip");
14
+ PreCondition.assertNotEmpty(fullTestNameParts, "fullTestNameParts");
15
+
16
+ this.skip = skip;
17
+ this.fullTestNameParts = fullTestNameParts;
18
+ }
19
+
20
+ public static create(skip: TestSkip, fullTestNameParts: JavascriptIterable<string>): SkippedTest
21
+ {
22
+ return new SkippedTest(skip, fullTestNameParts);
23
+ }
24
+
25
+ public getSkipMessage(): string
26
+ {
27
+ return this.skip.getMessage();
28
+ }
29
+
30
+ public getFullTestNameParts(): JavascriptIterable<string>
31
+ {
32
+ return this.fullTestNameParts;
33
+ }
34
+
35
+ public getFullTestName(): string
36
+ {
37
+ return join(" ", this.fullTestNameParts);
38
+ }
39
+ }
@@ -0,0 +1,66 @@
1
+ import { EmptyError } from "../sources/emptyError";
2
+ import { ListStack } from "../sources/listStack";
3
+ import { Stack } from "../sources/stack";
4
+ import { Test } from "./test";
5
+ import { TestRunner } from "./testRunner";
6
+
7
+ export function test(runner: TestRunner): void
8
+ {
9
+ runner.testFile("stack.ts", () =>
10
+ {
11
+ runner.testType("Stack<T>", () =>
12
+ {
13
+ runner.testFunction("create()", (test: Test) =>
14
+ {
15
+ const stack: ListStack<number> = Stack.create();
16
+ test.assertNotUndefinedAndNotNull(stack);
17
+ test.assertFalse(stack.any().await());
18
+ });
19
+
20
+ runner.testFunction("add()", (test: Test) =>
21
+ {
22
+ const stack: ListStack<number> = Stack.create();
23
+
24
+ stack.add(10).await();
25
+ test.assertTrue(stack.any().await());
26
+
27
+ stack.add(20).await();
28
+ test.assertTrue(stack.any().await());
29
+
30
+ test.assertEqual(20, stack.remove().await());
31
+ test.assertEqual(10, stack.remove().await());
32
+ test.assertFalse(stack.any().await());
33
+ });
34
+
35
+ runner.testFunction("addAll()", () =>
36
+ {
37
+ function addAllTest(values: number[]): void
38
+ {
39
+ runner.test(`with ${runner.toString(values)}`, (test: Test) =>
40
+ {
41
+ const stack: ListStack<number> = Stack.create();
42
+ stack.addAll(values).await();
43
+
44
+ for (const value of values.reverse())
45
+ {
46
+ test.assertTrue(stack.any().await());
47
+ test.assertEqual(value, stack.remove().await());
48
+ }
49
+ test.assertFalse(stack.any().await());
50
+ });
51
+ }
52
+
53
+ addAllTest([]);
54
+ addAllTest([1]);
55
+ addAllTest([1, 2]);
56
+ addAllTest([1, 2, 3]);
57
+ });
58
+
59
+ runner.testFunction("remove()", (test: Test) =>
60
+ {
61
+ const stack: ListStack<number> = Stack.create();
62
+ test.assertThrows(() => stack.remove().await(), new EmptyError());
63
+ });
64
+ });
65
+ });
66
+ }
@@ -0,0 +1,60 @@
1
+ import { Comparison } from "../sources/comparison";
2
+ import { StringComparer } from "../sources/stringComparer";
3
+ import { Test } from "./test";
4
+ import { TestRunner } from "./testRunner";
5
+
6
+ export function test(runner: TestRunner): void
7
+ {
8
+ runner.testFile("stringComparer.ts", () =>
9
+ {
10
+ runner.testType("StringComparer", () =>
11
+ {
12
+ runner.testFunction("compare(string, string)", () =>
13
+ {
14
+ function compareTest(left: string, right: string, expected: Comparison): void
15
+ {
16
+ runner.test(`with ${runner.andList([left, right])}`, (test: Test) =>
17
+ {
18
+ const comparer: StringComparer = StringComparer.create();
19
+ test.assertEqual(comparer.compare(left, right), expected);
20
+ test.assertEqual(comparer.lessThan(left, right), expected === Comparison.LessThan);
21
+ test.assertEqual(comparer.lessThanOrEqual(left, right), expected !== Comparison.GreaterThan);
22
+ test.assertEqual(comparer.equal(left, right), expected === Comparison.Equal);
23
+ test.assertEqual(comparer.greaterThanOrEqualTo(left, right), expected !== Comparison.LessThan);
24
+ test.assertEqual(comparer.greaterThan(left, right), expected === Comparison.GreaterThan);
25
+ });
26
+ }
27
+
28
+ compareTest(undefined!, undefined!, Comparison.Equal);
29
+ compareTest(undefined!, null!, Comparison.LessThan);
30
+ compareTest(undefined!, "", Comparison.LessThan);
31
+ compareTest(undefined!, "a", Comparison.LessThan);
32
+ compareTest(undefined!, "def", Comparison.LessThan);
33
+
34
+ compareTest(null!, undefined!, Comparison.GreaterThan);
35
+ compareTest(null!, null!, Comparison.Equal);
36
+ compareTest(null!, "", Comparison.LessThan);
37
+ compareTest(null!, "a", Comparison.LessThan);
38
+ compareTest(null!, "def", Comparison.LessThan);
39
+
40
+ compareTest("", undefined!, Comparison.GreaterThan);
41
+ compareTest("", null!, Comparison.GreaterThan);
42
+ compareTest("", "", Comparison.Equal);
43
+ compareTest("", "a", Comparison.LessThan);
44
+ compareTest("", "def", Comparison.LessThan);
45
+
46
+ compareTest("a", undefined!, Comparison.GreaterThan);
47
+ compareTest("a", null!, Comparison.GreaterThan);
48
+ compareTest("a", "", Comparison.GreaterThan);
49
+ compareTest("a", "a", Comparison.Equal);
50
+ compareTest("a", "def", Comparison.LessThan);
51
+
52
+ compareTest("def", undefined!, Comparison.GreaterThan);
53
+ compareTest("def", null!, Comparison.GreaterThan);
54
+ compareTest("def", "", Comparison.GreaterThan);
55
+ compareTest("def", "a", Comparison.GreaterThan);
56
+ compareTest("def", "def", Comparison.Equal);
57
+ });
58
+ });
59
+ });
60
+ }