mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-22 02:11:29 +00:00
Initial Move from Azure DevOps to GitHub
This commit is contained in:
33
src/Common/ObjectCache.test.ts
Normal file
33
src/Common/ObjectCache.test.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { ObjectCache } from "./ObjectCache";
|
||||
|
||||
describe("Object cache", () => {
|
||||
it("should keep size at or below limit", () => {
|
||||
const cache = new ObjectCache<number>(2);
|
||||
cache.set("a", 1);
|
||||
cache.set("b", 2);
|
||||
cache.set("c", 3);
|
||||
cache.set("d", 4);
|
||||
expect(cache.size()).toBe(2);
|
||||
});
|
||||
|
||||
it("should remove first added element to keep size at limit", () => {
|
||||
const cache = new ObjectCache<number>(2);
|
||||
cache.set("a", 1);
|
||||
cache.set("b", 2);
|
||||
cache.set("c", 3);
|
||||
expect(cache.has("a")).toBe(false);
|
||||
expect(cache.has("b")).toBe(true);
|
||||
expect(cache.has("c")).toBe(true);
|
||||
});
|
||||
|
||||
it("should remove first accessed element to keep size at limit", () => {
|
||||
const cache = new ObjectCache<number>(2);
|
||||
cache.set("a", 1);
|
||||
cache.set("b", 2);
|
||||
cache.get("a");
|
||||
cache.set("c", 3);
|
||||
expect(cache.has("a")).toBe(true);
|
||||
expect(cache.has("b")).toBe(false);
|
||||
expect(cache.has("c")).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user