From 8f1f6d6f52d477e60708b7bae03afb7330454efa Mon Sep 17 00:00:00 2001 From: Revone Date: Mon, 13 Nov 2023 22:27:29 +0800 Subject: [PATCH] style: Try to synchronize Prettier with the coding style of the IDE. --- .eslintrc.js | 4 +- .prettierrc.js | 4 +- src/data-structures/binary-tree/avl-tree.ts | 2 +- .../binary-tree/binary-indexed-tree.ts | 2 +- .../binary-tree/binary-tree.ts | 40 +++-- src/data-structures/binary-tree/bst.ts | 16 +- src/data-structures/binary-tree/rb-tree.ts | 17 +-- .../binary-tree/tree-multimap.ts | 10 +- src/data-structures/graph/abstract-graph.ts | 41 ++--- src/data-structures/graph/directed-graph.ts | 9 +- src/data-structures/graph/map-graph.ts | 12 +- src/data-structures/graph/undirected-graph.ts | 10 +- src/data-structures/hash/hash-map.ts | 2 +- src/data-structures/hash/tree-map.ts | 3 +- src/data-structures/hash/tree-set.ts | 3 +- src/data-structures/heap/heap.ts | 11 +- src/data-structures/heap/max-heap.ts | 2 +- src/data-structures/heap/min-heap.ts | 2 +- .../linked-list/doubly-linked-list.ts | 2 +- .../linked-list/singly-linked-list.ts | 2 +- src/data-structures/matrix/matrix.ts | 2 +- src/data-structures/matrix/vector2d.ts | 3 +- .../priority-queue/max-priority-queue.ts | 2 +- .../priority-queue/min-priority-queue.ts | 2 +- .../priority-queue/priority-queue.ts | 2 +- src/data-structures/queue/deque.ts | 7 +- src/data-structures/queue/queue.ts | 2 +- src/data-structures/trie/trie.ts | 2 +- src/types/data-structures/matrix/navigator.ts | 2 +- src/types/utils/utils.ts | 2 +- src/types/utils/validate-type.ts | 22 +-- test/integration/bst.test.ts | 2 +- .../binary-tree/rb-tree.test.ts | 37 +++-- .../data-structures/hash/hash-map.test.ts | 23 ++- .../linked-list/doubly-linked-list.test.ts | 36 ++--- .../priority-queue/max-priority-queue.test.ts | 4 +- .../priority-queue/priority-queue.test.ts | 22 ++- .../data-structures/queue/deque.test.ts | 17 +-- .../data-structures/queue/queue.test.ts | 17 +-- .../data-structures/stack/stack.test.ts | 21 ++- test/performance/reportor.ts | 6 +- test/performance/types/reportor.ts | 2 +- test/types/utils/json2html.ts | 2 +- .../binary-tree/avl-tree.test.ts | 5 +- .../binary-tree/binary-tree.test.ts | 140 ++++++++++-------- .../data-structures/binary-tree/bst.test.ts | 20 +-- .../binary-tree/overall.test.ts | 2 +- .../binary-tree/rb-tree.test.ts | 40 ++--- .../binary-tree/tree-multimap.test.ts | 4 +- .../graph/abstract-graph.test.ts | 15 +- .../graph/directed-graph.test.ts | 36 +---- .../graph/undirected-graph.test.ts | 2 +- test/unit/data-structures/heap/heap.test.ts | 13 +- .../linked-list/doubly-linked-list.test.ts | 2 +- .../linked-list/singly-linked-list.test.ts | 4 +- .../priority-queue/max-priority-queue.test.ts | 4 +- .../priority-queue/priority-queue.test.ts | 14 +- test/utils/big-o.ts | 2 +- test/utils/json2html.ts | 8 +- 59 files changed, 317 insertions(+), 425 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 701ce2c..b458a35 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -43,8 +43,8 @@ module.exports = { } } ], - "brace-style": ["error", "1tbs", { "allowSingleLine": true }], - "object-curly-spacing": ["error", "always"] + "brace-style": ["error", "1tbs", {"allowSingleLine": true}], + "object-curly-spacing": ["error", "never"] }, "settings": { "import/parsers": { diff --git a/.prettierrc.js b/.prettierrc.js index 8f951b7..2458204 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,9 +1,9 @@ module.exports = { "arrowParens": "avoid", - "bracketSpacing": true, + "bracketSpacing": false, "htmlWhitespaceSensitivity": "css", "insertPragma": false, - "bracketSameLine": true, + "bracketSameLine": false, "jsxSingleQuote": true, "printWidth": 120, "proseWrap": "preserve", diff --git a/src/data-structures/binary-tree/avl-tree.ts b/src/data-structures/binary-tree/avl-tree.ts index d218229..c21eafa 100644 --- a/src/data-structures/binary-tree/avl-tree.ts +++ b/src/data-structures/binary-tree/avl-tree.ts @@ -209,7 +209,7 @@ export class AVLTree = AVLTreeNode = BinaryTree * Represents a binary tree data structure. * @template N - The type of the binary tree's nodes. */ -export class BinaryTree = BinaryTreeNode>> - implements IBinaryTree { +export class BinaryTree = BinaryTreeNode>> implements IBinaryTree { iterationType: IterationType = IterationType.ITERATIVE; /** @@ -301,7 +300,8 @@ export class BinaryTree = BinaryTreeNode ): BiTreeDeleteResult[] { const deletedResult: BiTreeDeleteResult[] = []; if (!this.root) return deletedResult; - if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode) callback = (node => node) as C; + if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode) + callback = (node => node) as C; const curr = this.getNode(identifier, callback); if (!curr) return deletedResult; @@ -330,14 +330,12 @@ export class BinaryTree = BinaryTreeNode const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent; orgCurrent = this._swap(curr, leftSubTreeRightMost); if (parentOfLeftSubTreeMax) { - if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) - parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left; + if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost) parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left; else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left; needBalanced = parentOfLeftSubTreeMax; } } } - } this._size = this.size - 1; @@ -383,7 +381,6 @@ export class BinaryTree = BinaryTreeNode * Best Case - O(log n) (when using recursive iterationType), Worst Case - O(n) (when using iterative iterationType) */ - /** * Time Complexity: O(n) * Space Complexity: O(log n) @@ -412,7 +409,7 @@ export class BinaryTree = BinaryTreeNode return _getMaxHeight(beginRoot); } else { - const stack: { node: N; depth: number }[] = [{node: beginRoot, depth: 0}]; + const stack: {node: N; depth: number}[] = [{node: beginRoot, depth: 0}]; let maxHeight = 0; while (stack.length > 0) { @@ -539,7 +536,6 @@ export class BinaryTree = BinaryTreeNode * Space Complexity: O(log n). */ - /** * Time Complexity: O(n) * Space Complexity: O(log n). @@ -572,7 +568,8 @@ export class BinaryTree = BinaryTreeNode beginRoot: BTNKey | N | null | undefined = this.root, iterationType = this.iterationType ): N[] { - if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode) callback = (node => node) as C; + if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode) + callback = (node => node) as C; beginRoot = this.ensureNotKey(beginRoot); if (!beginRoot) return []; @@ -660,7 +657,8 @@ export class BinaryTree = BinaryTreeNode beginRoot: BTNKey | N | null | undefined = this.root, iterationType = this.iterationType ): boolean { - if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode) callback = (node => node) as C; + if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode) + callback = (node => node) as C; return this.getNodes(identifier, callback, true, beginRoot, iterationType).length > 0; } @@ -718,7 +716,8 @@ export class BinaryTree = BinaryTreeNode beginRoot: BTNKey | N | null | undefined = this.root, iterationType = this.iterationType ): N | null | undefined { - if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode) callback = (node => node) as C; + if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode) + callback = (node => node) as C; return this.getNodes(identifier, callback, true, beginRoot, iterationType)[0] ?? null; } @@ -836,7 +835,8 @@ export class BinaryTree = BinaryTreeNode beginRoot: BTNKey | N | null | undefined = this.root, iterationType = this.iterationType ): V | undefined { - if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode) callback = (node => node) as C; + if ((!callback || callback === this._defaultOneParamCallback) && (identifier as any) instanceof BinaryTreeNode) + callback = (node => node) as C; return this.getNode(identifier, callback, beginRoot, iterationType)?.value ?? undefined; } @@ -1165,7 +1165,7 @@ export class BinaryTree = BinaryTreeNode * @param {any} node - The parameter `node` is of type `any`, which means it can be any data type. * @returns a boolean value. */ - isNodeOrNull(node: any): node is (N | null) { + isNodeOrNull(node: any): node is N | null { return this.isRealNode(node) || node === null; } @@ -1238,7 +1238,6 @@ export class BinaryTree = BinaryTreeNode iterationType: IterationType = IterationType.ITERATIVE, includeNull = false ): ReturnType[] { - beginRoot = this.ensureNotKey(beginRoot); if (!beginRoot) return []; const ans: ReturnType[] = []; @@ -1285,7 +1284,7 @@ export class BinaryTree = BinaryTreeNode _traverse(beginRoot); } else { // 0: visit, 1: print - const stack: { opt: 0 | 1; node: N | null | undefined }[] = [{opt: 0, node: beginRoot}]; + const stack: {opt: 0 | 1; node: N | null | undefined}[] = [{opt: 0, node: beginRoot}]; while (stack.length > 0) { const cur = stack.pop(); @@ -1454,7 +1453,6 @@ export class BinaryTree = BinaryTreeNode * Space complexity: O(n) */ - /** * Time complexity: O(n) * Space complexity: O(n) @@ -1523,8 +1521,7 @@ export class BinaryTree = BinaryTreeNode return levelsNodes; } - getPredecessor(node: N): N - + getPredecessor(node: N): N; /** * The function `getPredecessor` returns the predecessor node of a given node in a binary tree. @@ -1549,7 +1546,6 @@ export class BinaryTree = BinaryTreeNode } } - /** * The function `getSuccessor` returns the next node in a binary tree given a current node. * @param {BTNKey | N | null} [x] - The parameter `x` can be of type `BTNKey`, `N`, or `null`. @@ -1681,7 +1677,6 @@ export class BinaryTree = BinaryTreeNode return ans; } - /** * The above function is an iterator for a binary tree that can be used to traverse the tree in * either an iterative or recursive manner. @@ -1691,7 +1686,7 @@ export class BinaryTree = BinaryTreeNode * @returns The `*[Symbol.iterator]` method returns a generator object that yields the keys of the * binary tree nodes in a specific order. */ - * [Symbol.iterator](node = this.root): Generator { + *[Symbol.iterator](node = this.root): Generator { if (!node) { return; } @@ -1817,7 +1812,6 @@ export class BinaryTree = BinaryTreeNode return destNode; } return undefined; - } /** diff --git a/src/data-structures/binary-tree/bst.ts b/src/data-structures/binary-tree/bst.ts index a2e9b48..67ca09a 100644 --- a/src/data-structures/binary-tree/bst.ts +++ b/src/data-structures/binary-tree/bst.ts @@ -41,7 +41,6 @@ export class BSTNode = BSTNodeNested> extend this._left = v; } - protected override _right?: N; /** @@ -63,10 +62,7 @@ export class BSTNode = BSTNodeNested> extend } } -export class BST = BSTNode>> - extends BinaryTree - implements IBinaryTree { - +export class BST = BSTNode>> extends BinaryTree implements IBinaryTree { /** * The constructor function initializes a binary search tree with an optional comparator function. * @param {BSTOptions} [options] - An optional object that contains additional configuration options @@ -109,7 +105,6 @@ export class BST = BSTNode> * Space Complexity: O(1) - Constant space is used. */ - /** * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n). * Space Complexity: O(1) - Constant space is used. @@ -230,9 +225,7 @@ export class BST = BSTNode> } const inserted: (N | undefined)[] = []; - const combinedArr: [BTNKey | N, V][] = keysOrNodes.map( - (value: BTNKey | N, index) => [value, data?.[index]] as [BTNKey | N, V] - ); + const combinedArr: [BTNKey | N, V][] = keysOrNodes.map((value: BTNKey | N, index) => [value, data?.[index]] as [BTNKey | N, V]); let sorted = []; @@ -244,7 +237,7 @@ export class BST = BSTNode> const _isBinaryTreeKeyOrNullTuple = (arr: [BTNKey | N, V][]): arr is [BTNKey, V][] => { for (const [keyOrNode] of arr) if (this.isNodeKey(keyOrNode)) return true; return false; - } + }; let sortedKeysOrNodes: (number | N | undefined)[] = [], sortedData: (V | undefined)[] | undefined = []; @@ -580,7 +573,7 @@ export class BST = BSTNode> if (l <= r) { const m = l + Math.floor((r - l) / 2); const midNode = sorted[m]; - debugger + debugger; this.add(midNode.key, midNode.value); stack.push([m + 1, r]); stack.push([l, m - 1]); @@ -672,5 +665,4 @@ export class BST = BSTNode> else if (compared < 0) return CP.lt; else return CP.eq; } - } diff --git a/src/data-structures/binary-tree/rb-tree.ts b/src/data-structures/binary-tree/rb-tree.ts index 1658c8c..9c95297 100644 --- a/src/data-structures/binary-tree/rb-tree.ts +++ b/src/data-structures/binary-tree/rb-tree.ts @@ -6,18 +6,10 @@ * @license MIT License */ -import { - BiTreeDeleteResult, - BTNCallback, - BTNKey, - IterationType, - RBTNColor, - RBTreeOptions, - RedBlackTreeNodeNested -} from '../../types'; -import {BST, BSTNode} from "./bst"; -import {IBinaryTree} from "../../interfaces"; -import {BinaryTreeNode} from "./binary-tree"; +import {BiTreeDeleteResult, BTNCallback, BTNKey, IterationType, RBTNColor, RBTreeOptions, RedBlackTreeNodeNested} from '../../types'; +import {BST, BSTNode} from './bst'; +import {IBinaryTree} from '../../interfaces'; +import {BinaryTreeNode} from './binary-tree'; export class RedBlackTreeNode = RedBlackTreeNodeNested> extends BSTNode { color: RBTNColor; @@ -38,7 +30,6 @@ export class RedBlackTreeNode = RedBla export class RedBlackTree = RedBlackTreeNode>> extends BST implements IBinaryTree { - NIL: N = new RedBlackTreeNode(NaN) as unknown as N; /** diff --git a/src/data-structures/binary-tree/tree-multimap.ts b/src/data-structures/binary-tree/tree-multimap.ts index f086a93..06faaf4 100644 --- a/src/data-structures/binary-tree/tree-multimap.ts +++ b/src/data-structures/binary-tree/tree-multimap.ts @@ -10,10 +10,7 @@ import {BiTreeDeleteResult, BTNCallback, CP, FamilyPosition, IterationType} from import {IBinaryTree} from '../../interfaces'; import {AVLTree, AVLTreeNode} from './avl-tree'; -export class TreeMultimapNode< - V = any, - N extends TreeMultimapNode = TreeMultimapNodeNested -> extends AVLTreeNode { +export class TreeMultimapNode = TreeMultimapNodeNested> extends AVLTreeNode { count: number; /** @@ -284,7 +281,8 @@ export class TreeMultimap = TreeMultim if (!curr) return deletedResult; const parent: N | undefined = curr?.parent ? curr.parent : undefined; - let needBalanced: N | undefined = undefined, orgCurrent: N | undefined = curr; + let needBalanced: N | undefined = undefined, + orgCurrent: N | undefined = curr; if (curr.count > 1 && !ignoreCount) { curr.count--; @@ -418,4 +416,4 @@ export class TreeMultimap = TreeMultim } return undefined; } -} \ No newline at end of file +} diff --git a/src/data-structures/graph/abstract-graph.ts b/src/data-structures/graph/abstract-graph.ts index dbcafbd..1bd23c4 100644 --- a/src/data-structures/graph/abstract-graph.ts +++ b/src/data-structures/graph/abstract-graph.ts @@ -300,7 +300,7 @@ export abstract class AbstractGraph< return []; } - const stack: { vertex: VO; path: VO[] }[] = []; + const stack: {vertex: VO; path: VO[]}[] = []; stack.push({vertex: vertex1, path: [vertex1]}); while (stack.length > 0) { @@ -514,12 +514,7 @@ export abstract class AbstractGraph< * shortest paths from the source vertex to all other vertices in the graph. If `genPaths * @returns The function `dijkstraWithoutHeap` returns an object of type `DijkstraResult`. */ - dijkstraWithoutHeap( - src: VO | VertexKey, - dest?: VO | VertexKey | null, - getMinDist?: boolean, - genPaths?: boolean - ): DijkstraResult { + dijkstraWithoutHeap(src: VO | VertexKey, dest?: VO | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult { if (getMinDist === undefined) getMinDist = false; if (genPaths === undefined) genPaths = false; @@ -614,14 +609,14 @@ export abstract class AbstractGraph< } getMinDist && - distMap.forEach((d, v) => { - if (v !== srcVertex) { - if (d < minDist) { - minDist = d; - if (genPaths) minDest = v; + distMap.forEach((d, v) => { + if (v !== srcVertex) { + if (d < minDist) { + minDist = d; + if (genPaths) minDest = v; + } } - } - }); + }); genPaths && getPaths(minDest); @@ -662,12 +657,7 @@ export abstract class AbstractGraph< * shortest paths from the source vertex to all other vertices in the graph. If `genPaths * @returns The function `dijkstra` returns an object of type `DijkstraResult`. */ - dijkstra( - src: VO | VertexKey, - dest?: VO | VertexKey | null, - getMinDist?: boolean, - genPaths?: boolean - ): DijkstraResult { + dijkstra(src: VO | VertexKey, dest?: VO | VertexKey | null, getMinDist?: boolean, genPaths?: boolean): DijkstraResult { if (getMinDist === undefined) getMinDist = false; if (genPaths === undefined) genPaths = false; @@ -691,7 +681,7 @@ export abstract class AbstractGraph< if (vertexOrKey instanceof AbstractVertex) distMap.set(vertexOrKey, Infinity); } - const heap = new PriorityQueue<{ key: number; value: VO }>({comparator: (a, b) => a.key - b.key}); + const heap = new PriorityQueue<{key: number; value: VO}>({comparator: (a, b) => a.key - b.key}); heap.add({key: 0, value: srcVertex}); distMap.set(srcVertex, 0); @@ -923,7 +913,7 @@ export abstract class AbstractGraph< * `predecessor` property is a 2D array of vertices (or `null`) representing the predecessor vertices in the shortest * path between vertices in the */ - floydWarshall(): { costs: number[][]; predecessor: (VO | null)[][] } { + floydWarshall(): {costs: number[][]; predecessor: (VO | null)[][]} { const idAndVertices = [...this._vertices]; const n = idAndVertices.length; @@ -992,12 +982,7 @@ export abstract class AbstractGraph< * are arrays of vertices that form cycles within the SCCs. * @returns The function `tarjan` returns an object with the following properties: */ - tarjan( - needCutVertexes: boolean = false, - needBridges: boolean = false, - needSCCs: boolean = true, - needCycles: boolean = false - ) { + tarjan(needCutVertexes: boolean = false, needBridges: boolean = false, needSCCs: boolean = true, needCycles: boolean = false) { // !! in undirected graph we will not let child visit parent when dfs // !! articulation point(in dfs search tree not in graph): (cur !== root && cur.has(child)) && (low(child) >= dfn(cur)) || (cur === root && cur.children() >= 2) // !! bridge: low(child) > dfn(cur) diff --git a/src/data-structures/graph/directed-graph.ts b/src/data-structures/graph/directed-graph.ts index a06d066..f9c02fa 100644 --- a/src/data-structures/graph/directed-graph.ts +++ b/src/data-structures/graph/directed-graph.ts @@ -45,12 +45,7 @@ export class DirectedEdge extends AbstractEdge { } } -export class DirectedGraph< - V = any, - E = any, - VO extends DirectedVertex = DirectedVertex, - EO extends DirectedEdge = DirectedEdge -> +export class DirectedGraph = DirectedVertex, EO extends DirectedEdge = DirectedEdge> extends AbstractGraph implements IGraph { /** @@ -590,4 +585,4 @@ export class DirectedGraph< return false; } } -} \ No newline at end of file +} diff --git a/src/data-structures/graph/map-graph.ts b/src/data-structures/graph/map-graph.ts index 7edce9b..a2fc395 100644 --- a/src/data-structures/graph/map-graph.ts +++ b/src/data-structures/graph/map-graph.ts @@ -40,12 +40,12 @@ export class MapEdge extends DirectedEdge { } } -export class MapGraph< - V = any, - E = any, - VO extends MapVertex = MapVertex, - EO extends MapEdge = MapEdge -> extends DirectedGraph { +export class MapGraph = MapVertex, EO extends MapEdge = MapEdge> extends DirectedGraph< + V, + E, + VO, + EO +> { /** * The constructor function initializes the origin and bottomRight properties of a MapGraphCoordinate object. * @param {MapGraphCoordinate} origin - The `origin` parameter is a `MapGraphCoordinate` object that represents the diff --git a/src/data-structures/graph/undirected-graph.ts b/src/data-structures/graph/undirected-graph.ts index 548a8c8..0d7988b 100644 --- a/src/data-structures/graph/undirected-graph.ts +++ b/src/data-structures/graph/undirected-graph.ts @@ -43,11 +43,11 @@ export class UndirectedEdge extends AbstractEdge { } export class UndirectedGraph< - V = any, - E = any, - VO extends UndirectedVertex = UndirectedVertex, - EO extends UndirectedEdge = UndirectedEdge -> + V = any, + E = any, + VO extends UndirectedVertex = UndirectedVertex, + EO extends UndirectedEdge = UndirectedEdge + > extends AbstractGraph implements IGraph { /** diff --git a/src/data-structures/hash/hash-map.ts b/src/data-structures/hash/hash-map.ts index cb59fc3..9595be5 100644 --- a/src/data-structures/hash/hash-map.ts +++ b/src/data-structures/hash/hash-map.ts @@ -133,7 +133,7 @@ export class HashMap { } } - * entries(): IterableIterator<[K, V]> { + *entries(): IterableIterator<[K, V]> { for (const bucket of this.table) { if (bucket) { for (const [key, value] of bucket) { diff --git a/src/data-structures/hash/tree-map.ts b/src/data-structures/hash/tree-map.ts index a6d743d..fe86360 100644 --- a/src/data-structures/hash/tree-map.ts +++ b/src/data-structures/hash/tree-map.ts @@ -1,2 +1 @@ -export class TreeMap { -} +export class TreeMap {} diff --git a/src/data-structures/hash/tree-set.ts b/src/data-structures/hash/tree-set.ts index 65f14db..591aeda 100644 --- a/src/data-structures/hash/tree-set.ts +++ b/src/data-structures/hash/tree-set.ts @@ -1,2 +1 @@ -export class TreeSet { -} +export class TreeSet {} diff --git a/src/data-structures/heap/heap.ts b/src/data-structures/heap/heap.ts index b4523c1..8544beb 100644 --- a/src/data-structures/heap/heap.ts +++ b/src/data-structures/heap/heap.ts @@ -8,7 +8,7 @@ import type {Comparator, DFSOrderPattern} from '../../types'; export class Heap { - constructor(options: { comparator: Comparator; nodes?: E[] }) { + constructor(options: {comparator: Comparator; nodes?: E[]}) { this._comparator = options.comparator; if (options.nodes && options.nodes.length > 0) { this._nodes = options.nodes; @@ -48,7 +48,7 @@ export class Heap { * @returns A new Heap instance. * @param options */ - static heapify(options: { nodes: E[]; comparator: Comparator }): Heap { + static heapify(options: {nodes: E[]; comparator: Comparator}): Heap { return new Heap(options); } @@ -445,7 +445,6 @@ export class FibonacciHeap { return this.push(element); } - /** * Time Complexity: O(1) * Space Complexity: O(1) @@ -473,7 +472,6 @@ export class FibonacciHeap { return this; } - /** * Time Complexity: O(1) * Space Complexity: O(1) @@ -743,10 +741,7 @@ export class FibonacciHeap { protected consolidate(): void { const A: (FibonacciHeapNode | undefined)[] = new Array(this.size); const nodes = this.consumeLinkedList(this.root); - let x: FibonacciHeapNode | undefined, - y: FibonacciHeapNode | undefined, - d: number, - t: FibonacciHeapNode | undefined; + let x: FibonacciHeapNode | undefined, y: FibonacciHeapNode | undefined, d: number, t: FibonacciHeapNode | undefined; for (const node of nodes) { x = node; diff --git a/src/data-structures/heap/max-heap.ts b/src/data-structures/heap/max-heap.ts index 139ef64..be2c9b1 100644 --- a/src/data-structures/heap/max-heap.ts +++ b/src/data-structures/heap/max-heap.ts @@ -11,7 +11,7 @@ import type {Comparator} from '../../types'; export class MaxHeap extends Heap { constructor( - options: { comparator: Comparator; nodes?: E[] } = { + options: {comparator: Comparator; nodes?: E[]} = { comparator: (a: E, b: E) => { if (!(typeof a === 'number' && typeof b === 'number')) { throw new Error('The a, b params of compare function must be number'); diff --git a/src/data-structures/heap/min-heap.ts b/src/data-structures/heap/min-heap.ts index 5057017..dc86f87 100644 --- a/src/data-structures/heap/min-heap.ts +++ b/src/data-structures/heap/min-heap.ts @@ -11,7 +11,7 @@ import type {Comparator} from '../../types'; export class MinHeap extends Heap { constructor( - options: { comparator: Comparator; nodes?: E[] } = { + options: {comparator: Comparator; nodes?: E[]} = { comparator: (a: E, b: E) => { if (!(typeof a === 'number' && typeof b === 'number')) { throw new Error('The a, b params of compare function must be number'); diff --git a/src/data-structures/linked-list/doubly-linked-list.ts b/src/data-structures/linked-list/doubly-linked-list.ts index 2499e87..d877137 100644 --- a/src/data-structures/linked-list/doubly-linked-list.ts +++ b/src/data-structures/linked-list/doubly-linked-list.ts @@ -826,7 +826,7 @@ export class DoublyLinkedList { /** * The function returns an iterator that iterates over the values of a linked list. */ - * [Symbol.iterator]() { + *[Symbol.iterator]() { let current = this.head; while (current) { diff --git a/src/data-structures/linked-list/singly-linked-list.ts b/src/data-structures/linked-list/singly-linked-list.ts index c1a26f0..58323ab 100644 --- a/src/data-structures/linked-list/singly-linked-list.ts +++ b/src/data-structures/linked-list/singly-linked-list.ts @@ -773,7 +773,7 @@ export class SinglyLinkedList { /** * The function returns an iterator that iterates over the values of a linked list. */ - * [Symbol.iterator]() { + *[Symbol.iterator]() { let current = this.head; while (current) { diff --git a/src/data-structures/matrix/matrix.ts b/src/data-structures/matrix/matrix.ts index 4f1b8b8..3559d58 100644 --- a/src/data-structures/matrix/matrix.ts +++ b/src/data-structures/matrix/matrix.ts @@ -14,7 +14,7 @@ export class MatrixNTI2D { * given initial value or 0 if not provided. * @param options - An object containing the following properties: */ - constructor(options: { row: number; col: number; initialVal?: V }) { + constructor(options: {row: number; col: number; initialVal?: V}) { const {row, col, initialVal} = options; this._matrix = new Array(row).fill(undefined).map(() => new Array(col).fill(initialVal || 0)); } diff --git a/src/data-structures/matrix/vector2d.ts b/src/data-structures/matrix/vector2d.ts index 2f62f4e..1b2ff44 100644 --- a/src/data-structures/matrix/vector2d.ts +++ b/src/data-structures/matrix/vector2d.ts @@ -10,8 +10,7 @@ export class Vector2D { public x: number = 0, public y: number = 0, public w: number = 1 // needed for matrix multiplication - ) { - } + ) {} /** * The function checks if the x and y values of a point are both zero. diff --git a/src/data-structures/priority-queue/max-priority-queue.ts b/src/data-structures/priority-queue/max-priority-queue.ts index 409c99f..dbb0793 100644 --- a/src/data-structures/priority-queue/max-priority-queue.ts +++ b/src/data-structures/priority-queue/max-priority-queue.ts @@ -10,7 +10,7 @@ import type {Comparator} from '../../types'; export class MaxPriorityQueue extends PriorityQueue { constructor( - options: { comparator: Comparator; nodes?: E[] } = { + options: {comparator: Comparator; nodes?: E[]} = { comparator: (a: E, b: E) => { if (!(typeof a === 'number' && typeof b === 'number')) { throw new Error('The a, b params of compare function must be number'); diff --git a/src/data-structures/priority-queue/min-priority-queue.ts b/src/data-structures/priority-queue/min-priority-queue.ts index da8ab64..8b8386f 100644 --- a/src/data-structures/priority-queue/min-priority-queue.ts +++ b/src/data-structures/priority-queue/min-priority-queue.ts @@ -10,7 +10,7 @@ import type {Comparator} from '../../types'; export class MinPriorityQueue extends PriorityQueue { constructor( - options: { comparator: Comparator; nodes?: E[] } = { + options: {comparator: Comparator; nodes?: E[]} = { comparator: (a: E, b: E) => { if (!(typeof a === 'number' && typeof b === 'number')) { throw new Error('The a, b params of compare function must be number'); diff --git a/src/data-structures/priority-queue/priority-queue.ts b/src/data-structures/priority-queue/priority-queue.ts index 60deb98..edfbaf2 100644 --- a/src/data-structures/priority-queue/priority-queue.ts +++ b/src/data-structures/priority-queue/priority-queue.ts @@ -10,7 +10,7 @@ import {Heap} from '../heap'; import {Comparator} from '../../types'; export class PriorityQueue extends Heap { - constructor(options: { comparator: Comparator; nodes?: E[] }) { + constructor(options: {comparator: Comparator; nodes?: E[]}) { super(options); } } diff --git a/src/data-structures/queue/deque.ts b/src/data-structures/queue/deque.ts index 8dafdb0..e3cb229 100644 --- a/src/data-structures/queue/deque.ts +++ b/src/data-structures/queue/deque.ts @@ -9,8 +9,7 @@ import {DoublyLinkedList} from '../linked-list'; // O(n) time complexity of obtaining the value // O(1) time complexity of adding at the beginning and the end -export class Deque extends DoublyLinkedList { -} +export class Deque extends DoublyLinkedList {} // O(1) time complexity of obtaining the value // O(n) time complexity of adding at the beginning and the end @@ -20,9 +19,9 @@ export class ObjectDeque { if (capacity !== undefined) this._capacity = capacity; } - protected _nodes: { [key: number]: E } = {}; + protected _nodes: {[key: number]: E} = {}; - get nodes(): { [p: number]: E } { + get nodes(): {[p: number]: E} { return this._nodes; } diff --git a/src/data-structures/queue/queue.ts b/src/data-structures/queue/queue.ts index c584856..c846074 100644 --- a/src/data-structures/queue/queue.ts +++ b/src/data-structures/queue/queue.ts @@ -300,7 +300,7 @@ export class Queue { return new Queue(this.nodes.slice(this.offset)); } - * [Symbol.iterator]() { + *[Symbol.iterator]() { for (const item of this.nodes) { yield item; } diff --git a/src/data-structures/trie/trie.ts b/src/data-structures/trie/trie.ts index 5de530e..fbf4f0e 100644 --- a/src/data-structures/trie/trie.ts +++ b/src/data-structures/trie/trie.ts @@ -342,4 +342,4 @@ export class Trie { } return str; } -} \ No newline at end of file +} diff --git a/src/types/data-structures/matrix/navigator.ts b/src/types/data-structures/matrix/navigator.ts index 34eddd9..9d8b9a9 100644 --- a/src/types/data-structures/matrix/navigator.ts +++ b/src/types/data-structures/matrix/navigator.ts @@ -1,6 +1,6 @@ export type Direction = 'up' | 'right' | 'down' | 'left'; -export type Turning = { [key in Direction]: Direction }; +export type Turning = {[key in Direction]: Direction}; export type NavigatorParams = { matrix: T[][]; diff --git a/src/types/utils/utils.ts b/src/types/utils/utils.ts index 1f3a505..f4d26c4 100644 --- a/src/types/utils/utils.ts +++ b/src/types/utils/utils.ts @@ -1,5 +1,5 @@ export type ToThunkFn = () => ReturnType; -export type Thunk = () => ReturnType & { __THUNK__: symbol }; +export type Thunk = () => ReturnType & {__THUNK__: symbol}; export type TrlFn = (...args: any[]) => any; export type TrlAsyncFn = (...args: any[]) => any; diff --git a/src/types/utils/validate-type.ts b/src/types/utils/validate-type.ts index 3ebf451..9d6bb57 100644 --- a/src/types/utils/validate-type.ts +++ b/src/types/utils/validate-type.ts @@ -1,6 +1,6 @@ -export type KeyValueObject = { [key: string]: any }; +export type KeyValueObject = {[key: string]: any}; -export type KeyValueObjectWithKey = { [key: string]: any; key: string | number | symbol }; +export type KeyValueObjectWithKey = {[key: string]: any; key: string | number | symbol}; export type NonNumberNonObjectButDefined = string | boolean | symbol | null; @@ -16,20 +16,6 @@ export type ObjectWithNumberKey = { key: number; }; -export type RestrictValByKey = - | NonNumberNonObjectButDefined - | ObjectWithoutKey - | ObjectWithNonNumberKey - | ObjectWithNumberKey; +export type RestrictValByKey = NonNumberNonObjectButDefined | ObjectWithoutKey | ObjectWithNonNumberKey | ObjectWithNumberKey; -export type DummyAny = - | string - | number - | boolean - | null - | undefined - | object - | symbol - | void - | ((...args: []) => any) - | never; +export type DummyAny = string | number | boolean | null | undefined | object | symbol | void | ((...args: []) => any) | never; diff --git a/test/integration/bst.test.ts b/test/integration/bst.test.ts index 59022fc..3eaa0f7 100644 --- a/test/integration/bst.test.ts +++ b/test/integration/bst.test.ts @@ -183,7 +183,7 @@ describe('Individual package BST operations test', () => { }); it('should perform various operations on a Binary Search Tree with object values', () => { - const objBST = new BST<{ key: number; keyA: number }>(); + const objBST = new BST<{key: number; keyA: number}>(); expect(objBST).toBeInstanceOf(BST); objBST.add(11, {key: 11, keyA: 11}); objBST.add(3, {key: 3, keyA: 3}); diff --git a/test/performance/data-structures/binary-tree/rb-tree.test.ts b/test/performance/data-structures/binary-tree/rb-tree.test.ts index 2dd7e44..f15c14f 100644 --- a/test/performance/data-structures/binary-tree/rb-tree.test.ts +++ b/test/performance/data-structures/binary-tree/rb-tree.test.ts @@ -2,7 +2,7 @@ import {RedBlackTree} from '../../../../src'; import * as Benchmark from 'benchmark'; import {getRandomIntArray, magnitude} from '../../../utils'; import {OrderedMap} from 'js-sdsl'; -import {isCompetitor} from "../../../config"; +import {isCompetitor} from '../../../config'; const suite = new Benchmark.Suite(); const rbTree = new RedBlackTree(); @@ -10,32 +10,31 @@ const {HUNDRED_THOUSAND} = magnitude; const arr = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSAND, true); const competitor = new OrderedMap(); -suite - .add(`${HUNDRED_THOUSAND.toLocaleString()} add`, () => { - rbTree.clear(); - for (let i = 0; i < arr.length; i++) { - rbTree.add(arr[i]); - } - }); - +suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add`, () => { + rbTree.clear(); + for (let i = 0; i < arr.length; i++) { + rbTree.add(arr[i]); + } +}); if (isCompetitor) { suite.add(`${HUNDRED_THOUSAND.toLocaleString()} competitor add`, () => { for (let i = 0; i < arr.length; i++) { competitor.setElement(arr[i], arr[i]); } - }) + }); } -suite.add(`${HUNDRED_THOUSAND.toLocaleString()} add & delete randomly`, () => { - rbTree.clear(); - for (let i = 0; i < arr.length; i++) { - rbTree.add(arr[i]); - } - for (let i = 0; i < arr.length; i++) { - rbTree.delete(arr[i]); - } -}) +suite + .add(`${HUNDRED_THOUSAND.toLocaleString()} add & delete randomly`, () => { + rbTree.clear(); + for (let i = 0; i < arr.length; i++) { + rbTree.add(arr[i]); + } + for (let i = 0; i < arr.length; i++) { + rbTree.delete(arr[i]); + } + }) .add(`${HUNDRED_THOUSAND.toLocaleString()} getNode`, () => { for (let i = 0; i < arr.length; i++) { rbTree.getNode(arr[i]); diff --git a/test/performance/data-structures/hash/hash-map.test.ts b/test/performance/data-structures/hash/hash-map.test.ts index e9f1c91..cfdf826 100644 --- a/test/performance/data-structures/hash/hash-map.test.ts +++ b/test/performance/data-structures/hash/hash-map.test.ts @@ -2,28 +2,26 @@ import {HashMap} from '../../../../src'; import {HashMap as CHashMap} from 'js-sdsl'; import * as Benchmark from 'benchmark'; import {magnitude} from '../../../utils'; -import {isCompetitor} from "../../../config"; +import {isCompetitor} from '../../../config'; const suite = new Benchmark.Suite(); const {TEN_THOUSAND} = magnitude; -suite - .add(`${TEN_THOUSAND.toLocaleString()} set`, () => { - const hm = new HashMap(); +suite.add(`${TEN_THOUSAND.toLocaleString()} set`, () => { + const hm = new HashMap(); - for (let i = 0; i < TEN_THOUSAND; i++) { - hm.set(i, i); - } - }); + for (let i = 0; i < TEN_THOUSAND; i++) { + hm.set(i, i); + } +}); if (isCompetitor) { - suite.add(`${TEN_THOUSAND.toLocaleString()} competitor set`, () => { const hm = new CHashMap(); for (let i = 0; i < TEN_THOUSAND; i++) { hm.setElement(i, i); } - }) + }); } suite.add(`${TEN_THOUSAND.toLocaleString()} set & get`, () => { const hm = new HashMap(); @@ -34,8 +32,7 @@ suite.add(`${TEN_THOUSAND.toLocaleString()} set & get`, () => { for (let i = 0; i < TEN_THOUSAND; i++) { hm.get(i); } -}) -; +}); if (isCompetitor) { suite.add(`${TEN_THOUSAND.toLocaleString()} competitor set & get`, () => { const hm = new CHashMap(); @@ -46,6 +43,6 @@ if (isCompetitor) { for (let i = 0; i < TEN_THOUSAND; i++) { hm.getElementByKey(i); } - }) + }); } export {suite}; diff --git a/test/performance/data-structures/linked-list/doubly-linked-list.test.ts b/test/performance/data-structures/linked-list/doubly-linked-list.test.ts index 7155cc9..9c4562e 100644 --- a/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +++ b/test/performance/data-structures/linked-list/doubly-linked-list.test.ts @@ -2,19 +2,18 @@ import {DoublyLinkedList, DoublyLinkedListNode} from '../../../../src'; import {LinkList as CLinkedList} from 'js-sdsl'; import * as Benchmark from 'benchmark'; import {magnitude} from '../../../utils'; -import {isCompetitor} from "../../../config"; +import {isCompetitor} from '../../../config'; const suite = new Benchmark.Suite(); const {LINEAR} = magnitude; -suite - .add(`${LINEAR.toLocaleString()} unshift`, () => { - const list = new DoublyLinkedList(); +suite.add(`${LINEAR.toLocaleString()} unshift`, () => { + const list = new DoublyLinkedList(); - for (let i = 0; i < LINEAR; i++) { - list.unshift(i); - } - }) + for (let i = 0; i < LINEAR; i++) { + list.unshift(i); + } +}); if (isCompetitor) { suite.add(`${LINEAR.toLocaleString()} competitor unshift`, () => { const list = new CLinkedList(); @@ -22,18 +21,19 @@ if (isCompetitor) { for (let i = 0; i < LINEAR; i++) { list.pushFront(i); } - }) + }); } -suite.add(`${LINEAR.toLocaleString()} unshift & shift`, () => { - const list = new DoublyLinkedList(); +suite + .add(`${LINEAR.toLocaleString()} unshift & shift`, () => { + const list = new DoublyLinkedList(); - for (let i = 0; i < LINEAR; i++) { - list.unshift(i); - } - for (let i = 0; i < LINEAR; i++) { - list.shift(); - } -}) + for (let i = 0; i < LINEAR; i++) { + list.unshift(i); + } + for (let i = 0; i < LINEAR; i++) { + list.shift(); + } + }) .add(`${LINEAR.toLocaleString()} insertBefore`, () => { const doublyList = new DoublyLinkedList(); let midNode: DoublyLinkedListNode | null = null; diff --git a/test/performance/data-structures/priority-queue/max-priority-queue.test.ts b/test/performance/data-structures/priority-queue/max-priority-queue.test.ts index ef44072..2892fec 100644 --- a/test/performance/data-structures/priority-queue/max-priority-queue.test.ts +++ b/test/performance/data-structures/priority-queue/max-priority-queue.test.ts @@ -6,9 +6,7 @@ const suite = new Benchmark.Suite(); const {TEN_THOUSAND} = magnitude; suite.add(`${TEN_THOUSAND.toLocaleString()} refill & poll`, () => { - const nodes = Array.from( - new Set(Array.from(new Array(TEN_THOUSAND), () => Math.floor(Math.random() * TEN_THOUSAND * 100))) - ); + const nodes = Array.from(new Set(Array.from(new Array(TEN_THOUSAND), () => Math.floor(Math.random() * TEN_THOUSAND * 100)))); const maxPQ = new MaxPriorityQueue(); maxPQ.refill(nodes); while (maxPQ.size > 0) { diff --git a/test/performance/data-structures/priority-queue/priority-queue.test.ts b/test/performance/data-structures/priority-queue/priority-queue.test.ts index b8f8693..0fcd5b3 100644 --- a/test/performance/data-structures/priority-queue/priority-queue.test.ts +++ b/test/performance/data-structures/priority-queue/priority-queue.test.ts @@ -2,23 +2,22 @@ import {PriorityQueue as CPriorityQueue} from 'js-sdsl'; import {PriorityQueue} from '../../../../src'; import * as Benchmark from 'benchmark'; import {magnitude} from '../../../utils'; -import {isCompetitor} from "../../../config"; +import {isCompetitor} from '../../../config'; const suite = new Benchmark.Suite(); const {TEN_THOUSAND} = magnitude; -suite - .add(`${TEN_THOUSAND.toLocaleString()} add & pop`, () => { - const pq = new PriorityQueue({comparator: (a, b) => b - a}); +suite.add(`${TEN_THOUSAND.toLocaleString()} add & pop`, () => { + const pq = new PriorityQueue({comparator: (a, b) => b - a}); - for (let i = 0; i < TEN_THOUSAND; i++) { - pq.add(i); - } + for (let i = 0; i < TEN_THOUSAND; i++) { + pq.add(i); + } - for (let i = 0; i < TEN_THOUSAND; i++) { - pq.pop(); - } - }); + for (let i = 0; i < TEN_THOUSAND; i++) { + pq.pop(); + } +}); if (isCompetitor) { suite.add(`${TEN_THOUSAND.toLocaleString()} competitor add & pop`, () => { const pq = new CPriorityQueue(); @@ -31,7 +30,6 @@ if (isCompetitor) { pq.pop(); } }); - } export {suite}; diff --git a/test/performance/data-structures/queue/deque.test.ts b/test/performance/data-structures/queue/deque.test.ts index 94bf54f..ceb021f 100644 --- a/test/performance/data-structures/queue/deque.test.ts +++ b/test/performance/data-structures/queue/deque.test.ts @@ -2,25 +2,24 @@ import {Deque} from '../../../../src'; import {Deque as CDeque} from 'js-sdsl'; import * as Benchmark from 'benchmark'; import {magnitude} from '../../../utils'; -import {isCompetitor} from "../../../config"; +import {isCompetitor} from '../../../config'; export const suite = new Benchmark.Suite(); const {LINEAR} = magnitude; -suite - .add(`${LINEAR.toLocaleString()} push`, () => { - const deque = new Deque(); - for (let i = 0; i < LINEAR; i++) { - deque.push(i); - } - }) +suite.add(`${LINEAR.toLocaleString()} push`, () => { + const deque = new Deque(); + for (let i = 0; i < LINEAR; i++) { + deque.push(i); + } +}); if (isCompetitor) { suite.add(`${LINEAR.toLocaleString()} competitor push`, () => { const deque = new CDeque(); for (let i = 0; i < LINEAR; i++) { deque.pushBack(i); } - }) + }); } suite.add(`${LINEAR.toLocaleString()} shift`, () => { const deque = new Deque(); diff --git a/test/performance/data-structures/queue/queue.test.ts b/test/performance/data-structures/queue/queue.test.ts index 062bfaf..7416abf 100644 --- a/test/performance/data-structures/queue/queue.test.ts +++ b/test/performance/data-structures/queue/queue.test.ts @@ -2,19 +2,18 @@ import {Queue} from '../../../../src'; import {Queue as CQueue} from 'js-sdsl'; import * as Benchmark from 'benchmark'; import {magnitude} from '../../../utils'; -import {isCompetitor} from "../../../config"; +import {isCompetitor} from '../../../config'; const suite = new Benchmark.Suite(); const {LINEAR} = magnitude; -suite - .add(`${LINEAR.toLocaleString()} push`, () => { - const queue = new Queue(); +suite.add(`${LINEAR.toLocaleString()} push`, () => { + const queue = new Queue(); - for (let i = 0; i < LINEAR; i++) { - queue.push(i); - } - }) + for (let i = 0; i < LINEAR; i++) { + queue.push(i); + } +}); if (isCompetitor) { suite.add(`${LINEAR.toLocaleString()} competitor push`, () => { const queue = new CQueue(); @@ -22,7 +21,7 @@ if (isCompetitor) { for (let i = 0; i < LINEAR; i++) { queue.push(i); } - }) + }); } suite.add(`${LINEAR.toLocaleString()} push & shift`, () => { const queue = new Queue(); diff --git a/test/performance/data-structures/stack/stack.test.ts b/test/performance/data-structures/stack/stack.test.ts index 0e4f89d..6132b49 100644 --- a/test/performance/data-structures/stack/stack.test.ts +++ b/test/performance/data-structures/stack/stack.test.ts @@ -2,19 +2,18 @@ import {Stack} from '../../../../src'; import {Stack as CStack} from 'js-sdsl'; import * as Benchmark from 'benchmark'; import {magnitude} from '../../../utils'; -import {isCompetitor} from "../../../config"; +import {isCompetitor} from '../../../config'; const suite = new Benchmark.Suite(); const {LINEAR} = magnitude; -suite - .add(`${LINEAR.toLocaleString()} push`, () => { - const stack = new Stack(); +suite.add(`${LINEAR.toLocaleString()} push`, () => { + const stack = new Stack(); - for (let i = 0; i < LINEAR; i++) { - stack.push(i); - } - }) + for (let i = 0; i < LINEAR; i++) { + stack.push(i); + } +}); if (isCompetitor) { suite.add(`${LINEAR.toLocaleString()} competitor push`, () => { const queue = new CStack(); @@ -22,7 +21,7 @@ if (isCompetitor) { for (let i = 0; i < LINEAR; i++) { queue.push(i); } - }) + }); } suite.add(`${LINEAR.toLocaleString()} push & pop`, () => { const queue = new Stack(); @@ -33,7 +32,7 @@ suite.add(`${LINEAR.toLocaleString()} push & pop`, () => { for (let i = 0; i < LINEAR; i++) { queue.pop(); } -}) +}); if (isCompetitor) { suite.add(`${LINEAR.toLocaleString()} competitor push & pop`, () => { const queue = new CStack(); @@ -44,7 +43,7 @@ if (isCompetitor) { for (let i = 0; i < LINEAR; i++) { queue.pop(); } - }) + }); } export {suite}; diff --git a/test/performance/reportor.ts b/test/performance/reportor.ts index 4b5aeda..628e1b0 100644 --- a/test/performance/reportor.ts +++ b/test/performance/reportor.ts @@ -11,7 +11,7 @@ const reportDistPath = path.join(parentDirectory, 'benchmark'); const testDir = path.join(__dirname, 'data-structures'); const testFiles = fastGlob.sync(path.join(testDir, '**', '*.test.ts')); -const report: { [key: string]: any } = {}; +const report: {[key: string]: any} = {}; let completedCount = 0; @@ -173,9 +173,7 @@ performanceTests.forEach(item => { console.log( // `Files: ${GREEN}${testFileCount}${END} `, // `Suites: ${GREEN}${performanceTests.length}${END} `, - `Suites Progress: ${isDone ? GREEN : YELLOW}${completedCount}${END}/${isDone ? GREEN : YELLOW}${ - performanceTests.length - }${END}`, + `Suites Progress: ${isDone ? GREEN : YELLOW}${completedCount}${END}/${isDone ? GREEN : YELLOW}${performanceTests.length}${END}`, `Time: ${isTimeWarn ? YELLOW : GREEN}${runTime}s${END}` ); if (isDone) { diff --git a/test/performance/types/reportor.ts b/test/performance/types/reportor.ts index e41166d..4b65e75 100644 --- a/test/performance/types/reportor.ts +++ b/test/performance/types/reportor.ts @@ -1,3 +1,3 @@ import * as Benchmark from 'benchmark'; -export type PerformanceTest = { testName: string; suite: Benchmark.Suite; file: string }; +export type PerformanceTest = {testName: string; suite: Benchmark.Suite; file: string}; diff --git a/test/types/utils/json2html.ts b/test/types/utils/json2html.ts index bf4e9f4..dbae264 100644 --- a/test/types/utils/json2html.ts +++ b/test/types/utils/json2html.ts @@ -1 +1 @@ -export type Json2htmlOptions = { plainHtml?: boolean } & Partial<{ [key: string]: any }>; +export type Json2htmlOptions = {plainHtml?: boolean} & Partial<{[key: string]: any}>; diff --git a/test/unit/data-structures/binary-tree/avl-tree.test.ts b/test/unit/data-structures/binary-tree/avl-tree.test.ts index fb09a75..348e587 100644 --- a/test/unit/data-structures/binary-tree/avl-tree.test.ts +++ b/test/unit/data-structures/binary-tree/avl-tree.test.ts @@ -219,7 +219,7 @@ describe('AVL Tree Test recursively', () => { }); describe('AVLTree APIs test', () => { - const avl = new AVLTree<{ id: number; text: string }>(); + const avl = new AVLTree<{id: number; text: string}>(); beforeEach(() => { avl.clear(); }); @@ -268,7 +268,7 @@ describe('AVLTree', () => { }); describe('BinaryTree APIs test', () => { - const avl = new AVLTree<{ id: number; text: string }>(); + const avl = new AVLTree<{id: number; text: string}>(); beforeEach(() => { avl.clear(); }); @@ -285,5 +285,4 @@ describe('AVLTree', () => { expect(bfsRes[0]?.key).toBe(2); }); }); - }); diff --git a/test/unit/data-structures/binary-tree/binary-tree.test.ts b/test/unit/data-structures/binary-tree/binary-tree.test.ts index 4301e03..ef32f1c 100644 --- a/test/unit/data-structures/binary-tree/binary-tree.test.ts +++ b/test/unit/data-structures/binary-tree/binary-tree.test.ts @@ -1,6 +1,6 @@ import {BinaryTree, BinaryTreeNode, IterationType} from '../../../../src'; -import {getRandomIntArray} from "../../../utils"; -import {FamilyPosition} from "binary-tree-typed"; +import {getRandomIntArray} from '../../../utils'; +import {FamilyPosition} from 'binary-tree-typed'; // import {isDebugTest} from '../../../config'; // const isDebug = isDebugTest; @@ -72,7 +72,6 @@ describe('BinaryTreeNode', () => { expect(leftChild.familyPosition).toBe('ROOT_LEFT'); rightChild.left = new BinaryTreeNode(5); expect(rightChild.familyPosition).toBe('ROOT_RIGHT'); - }); it('should determine only right child family position correctly', () => { @@ -106,8 +105,8 @@ describe('BinaryTree', () => { }); it('should delete nodes', () => { - expect(tree.getHeight(tree.root, IterationType.ITERATIVE)).toBe(-1) - expect(tree.getMinHeight()).toBe(-1) + expect(tree.getHeight(tree.root, IterationType.ITERATIVE)).toBe(-1); + expect(tree.getMinHeight()).toBe(-1); const node = tree.add(1); expect(tree.size).toBe(1); @@ -117,7 +116,6 @@ describe('BinaryTree', () => { tree.add(rightChild); const root = tree.root; - expect(leftChild.familyPosition).toBe('LEFT'); tree.add(null); tree.add(new BinaryTreeNode(4)); @@ -128,15 +126,14 @@ describe('BinaryTree', () => { expect(rightChild.familyPosition).toBe('ROOT_RIGHT'); tree.delete(new BinaryTreeNode(200)); - tree.delete(rightChild) + tree.delete(rightChild); if (node) { const result = tree.delete(node); expect(result).toHaveLength(1); expect(tree.size).toBe(3); - expect(tree.getMinHeight(tree.root, IterationType.RECURSIVE)).toBe(1) + expect(tree.getMinHeight(tree.root, IterationType.RECURSIVE)).toBe(1); } - }); it('should add and find nodes', () => { @@ -155,11 +152,10 @@ describe('BinaryTree', () => { expect(tree.has('3', node => node.value?.toString())).toBe(true); }); - it('should be a balance tree after malicious manipulation', () => { tree.add(3); tree.add(12); - tree.addMany(getRandomIntArray(100, 1, 100)) + tree.addMany(getRandomIntArray(100, 1, 100)); tree.add(10); expect(tree.isPerfectlyBalanced()).toBe(true); @@ -238,20 +234,16 @@ describe('BinaryTree', () => { expect(tree.isSubtreeBST(tree.getNode(4), IterationType.RECURSIVE)).toBe(true); expect(tree.isSubtreeBST(tree.getNode(4), IterationType.ITERATIVE)).toBe(true); - expect(tree.getNodes(2, undefined, false, null)).toEqual([]) - expect(tree.getNodes(tree.getNodeByKey(2), undefined, false, tree.root)).toEqual([tree.getNodeByKey(2)]) + expect(tree.getNodes(2, undefined, false, null)).toEqual([]); + expect(tree.getNodes(tree.getNodeByKey(2), undefined, false, tree.root)).toEqual([tree.getNodeByKey(2)]); }); it('should subTreeTraverse', () => { tree.addMany([4, 2, 6, null, 1, 3, null, 5, null, 7]); expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.ITERATIVE)).toEqual([6, 3, 7]); expect(tree.subTreeTraverse(node => node.key, tree.getNode(6), IterationType.RECURSIVE)).toEqual([6, 3, 7]); - expect( - tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.ITERATIVE, true) - ).toEqual([6, 3, 7, null]); - expect( - tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.RECURSIVE, true) - ).toEqual([6, 3, 7, null]); + expect(tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.ITERATIVE, true)).toEqual([6, 3, 7, null]); + expect(tree.subTreeTraverse(node => (node ? node.key : null), tree.getNode(6), IterationType.RECURSIVE, true)).toEqual([6, 3, 7, null]); }); it('should clear the tree', () => { @@ -323,45 +315,81 @@ describe('BinaryTree traversals', () => { const arr = [35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55]; tree.refill(arr); - expect( - tree.bfs(node => node, tree.root, IterationType.ITERATIVE, true).map(node => (node ? node.key : null)) - ).toEqual([35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55]); - expect( - tree.bfs(node => node, tree.root, IterationType.RECURSIVE, true).map(node => (node ? node.key : null)) - ).toEqual([35, 20, 40, 15, 29, null, 50, null, 16, 28, 30, 45, 55]); - expect( - tree.bfs(node => node, tree.root, IterationType.ITERATIVE).map(node => (node === null ? null : node.key)) - ).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]); - expect( - tree.bfs(node => node, tree.root, IterationType.RECURSIVE).map(node => (node === null ? null : node.key)) - ).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]); + expect(tree.bfs(node => node, tree.root, IterationType.ITERATIVE, true).map(node => (node ? node.key : null))).toEqual([ + 35, + 20, + 40, + 15, + 29, + null, + 50, + null, + 16, + 28, + 30, + 45, + 55 + ]); + expect(tree.bfs(node => node, tree.root, IterationType.RECURSIVE, true).map(node => (node ? node.key : null))).toEqual([ + 35, + 20, + 40, + 15, + 29, + null, + 50, + null, + 16, + 28, + 30, + 45, + 55 + ]); + expect(tree.bfs(node => node, tree.root, IterationType.ITERATIVE).map(node => (node === null ? null : node.key))).toEqual([ + 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55 + ]); + expect(tree.bfs(node => node, tree.root, IterationType.RECURSIVE).map(node => (node === null ? null : node.key))).toEqual([ + 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55 + ]); expect(tree.dfs(node => node.key, 'pre')).toEqual([35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55]); - expect(tree.dfs(node => node.key, 'pre', tree.root, IterationType.RECURSIVE)).toEqual([ - 35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55 + expect(tree.dfs(node => node.key, 'pre', tree.root, IterationType.RECURSIVE)).toEqual([35, 20, 15, 16, 29, 28, 30, 40, 50, 45, 55]); + expect(tree.dfs(node => node, 'pre', tree.root, IterationType.ITERATIVE, true).map(node => (node ? node.key : null))).toEqual([ + 35, + 20, + 15, + null, + 16, + 29, + 28, + 30, + 40, + null, + 50, + 45, + 55 + ]); + expect(tree.dfs(node => node, 'pre', tree.root, IterationType.RECURSIVE, true).map(node => (node ? node.key : null))).toEqual([ + 35, + 20, + 15, + null, + 16, + 29, + 28, + 30, + 40, + null, + 50, + 45, + 55 ]); - expect( - tree - .dfs(node => node, 'pre', tree.root, IterationType.ITERATIVE, true) - .map(node => (node ? node.key : null)) - ).toEqual([35, 20, 15, null, 16, 29, 28, 30, 40, null, 50, 45, 55]); - expect( - tree - .dfs(node => node, 'pre', tree.root, IterationType.RECURSIVE, true) - .map(node => (node ? node.key : null)) - ).toEqual([35, 20, 15, null, 16, 29, 28, 30, 40, null, 50, 45, 55]); expect(tree.dfs(node => node.key, 'in')).toEqual([15, 16, 20, 28, 29, 30, 35, 40, 45, 50, 55]); expect(tree.dfs(node => node.key, 'post')).toEqual([16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35]); - expect(tree.dfs(node => node.key, 'post', tree.root, IterationType.RECURSIVE)).toEqual([ - 16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35 - ]); - expect(tree.bfs(node => node.key, tree.root, IterationType.RECURSIVE)).toEqual([ - 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55 - ]); - expect(tree.bfs(node => node.key, tree.root, IterationType.ITERATIVE)).toEqual([ - 35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55 - ]); + expect(tree.dfs(node => node.key, 'post', tree.root, IterationType.RECURSIVE)).toEqual([16, 15, 28, 30, 29, 20, 45, 55, 50, 40, 35]); + expect(tree.bfs(node => node.key, tree.root, IterationType.RECURSIVE)).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]); + expect(tree.bfs(node => node.key, tree.root, IterationType.ITERATIVE)).toEqual([35, 20, 40, 15, 29, 50, 16, 28, 30, 45, 55]); expect(tree.listLevels(node => node.key)).toEqual([[35], [20, 40], [15, 29, 50], [16, 28, 30, 45, 55]]); @@ -532,13 +560,7 @@ describe('BinaryTree', () => { expect(nodes.length).toBe(1); expect(nodes[0].key).toBe(3); - const nodesRec = tree.getNodes( - 'B', - (node: BinaryTreeNode) => node.value, - false, - tree.root, - IterationType.RECURSIVE - ); + const nodesRec = tree.getNodes('B', (node: BinaryTreeNode) => node.value, false, tree.root, IterationType.RECURSIVE); expect(nodesRec.length).toBe(1); expect(nodesRec[0].key).toBe(3); diff --git a/test/unit/data-structures/binary-tree/bst.test.ts b/test/unit/data-structures/binary-tree/bst.test.ts index 6788e36..eff302e 100644 --- a/test/unit/data-structures/binary-tree/bst.test.ts +++ b/test/unit/data-structures/binary-tree/bst.test.ts @@ -189,7 +189,7 @@ describe('BST operations test', () => { }); it('should perform various operations on a Binary Search Tree with object values', () => { - const objBST = new BST<{ key: number; keyA: number }>(); + const objBST = new BST<{key: number; keyA: number}>(); expect(objBST).toBeInstanceOf(BST); objBST.add(11, {key: 11, keyA: 11}); objBST.add(3, {key: 3, keyA: 3}); @@ -260,7 +260,7 @@ describe('BST operations test', () => { objBST.perfectlyBalance(); expect(objBST.isPerfectlyBalanced()).toBe(true); - const bfsNodesAfterBalanced: BSTNode<{ key: number; keyA: number }>[] = []; + const bfsNodesAfterBalanced: BSTNode<{key: number; keyA: number}>[] = []; objBST.bfs(node => bfsNodesAfterBalanced.push(node)); expect(bfsNodesAfterBalanced[0].key).toBe(8); expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16); @@ -385,7 +385,7 @@ describe('BST operations test', () => { expect(bfsIDs[1]).toBe(12); expect(bfsIDs[2]).toBe(16); - const bfsNodes: BSTNode<{ key: number; keyA: number }>[] = []; + const bfsNodes: BSTNode<{key: number; keyA: number}>[] = []; objBST.bfs(node => bfsNodes.push(node)); expect(bfsNodes[0].key).toBe(2); expect(bfsNodes[1].key).toBe(12); @@ -580,7 +580,7 @@ describe('BST operations test recursively', () => { }); it('should perform various operations on a Binary Search Tree with object values', () => { - const objBST = new BST<{ key: number; keyA: number }>(); + const objBST = new BST<{key: number; keyA: number}>(); expect(objBST).toBeInstanceOf(BST); objBST.add(11, {key: 11, keyA: 11}); objBST.add(3, {key: 3, keyA: 3}); @@ -652,7 +652,7 @@ describe('BST operations test recursively', () => { objBST.perfectlyBalance(); expect(objBST.isPerfectlyBalanced()).toBe(true); - const bfsNodesAfterBalanced: BSTNode<{ key: number; keyA: number }>[] = []; + const bfsNodesAfterBalanced: BSTNode<{key: number; keyA: number}>[] = []; objBST.bfs(node => bfsNodesAfterBalanced.push(node)); expect(bfsNodesAfterBalanced[0].key).toBe(8); expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16); @@ -777,7 +777,7 @@ describe('BST operations test recursively', () => { expect(bfsIDs[1]).toBe(12); expect(bfsIDs[2]).toBe(16); - const bfsNodes: BSTNode<{ key: number; keyA: number }>[] = []; + const bfsNodes: BSTNode<{key: number; keyA: number}>[] = []; objBST.bfs(node => bfsNodes.push(node)); expect(bfsNodes[0].key).toBe(2); expect(bfsNodes[1].key).toBe(12); @@ -843,11 +843,7 @@ describe('BST Performance test', function () { bst.addMany([4, 2, 6, 1, 3, 5, 7]); expect(bst.subTreeTraverse(node => node.key, bst.getNode(6), IterationType.ITERATIVE)).toEqual([6, 5, 7]); expect(bst.subTreeTraverse(node => node.key, bst.getNode(6), IterationType.RECURSIVE)).toEqual([6, 5, 7]); - expect( - bst.subTreeTraverse(node => (node?.key ?? undefined), bst.getNode(6), IterationType.ITERATIVE, true) - ).toEqual([6, 5, 7]); - expect( - bst.subTreeTraverse(node => (node?.key ?? undefined), bst.getNode(6), IterationType.RECURSIVE, true) - ).toEqual([6, 5, 7]); + expect(bst.subTreeTraverse(node => node?.key ?? undefined, bst.getNode(6), IterationType.ITERATIVE, true)).toEqual([6, 5, 7]); + expect(bst.subTreeTraverse(node => node?.key ?? undefined, bst.getNode(6), IterationType.RECURSIVE, true)).toEqual([6, 5, 7]); }); }); diff --git a/test/unit/data-structures/binary-tree/overall.test.ts b/test/unit/data-structures/binary-tree/overall.test.ts index ee29844..d168b1c 100644 --- a/test/unit/data-structures/binary-tree/overall.test.ts +++ b/test/unit/data-structures/binary-tree/overall.test.ts @@ -29,7 +29,7 @@ describe('Overall BinaryTree Test', () => { bfsIDs[0] === 11; // true expect(bfsIDs[0]).toBe(11); - const objBST = new BST<{ key: number; keyA: number }>(); + const objBST = new BST<{key: number; keyA: number}>(); objBST.add(11, {key: 11, keyA: 11}); objBST.add(3, {key: 3, keyA: 3}); diff --git a/test/unit/data-structures/binary-tree/rb-tree.test.ts b/test/unit/data-structures/binary-tree/rb-tree.test.ts index 89f45fe..27884d4 100644 --- a/test/unit/data-structures/binary-tree/rb-tree.test.ts +++ b/test/unit/data-structures/binary-tree/rb-tree.test.ts @@ -1,7 +1,7 @@ import {IterationType, RBTNColor, RedBlackTree, RedBlackTreeNode} from '../../../../src'; import {getRandomInt, getRandomIntArray, magnitude} from '../../../utils'; import {isDebugTest} from '../../../config'; -import {OrderedMap} from "js-sdsl"; +import {OrderedMap} from 'js-sdsl'; const isDebug = isDebugTest; @@ -421,14 +421,10 @@ describe('RedBlackTree', () => { isDebug && tree.print(); expect(tree.dfs()).toEqual([ - 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 15, 16, 17, 18, - 19, 22, 23, 25, 28, 33, 50, 110, 111, - 155, 225 - ]) + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 22, 23, 25, 28, 33, 50, 110, 111, 155, 225 + ]); expect(tree.isBST()).toBe(true); - }); it('should fix the tree after insertion and deletion', () => { @@ -441,20 +437,14 @@ describe('RedBlackTree', () => { expect(tree.size).toBe(51); expect(tree.isBST()).toBe(true); - expect(tree.dfs(n => n.key, "in", tree.root, IterationType.ITERATIVE)).toEqual([ - 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, - 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - 93, 94, 95, 96, 97, 98, 99 - ]) - expect(tree.dfs(n => n.key, "in", tree.root, IterationType.RECURSIVE)).toEqual([ - 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, - 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, - 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, - 93, 94, 95, 96, 97, 98, 99 - ]) + expect(tree.dfs(n => n.key, 'in', tree.root, IterationType.ITERATIVE)).toEqual([ + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, + 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 + ]); + expect(tree.dfs(n => n.key, 'in', tree.root, IterationType.RECURSIVE)).toEqual([ + 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, + 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 + ]); }); it('should fix the tree after large scale insertion and deletion', () => { @@ -467,12 +457,12 @@ describe('RedBlackTree', () => { expect(tree.size).toBe(0); expect(tree.isBST()).toBe(true); - expect(tree.dfs(n => n.key, "in", tree.root, IterationType.ITERATIVE)).toEqual([]) + expect(tree.dfs(n => n.key, 'in', tree.root, IterationType.ITERATIVE)).toEqual([]); tree.clear(); for (let i = 0; i < 1000; i++) { - tree.add(getRandomInt(-100, 1000)) - tree.delete(getRandomInt(-100, 1000)) + tree.add(getRandomInt(-100, 1000)); + tree.delete(getRandomInt(-100, 1000)); } // TODO there is a bug when dfs the tree with NIL node @@ -482,7 +472,6 @@ describe('RedBlackTree', () => { const arr = getRandomIntArray(HUNDRED_THOUSAND, 0, HUNDRED_THOUSAND, true); const competitor = new OrderedMap(); - it('should fix the tree after large scale insertion and deletion', () => { tree.clear(); const tS = performance.now(); @@ -497,6 +486,5 @@ describe('RedBlackTree', () => { competitor.setElement(arr[i], arr[i]); } console.log(performance.now() - cS); - }); }); diff --git a/test/unit/data-structures/binary-tree/tree-multimap.test.ts b/test/unit/data-structures/binary-tree/tree-multimap.test.ts index 577eeb7..b4d76f1 100644 --- a/test/unit/data-structures/binary-tree/tree-multimap.test.ts +++ b/test/unit/data-structures/binary-tree/tree-multimap.test.ts @@ -207,7 +207,7 @@ describe('TreeMultimap operations test', () => { }); it('should perform various operations on a Binary Search Tree with object values', () => { - const objTreeMultimap = new TreeMultimap<{ key: number; keyA: number }>(); + const objTreeMultimap = new TreeMultimap<{key: number; keyA: number}>(); expect(objTreeMultimap).toBeInstanceOf(TreeMultimap); objTreeMultimap.add(11, {key: 11, keyA: 11}); objTreeMultimap.add(3, {key: 3, keyA: 3}); @@ -447,7 +447,7 @@ describe('TreeMultimap operations test recursively', () => { }); it('should perform various operations on a Binary Search Tree with object values', () => { - const objTreeMultimap = new TreeMultimap<{ key: number; keyA: number }>(); + const objTreeMultimap = new TreeMultimap<{key: number; keyA: number}>(); expect(objTreeMultimap).toBeInstanceOf(TreeMultimap); objTreeMultimap.add(11, {key: 11, keyA: 11}); objTreeMultimap.add(3, {key: 3, keyA: 3}); diff --git a/test/unit/data-structures/graph/abstract-graph.test.ts b/test/unit/data-structures/graph/abstract-graph.test.ts index 1e44c0b..bc01496 100644 --- a/test/unit/data-structures/graph/abstract-graph.test.ts +++ b/test/unit/data-structures/graph/abstract-graph.test.ts @@ -22,12 +22,12 @@ class MyEdge extends AbstractEdge { } } -class MyGraph< - V = any, - E = any, - VO extends MyVertex = MyVertex, - EO extends MyEdge = MyEdge -> extends AbstractGraph { +class MyGraph = MyVertex, EO extends MyEdge = MyEdge> extends AbstractGraph< + V, + E, + VO, + EO +> { createVertex(key: VertexKey, value?: V): VO { return new MyVertex(key, value) as VO; } @@ -74,8 +74,7 @@ class MyGraph< describe('AbstractGraph Operation Test', () => { const myGraph: MyGraph = new MyGraph(); - beforeEach(() => { - }); + beforeEach(() => {}); it('should edge cases', function () { myGraph.addVertex('A', 1); myGraph.addVertex('B', 2); diff --git a/test/unit/data-structures/graph/directed-graph.test.ts b/test/unit/data-structures/graph/directed-graph.test.ts index c8a1d9d..362e480 100644 --- a/test/unit/data-structures/graph/directed-graph.test.ts +++ b/test/unit/data-structures/graph/directed-graph.test.ts @@ -126,12 +126,12 @@ class MyEdge extends DirectedEdge { } } -class MyDirectedGraph< - V = any, - E = any, - VO extends MyVertex = MyVertex, - EO extends MyEdge = MyEdge -> extends DirectedGraph { +class MyDirectedGraph = MyVertex, EO extends MyEdge = MyEdge> extends DirectedGraph< + V, + E, + VO, + EO +> { createVertex(key: VertexKey, value: V): VO { return new MyVertex(key, value) as VO; } @@ -351,29 +351,9 @@ describe('Inherit from DirectedGraph and perform operations test2.', () => { expect(costs[2]).toEqual([3, 15, 38, 17, 35, Infinity, 64, Infinity, 22]); expect(costs[3]).toEqual([123, 135, 120, 137, 155, Infinity, 47, Infinity, 126]); expect(costs[4]).toEqual([133, 145, 130, 147, 165, Infinity, 57, Infinity, 136]); - expect(costs[5]).toEqual([ - Infinity, - Infinity, - Infinity, - Infinity, - Infinity, - Infinity, - Infinity, - Infinity, - Infinity - ]); + expect(costs[5]).toEqual([Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity]); expect(costs[6]).toEqual([76, 88, 73, 90, 108, Infinity, 137, Infinity, 79]); - expect(costs[7]).toEqual([ - Infinity, - Infinity, - Infinity, - Infinity, - Infinity, - Infinity, - Infinity, - Infinity, - Infinity - ]); + expect(costs[7]).toEqual([Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity, Infinity]); expect(costs[8]).toEqual([173, 185, 170, 187, 205, Infinity, 97, Infinity, 176]); expect(predecessor).toBeInstanceOf(Array); diff --git a/test/unit/data-structures/graph/undirected-graph.test.ts b/test/unit/data-structures/graph/undirected-graph.test.ts index 454b259..e8aad56 100644 --- a/test/unit/data-structures/graph/undirected-graph.test.ts +++ b/test/unit/data-structures/graph/undirected-graph.test.ts @@ -150,7 +150,7 @@ describe('UndirectedGraph', () => { }); it('should getAllPathsBetween work well in 66 vertexes 97 edges graph', () => { - const graph = new UndirectedGraph<{ name: string }, number>(); + const graph = new UndirectedGraph<{name: string}, number>(); for (const v of saltyVertexes) { graph.addVertex(v.name, v); } diff --git a/test/unit/data-structures/heap/heap.test.ts b/test/unit/data-structures/heap/heap.test.ts index 24ea8d6..1f9d5b4 100644 --- a/test/unit/data-structures/heap/heap.test.ts +++ b/test/unit/data-structures/heap/heap.test.ts @@ -22,7 +22,7 @@ describe('Heap Operation Test', () => { }); it('should object heap work well', function () { - const minHeap = new MinHeap<{ a: string; key: number }>({comparator: (a, b) => a.key - b.key}); + const minHeap = new MinHeap<{a: string; key: number}>({comparator: (a, b) => a.key - b.key}); minHeap.add({key: 1, a: 'a1'}); minHeap.add({key: 6, a: 'a6'}); minHeap.add({key: 2, a: 'a2'}); @@ -37,7 +37,7 @@ describe('Heap Operation Test', () => { i++; } - const maxHeap = new MaxHeap<{ key: number; a: string }>({comparator: (a, b) => b.key - a.key}); + const maxHeap = new MaxHeap<{key: number; a: string}>({comparator: (a, b) => b.key - a.key}); maxHeap.add({key: 1, a: 'a1'}); maxHeap.add({key: 6, a: 'a6'}); maxHeap.add({key: 5, a: 'a5'}); @@ -45,14 +45,7 @@ describe('Heap Operation Test', () => { maxHeap.add({key: 0, a: 'a0'}); maxHeap.add({key: 9, a: 'a9'}); expect(maxHeap.peek()).toEqual({a: 'a9', key: 9}); - expect(maxHeap.toArray().map(item => ({a: item.a}))).toEqual([ - {a: 'a9'}, - {a: 'a2'}, - {a: 'a6'}, - {a: 'a1'}, - {a: 'a0'}, - {a: 'a5'} - ]); + expect(maxHeap.toArray().map(item => ({a: item.a}))).toEqual([{a: 'a9'}, {a: 'a2'}, {a: 'a6'}, {a: 'a1'}, {a: 'a0'}, {a: 'a5'}]); const maxExpectPolled = [{a: 'a9'}, {a: 'a6'}, {a: 'a5'}, {a: 'a2'}, {a: 'a1'}, {a: 'a0'}]; let maxI = 0; while (maxHeap.size > 0) { diff --git a/test/unit/data-structures/linked-list/doubly-linked-list.test.ts b/test/unit/data-structures/linked-list/doubly-linked-list.test.ts index 139e4a3..7ca69fa 100644 --- a/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +++ b/test/unit/data-structures/linked-list/doubly-linked-list.test.ts @@ -60,7 +60,7 @@ describe('DoublyLinkedList Operation Test', () => { describe('DoublyLinkedList Operation Test', () => { let list: DoublyLinkedList; - let objectList: DoublyLinkedList<{ keyA: number }>; + let objectList: DoublyLinkedList<{keyA: number}>; beforeEach(() => { list = new DoublyLinkedList(); diff --git a/test/unit/data-structures/linked-list/singly-linked-list.test.ts b/test/unit/data-structures/linked-list/singly-linked-list.test.ts index cff8104..a80fb87 100644 --- a/test/unit/data-structures/linked-list/singly-linked-list.test.ts +++ b/test/unit/data-structures/linked-list/singly-linked-list.test.ts @@ -11,10 +11,10 @@ describe('SinglyLinkedListNode', () => { describe('SinglyLinkedList Operation Test', () => { let list: SinglyLinkedList; - let objectList: SinglyLinkedList<{ keyA: number }>; + let objectList: SinglyLinkedList<{keyA: number}>; beforeEach(() => { list = new SinglyLinkedList(); - objectList = new SinglyLinkedList<{ keyA: number }>(); + objectList = new SinglyLinkedList<{keyA: number}>(); }); describe('push', () => { diff --git a/test/unit/data-structures/priority-queue/max-priority-queue.test.ts b/test/unit/data-structures/priority-queue/max-priority-queue.test.ts index b2609b6..844c21b 100644 --- a/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +++ b/test/unit/data-structures/priority-queue/max-priority-queue.test.ts @@ -16,7 +16,7 @@ describe('MaxPriorityQueue Operation Test', () => { }); it('should add elements and maintain heap property in a object MaxPriorityQueue', () => { - const priorityQueue = new MaxPriorityQueue<{ keyA: number }>({comparator: (a, b) => b.keyA - a.keyA}); + const priorityQueue = new MaxPriorityQueue<{keyA: number}>({comparator: (a, b) => b.keyA - a.keyA}); priorityQueue.refill([{keyA: 5}, {keyA: 3}, {keyA: 1}]); priorityQueue.add({keyA: 7}); @@ -63,7 +63,7 @@ describe('MaxPriorityQueue Operation Test', () => { it('should correctly heapify an object array', () => { const nodes = [{keyA: 5}, {keyA: 3}, {keyA: 7}, {keyA: 1}]; - const maxPQ = MaxPriorityQueue.heapify<{ keyA: number }>({nodes: nodes, comparator: (a, b) => b.keyA - a.keyA}); + const maxPQ = MaxPriorityQueue.heapify<{keyA: number}>({nodes: nodes, comparator: (a, b) => b.keyA - a.keyA}); expect(maxPQ.poll()?.keyA).toBe(7); expect(maxPQ.poll()?.keyA).toBe(5); diff --git a/test/unit/data-structures/priority-queue/priority-queue.test.ts b/test/unit/data-structures/priority-queue/priority-queue.test.ts index 312b2e7..463f469 100644 --- a/test/unit/data-structures/priority-queue/priority-queue.test.ts +++ b/test/unit/data-structures/priority-queue/priority-queue.test.ts @@ -1,6 +1,6 @@ import {PriorityQueue} from '../../../../src'; import {PriorityQueue as CPriorityQueue} from 'js-sdsl'; -import {isDebugTest} from "../../../config"; +import {isDebugTest} from '../../../config'; const isDebug = isDebugTest; describe('PriorityQueue Operation Test', () => { @@ -13,9 +13,9 @@ describe('PriorityQueue Operation Test', () => { minPQ.poll(); expect(minPQ.toArray()).toEqual([4, 5, 6]); expect(minPQ.peek()).toBe(4); - expect(PriorityQueue.heapify({nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10], comparator: (a, b) => a - b}).toArray()).toEqual( - [1, 2, 3, 5, 6, 7, 8, 9, 10] - ); + expect(PriorityQueue.heapify({nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10], comparator: (a, b) => a - b}).toArray()).toEqual([ + 1, 2, 3, 5, 6, 7, 8, 9, 10 + ]); }); it('should Max PriorityQueue poll, peek, heapify, toArray work well', function () { @@ -27,9 +27,9 @@ describe('PriorityQueue Operation Test', () => { maxPriorityQueue.poll(); expect(maxPriorityQueue.toArray()).toEqual([3, 2, 1]); expect(maxPriorityQueue.peek()).toBe(3); - expect(PriorityQueue.heapify({nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10], comparator: (a, b) => a - b}).toArray()).toEqual( - [1, 2, 3, 5, 6, 7, 8, 9, 10] - ); + expect(PriorityQueue.heapify({nodes: [3, 2, 1, 5, 6, 7, 8, 9, 10], comparator: (a, b) => a - b}).toArray()).toEqual([ + 1, 2, 3, 5, 6, 7, 8, 9, 10 + ]); }); it('should PriorityQueue clone, sort, getNodes, dfs work well', function () { diff --git a/test/utils/big-o.ts b/test/utils/big-o.ts index e46c2ff..5d5d906 100644 --- a/test/utils/big-o.ts +++ b/test/utils/big-o.ts @@ -32,7 +32,7 @@ export const bigO = { function findPotentialN(input: any): number { let longestArray: any[] = []; - let mostProperties: { [key: string]: any } = {}; + let mostProperties: {[key: string]: any} = {}; function recurse(obj: any) { if (Array.isArray(obj)) { diff --git a/test/utils/json2html.ts b/test/utils/json2html.ts index 8eefe33..b3b6e3e 100644 --- a/test/utils/json2html.ts +++ b/test/utils/json2html.ts @@ -14,9 +14,7 @@ function makeLabelDiv(options: any, level: number, keyName: string | number, dat return `
${keyName} 
`; } else if (typeof keyName === 'string') { if (datatype === 'array') { - return `
${keyName}
`; + return `
${keyName}
`; } else if (datatype === 'object') { return `
_render(idx.toString(), val, options, level + 1, idx % 2)) - .join("
") + + data.map((val: any, idx: number) => _render(idx.toString(), val, options, level + 1, idx % 2)).join("
") + '
'; } return `