Skip to content

Commit a5ff35b

Browse files
committed
Create test.ts
1 parent b9fc1e1 commit a5ff35b

File tree

1 file changed

+16
-0
lines changed
  • design-front-middle-back-queue

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import FrontMiddleBackQueue from "./index.ts";
2+
import { assertEquals } from 'https://deno.land/[email protected]/testing/asserts.ts';
3+
Deno.test("design-front-middle-back-queue", () => {
4+
const res: Array<number> = [];
5+
const q: FrontMiddleBackQueue = new FrontMiddleBackQueue();
6+
q.pushFront(1); // [1]
7+
q.pushBack(2); // [1, 2]
8+
q.pushMiddle(3); // [1, 3, 2]
9+
q.pushMiddle(4); // [1, 4, 3, 2]
10+
res.push(q.popFront()); // 返回 1 -> [4, 3, 2]
11+
res.push(q.popMiddle()); // 返回 3 -> [4, 2]
12+
res.push(q.popMiddle()); // 返回 4 -> [2]
13+
res.push(q.popBack()); // 返回 2 -> []
14+
res.push(q.popFront()); // 返回 -1 -> [] (队列为空)
15+
assertEquals(res, [1, 3, 4, 2, -1]);
16+
});

0 commit comments

Comments
 (0)