@raikuxq/alg-ds 1.0.2 → 1.1.2
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/.idea/algorythmes.iml +15 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/deployment.xml +14 -0
- package/.idea/inspectionProfiles/Project_Default.xml +7 -0
- package/.idea/jsLinters/eslint.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README.md +12 -0
- package/lib/algotirhms.ts +35 -0
- package/lib/constants.ts +3 -0
- package/lib/data-structures.ts +23 -0
- package/lib/helpers.ts +13 -0
- package/lib/sorts.ts +7 -0
- package/lib/types.ts +53 -0
- package/{src/exports → lib}/utils.ts +2 -2
- package/package.json +4 -3
- package/src/data-structures/HashTable/HashTable.ts +202 -0
- package/src/data-structures/HashTable/HashTableNode.ts +31 -0
- package/src/demo/demo.hashtable.ts +28 -0
- package/src/demo/performance/bst-compare.ts +1 -4
- package/src/demo/performance/hash-table.compare.ts +40 -0
- package/src/index.ts +44 -40
- package/src/types/IKeyValueStorage.ts +8 -0
- package/.eslintrc.js +0 -14
- package/jest.config.js +0 -4
- package/nodemon.json +0 -6
- package/src/exports/algotirhms.ts +0 -35
- package/src/exports/constants.ts +0 -3
- package/src/exports/helpers.ts +0 -13
- package/src/exports/main.ts +0 -21
- package/src/exports/sorts.ts +0 -7
- package/src/exports/types.ts +0 -53
- package/test/unit/algorithms/binary-search.test.ts +0 -25
- package/test/unit/algorithms/factorial.test.ts +0 -43
- package/test/unit/algorithms/fibonacci.test.ts +0 -41
- package/test/unit/algorithms/sorts.test.ts +0 -74
- package/test/unit/algorithms/transpose-matrix.test.ts +0 -39
- package/test/unit/data-structures/binary-tree/binary-search-tree.test.ts +0 -230
- package/test/unit/data-structures/graph/graph.create-from-matrix.test.ts +0 -106
- package/test/unit/data-structures/graph/graph.has-path.test.ts +0 -115
- package/test/unit/data-structures/graph/graph.presenter.lists.test.ts +0 -76
- package/test/unit/data-structures/graph/graph.presenter.matrix.test.ts +0 -73
- package/test/unit/data-structures/graph/graph.shortest-path.test.ts +0 -207
- package/test/unit/data-structures/graph/graph.test.ts +0 -394
- package/test/unit/data-structures/graph/graph.transpose.test.ts +0 -52
- package/test/unit/data-structures/linked-list/linked-list.test.ts +0 -477
- package/test/unit/data-structures/looped-array/looped-array.test.ts +0 -387
- package/test/unit/data-structures/queue/queue.test.ts +0 -147
- package/test/unit/data-structures/stack/stack.test.ts +0 -155
- package/tsconfig.json +0 -18
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
import LoopedArray from "../../../../src/data-structures/LoopedArray/LoopedArray";
|
|
2
|
-
import IArrayFacade from "../../../../src/types/IArrayFacade";
|
|
3
|
-
import ILinearStorage from "../../../../src/types/ILinearStorage";
|
|
4
|
-
|
|
5
|
-
describe("Looped Array", () => {
|
|
6
|
-
describe("constructor", () => {
|
|
7
|
-
it("should throw when capacity is less than 1", () => {
|
|
8
|
-
expect(() => {
|
|
9
|
-
new LoopedArray(-5);
|
|
10
|
-
}).toThrowError();
|
|
11
|
-
|
|
12
|
-
expect(() => {
|
|
13
|
-
new LoopedArray(0);
|
|
14
|
-
}).toThrowError();
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe("method push", () => {
|
|
19
|
-
const loopedArray: IArrayFacade<string> = new LoopedArray(5);
|
|
20
|
-
|
|
21
|
-
loopedArray.push("q");
|
|
22
|
-
loopedArray.push("w");
|
|
23
|
-
loopedArray.push("e");
|
|
24
|
-
loopedArray.push("r");
|
|
25
|
-
loopedArray.push("t");
|
|
26
|
-
|
|
27
|
-
it("should collect correct elements before overwriting", () => {
|
|
28
|
-
expect(loopedArray.getAsArray()).toEqual(["q", "w", "e", "r", "t"]);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it("should correctly overwrite ", () => {
|
|
32
|
-
loopedArray.push("y");
|
|
33
|
-
loopedArray.push("u");
|
|
34
|
-
loopedArray.push("i");
|
|
35
|
-
|
|
36
|
-
expect(loopedArray.getAsArray()).toEqual(["y", "u", "i"]);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("should add elements to array's end", () => {
|
|
40
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
41
|
-
array.push(1);
|
|
42
|
-
|
|
43
|
-
expect(array.peek()).toBe(1);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("should overwrite when array is full", () => {
|
|
47
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(2);
|
|
48
|
-
array.push(1);
|
|
49
|
-
array.push(2);
|
|
50
|
-
array.push(3);
|
|
51
|
-
|
|
52
|
-
expect(array.getAsArray()).toEqual([3]);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("method unshift", () => {
|
|
57
|
-
const loopedArray: IArrayFacade<string> = new LoopedArray(5);
|
|
58
|
-
|
|
59
|
-
loopedArray.unshift("q");
|
|
60
|
-
loopedArray.unshift("w");
|
|
61
|
-
loopedArray.unshift("e");
|
|
62
|
-
loopedArray.unshift("r");
|
|
63
|
-
loopedArray.unshift("t");
|
|
64
|
-
|
|
65
|
-
it("should collect correct elements before overwriting", () => {
|
|
66
|
-
expect(loopedArray.getAsArray()).toEqual(["t", "r", "e", "w", "q"]);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("should correctly overwrite ", () => {
|
|
70
|
-
loopedArray.unshift("y");
|
|
71
|
-
loopedArray.unshift("u");
|
|
72
|
-
loopedArray.unshift("i");
|
|
73
|
-
|
|
74
|
-
expect(loopedArray.getAsArray()).toEqual(["i", "u", "y"]);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("should add elements to array's start", () => {
|
|
78
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
79
|
-
array.unshift(1);
|
|
80
|
-
array.unshift(0);
|
|
81
|
-
|
|
82
|
-
expect(array.peekFromStart()).toBe(0);
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("should overwrite when array is full", () => {
|
|
86
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(2);
|
|
87
|
-
array.unshift(1);
|
|
88
|
-
array.unshift(2);
|
|
89
|
-
array.unshift(3);
|
|
90
|
-
array.unshift(4);
|
|
91
|
-
|
|
92
|
-
expect(array.getAsArray()).toEqual([4, 3]);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe("method pushFromIndex", () => {
|
|
97
|
-
it("should overwrite elements by index", () => {
|
|
98
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
99
|
-
array.pushFromArray([10, 30, 40, 50]);
|
|
100
|
-
array.pushFromIndex(20, 1);
|
|
101
|
-
|
|
102
|
-
expect(array.getAsArray()).toEqual([10, 20, 40, 50]);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("should add elements to array from start", () => {
|
|
106
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
107
|
-
array.pushFromArray([0]);
|
|
108
|
-
array.pushFromIndex(10, 1);
|
|
109
|
-
|
|
110
|
-
expect(array.getAsArray()).toEqual([0, 10]);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("should add elements to empty array", () => {
|
|
114
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
115
|
-
array.pushFromIndex(10, 0);
|
|
116
|
-
|
|
117
|
-
expect(array.getAsArray()).toEqual([10]);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("should add elements to array from end", () => {
|
|
121
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
122
|
-
array.pushFromArray([0, 10, 30]);
|
|
123
|
-
array.pushFromIndex(20, 2);
|
|
124
|
-
|
|
125
|
-
expect(array.getAsArray()).toEqual([0, 10, 20]);
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe("method pushFromArray", () => {
|
|
130
|
-
it("should add elements to array's end", () => {
|
|
131
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
132
|
-
const arr = [1, 2, 3, 4, 5];
|
|
133
|
-
array.pushFromArray(arr);
|
|
134
|
-
|
|
135
|
-
expect(array.getAsArray()).toEqual(arr);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it("should overwrite when array is full", () => {
|
|
139
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(2);
|
|
140
|
-
array.pushFromArray([1]);
|
|
141
|
-
array.pushFromArray([2, 3]);
|
|
142
|
-
|
|
143
|
-
expect(array.getAsArray()).toEqual([3]);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe("method peekFromStart", () => {
|
|
148
|
-
it("should return first element of array", () => {
|
|
149
|
-
const loopedArray: IArrayFacade<string> = new LoopedArray(5);
|
|
150
|
-
loopedArray.push("q");
|
|
151
|
-
loopedArray.push("w");
|
|
152
|
-
loopedArray.push("e");
|
|
153
|
-
|
|
154
|
-
expect(loopedArray.peekFromStart()).toEqual("q");
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it("should return undefined when array is empty", () => {
|
|
158
|
-
const loopedArray: IArrayFacade<number> = new LoopedArray(5);
|
|
159
|
-
|
|
160
|
-
expect(loopedArray.peekFromStart()).toEqual(undefined);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("should return undefined when array is empty", () => {
|
|
164
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
165
|
-
expect(array.peekFromStart()).toBeUndefined();
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("should return first element from array", () => {
|
|
169
|
-
const array: IArrayFacade<number> = new LoopedArray(5);
|
|
170
|
-
array.pushFromArray([10, 20, 30, 40, 50]);
|
|
171
|
-
|
|
172
|
-
expect(array.peekFromStart()).toBe(10);
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
describe("method peek", () => {
|
|
177
|
-
it("should return last element of array", () => {
|
|
178
|
-
const loopedArray: IArrayFacade<string> = new LoopedArray(5);
|
|
179
|
-
loopedArray.push("q");
|
|
180
|
-
loopedArray.push("w");
|
|
181
|
-
loopedArray.push("e");
|
|
182
|
-
|
|
183
|
-
expect(loopedArray.peek()).toEqual("e");
|
|
184
|
-
});
|
|
185
|
-
it("should return undefined when array is empty", () => {
|
|
186
|
-
const loopedArray: IArrayFacade<number> = new LoopedArray(5);
|
|
187
|
-
|
|
188
|
-
expect(loopedArray.peek()).toEqual(undefined);
|
|
189
|
-
});
|
|
190
|
-
it("should return undefined when array is empty", () => {
|
|
191
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
192
|
-
|
|
193
|
-
expect(array.peek()).toBeUndefined();
|
|
194
|
-
});
|
|
195
|
-
it("should return first element from array", () => {
|
|
196
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
197
|
-
array.pushFromArray([10, 20, 30, 40, 50]);
|
|
198
|
-
|
|
199
|
-
expect(array.peek()).toBe(50);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe("method peekByIndex", () => {
|
|
204
|
-
it("should throw when array is empty", () => {
|
|
205
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
206
|
-
|
|
207
|
-
expect(array.peekByIndex(0)).toBeUndefined();
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
it("should return element by its index from array", () => {
|
|
211
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
212
|
-
array.pushFromArray([10, 20, 30, 40, 50]);
|
|
213
|
-
|
|
214
|
-
expect(array.peekByIndex(2)).toBe(30);
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it("should return undefined when index exceed array length", () => {
|
|
218
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
219
|
-
|
|
220
|
-
expect(array.peekByIndex(1000)).toBeUndefined();
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
describe("method shift", () => {
|
|
225
|
-
describe("should delete first element and return its value", () => {
|
|
226
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
227
|
-
array.pushFromArray([10, 20]);
|
|
228
|
-
const shifted = array.shift();
|
|
229
|
-
|
|
230
|
-
it("should delete correct", () => {
|
|
231
|
-
expect(array.getAsArray()).toEqual([20]);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it("should return correct value", () => {
|
|
235
|
-
expect(shifted).toBe(10);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it("should throw when array is empty", () => {
|
|
240
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
241
|
-
expect(() => {
|
|
242
|
-
array.shift();
|
|
243
|
-
}).toThrowError();
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
describe("method pop", () => {
|
|
248
|
-
describe("should delete last element and return its value", () => {
|
|
249
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
250
|
-
array.pushFromArray([10, 40]);
|
|
251
|
-
const shifted = array.pop();
|
|
252
|
-
|
|
253
|
-
it("should delete correct", () => {
|
|
254
|
-
expect(array.getAsArray()).toEqual([10]);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it("should return correct value", () => {
|
|
258
|
-
expect(shifted).toBe(40);
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it("should throw when array is empty", () => {
|
|
263
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
264
|
-
|
|
265
|
-
expect(() => {
|
|
266
|
-
array.pop();
|
|
267
|
-
}).toThrowError();
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
describe("method deleteFromIndex", () => {
|
|
272
|
-
describe("should replace element with undefined by index and return its value", () => {
|
|
273
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
274
|
-
array.pushFromArray([10, 20, 30]);
|
|
275
|
-
const shifted = array.deleteFromIndex(1);
|
|
276
|
-
|
|
277
|
-
it("should delete correct", () => {
|
|
278
|
-
expect(array.getAsArray()).toEqual([10, undefined, 30]);
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it("should return correct value", () => {
|
|
282
|
-
expect(shifted).toBe(20);
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it("should throw when array is empty", () => {
|
|
287
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
288
|
-
|
|
289
|
-
expect(() => {
|
|
290
|
-
array.shift();
|
|
291
|
-
}).toThrowError();
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
describe("method reverse", () => {
|
|
296
|
-
it("should correct reverse array", () => {
|
|
297
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(12);
|
|
298
|
-
const arraySource = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110];
|
|
299
|
-
const reversedArray = [...arraySource].reverse();
|
|
300
|
-
array.pushFromArray(arraySource);
|
|
301
|
-
array.reverse();
|
|
302
|
-
|
|
303
|
-
expect(array.getAsArray()).toEqual(reversedArray);
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
describe("method clear", () => {
|
|
308
|
-
it("should correct clear array", () => {
|
|
309
|
-
const array: IArrayFacade<number> = new LoopedArray<number>(10);
|
|
310
|
-
const testArray: Array<number> = [10, 20, 30, 40, 50, 60, 70, 80, 90];
|
|
311
|
-
array.pushFromArray(testArray);
|
|
312
|
-
array.clear();
|
|
313
|
-
|
|
314
|
-
expect(array.isEmpty()).toBe(true);
|
|
315
|
-
});
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
describe("method has", function () {
|
|
319
|
-
const array = new LoopedArray<number>(10);
|
|
320
|
-
array.push(5);
|
|
321
|
-
|
|
322
|
-
it("should return true when value exists", () => {
|
|
323
|
-
expect(array.has(5)).toBe(true);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
it("should return false when value does not exist", () => {
|
|
327
|
-
expect(array.has(10)).toBe(false);
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
describe("method length", function () {
|
|
332
|
-
describe("when array is non empty", () => {
|
|
333
|
-
describe("after adding", () => {
|
|
334
|
-
it("should return updated length value", () => {
|
|
335
|
-
const array = new LoopedArray<number>(10);
|
|
336
|
-
array.push(5);
|
|
337
|
-
array.push(15);
|
|
338
|
-
array.push(10);
|
|
339
|
-
|
|
340
|
-
expect(array.length()).toBe(3);
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
describe("after deleting", () => {
|
|
345
|
-
it("should return updated length value", () => {
|
|
346
|
-
const array = new LoopedArray<number>(10);
|
|
347
|
-
array.push(5);
|
|
348
|
-
array.push(15);
|
|
349
|
-
array.push(10);
|
|
350
|
-
array.pop();
|
|
351
|
-
|
|
352
|
-
expect(array.length()).toBe(2);
|
|
353
|
-
});
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
describe("when array is empty", () => {
|
|
358
|
-
it("should return zero value", () => {
|
|
359
|
-
const array = new LoopedArray<number>(10);
|
|
360
|
-
|
|
361
|
-
expect(array.length()).toBe(0);
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
describe("method isEmpty", () => {
|
|
367
|
-
it("should return true when array is empty", () => {
|
|
368
|
-
const array: ILinearStorage<number> = new LoopedArray<number>(10);
|
|
369
|
-
expect(array.isEmpty()).toBe(true);
|
|
370
|
-
});
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
describe("method isFull", () => {
|
|
374
|
-
it("should return false when array elements length lower than its capacity", () => {
|
|
375
|
-
const array: ILinearStorage<number> = new LoopedArray<number>(100);
|
|
376
|
-
array.push(10);
|
|
377
|
-
|
|
378
|
-
expect(array.isFull()).toBe(false);
|
|
379
|
-
});
|
|
380
|
-
it("should return true when array elements length same as its capacity", () => {
|
|
381
|
-
const array: ILinearStorage<number> = new LoopedArray<number>(1);
|
|
382
|
-
array.push(10);
|
|
383
|
-
|
|
384
|
-
expect(array.isFull()).toBe(true);
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
});
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import Queue from "../../../../src/data-structures/Queue/Queue";
|
|
2
|
-
import ILinearStorage from "../../../../src/types/ILinearStorage";
|
|
3
|
-
|
|
4
|
-
describe("queue", () => {
|
|
5
|
-
describe("method peek", () => {
|
|
6
|
-
it("should correct peek value from top", () => {
|
|
7
|
-
const queue: ILinearStorage<number> = new Queue();
|
|
8
|
-
queue.push(5);
|
|
9
|
-
queue.push(10);
|
|
10
|
-
|
|
11
|
-
expect(queue.peek()).toBe(5);
|
|
12
|
-
});
|
|
13
|
-
it("should throw when queue is empty", () => {
|
|
14
|
-
const queue: ILinearStorage<number> = new Queue();
|
|
15
|
-
|
|
16
|
-
expect(() => {
|
|
17
|
-
queue.peek();
|
|
18
|
-
}).toThrowError();
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe("method push", () => {
|
|
23
|
-
it("should correct push to top", () => {
|
|
24
|
-
const queue: ILinearStorage<number> = new Queue();
|
|
25
|
-
queue.push(5);
|
|
26
|
-
queue.push(10);
|
|
27
|
-
|
|
28
|
-
expect(queue.peek()).toBe(5);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe("method pop", () => {
|
|
33
|
-
describe("should correct pop from top", () => {
|
|
34
|
-
const queue: ILinearStorage<number> = new Queue();
|
|
35
|
-
queue.push(5);
|
|
36
|
-
queue.push(10);
|
|
37
|
-
const popd = queue.pop();
|
|
38
|
-
|
|
39
|
-
it("should delete correct", () => {
|
|
40
|
-
expect(queue.peek()).toBe(10);
|
|
41
|
-
});
|
|
42
|
-
it("should return correct value", () => {
|
|
43
|
-
expect(popd).toBe(5);
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
it("should throw when queue is empty", () => {
|
|
47
|
-
const queue: ILinearStorage<number> = new Queue();
|
|
48
|
-
|
|
49
|
-
expect(() => {
|
|
50
|
-
queue.pop();
|
|
51
|
-
}).toThrowError();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("method has", function () {
|
|
56
|
-
const queue = new Queue();
|
|
57
|
-
queue.push(5);
|
|
58
|
-
|
|
59
|
-
it("should return true when value exists", () => {
|
|
60
|
-
expect(queue.has(5)).toBe(true);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("should return false when value does not exist", () => {
|
|
64
|
-
expect(queue.has(10)).toBe(false);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe("method length", function () {
|
|
69
|
-
describe("when queue is non empty", () => {
|
|
70
|
-
describe("after adding", () => {
|
|
71
|
-
it("should return updated length value", () => {
|
|
72
|
-
const queue = new Queue();
|
|
73
|
-
queue.push(5);
|
|
74
|
-
queue.push(15);
|
|
75
|
-
queue.push(10);
|
|
76
|
-
|
|
77
|
-
expect(queue.length()).toBe(3);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe("after deleting", () => {
|
|
82
|
-
it("should return updated length value", () => {
|
|
83
|
-
const queue = new Queue();
|
|
84
|
-
queue.push(5);
|
|
85
|
-
queue.push(15);
|
|
86
|
-
queue.push(10);
|
|
87
|
-
queue.pop();
|
|
88
|
-
|
|
89
|
-
expect(queue.length()).toBe(2);
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
describe("when queue is empty", () => {
|
|
95
|
-
it("should return zero value", () => {
|
|
96
|
-
const queue = new Queue();
|
|
97
|
-
|
|
98
|
-
expect(queue.length()).toBe(0);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe("method isEmpty", () => {
|
|
104
|
-
it("should return true when queue is empty", () => {
|
|
105
|
-
const queue: ILinearStorage<number> = new Queue();
|
|
106
|
-
expect(queue.isEmpty()).toBe(true);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe("method isFull", () => {
|
|
111
|
-
it("should return false when queue elements length lower than its capacity", () => {
|
|
112
|
-
const queue: ILinearStorage<number> = new Queue(100);
|
|
113
|
-
queue.push(10);
|
|
114
|
-
|
|
115
|
-
expect(queue.isFull()).toBe(false);
|
|
116
|
-
});
|
|
117
|
-
it("should return true when queue elements length same as its capacity", () => {
|
|
118
|
-
const queue: ILinearStorage<number> = new Queue(1);
|
|
119
|
-
queue.push(10);
|
|
120
|
-
|
|
121
|
-
expect(queue.isFull()).toBe(true);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe("method reverse", () => {
|
|
126
|
-
it("should correctly reverse queue", () => {
|
|
127
|
-
const queue: ILinearStorage<number> = new Queue();
|
|
128
|
-
queue.push(5);
|
|
129
|
-
queue.push(10);
|
|
130
|
-
queue.push(15);
|
|
131
|
-
queue.reverse();
|
|
132
|
-
|
|
133
|
-
expect(queue.peek()).toBe(15);
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe("method clear", () => {
|
|
138
|
-
it("should correctly clear queue", () => {
|
|
139
|
-
const queue = new Queue();
|
|
140
|
-
queue.push(10);
|
|
141
|
-
queue.push(20);
|
|
142
|
-
queue.clear();
|
|
143
|
-
|
|
144
|
-
expect(queue.isEmpty()).toBe(true);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
});
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import Stack from "../../../../src/data-structures/Stack/Stack";
|
|
2
|
-
import ILinearStorage from "../../../../src/types/ILinearStorage";
|
|
3
|
-
|
|
4
|
-
describe("stack", () => {
|
|
5
|
-
describe("method peek", () => {
|
|
6
|
-
it("should correct peek value from top", () => {
|
|
7
|
-
const stack: ILinearStorage<number> = new Stack(100);
|
|
8
|
-
stack.push(5);
|
|
9
|
-
stack.push(10);
|
|
10
|
-
|
|
11
|
-
expect(stack.peek()).toBe(10);
|
|
12
|
-
});
|
|
13
|
-
it("should throw when stack is empty", () => {
|
|
14
|
-
const stack: ILinearStorage<number> = new Stack(1);
|
|
15
|
-
|
|
16
|
-
expect(() => {
|
|
17
|
-
stack.peek();
|
|
18
|
-
}).toThrowError();
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe("method push", () => {
|
|
23
|
-
it("should correct push to top", () => {
|
|
24
|
-
const stack: ILinearStorage<number> = new Stack(100);
|
|
25
|
-
stack.push(5);
|
|
26
|
-
stack.push(10);
|
|
27
|
-
|
|
28
|
-
expect(stack.peek()).toBe(10);
|
|
29
|
-
});
|
|
30
|
-
it("should throw when stack is full", () => {
|
|
31
|
-
const stack: ILinearStorage<number> = new Stack(1);
|
|
32
|
-
stack.push(10);
|
|
33
|
-
|
|
34
|
-
expect(() => {
|
|
35
|
-
stack.push(20);
|
|
36
|
-
}).toThrowError();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe("method pop", () => {
|
|
41
|
-
describe("should correct pop from top", () => {
|
|
42
|
-
const stack: ILinearStorage<number> = new Stack(100);
|
|
43
|
-
stack.push(5);
|
|
44
|
-
stack.push(10);
|
|
45
|
-
const popped = stack.pop();
|
|
46
|
-
|
|
47
|
-
it("should delete correct", () => {
|
|
48
|
-
expect(stack.peek()).toBe(5);
|
|
49
|
-
});
|
|
50
|
-
it("should return correct value", () => {
|
|
51
|
-
expect(popped).toBe(10);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
it("should throw when stack is empty", () => {
|
|
55
|
-
const stack: ILinearStorage<number> = new Stack(1);
|
|
56
|
-
|
|
57
|
-
expect(() => {
|
|
58
|
-
stack.pop();
|
|
59
|
-
}).toThrowError();
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe("method has", function () {
|
|
64
|
-
const stack = new Stack();
|
|
65
|
-
stack.push(5);
|
|
66
|
-
|
|
67
|
-
it("should return true when value exists", () => {
|
|
68
|
-
expect(stack.has(5)).toBe(true);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("should return false when value does not exist", () => {
|
|
72
|
-
expect(stack.has(10)).toBe(false);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe("method length", function () {
|
|
77
|
-
describe("when stack is non empty", () => {
|
|
78
|
-
describe("after adding", () => {
|
|
79
|
-
it("should return updated length value", () => {
|
|
80
|
-
const stack = new Stack();
|
|
81
|
-
stack.push(5);
|
|
82
|
-
stack.push(15);
|
|
83
|
-
stack.push(10);
|
|
84
|
-
|
|
85
|
-
expect(stack.length()).toBe(3);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
describe("after deleting", () => {
|
|
90
|
-
it("should return updated length value", () => {
|
|
91
|
-
const stack = new Stack();
|
|
92
|
-
stack.push(5);
|
|
93
|
-
stack.push(15);
|
|
94
|
-
stack.push(10);
|
|
95
|
-
stack.pop();
|
|
96
|
-
|
|
97
|
-
expect(stack.length()).toBe(2);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe("when stack is empty", () => {
|
|
103
|
-
it("should return zero value", () => {
|
|
104
|
-
const stack = new Stack();
|
|
105
|
-
|
|
106
|
-
expect(stack.length()).toBe(0);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe("method isEmpty", () => {
|
|
112
|
-
it("should return true when stack is empty", () => {
|
|
113
|
-
const stack: ILinearStorage<number> = new Stack(100);
|
|
114
|
-
expect(stack.isEmpty()).toBe(true);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
describe("method isFull", () => {
|
|
119
|
-
it("should return false when stack elements length lower than its capacity", () => {
|
|
120
|
-
const stack: ILinearStorage<number> = new Stack(100);
|
|
121
|
-
stack.push(10);
|
|
122
|
-
|
|
123
|
-
expect(stack.isFull()).toBe(false);
|
|
124
|
-
});
|
|
125
|
-
it("should return true when stack elements length same as its capacity", () => {
|
|
126
|
-
const stack: ILinearStorage<number> = new Stack(1);
|
|
127
|
-
stack.push(10);
|
|
128
|
-
|
|
129
|
-
expect(stack.isFull()).toBe(true);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
describe("method clear", () => {
|
|
134
|
-
it("should correctly clear stack", () => {
|
|
135
|
-
const stack = new Stack();
|
|
136
|
-
stack.push(10);
|
|
137
|
-
stack.push(20);
|
|
138
|
-
stack.clear();
|
|
139
|
-
|
|
140
|
-
expect(stack.isEmpty()).toBe(true);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
describe("method reverse", () => {
|
|
145
|
-
it("should correctly reverse stack", () => {
|
|
146
|
-
const stack: ILinearStorage<number> = new Stack();
|
|
147
|
-
stack.push(5);
|
|
148
|
-
stack.push(10);
|
|
149
|
-
stack.push(15);
|
|
150
|
-
stack.reverse();
|
|
151
|
-
|
|
152
|
-
expect(stack.peek()).toBe(5);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es5",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"lib": ["es6"],
|
|
6
|
-
"allowJs": true,
|
|
7
|
-
"outDir": ".build",
|
|
8
|
-
"declaration": true,
|
|
9
|
-
"rootDir": "src",
|
|
10
|
-
"strict": true,
|
|
11
|
-
"noImplicitAny": true,
|
|
12
|
-
"esModuleInterop": true,
|
|
13
|
-
"resolveJsonModule": true
|
|
14
|
-
},
|
|
15
|
-
"include": [
|
|
16
|
-
"src/**/*"
|
|
17
|
-
]
|
|
18
|
-
}
|