-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.spec.ts
More file actions
31 lines (30 loc) · 892 Bytes
/
Copy pathtest.spec.ts
File metadata and controls
31 lines (30 loc) · 892 Bytes
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
import ArrayQueue from './ArrayQueue';
import LinkedQueue from './LinkedQueue';
[0, 1].forEach((index) => {
describe(`测试${index === 0 ? '顺序' : '链式'}队列`, () => {
let queue: ArrayQueue<number> | LinkedQueue<number>;
const count = 1000;
beforeAll(() => {
queue = index === 0 ? new ArrayQueue() : new LinkedQueue();
});
it('测试入队列', () => {
for (let i = 0; i < count; i++) {
queue.enqueue(i);
}
});
it('测试出队列', () => {
for (let i = 0; i < count; i++) {
expect(queue.dequeue()).toBe(i);
}
expect(queue.dequeue()).toBeNull();
});
it('测试清空队列', () => {
for (let i = 0; i < count; i++) {
queue.enqueue(i);
expect(queue.getQueueCount()).toBe(i + 1);
}
queue.clear();
expect(queue.getQueueCount()).toBe(0);
});
});
});