Skip to content

test: Put tests together in one file #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
* Heap
* [Heap](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/heap/heap.ts)
* Test
* [Max Heap.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/heap/test/max_heap.test.ts)
* [Min Heap.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/heap/test/min_heap.test.ts)
* [Heap.Test](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/heap/test/heap.test.ts)
* List
* [Doubly Linked List](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/list/doubly_linked_list.ts)
* [Linked List](https://github.com/TheAlgorithms/TypeScript/blob/HEAD/data_structures/list/linked_list.ts)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,57 @@
import { MinHeap, PriorityQueue } from "../heap";
import { MaxHeap, MinHeap, PriorityQueue } from "../heap";

describe("MaxHeap", () => {
let heap: MaxHeap<number>;
const elements: number[] = [
12, 4, 43, 42, 9, 7, 39, 16, 55, 1, 51, 34, 81, 18,
];

beforeEach(() => {
heap = new MaxHeap();
for (let element of elements) {
heap.insert(element);
}
});

it("should initialize a heap from input array", () => {
expect(heap.isEmpty()).toEqual(false);
heap.check();
});

it("should remove and return the max element in the heap", () => {
const maxValue = heap.extract();

expect(maxValue).toEqual(81);
heap.check();
});

it("should insert a new element and bubble Up the element to it correct index in the heap", () => {
heap.insert(61);
heap.check();
});

const extract_all = (heap: MaxHeap<number>) => {
[...elements].sort((a, b) => b - a).forEach((element: number) => {
expect(heap.extract()).toEqual(element);
});
heap.check();
expect(heap.size()).toEqual(0);
}

it("should remove and return the max elements in order", () => {
extract_all(heap);
});

it("should insert all, then remove and return the max elements in order", () => {
heap = new MaxHeap();
elements.forEach((element: number) => {
heap.insert(element);
});
heap.check();
expect(heap.size()).toEqual(elements.length);
extract_all(heap);
});
});

describe("MinHeap", () => {
let heap: MinHeap<number>;
Expand Down
54 changes: 0 additions & 54 deletions data_structures/heap/test/max_heap.test.ts

This file was deleted.