election-game/backend/packages/protocol/test/protocol.test.ts

63 lines
1.9 KiB
TypeScript
Raw Normal View History

import { describe, expect, it } from "vitest";
選戰卡牌第四版:本週戰場、加開行程、逆風重排、逐張地圖校準;手機版修正;刪除人物資料庫與 AI 評分 玩法(docs/26): - 本週戰場:每週一個選情接近的大區,對手全力搶攻,週末淨增多的一方贏(聲勢 +1、多抽一張) - 加開行程:每週一次花資金換 1 點體力;起始資金壓到 500–1,000 萬 - 對手落後 3 個百分點以上急起直追;打對台可以搶廣告版面、讓造勢冷場;大絕招集氣加快 - 逆風 0–10 重排成一級一條規則(ASC_RULES),每一級都看得出差別 - 平衡:空戰對手、對手規則、六種類型、空戰/攻防流派、擴散不看鄰區數、區的大小係數、 對手規模依區數、只有一區的選區沒有本命區和戰場、總統大選全國動員、勢均力敵的第三位候選人 - 逐張地圖校準:apps/sim rogue-calibrate 跑過 219 張勢均力敵地圖,calibration.ts 存每張的對手係數 - 模擬工具載入劇本和伺服器一致(總統合成縣市、立委只取選區村里) 畫面: - 戰場比數、加開按鈕、急起直追提示、週末戰場輸贏;遊戲中「存檔離開」回主選單 - 手機直放、橫放的破版修正(圖鑑完成度、遊戲畫面、首頁、捏人物、服裝店、小遊戲等) 刪除(依使用者決定):人物資料庫(Wikidata、內閣、現任名單 → people.json)與 AI 評分管線、 config/people、相關測試、protocol 的 people.ts、docs/rubric-v1.md;records 用到的 names、cec_results 保留 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Uirha5kfuiGbEBhsk7ijDg
2026-10-29 23:42:15 +00:00
import { AGE_BANDS, CellsBlock, LEANS, VillageCode, VillageRecord } from "../src/index.ts";
const village = {
code: "68000010001",
name: "示例里",
townCode: "68000010",
townName: "桃園區",
countyCode: "68000",
countyName: "桃園市",
population: {
total: 3000,
adults: 2400,
byAgeBand: { "20-29": 400, "30-39": 500, "40-49": 500, "50-64": 600, "65+": 400 },
indigenousLowland: 10,
indigenousHighland: 5,
},
electors: 2380,
baseTurnout: 0.68,
lean: { a_core: 0.2, a_lean: 0.15, middle: 0.2, b_lean: 0.15, b_core: 0.2, c_lean: 0.1 },
attributes: {
areaKm2: 0.8,
densityPerKm2: 3750,
templeCount: 2,
churchCount: 1,
templesPer1000: 0.67,
hakkaShare: null,
incomeMedian: 650,
incomeMean: 900,
factionStrength: 0.5,
},
flags: [],
};
describe("村里代碼", () => {
it("接受 11 碼數字", () => {
expect(VillageCode.safeParse("68000010001").success).toBe(true);
});
it("拒絕中選會的 4 碼村里段與字母代碼", () => {
expect(VillageCode.safeParse("0001").success).toBe(false);
expect(VillageCode.safeParse("680000100A1").success).toBe(false);
});
});
describe("VillageRecord", () => {
it("接受完整的村里紀錄", () => {
expect(VillageRecord.safeParse(village).success).toBe(true);
});
it("拒絕超出 0–1 的比例", () => {
const bad = { ...village, baseTurnout: 1.2 };
expect(VillageRecord.safeParse(bad).success).toBe(false);
});
});
describe("CellsBlock", () => {
it("每個村里必須剛好 30 格", () => {
const ok = { ages: [...AGE_BANDS], leans: [...LEANS], values: { "68000010001": new Array(30).fill(1) } };
const bad = { ...ok, values: { "68000010001": new Array(29).fill(1) } };
expect(CellsBlock.safeParse(ok).success).toBe(true);
expect(CellsBlock.safeParse(bad).success).toBe(false);
});
});