46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { decideMovie, paretoFilter } from "../algorithm.js";
|
|
|
|
function testParetoFilter() {
|
|
const movies = ["A", "B"];
|
|
const people = ["P1", "P2"];
|
|
const ratings = {
|
|
P1: { A: 1, B: 3 },
|
|
P2: { A: 2, B: 4 },
|
|
};
|
|
const remaining = paretoFilter(movies, people, ratings);
|
|
assert.deepEqual(remaining, ["B"]);
|
|
}
|
|
|
|
function testNashProtectsAgainstHardNo() {
|
|
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 });
|
|
assert.equal(result.winner.movie, "Consensus");
|
|
}
|
|
|
|
function testTieBreaker() {
|
|
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 });
|
|
assert.equal(result.winner.movie, "Alpha");
|
|
}
|
|
|
|
function run() {
|
|
testParetoFilter();
|
|
testNashProtectsAgainstHardNo();
|
|
testTieBreaker();
|
|
console.log("All tests passed");
|
|
}
|
|
|
|
run();
|