server/laf-cloud/tests/revive-cost-ab.test.mjs
2026-09-01 16:04:15 +08:00

49 lines
1.6 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
const configUrl = new URL("../../../assets/Script/module/Config/ReviveCostConfig.ts", import.meta.url);
const { getABReviveCoinCost, MAX_REVIVE_COST_STEP, REVIVE_COST_AB_NAME } = await import(configUrl);
function assignment(group, overrides = {}) {
return {
experimentId: "exp_layer_3_003",
layer: "3",
name: REVIVE_COST_AB_NAME,
enabled: true,
group,
...overrides,
};
}
test("Default and group A always cost 500", () => {
for (const group of ["Default", "A"]) {
assert.deepEqual(
Array.from({ length: 9 }, (_, count) => getABReviveCoinCost(assignment(group), count)),
Array(9).fill(500),
);
}
});
test("group B ascends 500, 700, 900 and stays at 900", () => {
assert.deepEqual(
Array.from({ length: 7 }, (_, count) => getABReviveCoinCost(assignment("B"), count)),
[500, 700, 900, 900, 900, 900, 900],
);
});
test("group C ascends through 1500 and stays at 1500", () => {
assert.deepEqual(
Array.from({ length: 8 }, (_, count) => getABReviveCoinCost(assignment("C"), count)),
[500, 700, 900, 1100, 1300, 1500, 1500, 1500],
);
assert.equal(MAX_REVIVE_COST_STEP, 5);
});
test("disabled, missing, or unrelated assignments use the 500 fallback", () => {
assert.equal(getABReviveCoinCost(null, 5), 500);
assert.equal(getABReviveCoinCost(assignment("C", { enabled: false }), 5), 500);
assert.equal(getABReviveCoinCost(assignment("C", { layer: "2" }), 5), 500);
assert.equal(getABReviveCoinCost(assignment("C", { name: "another_experiment" }), 5), 500);
assert.equal(getABReviveCoinCost(assignment("D"), 5), 500);
});