test: 新增测试代码文件

This commit is contained in:
claude-code-best
2026-04-02 14:44:56 +08:00
parent 9c3803d16b
commit 006ad97fbb
32 changed files with 1102 additions and 68 deletions

View File

@@ -83,4 +83,20 @@ describe("CircularBuffer", () => {
buf.add("c");
expect(buf.toArray()).toEqual(["b", "c"]);
});
test("capacity=1 keeps only the most recent item", () => {
const buf = new CircularBuffer<number>(1);
buf.add(10);
expect(buf.toArray()).toEqual([10]);
buf.add(20);
expect(buf.toArray()).toEqual([20]);
buf.add(30);
expect(buf.toArray()).toEqual([30]);
expect(buf.getRecent(1)).toEqual([30]);
});
test("getRecent on empty buffer returns empty array", () => {
const buf = new CircularBuffer<number>(5);
expect(buf.getRecent(3)).toEqual([]);
});
});