-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueue-with-dll.test.ts
38 lines (34 loc) · 1.25 KB
/
queue-with-dll.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { QueueWithDoubleLinkedList } from './queue-with-dll';
type TaskType = 'wake-up' | 'breakfast' | 'work' | 'lunch' | 'dinner' | 'sleep';
describe('QueueWithDLL', () => {
it('should create an instance', () => {
const queue = new QueueWithDoubleLinkedList<TaskType>();
expect(queue).toBeTruthy();
expect(queue.length).toBe(0);
expect(queue.toArray()).toEqual([]);
});
it('should enqueue', () => {
const queue = new QueueWithDoubleLinkedList<TaskType>();
expect(queue.toArray()).toEqual([]);
expect(queue.length).toBe(0);
queue.enqueue('wake-up');
expect(queue.length).toBe(1);
queue.enqueue('breakfast');
expect(queue.length).toBe(2);
expect(queue.toArray()).toEqual(['wake-up', 'breakfast']);
});
it('should dequeue', () => {
const queue = new QueueWithDoubleLinkedList<TaskType>();
expect(queue.length).toBe(0);
queue.enqueue('wake-up');
expect(queue.length).toBe(1);
queue.enqueue('work');
expect(queue.length).toBe(2);
expect(queue.toArray()).toEqual(['wake-up', 'work']);
expect(queue.dequeue()).toBe('wake-up');
expect(queue.length).toBe(1);
expect(queue.dequeue()).toBe('work');
expect(queue.length).toBe(0);
expect(queue.toArray()).toEqual([]);
});
});