[pkgs] all sub packages add unit test cases

This commit is contained in:
Revone 2023-10-08 18:25:29 +08:00
parent 40ad74f609
commit f4d234df29
5 changed files with 48 additions and 48 deletions

View file

@ -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)

View file

@ -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",

View file

@ -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<number>(1, 42);
const node: BinaryTreeNode<number> = new BinaryTreeNode<number>(1, 42);
expect(node.val).toBe(42);
node.val = 55;

View file

@ -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<number>({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<number>({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<number>({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]);
});
});

View file

@ -15,6 +15,48 @@ describe('PriorityQueue Operation Test', () => {
})
).toBe(false);
});
it('should PriorityQueue poll, pee, heapify, toArray work well', function () {
const minPQ = new PriorityQueue<number>({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<number>({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<number>({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));
});
});