Merge branch 'v29'

This commit is contained in:
evanpelle
2026-01-28 16:06:32 -08:00
49 changed files with 2969 additions and 739 deletions
+8 -8
View File
@@ -56,7 +56,7 @@ describe("Ranking class", () => {
cosmetics: { flag: "USA" },
stats: {
units: { port: [2n, 0n, 0n, 2n] },
conquests: 5n,
conquests: [5n],
gold: [0n, 100n, 20n, 0n, 15n, 5n], // total 140
bombs: {
abomb: [1n],
@@ -71,7 +71,7 @@ describe("Ranking class", () => {
username: "Bob",
stats: {
units: { city: [2n, 0n, 0n, 2n] },
conquests: 8n,
conquests: [8n],
gold: [0n, 50n, 10n, 5n], // total 65, no train trade
bombs: {
abomb: [0n],
@@ -86,7 +86,7 @@ describe("Ranking class", () => {
username: "Charlie",
stats: {
// no units, but has conquests/killedAt to count as played
conquests: 8n,
conquests: [8n],
killedAt: BigInt(600),
gold: [0n, 10n, 2n, 10n, 0n, 5n], // total 27
bombs: {},
@@ -110,21 +110,21 @@ describe("Ranking class", () => {
test("summarizes players correctly", () => {
const r = new Ranking(makeSession());
const players = r.sortedBy(RankType.Conquests);
const players = r.sortedBy(RankType.ConquestHumans);
expect(players.length).toBe(3);
const p1 = players.find((p) => p.id === "p1")!;
expect(p1.username).toBe("Alice");
expect(p1.flag).toBe("USA");
expect(p1.conquests).toBe(5);
expect(p1.conquests).toStrictEqual([5n]);
expect(p1.atoms).toBe(1);
expect(p1.mirv).toBe(2);
});
test("correctly identifies winner", () => {
const r = new Ranking(makeSession());
const p2 = r.sortedBy(RankType.Conquests).find((p) => p.id === "p2")!;
const p2 = r.sortedBy(RankType.ConquestHumans).find((p) => p.id === "p2")!;
expect(p2.winner).toBe(true);
});
@@ -157,7 +157,7 @@ describe("Ranking class", () => {
test("lifetime score is percentage of duration", () => {
const r = new Ranking(makeSession());
const p3 = r.sortedBy(RankType.Conquests).find((p) => p.id === "p3")!;
const p3 = r.sortedBy(RankType.ConquestHumans).find((p) => p.id === "p3")!;
const expected = Number(BigInt(600)) / gameDuration;
expect(r.score(p3, RankType.Lifetime)).toBe(expected);
});
@@ -170,7 +170,7 @@ describe("Ranking class", () => {
test("winners should be ahead of players with same score", () => {
const r = new Ranking(makeSession());
const sortedPlayers = r.sortedBy(RankType.Conquests);
const sortedPlayers = r.sortedBy(RankType.ConquestHumans);
expect(sortedPlayers[0].id).toBe("p2"); // p2 & p3 same score but winner first
});
+2 -2
View File
@@ -162,14 +162,14 @@ describe("Stats", () => {
expect(stats.stats()).toStrictEqual({
client1: {
gold: [0n, 1n],
conquests: 1n,
conquests: [1n],
},
});
stats.goldWar(player1, player2, 1);
expect(stats.stats()).toStrictEqual({
client1: {
gold: [0n, 2n],
conquests: 2n,
conquests: [2n],
},
});
});