34 lines
687 B
TypeScript
34 lines
687 B
TypeScript
import { expect, test } from "vitest";
|
|
import {
|
|
createDictionary,
|
|
type Dictionary,
|
|
deleteEntrySave,
|
|
forEntry,
|
|
getEntry,
|
|
setEntrySave,
|
|
} from "./Dictionary.ts";
|
|
|
|
test("Dictionary", () => {
|
|
const dict: Dictionary<string, number> = createDictionary([
|
|
["a", 1],
|
|
["b", 2],
|
|
["c", 3],
|
|
]);
|
|
setEntrySave(dict, "foo", 42);
|
|
setEntrySave(dict, "bar", 0);
|
|
deleteEntrySave(dict, "bar");
|
|
|
|
console.table(dict.entries);
|
|
console.table(dict.indices);
|
|
|
|
expect(getEntry(dict, "foo")).toBe(42);
|
|
expect(getEntry(dict, "bar")).toBe(undefined);
|
|
expect(dict.indices.size).toBe(dict.entries.length);
|
|
|
|
let sum = 0;
|
|
forEntry(dict, (value) => {
|
|
sum += value;
|
|
});
|
|
expect(sum).toBe(48);
|
|
});
|