Skip to content

Commit ab6aac6

Browse files
committed
Normalize frontend purity tokens
1 parent 4389543 commit ab6aac6

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/mapContracts.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,17 @@ export const RESOURCES = [
3636
export const DEFAULT_PHASE_IDS = ["phase1", "phase2", "phase3", "phase4", "phase5", "collectibles"];
3737

3838
export function parsePurityMultiplier(purity) {
39-
if (purity.includes("pure") && !purity.includes("impure")) {
39+
const normalizedPurity = String(purity).toLowerCase();
40+
41+
if (normalizedPurity === "rp_pure" || normalizedPurity === "pure") {
4042
return 2.0;
4143
}
42-
if (purity.includes("impure") || purity.includes("inpure")) {
44+
if (
45+
normalizedPurity === "rp_impure" ||
46+
normalizedPurity === "rp_inpure" ||
47+
normalizedPurity === "impure" ||
48+
normalizedPurity === "inpure"
49+
) {
4350
return 0.5;
4451
}
4552
return 1.0;

src/mapContracts.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
hasOptimizationObjective,
66
nonZeroWeights,
77
parseNodes,
8+
parsePurityMultiplier,
89
RESOURCES,
910
} from "./mapContracts.js";
1011

@@ -66,6 +67,19 @@ describe("map contracts", () => {
6667
expect(nodes.waterwellIndices).toEqual([]);
6768
});
6869

70+
test("parsePurityMultiplier maps engine purity tokens", () => {
71+
expect(parsePurityMultiplier("RP_Inpure")).toBe(0.5);
72+
expect(parsePurityMultiplier("RP_Impure")).toBe(0.5);
73+
expect(parsePurityMultiplier("RP_Normal")).toBe(1.0);
74+
expect(parsePurityMultiplier("RP_Pure")).toBe(2.0);
75+
});
76+
77+
test("parsePurityMultiplier maps lowercase purity tokens", () => {
78+
expect(parsePurityMultiplier("impure")).toBe(0.5);
79+
expect(parsePurityMultiplier("normal")).toBe(1.0);
80+
expect(parsePurityMultiplier("pure")).toBe(2.0);
81+
});
82+
6983
test("empty optimization objectives are detectable before API calls", () => {
7084
expect(nonZeroWeights({ iron: 0, copper: 1 })).toEqual({ copper: 1 });
7185
expect(hasOptimizationObjective({ iron: 0, copper: 0 })).toBe(false);

0 commit comments

Comments
 (0)