add more tests
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { box } from "./box.ts";
|
||||
import MapArray from "./MapArray.ts";
|
||||
|
||||
test("MapArray", () => {
|
||||
const mapArray = new MapArray([
|
||||
["a", box(1)],
|
||||
["b", box(2)],
|
||||
["c", box(3)],
|
||||
]);
|
||||
mapArray.set("foo", box(42));
|
||||
mapArray.set("bar", box(0));
|
||||
mapArray.delete("bar");
|
||||
|
||||
expect(mapArray.get("foo")!.value).toBe(42);
|
||||
expect(mapArray.get("bar")).toBe(undefined);
|
||||
expect(mapArray.map.size).toBe(mapArray.array.length);
|
||||
expect(
|
||||
mapArray.entries().reduce(
|
||||
(a, c) => {
|
||||
a[1].value = a[1].value + c[1].value;
|
||||
return a;
|
||||
},
|
||||
["_", box(0)],
|
||||
)[1].value,
|
||||
).toBe(48);
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Box } from "#/engine/Box.ts";
|
||||
import type { Box } from "./box.ts";
|
||||
|
||||
export default class MapArray<K, V> {
|
||||
map: Map<K, Box<V>>;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { expect, test } from "vitest";
|
||||
import { type Box, box } from "./box.ts";
|
||||
|
||||
test("box", () => {
|
||||
const b: Box<number> = box(42);
|
||||
expect(b).toEqual({ value: 42 });
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
export type Box<T> = {
|
||||
value: T;
|
||||
};
|
||||
|
||||
export function box<T>(value: T): Box<T> {
|
||||
return { value };
|
||||
}
|
||||
Reference in New Issue
Block a user