replace vanilla TS + Bun.serve() + MariaDB with: - frontend: React 19, Vite 6, TanStack Router/Query, Tailwind v4 - backend: Hono + @hono/node-server, Drizzle ORM, PostgreSQL, Zod - shared: algorithm, round-state, types in src/shared/ - tooling: Biome (lint/format), Vitest (tests) - deploy: static files at /movie-select/, API at /movie-select/api URL scheme changes from /movies/ to /movie-select/, API from action-based to RESTful endpoints. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { expect, test } from "vitest";
|
|
import { decideMovie, paretoFilter } from "../../src/shared/algorithm.ts";
|
|
|
|
test("paretoFilter removes dominated movies", () => {
|
|
const movies = ["A", "B"];
|
|
const people = ["P1", "P2"];
|
|
const ratings = { P1: { A: 1, B: 3 }, P2: { A: 2, B: 4 } };
|
|
expect(paretoFilter(movies, people, ratings)).toEqual(["B"]);
|
|
});
|
|
|
|
test("nash protects against hard no", () => {
|
|
const movies = ["Consensus", "Polarizing"];
|
|
const people = ["A", "B", "C"];
|
|
const ratings = {
|
|
A: { Consensus: 3, Polarizing: 5 },
|
|
B: { Consensus: 3, Polarizing: 5 },
|
|
C: { Consensus: 3, Polarizing: 0 },
|
|
};
|
|
const result = decideMovie({ movies, people, ratings });
|
|
expect(result.winner.movie).toBe("Consensus");
|
|
});
|
|
|
|
test("tie-breaker uses alphabetical order", () => {
|
|
const movies = ["Alpha", "Beta"];
|
|
const people = ["A", "B"];
|
|
const ratings = {
|
|
A: { Alpha: 2, Beta: 2 },
|
|
B: { Alpha: 2, Beta: 2 },
|
|
};
|
|
const result = decideMovie({ movies, people, ratings });
|
|
expect(result.winner.movie).toBe("Alpha");
|
|
});
|