35 lines
912 B
JavaScript
35 lines
912 B
JavaScript
import assert from "node:assert/strict";
|
|
import { allUsersDone, hasCompleteRatings, collectCompleteRatings } from "../round-state.js";
|
|
|
|
function testAllUsersDone() {
|
|
assert.equal(allUsersDone(["A", "B"], ["A", "B"]), true);
|
|
assert.equal(allUsersDone(["A", "B"], ["A"]), false);
|
|
assert.equal(allUsersDone([], []), false);
|
|
}
|
|
|
|
function testCompleteRatings() {
|
|
assert.equal(hasCompleteRatings(["M1", "M2"], { M1: 2, M2: 5 }), true);
|
|
assert.equal(hasCompleteRatings(["M1", "M2"], { M1: 2 }), false);
|
|
}
|
|
|
|
function testCollectCompleteRatings() {
|
|
const users = ["A", "B"];
|
|
const movieTitles = ["M1", "M2"];
|
|
const votes = {
|
|
A: { M1: 1, M2: 2 },
|
|
B: { M1: 3 },
|
|
};
|
|
assert.deepEqual(collectCompleteRatings(users, movieTitles, votes), {
|
|
A: { M1: 1, M2: 2 },
|
|
});
|
|
}
|
|
|
|
function run() {
|
|
testAllUsersDone();
|
|
testCompleteRatings();
|
|
testCollectCompleteRatings();
|
|
console.log("Round state tests passed");
|
|
}
|
|
|
|
run();
|