From f4d234df29e83f9a5bc010c118444987c6fbe3d1 Mon Sep 17 00:00:00 2001 From: Revone Date: Sun, 8 Oct 2023 18:25:29 +0800 Subject: [PATCH] [pkgs] all sub packages add unit test cases --- CHANGELOG.md | 2 +- package.json | 2 +- .../binary-tree/binary-tree.test.ts | 5 +-- .../priority-queue/min-priority-queue.test.ts | 44 +------------------ .../priority-queue/priority-queue.test.ts | 43 ++++++++++++++++++ 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cbd8e0..7d00877 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. - [Semantic Versioning](https://semver.org/spec/v2.0.0.html) - [`auto-changelog`](https://github.com/CookPete/auto-changelog) -## [v1.34.2](https://github.com/zrwusa/data-structure-typed/compare/v1.34.1...main) (upcoming) +## [v1.34.3](https://github.com/zrwusa/data-structure-typed/compare/v1.34.1...main) (upcoming) ## [v1.34.1](https://github.com/zrwusa/data-structure-typed/compare/v1.33.4...v1.34.1) (6 October 2023) diff --git a/package.json b/package.json index cd24e42..47dc859 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "data-structure-typed", - "version": "1.34.3", + "version": "1.34.5", "description": "Data Structures of Javascript & TypeScript. Binary Tree, BST, Graph, Heap, Priority Queue, Linked List, Queue, Deque, Stack, AVL Tree, Tree Multiset, Trie, Directed Graph, Undirected Graph, Singly Linked List, Doubly Linked List, Max Heap, Max Priority Queue, Min Heap, Min Priority Queue.", "main": "dist/index.js", "module": "lib/index.js", 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 4edd3a8..26c7ec5 100644 --- a/test/unit/data-structures/binary-tree/binary-tree.test.ts +++ b/test/unit/data-structures/binary-tree/binary-tree.test.ts @@ -1,5 +1,4 @@ -import {BinaryTreeNode} from '../../../../src'; -import {BinaryTree} from 'binary-tree-typed'; +import {BinaryTree, BinaryTreeNode} from '../../../../src'; describe('BinaryTreeNode', () => { it('should create an instance of BinaryTreeNode', () => { @@ -16,7 +15,7 @@ describe('BinaryTreeNode', () => { }); it('should set and get the value correctly', () => { - const node = new BinaryTreeNode(1, 42); + const node: BinaryTreeNode = new BinaryTreeNode(1, 42); expect(node.val).toBe(42); node.val = 55; diff --git a/test/unit/data-structures/priority-queue/min-priority-queue.test.ts b/test/unit/data-structures/priority-queue/min-priority-queue.test.ts index ae6e2e5..e80bab7 100644 --- a/test/unit/data-structures/priority-queue/min-priority-queue.test.ts +++ b/test/unit/data-structures/priority-queue/min-priority-queue.test.ts @@ -1,4 +1,4 @@ -import {MinPriorityQueue, PriorityQueue} from '../../../../src'; +import {MinPriorityQueue} from '../../../../src'; describe('MinPriorityQueue Operation Test', () => { it('should check if a node exists in the queue', () => { @@ -60,46 +60,4 @@ describe('MinPriorityQueue Operation Test', () => { const sortedArray = priorityQueue.sort(); expect(sortedArray).toEqual([1, 3, 5, 7]); }); - - it('should PriorityQueue poll, pee, heapify, toArray work well', function () { - const minPQ = new PriorityQueue({nodes: [5, 2, 3, 4, 6, 1], comparator: (a, b) => a - b}); - expect(minPQ.toArray()).toEqual([1, 2, 3, 4, 6, 5]); - minPQ.poll(); - minPQ.poll(); - 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]); - }); - - it('should Max PriorityQueue poll, peek, heapify, toArray work well', function () { - const maxPriorityQueue = new PriorityQueue({nodes: [5, 2, 3, 4, 6, 1], comparator: (a, b) => b - a}); - expect(maxPriorityQueue.toArray()).toEqual([6, 5, 3, 4, 2, 1]); - maxPriorityQueue.poll(); - maxPriorityQueue.poll(); - 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]); - }); - - it('should PriorityQueue clone, sort, getNodes, DFS work well', function () { - const minPQ1 = new PriorityQueue({nodes: [2, 5, 8, 3, 1, 6, 7, 4], comparator: (a, b) => a - b}); - const clonedPriorityQueue = minPQ1.clone(); - expect(clonedPriorityQueue.getNodes()).toEqual(minPQ1.getNodes()); - expect(clonedPriorityQueue.sort()).toEqual([1, 2, 3, 4, 5, 6, 7, 8]); - expect(minPQ1.DFS('in')).toEqual([4, 3, 2, 5, 1, 8, 6, 7]); - expect(minPQ1.DFS('post')).toEqual([4, 3, 5, 2, 8, 7, 6, 1]); - expect(minPQ1.DFS('pre')).toEqual([1, 2, 3, 4, 5, 6, 8, 7]); - }); }); 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 977a73e..e65777c 100644 --- a/test/unit/data-structures/priority-queue/priority-queue.test.ts +++ b/test/unit/data-structures/priority-queue/priority-queue.test.ts @@ -15,6 +15,48 @@ describe('PriorityQueue Operation Test', () => { }) ).toBe(false); }); + + it('should PriorityQueue poll, pee, heapify, toArray work well', function () { + const minPQ = new PriorityQueue({nodes: [5, 2, 3, 4, 6, 1], comparator: (a, b) => a - b}); + expect(minPQ.toArray()).toEqual([1, 2, 3, 4, 6, 5]); + minPQ.poll(); + minPQ.poll(); + 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]); + }); + + it('should Max PriorityQueue poll, peek, heapify, toArray work well', function () { + const maxPriorityQueue = new PriorityQueue({nodes: [5, 2, 3, 4, 6, 1], comparator: (a, b) => b - a}); + expect(maxPriorityQueue.toArray()).toEqual([6, 5, 3, 4, 2, 1]); + maxPriorityQueue.poll(); + maxPriorityQueue.poll(); + 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]); + }); + + it('should PriorityQueue clone, sort, getNodes, DFS work well', function () { + const minPQ1 = new PriorityQueue({nodes: [2, 5, 8, 3, 1, 6, 7, 4], comparator: (a, b) => a - b}); + const clonedPriorityQueue = minPQ1.clone(); + expect(clonedPriorityQueue.getNodes()).toEqual(minPQ1.getNodes()); + expect(clonedPriorityQueue.sort()).toEqual([1, 2, 3, 4, 5, 6, 7, 8]); + expect(minPQ1.DFS('in')).toEqual([4, 3, 2, 5, 1, 8, 6, 7]); + expect(minPQ1.DFS('post')).toEqual([4, 3, 5, 2, 8, 7, 6, 1]); + expect(minPQ1.DFS('pre')).toEqual([1, 2, 3, 4, 5, 6, 8, 7]); + }); }); describe('Priority Queue Performance Test', () => { @@ -25,3 +67,4 @@ describe('Priority Queue Performance Test', () => { expect(sorted).toEqual(values.sort((a, b) => a - b)); }); }); +