add more tests

This commit is contained in:
Schluffe
2026-08-11 00:56:55 +02:00
parent 81eaeda05a
commit 09b6282a2e
6 changed files with 37 additions and 3 deletions
+1 -1
View File
@@ -1,10 +1,10 @@
import { box } from "#/engine/Box.ts";
import { import {
type Process as EntityProcess, type Process as EntityProcess,
entityBlueprintMap, entityBlueprintMap,
entityProcessMap, entityProcessMap,
} from "#/engine/Entity.ts"; } from "#/engine/Entity.ts";
import { type Graph, getNeighbours } from "#/engine/Graph.ts"; import { type Graph, getNeighbours } from "#/engine/Graph.ts";
import { box } from "#/engine/lib/box";
import { type Cache, memoize } from "#/engine/lib/cache.ts"; import { type Cache, memoize } from "#/engine/lib/cache.ts";
import MapArray from "#/engine/lib/MapArray.ts"; import MapArray from "#/engine/lib/MapArray.ts";
+27
View File
@@ -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 -1
View File
@@ -1,4 +1,4 @@
import type { Box } from "#/engine/Box.ts"; import type { Box } from "./box.ts";
export default class MapArray<K, V> { export default class MapArray<K, V> {
map: Map<K, Box<V>>; map: Map<K, Box<V>>;
+7
View File
@@ -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 });
});
View File
+1 -1
View File
@@ -1,4 +1,4 @@
import type { Box } from "#/engine/Box.ts"; import type { Box } from "#/engine/lib/box";
import { sceneChangeSet, sceneComponentsMap } from "#/engine/Scene.ts"; import { sceneChangeSet, sceneComponentsMap } from "#/engine/Scene.ts";
import { drawSprite, type Sprite, spriteSheetMap } from "#/engine/Sprite.ts"; import { drawSprite, type Sprite, spriteSheetMap } from "#/engine/Sprite.ts";
import type { Vector } from "#/engine/Vector.ts"; import type { Vector } from "#/engine/Vector.ts";