test: more tests

This commit is contained in:
Shibo Lyu 2024-05-04 22:17:19 +08:00
parent 302d6cef3e
commit 9a4927f9b2
6 changed files with 86 additions and 6 deletions

View file

@ -4,8 +4,10 @@ import {
} from "https://deno.land/std@0.224.0/assert/mod.ts";
import { createBoard, renderFullBoard } from "../logic/board.ts";
import { BoardData } from "../mod.ts";
import { BoardData } from "../types/board.ts";
import { checkFullBoard } from "./checkFullBoard.ts";
import { locateSection } from "../logic/board.ts";
import { applyChangeOnBoard } from "../logic/board.ts";
Deno.test("board", async (t) => {
let board: BoardData | undefined;
@ -35,11 +37,46 @@ Deno.test("board", async (t) => {
assertEquals(board.sections[1][1].offsetY, 3);
});
await t.step("locateSection", () => {
assert(board);
const { sx, sy } = locateSection({ x: 0, y: 0 }, board.config);
assertEquals(sx, 0);
assertEquals(sy, 0);
const { sx: sx2, sy: sy2 } = locateSection({ x: 4, y: 0 }, board.config);
assertEquals(sx2, 1);
assertEquals(sy2, 0);
});
await t.step("applyChangeOnBoard", () => {
assert(board);
applyChangeOnBoard({ x: 0, y: 0, ch: "A" }, board);
applyChangeOnBoard({ x: 4, y: 0, ch: "B" }, board);
applyChangeOnBoard({ x: 0, y: 3, ch: "C" }, board);
applyChangeOnBoard({ x: 4, y: 3, ch: "D" }, board);
assertEquals(board.sections[0][0].ch[0][0], "A");
assertEquals(board.sections[0][1].ch[0][0], "B");
assertEquals(board.sections[1][0].ch[0][0], "C");
assertEquals(board.sections[1][1].ch[0][0], "D");
applyChangeOnBoard({ x: 0, y: 1, ch: "你" }, board);
applyChangeOnBoard({ x: 4, y: 2, ch: "好" }, board);
applyChangeOnBoard({ x: 0, y: 4, ch: "嗎" }, board);
applyChangeOnBoard({ x: 4, y: 4, ch: "嘛" }, board);
assertEquals(board.sections[0][0].ch[1][0], "你");
assertEquals(board.sections[0][1].ch[2][0], "好");
assertEquals(board.sections[1][0].ch[1][0], "嗎");
assertEquals(board.sections[1][1].ch[2][0], "嘛");
});
await t.step("renderFullBoard", () => {
assert(board);
const rendered = renderFullBoard(board);
checkFullBoard(rendered);
});
});

View file

@ -112,4 +112,12 @@ Deno.test("section", async (t) => {
assertEquals(section.ch[0][1], " ");
assertEquals(section.width[0][0], 2);
});
await t.step("applyChange incorrect section", () => {
assertThrows(() => {
assert(section);
applyChange({ x: 6, y: 3, ch: "あ" }, section);
});
});
});