data-structure-typed 1.48.1 → 1.48.3
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/CHANGELOG.md +1 -1
- package/README.md +24 -18
- package/benchmark/report.html +16 -16
- package/benchmark/report.json +172 -172
- package/dist/cjs/data-structures/base/index.d.ts +1 -0
- package/dist/cjs/data-structures/base/index.js +18 -0
- package/dist/cjs/data-structures/base/index.js.map +1 -0
- package/dist/cjs/data-structures/base/iterable-base.d.ts +232 -0
- package/dist/cjs/data-structures/base/iterable-base.js +313 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -0
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +16 -16
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +121 -152
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +140 -182
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +28 -47
- package/dist/cjs/data-structures/binary-tree/bst.js +54 -57
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +15 -15
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +7 -7
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +22 -22
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +11 -11
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +44 -6
- package/dist/cjs/data-structures/graph/abstract-graph.js +50 -27
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +59 -100
- package/dist/cjs/data-structures/hash/hash-map.js +69 -173
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +50 -7
- package/dist/cjs/data-structures/heap/heap.js +60 -30
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/index.d.ts +1 -0
- package/dist/cjs/data-structures/index.js +1 -0
- package/dist/cjs/data-structures/index.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +46 -73
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +32 -51
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +40 -73
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +29 -51
- package/dist/cjs/data-structures/queue/deque.js +36 -71
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +49 -48
- package/dist/cjs/data-structures/queue/queue.js +69 -82
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +43 -10
- package/dist/cjs/data-structures/stack/stack.js +50 -31
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +41 -6
- package/dist/cjs/data-structures/trie/trie.js +53 -32
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/interfaces/binary-tree.d.ts +6 -6
- package/dist/cjs/types/common.d.ts +11 -8
- package/dist/cjs/types/common.js +6 -1
- package/dist/cjs/types/common.js.map +1 -1
- package/dist/cjs/types/data-structures/base/base.d.ts +5 -0
- package/dist/cjs/types/data-structures/base/base.js +3 -0
- package/dist/cjs/types/data-structures/base/base.js.map +1 -0
- package/dist/cjs/types/data-structures/base/index.d.ts +1 -0
- package/dist/cjs/types/data-structures/base/index.js +18 -0
- package/dist/cjs/types/data-structures/base/index.js.map +1 -0
- package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/dist/cjs/types/data-structures/index.d.ts +1 -0
- package/dist/cjs/types/data-structures/index.js +1 -0
- package/dist/cjs/types/data-structures/index.js.map +1 -1
- package/dist/mjs/data-structures/base/index.d.ts +1 -0
- package/dist/mjs/data-structures/base/index.js +1 -0
- package/dist/mjs/data-structures/base/iterable-base.d.ts +232 -0
- package/dist/mjs/data-structures/base/iterable-base.js +307 -0
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +16 -16
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +7 -7
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +121 -152
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +140 -182
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +28 -47
- package/dist/mjs/data-structures/binary-tree/bst.js +55 -57
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +15 -15
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +7 -7
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +22 -22
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +11 -11
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +44 -6
- package/dist/mjs/data-structures/graph/abstract-graph.js +52 -27
- package/dist/mjs/data-structures/hash/hash-map.d.ts +59 -100
- package/dist/mjs/data-structures/hash/hash-map.js +69 -173
- package/dist/mjs/data-structures/heap/heap.d.ts +50 -7
- package/dist/mjs/data-structures/heap/heap.js +60 -30
- package/dist/mjs/data-structures/index.d.ts +1 -0
- package/dist/mjs/data-structures/index.js +1 -0
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +38 -51
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +46 -73
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +32 -51
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +40 -73
- package/dist/mjs/data-structures/queue/deque.d.ts +29 -51
- package/dist/mjs/data-structures/queue/deque.js +36 -71
- package/dist/mjs/data-structures/queue/queue.d.ts +49 -48
- package/dist/mjs/data-structures/queue/queue.js +66 -79
- package/dist/mjs/data-structures/stack/stack.d.ts +43 -10
- package/dist/mjs/data-structures/stack/stack.js +50 -31
- package/dist/mjs/data-structures/trie/trie.d.ts +41 -6
- package/dist/mjs/data-structures/trie/trie.js +53 -32
- package/dist/mjs/interfaces/binary-tree.d.ts +6 -6
- package/dist/mjs/types/common.d.ts +11 -8
- package/dist/mjs/types/common.js +5 -0
- package/dist/mjs/types/data-structures/base/base.d.ts +5 -0
- package/dist/mjs/types/data-structures/base/base.js +1 -0
- package/dist/mjs/types/data-structures/base/index.d.ts +1 -0
- package/dist/mjs/types/data-structures/base/index.js +1 -0
- package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
- package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +6 -6
- package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
- package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
- package/dist/mjs/types/data-structures/index.d.ts +1 -0
- package/dist/mjs/types/data-structures/index.js +1 -0
- package/dist/umd/data-structure-typed.js +991 -848
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-base.ts +329 -0
- package/src/data-structures/binary-tree/avl-tree.ts +20 -21
- package/src/data-structures/binary-tree/binary-tree.ts +222 -267
- package/src/data-structures/binary-tree/bst.ts +86 -82
- package/src/data-structures/binary-tree/rb-tree.ts +25 -26
- package/src/data-structures/binary-tree/tree-multimap.ts +30 -35
- package/src/data-structures/graph/abstract-graph.ts +55 -28
- package/src/data-structures/hash/hash-map.ts +76 -185
- package/src/data-structures/heap/heap.ts +63 -36
- package/src/data-structures/index.ts +1 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +50 -79
- package/src/data-structures/linked-list/singly-linked-list.ts +45 -80
- package/src/data-structures/queue/deque.ts +40 -82
- package/src/data-structures/queue/queue.ts +72 -87
- package/src/data-structures/stack/stack.ts +53 -34
- package/src/data-structures/trie/trie.ts +58 -35
- package/src/interfaces/binary-tree.ts +5 -6
- package/src/types/common.ts +11 -8
- package/src/types/data-structures/base/base.ts +6 -0
- package/src/types/data-structures/base/index.ts +1 -0
- package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
- package/src/types/data-structures/binary-tree/bst.ts +6 -6
- package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
- package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
- package/src/types/data-structures/index.ts +1 -0
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +13 -13
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +16 -16
- package/test/unit/data-structures/binary-tree/bst.test.ts +20 -19
- package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +9 -9
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +15 -15
- package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
- package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +28 -0
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +25 -0
- package/test/unit/data-structures/queue/deque.test.ts +25 -0
- package/test/unit/unrestricted-interconversion.test.ts +1 -1
|
@@ -252,7 +252,7 @@ describe('TreeMultimap operations test1', () => {
|
|
|
252
252
|
});
|
|
253
253
|
|
|
254
254
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
255
|
-
const objTreeMultimap = new TreeMultimap<{ key: number; keyA: number }>();
|
|
255
|
+
const objTreeMultimap = new TreeMultimap<number, { key: number; keyA: number }>();
|
|
256
256
|
expect(objTreeMultimap).toBeInstanceOf(TreeMultimap);
|
|
257
257
|
objTreeMultimap.add([11, { key: 11, keyA: 11 }]);
|
|
258
258
|
objTreeMultimap.add([3, { key: 3, keyA: 3 }]);
|
|
@@ -508,7 +508,7 @@ describe('TreeMultimap operations test recursively1', () => {
|
|
|
508
508
|
});
|
|
509
509
|
|
|
510
510
|
it('should perform various operations on a Binary Search Tree with object values', () => {
|
|
511
|
-
const objTreeMultimap = new TreeMultimap<{ key: number; keyA: number }>();
|
|
511
|
+
const objTreeMultimap = new TreeMultimap<number, { key: number; keyA: number }>();
|
|
512
512
|
expect(objTreeMultimap).toBeInstanceOf(TreeMultimap);
|
|
513
513
|
objTreeMultimap.add([11, { key: 11, keyA: 11 }]);
|
|
514
514
|
objTreeMultimap.add([3, { key: 3, keyA: 3 }]);
|
|
@@ -544,7 +544,7 @@ describe('TreeMultimap operations test recursively1', () => {
|
|
|
544
544
|
});
|
|
545
545
|
|
|
546
546
|
describe('TreeMultimap Performance test', function () {
|
|
547
|
-
const treeMS = new TreeMultimap<
|
|
547
|
+
const treeMS = new TreeMultimap<number, number>();
|
|
548
548
|
const inputSize = 100000; // Adjust input sizes as needed
|
|
549
549
|
|
|
550
550
|
beforeEach(() => {
|
|
@@ -602,9 +602,9 @@ describe('TreeMultimap Performance test', function () {
|
|
|
602
602
|
});
|
|
603
603
|
|
|
604
604
|
describe('TreeMultimap iterative methods test', () => {
|
|
605
|
-
let treeMM: TreeMultimap<string>;
|
|
605
|
+
let treeMM: TreeMultimap<number, string>;
|
|
606
606
|
beforeEach(() => {
|
|
607
|
-
treeMM = new TreeMultimap<string>();
|
|
607
|
+
treeMM = new TreeMultimap<number, string>();
|
|
608
608
|
treeMM.add([1, 'a'], 10);
|
|
609
609
|
treeMM.add([2, 'b'], 10);
|
|
610
610
|
treeMM.add([3, 'c'], 1);
|
|
@@ -619,30 +619,30 @@ describe('TreeMultimap iterative methods test', () => {
|
|
|
619
619
|
|
|
620
620
|
test('forEach should iterate over all elements', () => {
|
|
621
621
|
const mockCallback = jest.fn();
|
|
622
|
-
treeMM.forEach((
|
|
623
|
-
mockCallback(
|
|
622
|
+
treeMM.forEach((value, key) => {
|
|
623
|
+
mockCallback(value, key);
|
|
624
624
|
});
|
|
625
625
|
|
|
626
626
|
expect(mockCallback.mock.calls.length).toBe(3);
|
|
627
|
-
expect(mockCallback.mock.calls[0]
|
|
628
|
-
expect(mockCallback.mock.calls[1]
|
|
629
|
-
expect(mockCallback.mock.calls[2]
|
|
627
|
+
expect(mockCallback.mock.calls[0]).toEqual(['a', 1]);
|
|
628
|
+
expect(mockCallback.mock.calls[1]).toEqual(['b', 2]);
|
|
629
|
+
expect(mockCallback.mock.calls[2]).toEqual(['c', 3]);
|
|
630
630
|
});
|
|
631
631
|
|
|
632
632
|
test('filter should return a new tree with filtered elements', () => {
|
|
633
|
-
const filteredTree = treeMM.filter((
|
|
633
|
+
const filteredTree = treeMM.filter((value, key) => key > 1);
|
|
634
634
|
expect(filteredTree.size).toBe(2);
|
|
635
635
|
expect([...filteredTree]).toEqual([[2, 'b'], [3, 'c']]);
|
|
636
636
|
});
|
|
637
637
|
|
|
638
638
|
test('map should return a new tree with modified elements', () => {
|
|
639
|
-
const mappedTree = treeMM.map((
|
|
639
|
+
const mappedTree = treeMM.map((value, key) => (key * 2).toString());
|
|
640
640
|
expect(mappedTree.size).toBe(3);
|
|
641
641
|
expect([...mappedTree]).toEqual([[1, '2'], [2, '4'], [3, '6']]);
|
|
642
642
|
});
|
|
643
643
|
|
|
644
644
|
test('reduce should accumulate values', () => {
|
|
645
|
-
const sum = treeMM.reduce((acc,
|
|
645
|
+
const sum = treeMM.reduce((acc, value, key) => acc + key, 0);
|
|
646
646
|
expect(sum).toBe(6);
|
|
647
647
|
});
|
|
648
648
|
|
|
@@ -665,11 +665,11 @@ describe('TreeMultimap iterative methods test', () => {
|
|
|
665
665
|
|
|
666
666
|
test('should keys', () => {
|
|
667
667
|
const keys = treeMM.keys();
|
|
668
|
-
expect(keys).toEqual([1, 2, 3]);
|
|
668
|
+
expect([...keys]).toEqual([1, 2, 3]);
|
|
669
669
|
});
|
|
670
670
|
|
|
671
671
|
test('should values', () => {
|
|
672
672
|
const values = treeMM.values();
|
|
673
|
-
expect(values).toEqual(['a', 'b', 'c']);
|
|
673
|
+
expect([...values]).toEqual(['a', 'b', 'c']);
|
|
674
674
|
});
|
|
675
675
|
});
|
|
@@ -616,22 +616,22 @@ describe('DirectedGraph iterative Methods', () => {
|
|
|
616
616
|
|
|
617
617
|
test('forEach should apply a function to each vertex', () => {
|
|
618
618
|
const result: VertexKey[] = [];
|
|
619
|
-
graph.forEach(
|
|
619
|
+
graph.forEach((value, key) => key && result.push(key));
|
|
620
620
|
expect(result).toEqual(vertices);
|
|
621
621
|
});
|
|
622
622
|
|
|
623
623
|
test('filter should return vertices that satisfy the condition', () => {
|
|
624
|
-
const filtered = graph.filter(vertex => vertex
|
|
624
|
+
const filtered = graph.filter((value, vertex) => vertex === 'A' || vertex === 'B');
|
|
625
625
|
expect(filtered).toEqual([["A", undefined], ["B", undefined]]);
|
|
626
626
|
});
|
|
627
627
|
|
|
628
628
|
test('map should apply a function to each vertex and return a new array', () => {
|
|
629
|
-
const mapped = graph.map(vertex => vertex
|
|
629
|
+
const mapped = graph.map((value, vertex) => vertex + '_mapped');
|
|
630
630
|
expect(mapped).toEqual(vertices.map(v => v + '_mapped'));
|
|
631
631
|
});
|
|
632
632
|
|
|
633
633
|
test('reduce should accumulate a value based on each vertex', () => {
|
|
634
|
-
const concatenated = graph.reduce((acc,
|
|
634
|
+
const concatenated = graph.reduce((acc, value, key) => acc + key, '');
|
|
635
635
|
expect(concatenated).toBe(vertices.join(''));
|
|
636
636
|
});
|
|
637
637
|
});
|
|
@@ -548,10 +548,10 @@ describe('LinkedHashMap setMany, keys, values', () => {
|
|
|
548
548
|
})
|
|
549
549
|
|
|
550
550
|
test('keys', () => {
|
|
551
|
-
expect(hm.keys()).toEqual([2, 3, 4, 5, 6])
|
|
551
|
+
expect([...hm.keys()]).toEqual([2, 3, 4, 5, 6])
|
|
552
552
|
});
|
|
553
553
|
|
|
554
554
|
test('values', () => {
|
|
555
|
-
expect(hm.values()).toEqual([2, 3, 4, 5, 6])
|
|
555
|
+
expect([...hm.values()]).toEqual([2, 3, 4, 5, 6])
|
|
556
556
|
});
|
|
557
557
|
});
|
|
@@ -397,3 +397,31 @@ describe('DoublyLinkedList Operation Test', () => {
|
|
|
397
397
|
expect(shiftedObj).toBe(obj1);
|
|
398
398
|
});
|
|
399
399
|
});
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
describe('iterable methods', () => {
|
|
403
|
+
it('should forEach, some, every, filter, map, reduce of the deque', () => {
|
|
404
|
+
const dl = new DoublyLinkedList<number>()
|
|
405
|
+
dl.push(1);
|
|
406
|
+
dl.push(2);
|
|
407
|
+
dl.push(3);
|
|
408
|
+
|
|
409
|
+
const mockCallback = jest.fn();
|
|
410
|
+
dl.forEach((element) => {
|
|
411
|
+
mockCallback(element);
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
expect(mockCallback.mock.calls.length).toBe(3);
|
|
415
|
+
expect(mockCallback.mock.calls[0]).toEqual([1]);
|
|
416
|
+
expect(mockCallback.mock.calls[1]).toEqual([2]);
|
|
417
|
+
expect(mockCallback.mock.calls[2]).toEqual([3]);
|
|
418
|
+
|
|
419
|
+
expect(dl.every(element => element > 0)).toBe(true);
|
|
420
|
+
expect(dl.every(element => element > 1)).toBe(false);
|
|
421
|
+
expect(dl.some(element => element > 2)).toBe(true);
|
|
422
|
+
|
|
423
|
+
expect([...dl.filter(element => element > 2)]).toEqual([3]);
|
|
424
|
+
expect([...dl.map(element => element * 2)]).toEqual([2, 4, 6]);
|
|
425
|
+
expect(dl.reduce((accumulator, element) => accumulator + element, 0)).toEqual(6);
|
|
426
|
+
});
|
|
427
|
+
});
|
|
@@ -471,3 +471,28 @@ describe('SinglyLinkedList', () => {
|
|
|
471
471
|
expect(list1.reduce((acc, value) => acc + value, 0)).toEqual(6);
|
|
472
472
|
});
|
|
473
473
|
});
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
describe('iterable methods', () => {
|
|
477
|
+
it('should forEach, some, every, filter, map, reduce of the deque', () => {
|
|
478
|
+
const sl = new SinglyLinkedList<number>([1, 2, 3])
|
|
479
|
+
|
|
480
|
+
const mockCallback = jest.fn();
|
|
481
|
+
sl.forEach((element) => {
|
|
482
|
+
mockCallback(element);
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
expect(mockCallback.mock.calls.length).toBe(3);
|
|
486
|
+
expect(mockCallback.mock.calls[0]).toEqual([1]);
|
|
487
|
+
expect(mockCallback.mock.calls[1]).toEqual([2]);
|
|
488
|
+
expect(mockCallback.mock.calls[2]).toEqual([3]);
|
|
489
|
+
|
|
490
|
+
expect(sl.every(element => element > 0)).toBe(true);
|
|
491
|
+
expect(sl.every(element => element > 1)).toBe(false);
|
|
492
|
+
expect(sl.some(element => element > 2)).toBe(true);
|
|
493
|
+
|
|
494
|
+
expect([...sl.filter(element => element > 2)]).toEqual([3]);
|
|
495
|
+
expect([...sl.map(element => element * 2)]).toEqual([2, 4, 6]);
|
|
496
|
+
expect(sl.reduce((accumulator, element) => accumulator + element, 0)).toEqual(6);
|
|
497
|
+
});
|
|
498
|
+
});
|
|
@@ -447,4 +447,29 @@ describe('Deque', () => {
|
|
|
447
447
|
});
|
|
448
448
|
});
|
|
449
449
|
|
|
450
|
+
describe('iterable methods', () => {
|
|
451
|
+
it('should forEach, some, every, filter, map, reduce of the deque', () => {
|
|
452
|
+
deque.push(1);
|
|
453
|
+
deque.push(2);
|
|
454
|
+
deque.push(3);
|
|
455
|
+
|
|
456
|
+
const mockCallback = jest.fn();
|
|
457
|
+
deque.forEach((element) => {
|
|
458
|
+
mockCallback(element);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
expect(mockCallback.mock.calls.length).toBe(3);
|
|
462
|
+
expect(mockCallback.mock.calls[0]).toEqual([1]);
|
|
463
|
+
expect(mockCallback.mock.calls[1]).toEqual([2]);
|
|
464
|
+
expect(mockCallback.mock.calls[2]).toEqual([3]);
|
|
465
|
+
|
|
466
|
+
expect(deque.every(element => element > 0)).toBe(true);
|
|
467
|
+
expect(deque.every(element => element > 1)).toBe(false);
|
|
468
|
+
expect(deque.some(element => element > 2)).toBe(true);
|
|
469
|
+
|
|
470
|
+
expect([...deque.filter(element => element > 2)]).toEqual([3]);
|
|
471
|
+
expect([...deque.map(element => element * 2)]).toEqual([2, 4, 6]);
|
|
472
|
+
expect(deque.reduce((accumulator, element) => accumulator + element, 0)).toEqual(6);
|
|
473
|
+
});
|
|
474
|
+
});
|
|
450
475
|
});
|
|
@@ -145,7 +145,7 @@ describe('conversions', () => {
|
|
|
145
145
|
expect(dq.size).toBe(10);
|
|
146
146
|
isDebug && dq.print();
|
|
147
147
|
const entries = dq.map((el, i) => <[number, string]>[i, el]);
|
|
148
|
-
const avl = new AVLTree<string>(entries);
|
|
148
|
+
const avl = new AVLTree<number, string>(entries);
|
|
149
149
|
expect(avl.size).toBe(10)
|
|
150
150
|
isDebug && avl.print();
|
|
151
151
|
})
|