Differential D4912 Diff 21475 ps/trunk/binaries/data/mods/public/simulation/helpers/tests/test_Requirements.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/helpers/tests/test_Requirements.js
Show All 15 Lines | |||||
const met = () => TS_ASSERT(RequirementsHelper.AreRequirementsMet(template, playerID)); | const met = () => TS_ASSERT(RequirementsHelper.AreRequirementsMet(template, playerID)); | ||||
const notMet = () => TS_ASSERT(!RequirementsHelper.AreRequirementsMet(template, playerID)); | const notMet = () => TS_ASSERT(!RequirementsHelper.AreRequirementsMet(template, playerID)); | ||||
met(); | met(); | ||||
// Simple requirements are assumed to be additive. | // Simple requirements are assumed to be additive. | ||||
template = { | template = { | ||||
"Techs": "phase_city" | "Techs": { "_string": "phase_city" } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => false | "IsTechnologyResearched": (tech) => false | ||||
}); | }); | ||||
notMet(); | notMet(); | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => tech === "phase_town" | "IsTechnologyResearched": (tech) => tech === "phase_town" | ||||
}); | }); | ||||
notMet(); | notMet(); | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => tech === "phase_town" || tech === "phase_city" | "IsTechnologyResearched": (tech) => tech === "phase_town" || tech === "phase_city" | ||||
}); | }); | ||||
met(); | met(); | ||||
template = { | template = { | ||||
"Techs": "cartography phase_city" | "Techs": { "_string": "cartography phase_city" } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => false | "IsTechnologyResearched": (tech) => false | ||||
}); | }); | ||||
notMet(); | notMet(); | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Lines | AddMock(playerEnt, IID_TechnologyManager, { | ||||
} | } | ||||
}); | }); | ||||
met(); | met(); | ||||
// Technology requirements. | // Technology requirements. | ||||
template = { | template = { | ||||
"All": { | "All": { | ||||
"Techs": "phase_town" | "Techs": { "_string": "phase_town" } | ||||
} | } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => false | "IsTechnologyResearched": (tech) => false | ||||
}); | }); | ||||
notMet(); | notMet(); | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => tech === "phase_town" | "IsTechnologyResearched": (tech) => tech === "phase_town" | ||||
}); | }); | ||||
met(); | met(); | ||||
template = { | template = { | ||||
"All": { | "All": { | ||||
"Techs": "phase_city" | "Techs": { "_string": "phase_city" } | ||||
} | } | ||||
}; | }; | ||||
notMet(); | notMet(); | ||||
template = { | template = { | ||||
"All": { | "All": { | ||||
"Techs": "phase_town phase_city" | "Techs": { "_string": "phase_town phase_city" } | ||||
} | } | ||||
}; | }; | ||||
notMet(); | notMet(); | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => tech === "phase_town" || tech === "phase_city" | "IsTechnologyResearched": (tech) => tech === "phase_town" || tech === "phase_city" | ||||
}); | }); | ||||
met(); | met(); | ||||
template = { | template = { | ||||
"All": { | "All": { | ||||
"Techs": "!phase_city" | "Techs": { "_string": "!phase_city" } | ||||
} | } | ||||
}; | }; | ||||
notMet(); | notMet(); | ||||
template = { | template = { | ||||
"All": { | "All": { | ||||
"Techs": "!phase_town phase_city" | "Techs": { "_string": "!phase_town phase_city"} | ||||
} | } | ||||
}; | }; | ||||
notMet(); | notMet(); | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => tech === "phase_city" | "IsTechnologyResearched": (tech) => tech === "phase_city" | ||||
}); | }); | ||||
met(); | met(); | ||||
// Combination of Entity and Technology requirements. | // Combination of Entity and Technology requirements. | ||||
template = { | template = { | ||||
"All": { | "All": { | ||||
"Entities": { | "Entities": { | ||||
"class_1": { | "class_1": { | ||||
"Count": 3, | "Count": 3, | ||||
"Variants": 2 | "Variants": 2 | ||||
} | } | ||||
}, | }, | ||||
"Techs": "phase_town" | "Techs": { "_string": "phase_town" } | ||||
} | } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"classCounts": { | "classCounts": { | ||||
"class_1": 3 | "class_1": 3 | ||||
}, | }, | ||||
"IsTechnologyResearched": (tech) => false, | "IsTechnologyResearched": (tech) => false, | ||||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | AddMock(playerEnt, IID_TechnologyManager, { | ||||
} | } | ||||
}); | }); | ||||
met(); | met(); | ||||
// Technology requirements. | // Technology requirements. | ||||
template = { | template = { | ||||
"Any": { | "Any": { | ||||
"Techs": "phase_town" | "Techs": { "_string": "phase_town" } | ||||
} | } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => tech === "phase_city" | "IsTechnologyResearched": (tech) => tech === "phase_city" | ||||
}); | }); | ||||
notMet(); | notMet(); | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => tech === "phase_town" | "IsTechnologyResearched": (tech) => tech === "phase_town" | ||||
}); | }); | ||||
met(); | met(); | ||||
template = { | template = { | ||||
"Any": { | "Any": { | ||||
"Techs": "phase_town phase_city" | "Techs": { "_string": "phase_town phase_city" } | ||||
} | } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => tech === "phase_city" | "IsTechnologyResearched": (tech) => tech === "phase_city" | ||||
}); | }); | ||||
met(); | met(); | ||||
template = { | template = { | ||||
"Any": { | "Any": { | ||||
"Techs": "!phase_town" | "Techs": { "_string": "!phase_town" } | ||||
} | } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => tech === "phase_town" | "IsTechnologyResearched": (tech) => tech === "phase_town" | ||||
}); | }); | ||||
notMet(); | notMet(); | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => tech === "phase_city" | "IsTechnologyResearched": (tech) => tech === "phase_city" | ||||
}); | }); | ||||
met(); | met(); | ||||
template = { | template = { | ||||
"Any": { | "Any": { | ||||
"Techs": "!phase_town phase_city" | "Techs": { "_string": "!phase_town phase_city" } | ||||
} | } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"IsTechnologyResearched": (tech) => tech === "phase_town" || tech === "phase_city" | "IsTechnologyResearched": (tech) => tech === "phase_town" || tech === "phase_city" | ||||
}); | }); | ||||
met(); | met(); | ||||
// Combinational requirements of entities and technologies. | // Combinational requirements of entities and technologies. | ||||
template = { | template = { | ||||
"Any": { | "Any": { | ||||
"Entities": { | "Entities": { | ||||
"class_1": { | "class_1": { | ||||
"Count": 3, | "Count": 3, | ||||
"Variants": 2 | "Variants": 2 | ||||
} | } | ||||
}, | }, | ||||
"Techs": "!phase_town" | "Techs": { "_string": "!phase_town" } | ||||
} | } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"classCounts": { | "classCounts": { | ||||
"class_1": 3 | "class_1": 3 | ||||
}, | }, | ||||
"IsTechnologyResearched": (tech) => tech === "phase_town", | "IsTechnologyResearched": (tech) => tech === "phase_town", | ||||
"typeCountsByClass": { | "typeCountsByClass": { | ||||
"class_1": { | "class_1": { | ||||
"template_1": 3 | "template_1": 3 | ||||
} | } | ||||
} | } | ||||
}); | }); | ||||
met(); | met(); | ||||
// Nested requirements. | // Nested requirements. | ||||
template = { | template = { | ||||
"All": { | "All": { | ||||
"All": { | "All": { | ||||
"Techs": "!phase_town" | "Techs": { "_string": "!phase_town" } | ||||
}, | }, | ||||
"Any": { | "Any": { | ||||
"Entities": { | "Entities": { | ||||
"class_1": { | "class_1": { | ||||
"Count": 3, | "Count": 3, | ||||
"Variants": 2 | "Variants": 2 | ||||
} | } | ||||
}, | }, | ||||
"Techs": "phase_city" | "Techs": { "_string": "phase_city" } | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"classCounts": { | "classCounts": { | ||||
"class_1": 3 | "class_1": 3 | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | AddMock(playerEnt, IID_TechnologyManager, { | ||||
} | } | ||||
}); | }); | ||||
met(); | met(); | ||||
template = { | template = { | ||||
"Any": { | "Any": { | ||||
"All": { | "All": { | ||||
"Techs": "!phase_town" | "Techs": { "_string": "!phase_town" } | ||||
}, | }, | ||||
"Any": { | "Any": { | ||||
"Entities": { | "Entities": { | ||||
"class_1": { | "class_1": { | ||||
"Count": 3, | "Count": 3, | ||||
"Variants": 2 | "Variants": 2 | ||||
} | } | ||||
}, | }, | ||||
"Techs": "phase_city" | "Techs": { "_string": "phase_city" } | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"classCounts": { | "classCounts": { | ||||
"class_1": 2 | "class_1": 2 | ||||
}, | }, | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
met(); | met(); | ||||
// Two levels deep nested. | // Two levels deep nested. | ||||
template = { | template = { | ||||
"All": { | "All": { | ||||
"Any": { | "Any": { | ||||
"All": { | "All": { | ||||
"Techs": "cartography phase_imperial", | "Techs": { "_string": "cartography phase_imperial" } | ||||
}, | }, | ||||
"Entities": { | "Entities": { | ||||
"class_1": { | "class_1": { | ||||
"Count": 3, | "Count": 3, | ||||
"Variants": 2 | "Variants": 2 | ||||
} | } | ||||
}, | }, | ||||
"Techs": "phase_city" | "Techs": { "_string": "phase_city" } | ||||
}, | }, | ||||
"Techs": "!phase_town" | "Techs": { "_string": "!phase_town" } | ||||
} | } | ||||
}; | }; | ||||
AddMock(playerEnt, IID_TechnologyManager, { | AddMock(playerEnt, IID_TechnologyManager, { | ||||
"classCounts": { | "classCounts": { | ||||
"class_1": 2 | "class_1": 2 | ||||
}, | }, | ||||
"IsTechnologyResearched": (tech) => tech === "phase_town", | "IsTechnologyResearched": (tech) => tech === "phase_town", | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator