forked from TheAlgorithms/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular_queue.test.ts
More file actions
65 lines (48 loc) · 1.4 KB
/
Copy pathcircular_queue.test.ts
File metadata and controls
65 lines (48 loc) · 1.4 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { CircularQueue } from '../circular_queue'
describe('Circular Queue', () => {
let queue: CircularQueue<number>
beforeEach(() => {
queue = new CircularQueue(5)
})
it('should enqueue an element', () => {
queue.enqueue(1)
expect(queue.peek()).toBe(1)
})
it('should throw an error on enqueue when queue is full', () => {
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(3)
queue.enqueue(4)
queue.enqueue(5)
expect(() => queue.enqueue(6)).toThrowError('Queue is full')
})
it('should dequeue an element', () => {
queue.enqueue(1)
queue.enqueue(2)
expect(queue.dequeue()).toBe(1)
})
it('should throw an error on dequeue when queue is empty', () => {
expect(() => queue.dequeue()).toThrowError('Queue is empty')
})
it('should peek an element', () => {
queue.enqueue(1)
queue.enqueue(2)
expect(queue.peek()).toBe(1)
})
it('should return null on peek when queue is empty', () => {
expect(queue.peek()).toBeNull()
})
it('should return true on isEmpty when queue is empty', () => {
expect(queue.isEmpty()).toBeTruthy()
})
it('should return false on isEmpty when queue is not empty', () => {
queue.enqueue(1)
expect(queue.isEmpty()).toBeFalsy()
})
it('should return the correct length', () => {
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(3)
expect(queue.length()).toBe(3)
})
})