[test] test bug fixed

This commit is contained in:
Revone 2023-10-11 23:36:10 +08:00
parent 071cea8bd0
commit afd99bdf97
7 changed files with 20 additions and 26 deletions

View file

@ -28,7 +28,7 @@
"check:deps": "dependency-cruiser src",
"changelog": "auto-changelog",
"coverage:badge": "istanbul-badges-readme",
"ci": "env && npm run lint && npm run build && npm run test && git fetch --tags && npm run changelog"
"ci": "env && npm run lint && npm run build && npm run update:individuals && npm run test && git fetch --tags && npm run changelog"
},
"repository": {
"type": "git",

View file

@ -31,12 +31,12 @@ describe('AVL Tree Test', () => {
// node15 has type problem. After the uniform design, the generics of containers (DirectedGraph, BST) are based on the type of value. However, this design has a drawback: when I attempt to inherit from the Vertex or BSTNode classes, the types of the results obtained by all methods are those of the parent class.
expect(node15?.val).toBe(15);
const dfs = tree.DFS('in', 'node');
const dfs = tree.dfs('in', 'node');
expect(dfs[0].key).toBe(1);
expect(dfs[dfs.length - 1].key).toBe(16);
tree.perfectlyBalance();
const bfs = tree.BFS('node');
const bfs = tree.bfs('node');
expect(tree.isPerfectlyBalanced()).toBe(true);
expect(bfs[0].key).toBe(8);
expect(bfs[bfs.length - 1].key).toBe(16);
@ -95,12 +95,12 @@ describe('AVL Tree Test', () => {
expect(tree.getHeight()).toBe(1);
expect(tree.isAVLBalanced()).toBe(true);
const lastBFSIds = tree.BFS();
const lastBFSIds = tree.bfs();
expect(lastBFSIds[0]).toBe(12);
expect(lastBFSIds[1]).toBe(2);
expect(lastBFSIds[2]).toBe(16);
const lastBFSNodes = tree.BFS('node');
const lastBFSNodes = tree.bfs('node');
expect(lastBFSNodes[0].key).toBe(12);
expect(lastBFSNodes[1].key).toBe(2);
expect(lastBFSNodes[2].key).toBe(16);

View file

@ -44,14 +44,14 @@ describe('Individual package BST operations test', () => {
const node11 = bst.get(11);
expect(node11).toBeInstanceOf(BSTNode);
const dfsInorderNodes = bst.DFS('in', 'node');
const dfsInorderNodes = bst.dfs('in', 'node');
expect(dfsInorderNodes[0].key).toBe(1);
expect(dfsInorderNodes[dfsInorderNodes.length - 1].key).toBe(16);
bst.perfectlyBalance();
expect(bst.isPerfectlyBalanced()).toBe(true);
const bfsNodesAfterBalanced = bst.BFS('node');
const bfsNodesAfterBalanced = bst.bfs('node');
expect(bfsNodesAfterBalanced[0].key).toBe(8);
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);
@ -169,12 +169,12 @@ describe('Individual package BST operations test', () => {
expect(bst.isAVLBalanced()).toBe(false);
const bfsIDs = bst.BFS();
const bfsIDs = bst.bfs();
expect(bfsIDs[0]).toBe(2);
expect(bfsIDs[1]).toBe(12);
expect(bfsIDs[2]).toBe(16);
const bfsNodes = bst.BFS('node');
const bfsNodes = bst.bfs('node');
expect(bfsNodes[0].key).toBe(2);
expect(bfsNodes[1].key).toBe(12);
expect(bfsNodes[2].key).toBe(16);
@ -242,14 +242,14 @@ describe('Individual package BST operations test', () => {
const node11 = objBST.get(11);
expect(node11).toBeInstanceOf(BSTNode);
const dfsInorderNodes = objBST.DFS('in', 'node');
const dfsInorderNodes = objBST.dfs('in', 'node');
expect(dfsInorderNodes[0].key).toBe(1);
expect(dfsInorderNodes[dfsInorderNodes.length - 1].key).toBe(16);
objBST.perfectlyBalance();
expect(objBST.isPerfectlyBalanced()).toBe(true);
const bfsNodesAfterBalanced = objBST.BFS('node');
const bfsNodesAfterBalanced = objBST.bfs('node');
expect(bfsNodesAfterBalanced[0].key).toBe(8);
expect(bfsNodesAfterBalanced[bfsNodesAfterBalanced.length - 1].key).toBe(16);
@ -367,12 +367,12 @@ describe('Individual package BST operations test', () => {
expect(objBST.isAVLBalanced()).toBe(false);
const bfsIDs = objBST.BFS();
const bfsIDs = objBST.bfs();
expect(bfsIDs[0]).toBe(2);
expect(bfsIDs[1]).toBe(12);
expect(bfsIDs[2]).toBe(16);
const bfsNodes = objBST.BFS('node');
const bfsNodes = objBST.bfs('node');
expect(bfsNodes[0].key).toBe(2);
expect(bfsNodes[1].key).toBe(12);
expect(bfsNodes[2].key).toBe(16);

View file

@ -1,4 +1,4 @@
import {DirectedEdge, DirectedGraph, DirectedVertex, VertexId} from '../../../../src';
import {DirectedEdge, DirectedGraph, DirectedVertex, VertexKey} from '../../../../src';
describe('DirectedGraph Operation Test', () => {
let graph: DirectedGraph;
@ -63,7 +63,7 @@ describe('DirectedGraph Operation Test', () => {
});
class MyVertex<V extends string> extends DirectedVertex<V> {
constructor(key: VertexId, val?: V) {
constructor(key: VertexKey, val?: V) {
super(key, val);
this._data = val;
}
@ -80,7 +80,7 @@ class MyVertex<V extends string> extends DirectedVertex<V> {
}
class MyEdge<E extends string> extends DirectedEdge<E> {
constructor(v1: VertexId, v2: VertexId, weight?: number, val?: E) {
constructor(v1: VertexKey, v2: VertexKey, weight?: number, val?: E) {
super(v1, v2, weight, val);
this._data = val;
}
@ -97,11 +97,11 @@ class MyEdge<E extends string> extends DirectedEdge<E> {
}
class MyDirectedGraph<V extends MyVertex<string>, E extends MyEdge<string>> extends DirectedGraph<V, E> {
createVertex(key: VertexId, val: V['val']): V {
createVertex(key: VertexKey, val: V['val']): V {
return new MyVertex(key, val) as V;
}
createEdge(src: VertexId, dest: VertexId, weight?: number, val?: E['val']): E {
createEdge(src: VertexKey, dest: VertexKey, weight?: number, val?: E['val']): E {
return new MyEdge(src, dest, weight ?? 1, val) as E;
}
}

View file

@ -1,2 +0,0 @@
export * from './directed-graph.test';
export * from './undirected-graph.test';

View file

@ -29,8 +29,8 @@ describe('Overall Graph Operation Test', () => {
graph.addEdge('A', 'B');
graph.addEdge('B', 'C');
const topologicalOrderIds = graph.topologicalSort();
expect(topologicalOrderIds).toEqual(['A', 'B', 'C']);
const topologicalOrderKeys = graph.topologicalSort();
expect(topologicalOrderKeys).toEqual(['A', 'B', 'C']);
});
it('Overall UndirectedGraph Operation Test', () => {
const graph = new UndirectedGraph();

View file

@ -1,4 +0,0 @@
export * from './singly-linked-list.test';
export * from './doubly-linked-list.test';
export * from './linked-list.test';
export * from './skip-linked-list.test';