135 lines
3.5 KiB
TypeScript
135 lines
3.5 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
DEFAULT_LANE_CHECKPOINT,
|
|
pairLaneParticipants,
|
|
resolveCheckpointComparison,
|
|
} from "../src/lib/internal-game-matchups.ts";
|
|
|
|
function participant(
|
|
name: string,
|
|
side: "blue" | "red",
|
|
teamPosition: string,
|
|
gold: number,
|
|
cs: number,
|
|
xp: number,
|
|
) {
|
|
return {
|
|
name,
|
|
side,
|
|
teamPosition,
|
|
checkpoints: {
|
|
at15: {
|
|
timestamp: 900,
|
|
gold,
|
|
cs,
|
|
xp,
|
|
kills: side === "blue" ? 2 : 1,
|
|
deaths: side === "blue" ? 1 : 2,
|
|
assists: 3,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
test("pairLaneParticipants matches shuffled players by normalized team position", () => {
|
|
const blue = [
|
|
participant("Blue ADC", "blue", "BOTTOM", 6_000, 120, 7_000),
|
|
participant("Blue Top", "blue", "TOP", 5_500, 110, 6_800),
|
|
participant("Blue Mid", "blue", "MID", 6_200, 115, 7_100),
|
|
];
|
|
const red = [
|
|
participant("Red Mid", "red", "MIDDLE", 5_900, 109, 6_900),
|
|
participant("Red Top", "red", "TOP", 5_300, 105, 6_600),
|
|
participant("Red ADC", "red", "ADC", 5_800, 116, 6_850),
|
|
];
|
|
|
|
const pairs = pairLaneParticipants(blue, red);
|
|
|
|
assert.deepEqual(
|
|
pairs.map((pair) => [pair.position, pair.blue?.name, pair.red?.name]),
|
|
[
|
|
["TOP", "Blue Top", "Red Top"],
|
|
["MIDDLE", "Blue Mid", "Red Mid"],
|
|
["BOTTOM", "Blue ADC", "Red ADC"],
|
|
],
|
|
);
|
|
});
|
|
|
|
test("pairLaneParticipants leaves a duplicated role ambiguous instead of pairing by index", () => {
|
|
const blue = [
|
|
participant("Blue Top A", "blue", "TOP", 5_500, 110, 6_800),
|
|
participant("Blue Top B", "blue", "TOP", 5_000, 100, 6_200),
|
|
];
|
|
const red = [
|
|
participant("Red Top", "red", "TOP", 5_300, 105, 6_600),
|
|
];
|
|
|
|
assert.deepEqual(pairLaneParticipants(blue, red), [
|
|
{
|
|
position: "TOP",
|
|
blue: null,
|
|
red: red[0],
|
|
ambiguousBlue: true,
|
|
ambiguousRed: false,
|
|
},
|
|
]);
|
|
});
|
|
|
|
test("resolveCheckpointComparison calculates blue-side GD, CSD, and XPD", () => {
|
|
const blue = participant("Blue Mid", "blue", "MIDDLE", 6_200, 115, 7_100);
|
|
const red = participant("Red Mid", "red", "MIDDLE", 5_900, 109, 6_900);
|
|
|
|
const comparison = resolveCheckpointComparison(blue, red, "at15");
|
|
|
|
assert.deepEqual(comparison, {
|
|
blue: blue.checkpoints.at15,
|
|
red: red.checkpoints.at15,
|
|
goldDiff: 300,
|
|
csDiff: 6,
|
|
xpDiff: 200,
|
|
});
|
|
});
|
|
|
|
test("resolveCheckpointComparison returns null when either checkpoint is unavailable", () => {
|
|
const blue = participant("Blue Mid", "blue", "MIDDLE", 6_200, 115, 7_100);
|
|
const red = participant("Red Mid", "red", "MIDDLE", 5_900, 109, 6_900);
|
|
|
|
assert.equal(resolveCheckpointComparison(blue, red, "at10"), null);
|
|
assert.equal(resolveCheckpointComparison(blue, null, "at15"), null);
|
|
});
|
|
|
|
test("the lane panel defaults to 15 minutes and supports an available 10-minute comparison", () => {
|
|
assert.equal(DEFAULT_LANE_CHECKPOINT, "at15");
|
|
|
|
const blue = participant("Blue Mid", "blue", "MIDDLE", 6_200, 115, 7_100);
|
|
const red = participant("Red Mid", "red", "MIDDLE", 5_900, 109, 6_900);
|
|
blue.checkpoints.at10 = {
|
|
timestamp: 590,
|
|
gold: 4_000,
|
|
cs: 75,
|
|
xp: 4_600,
|
|
kills: 1,
|
|
deaths: 0,
|
|
assists: 2,
|
|
};
|
|
red.checkpoints.at10 = {
|
|
timestamp: 590,
|
|
gold: 3_700,
|
|
cs: 69,
|
|
xp: 4_450,
|
|
kills: 0,
|
|
deaths: 1,
|
|
assists: 1,
|
|
};
|
|
|
|
assert.deepEqual(resolveCheckpointComparison(blue, red, "at10"), {
|
|
blue: blue.checkpoints.at10,
|
|
red: red.checkpoints.at10,
|
|
goldDiff: 300,
|
|
csDiff: 6,
|
|
xpDiff: 150,
|
|
});
|
|
});
|