Differential D4514 Diff 19791 binaries/data/mods/public/simulation/helpers/tests/test_Requirements.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/simulation/helpers/tests/test_Requirements.js
- This file was added.
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
svn:mime-type | null | text/plain \ No newline at end of property |
Engine.LoadComponentScript("interfaces/PlayerManager.js"); | |||||
Engine.LoadComponentScript("interfaces/TechnologyManager.js"); | |||||
Engine.LoadHelperScript("Player.js"); | |||||
Engine.LoadHelperScript("Requirements.js"); | |||||
const playerID = 1; | |||||
const playerEnt = 11; | |||||
AddMock(SYSTEM_ENTITY, IID_PlayerManager, { | |||||
"GetPlayerByID": () => playerEnt | |||||
}); | |||||
// First test no requirements. | |||||
let template = { | |||||
}; | |||||
const met = (bool) => { | |||||
if (bool) | |||||
TS_ASSERT(RequirementsHelper.AreRequirementsMet(template, playerID)); | |||||
else | |||||
TS_ASSERT(!RequirementsHelper.AreRequirementsMet(template, playerID)); | |||||
}; | |||||
met(true); | |||||
// Additive requirements (all should to be met). | |||||
// Entity requirements. | |||||
template = { | |||||
"All": { | |||||
"Entities": { | |||||
"class_1": { | |||||
"Count": 1 | |||||
} | |||||
} | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": {}, | |||||
"typeCountsByClass": {} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 0 | |||||
}, | |||||
"typeCountsByClass": {} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_2": 1 | |||||
}, | |||||
"typeCountsByClass": {} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 1 | |||||
}, | |||||
"typeCountsByClass": {} | |||||
}); | |||||
met(true); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 1 | |||||
}, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
template = { | |||||
"All": { | |||||
"Entities": { | |||||
"class_1": { | |||||
"Variants": 2 | |||||
} | |||||
} | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2 | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 1, | |||||
"template_2": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 1 | |||||
}, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
template = { | |||||
"All": { | |||||
"Entities": { | |||||
"class_1": { | |||||
"Count": 1, | |||||
"Variants": 2 | |||||
} | |||||
} | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 1 | |||||
}, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 1, | |||||
"template_2": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
template = { | |||||
"All": { | |||||
"Entities": { | |||||
"class_1": { | |||||
"Count": 3, | |||||
"Variants": 2 | |||||
} | |||||
} | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 1, | |||||
"template_2": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 3 | |||||
}, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2, | |||||
"template_2": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
// Technology requirements. | |||||
template = { | |||||
"All": { | |||||
"Techs": "phase_town" | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"IsTechnologyResearched": (tech) => false | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town" | |||||
}); | |||||
met(true); | |||||
template = { | |||||
"All": { | |||||
"Techs": "phase_city" | |||||
} | |||||
}; | |||||
met(false); | |||||
template = { | |||||
"All": { | |||||
"Techs": "phase_town phase_city" | |||||
} | |||||
}; | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town" || tech === "phase_city" | |||||
}); | |||||
met(true); | |||||
template = { | |||||
"All": { | |||||
"Techs": "!phase_city" | |||||
} | |||||
}; | |||||
met(false); | |||||
template = { | |||||
"All": { | |||||
"Techs": "!phase_town phase_city" | |||||
} | |||||
}; | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"IsTechnologyResearched": (tech) => tech === "phase_city" | |||||
}); | |||||
met(true); | |||||
// Combination of Entity and Technology requirements. | |||||
template = { | |||||
"All": { | |||||
"Entities": { | |||||
"class_1": { | |||||
"Count": 3, | |||||
"Variants": 2 | |||||
} | |||||
}, | |||||
"Techs": "phase_town" | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 3 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => false, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2, | |||||
"template_2": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 3 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2, | |||||
"template_2": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 3 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_city", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2, | |||||
"template_2": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
// Choice requirements (at least one needs to be met). | |||||
// Entity requirements. | |||||
template = { | |||||
"Any": { | |||||
"Entities": { | |||||
"class_1": { | |||||
"Count": 1, | |||||
} | |||||
}, | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 0 | |||||
} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 1 | |||||
} | |||||
}); | |||||
met(true); | |||||
template = { | |||||
"Any": { | |||||
"Entities": { | |||||
"class_1": { | |||||
"Count": 5, | |||||
"Variants": 2 | |||||
} | |||||
}, | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 3 | |||||
}, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 3, | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 3 | |||||
}, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2, | |||||
"template_2": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
// Technology requirements. | |||||
template = { | |||||
"Any": { | |||||
"Techs": "phase_town" | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"IsTechnologyResearched": (tech) => tech === "phase_city" | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town" | |||||
}); | |||||
met(true); | |||||
template = { | |||||
"Any": { | |||||
"Techs": "phase_town phase_city" | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"IsTechnologyResearched": (tech) => tech === "phase_city" | |||||
}); | |||||
met(true); | |||||
template = { | |||||
"Any": { | |||||
"Techs": "!phase_town" | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town" | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"IsTechnologyResearched": (tech) => tech === "phase_city" | |||||
}); | |||||
met(true); | |||||
template = { | |||||
"Any": { | |||||
"Techs": "!phase_town phase_city" | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town" || tech === "phase_city" | |||||
}); | |||||
met(true); | |||||
// Combinational requirements of entities and technologies. | |||||
template = { | |||||
"Any": { | |||||
"Entities": { | |||||
"class_1": { | |||||
"Count": 3, | |||||
"Variants": 2 | |||||
} | |||||
}, | |||||
"Techs": "!phase_town" | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 3 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 3 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
// Nested requirements. | |||||
template = { | |||||
"All": { | |||||
"All": { | |||||
"Techs": "!phase_town" | |||||
}, | |||||
"Any": { | |||||
"Entities": { | |||||
"class_1": { | |||||
"Count": 3, | |||||
"Variants": 2 | |||||
} | |||||
}, | |||||
"Techs": "phase_city" | |||||
} | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 3 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 3 | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 3 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town" || tech === "phase_city", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 3 | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_city", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => false, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 1, | |||||
"template_2": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
template = { | |||||
"Any": { | |||||
"All": { | |||||
"Techs": "!phase_town" | |||||
}, | |||||
"Any": { | |||||
"Entities": { | |||||
"class_1": { | |||||
"Count": 3, | |||||
"Variants": 2 | |||||
} | |||||
}, | |||||
"Techs": "phase_city" | |||||
} | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2 | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 3 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town" || tech === "phase_city", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 3 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_city", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => false, | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 1, | |||||
"template_2": 1 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
// Two levels deep nested. | |||||
template = { | |||||
"All": { | |||||
"Any": { | |||||
"All": { | |||||
"Techs": "cartography phase_imperial", | |||||
}, | |||||
"Entities": { | |||||
"class_1": { | |||||
"Count": 3, | |||||
"Variants": 2 | |||||
} | |||||
}, | |||||
"Techs": "phase_city" | |||||
}, | |||||
"Techs": "!phase_town" | |||||
} | |||||
}; | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_town", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2 | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_city", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2 | |||||
} | |||||
} | |||||
}); | |||||
met(true); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "phase_imperial", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2 | |||||
} | |||||
} | |||||
}); | |||||
met(false); | |||||
AddMock(playerEnt, IID_TechnologyManager, { | |||||
"classCounts": { | |||||
"class_1": 2 | |||||
}, | |||||
"IsTechnologyResearched": (tech) => tech === "cartography" || tech === "phase_imperial", | |||||
"typeCountsByClass": { | |||||
"class_1": { | |||||
"template_1": 2 | |||||
} | |||||
} | |||||
}); | |||||
met(true); |
Wildfire Games · Phabricator