33 lines
1009 B
TypeScript
33 lines
1009 B
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")
|
|
})
|