2023-11-23 10:40:30 +00:00
|
|
|
import {
|
2023-11-23 13:43:45 +00:00
|
|
|
AVLTree,
|
|
|
|
BinaryTree,
|
|
|
|
BST,
|
2023-11-23 10:40:30 +00:00
|
|
|
Deque,
|
|
|
|
DoublyLinkedList,
|
2023-11-25 14:32:09 +00:00
|
|
|
HashMap,
|
|
|
|
Heap,
|
2023-11-23 10:40:30 +00:00
|
|
|
MaxHeap,
|
|
|
|
MaxPriorityQueue,
|
|
|
|
MinHeap,
|
|
|
|
MinPriorityQueue,
|
|
|
|
Queue,
|
2023-11-23 13:43:45 +00:00
|
|
|
RedBlackTree,
|
2023-11-23 10:40:30 +00:00
|
|
|
SinglyLinkedList,
|
2023-11-23 13:43:45 +00:00
|
|
|
Stack,
|
2023-11-25 14:32:09 +00:00
|
|
|
TreeMultimap,
|
|
|
|
Trie
|
2023-11-23 10:40:30 +00:00
|
|
|
} from '../../src';
|
2023-11-23 13:43:45 +00:00
|
|
|
import { isDebugTest } from "../config";
|
2023-11-23 10:40:30 +00:00
|
|
|
|
2023-11-23 13:43:45 +00:00
|
|
|
const isDebug = isDebugTest;
|
2023-11-23 10:40:30 +00:00
|
|
|
const orgArr: number[] = [6, 1, 2, 7, 5, 3, 4, 9, 8];
|
2023-11-25 14:32:09 +00:00
|
|
|
const orgStrArr: string[] = [
|
|
|
|
"trie",
|
|
|
|
"trial",
|
|
|
|
"trick",
|
|
|
|
"trip",
|
|
|
|
"tree",
|
|
|
|
"trend",
|
|
|
|
"triangle",
|
|
|
|
"track",
|
|
|
|
"trace",
|
|
|
|
"transmit"
|
|
|
|
];
|
2023-11-23 13:43:45 +00:00
|
|
|
const entries: [number, number][] = [[6, 6], [1, 1], [2, 2], [7, 7], [5, 5], [3, 3], [4, 4], [9, 9], [8, 8]];
|
|
|
|
|
2023-11-23 10:40:30 +00:00
|
|
|
describe('conversions', () => {
|
|
|
|
it('Array to Queue', () => {
|
|
|
|
const q = new Queue<number>(orgArr);
|
2023-11-23 13:43:45 +00:00
|
|
|
isDebug && q.print();
|
2023-11-23 10:40:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Array to Deque', () => {
|
|
|
|
const dq = new Deque<number>(orgArr);
|
2023-11-23 13:43:45 +00:00
|
|
|
isDebug && dq.print();
|
2023-11-23 10:40:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Array to SinglyLinkedList', () => {
|
|
|
|
const sl = new SinglyLinkedList<number>(orgArr);
|
2023-11-23 13:43:45 +00:00
|
|
|
isDebug && sl.print();
|
2023-11-23 10:40:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Array to DoublyLinkedList', () => {
|
|
|
|
const dl = new DoublyLinkedList<number>(orgArr);
|
2023-11-23 13:43:45 +00:00
|
|
|
isDebug && dl.print();
|
2023-11-23 10:40:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Array to Stack', () => {
|
|
|
|
const stack = new Stack<number>(orgArr);
|
2023-11-23 13:43:45 +00:00
|
|
|
isDebug && stack.print();
|
2023-11-23 10:40:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Array to MinHeap', () => {
|
|
|
|
const minHeap = new MinHeap<number>(orgArr);
|
2023-11-23 13:43:45 +00:00
|
|
|
isDebug && minHeap.print();
|
2023-11-23 10:40:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Array to MaxHeap', () => {
|
|
|
|
const maxHeap = new MaxHeap<number>(orgArr);
|
2023-11-23 13:43:45 +00:00
|
|
|
isDebug && maxHeap.print();
|
2023-11-23 10:40:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Array to MinPriorityQueue', () => {
|
|
|
|
const minPQ = new MinPriorityQueue<number>(orgArr);
|
2023-11-23 13:43:45 +00:00
|
|
|
isDebug && minPQ.print();
|
2023-11-23 10:40:30 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Array to MaxPriorityQueue', () => {
|
|
|
|
const maxPQ = new MaxPriorityQueue<number>(orgArr);
|
2023-11-23 13:43:45 +00:00
|
|
|
isDebug && maxPQ.print();
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Entry Array to BinaryTree', () => {
|
|
|
|
const biTree = new BinaryTree<number>(entries);
|
|
|
|
isDebug && biTree.print();
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Entry Array to BST', () => {
|
2023-11-25 14:32:09 +00:00
|
|
|
const bst = new BST<number>(entries);
|
2023-11-23 13:43:45 +00:00
|
|
|
expect(bst.size).toBe(9)
|
|
|
|
isDebug && bst.print();
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Entry Array to RedBlackTree', () => {
|
2023-11-25 14:32:09 +00:00
|
|
|
const rbTree = new RedBlackTree<number>(entries);
|
2023-11-23 13:43:45 +00:00
|
|
|
expect(rbTree.size).toBe(9)
|
|
|
|
isDebug && rbTree.print();
|
2023-11-23 10:40:30 +00:00
|
|
|
})
|
2023-11-23 13:43:45 +00:00
|
|
|
|
|
|
|
it('Entry Array to AVLTree', () => {
|
2023-11-25 14:32:09 +00:00
|
|
|
const avl = new AVLTree<number>(entries);
|
2023-11-23 13:43:45 +00:00
|
|
|
expect(avl.size).toBe(9)
|
|
|
|
isDebug && avl.print();
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Entry Array to TreeMultimap', () => {
|
2023-11-25 14:32:09 +00:00
|
|
|
const treeMulti = new TreeMultimap<number>(entries);
|
2023-11-23 13:43:45 +00:00
|
|
|
expect(treeMulti.size).toBe(9)
|
|
|
|
isDebug && treeMulti.print();
|
|
|
|
})
|
2023-11-25 14:32:09 +00:00
|
|
|
|
|
|
|
it('HashMap to RedBlackTree', () => {
|
|
|
|
const hm = new HashMap(entries);
|
|
|
|
isDebug && hm.print()
|
|
|
|
const rbTree = new RedBlackTree<number>(hm);
|
|
|
|
expect(rbTree.size).toBe(9)
|
|
|
|
isDebug && rbTree.print();
|
|
|
|
})
|
|
|
|
|
|
|
|
it('PriorityQueue to BST', () => {
|
|
|
|
const pq = new MinPriorityQueue(orgArr);
|
|
|
|
isDebug && pq.print();
|
|
|
|
const bst = new BST<number>(pq);
|
|
|
|
expect(bst.size).toBe(9)
|
|
|
|
isDebug && bst.print();
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Deque to RedBlackTree', () => {
|
|
|
|
const dq = new Deque(orgArr);
|
|
|
|
isDebug && dq.print();
|
|
|
|
const rbTree = new RedBlackTree<number>(dq);
|
|
|
|
expect(rbTree.size).toBe(9)
|
|
|
|
isDebug && rbTree.print();
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Trie to Heap to Deque', () => {
|
|
|
|
const trie = new Trie(orgStrArr);
|
|
|
|
expect(trie.size).toBe(10);
|
|
|
|
isDebug && trie.print();
|
|
|
|
const heap = new Heap<string>(trie, { comparator: (a, b) => Number(a) - Number(b) });
|
|
|
|
expect(heap.size).toBe(10);
|
|
|
|
isDebug && heap.print();
|
|
|
|
const dq = new Deque<string>(heap);
|
|
|
|
expect(dq.size).toBe(10);
|
|
|
|
isDebug && dq.print();
|
|
|
|
const entries = dq.map((el, i) => <[number, string]>[i, el]);
|
2023-12-04 13:58:41 +00:00
|
|
|
const avl = new AVLTree<number, string>(entries);
|
2023-11-25 14:32:09 +00:00
|
|
|
expect(avl.size).toBe(10)
|
|
|
|
isDebug && avl.print();
|
|
|
|
})
|
|
|
|
|
2023-11-23 13:43:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|