2024-02-09 04:00:45 +08:00
|
|
|
import { sleep } from "$lib/async.ts";
|
2024-07-30 23:24:17 +08:00
|
|
|
import { assertEquals } from "@std/assert";
|
2023-10-03 20:16:33 +08:00
|
|
|
import { LimitedMap } from "./limited_map.ts";
|
|
|
|
|
|
|
|
Deno.test("limited map", async () => {
|
|
|
|
const mp = new LimitedMap<string>(3);
|
|
|
|
mp.set("a", "a");
|
2024-01-14 00:30:15 +08:00
|
|
|
mp.set("b", "b", 5);
|
2023-10-03 20:16:33 +08:00
|
|
|
mp.set("c", "c");
|
|
|
|
assertEquals(mp.get("a"), "a");
|
|
|
|
assertEquals(mp.get("b"), "b");
|
|
|
|
assertEquals(mp.get("c"), "c");
|
|
|
|
// Drops the first key
|
|
|
|
mp.set("d", "d");
|
2024-01-14 00:30:15 +08:00
|
|
|
// console.log(mp.toJSON());
|
2023-10-03 20:16:33 +08:00
|
|
|
assertEquals(mp.get("a"), undefined);
|
2024-01-14 00:30:15 +08:00
|
|
|
await sleep(10);
|
|
|
|
// "b" should have been dropped
|
|
|
|
assertEquals(mp.get("b"), undefined);
|
|
|
|
assertEquals(mp.get("c"), "c");
|
|
|
|
|
|
|
|
console.log(mp.toJSON());
|
2023-10-03 20:16:33 +08:00
|
|
|
});
|