Differential D1843 Diff 16414 ps/trunk/binaries/data/mods/public/simulation/components/tests/test_ProductionQueue.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/tests/test_ProductionQueue.js
Show First 20 Lines • Show All 292 Lines • ▼ Show 20 Lines | function regression_test_d1879() | ||||
cmpProdQueue.AddBatch("some_template", "unit", 3); | cmpProdQueue.AddBatch("some_template", "unit", 3); | ||||
cmpProdQueue.ProgressTimeout(null, 0); | cmpProdQueue.ProgressTimeout(null, 0); | ||||
TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 1); | TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 1); | ||||
TS_ASSERT_EQUALS(cmpEntLimits.GetCounts().some_limit, 6); | TS_ASSERT_EQUALS(cmpEntLimits.GetCounts().some_limit, 6); | ||||
TS_ASSERT_EQUALS(cmpEntLimits.GetMatchCounts().some_template, 6); | TS_ASSERT_EQUALS(cmpEntLimits.GetMatchCounts().some_template, 6); | ||||
// Check that when the batch is removed the counts are subtracted again. | // Check that when the batch is removed the counts are subtracted again. | ||||
cmpProdQueue.RemoveBatch(cmpProdQueue.GetQueue()[0].id); | cmpProdQueue.RemoveItem(cmpProdQueue.GetQueue()[0].id); | ||||
TS_ASSERT_EQUALS(cmpEntLimits.GetCounts().some_limit, 3); | TS_ASSERT_EQUALS(cmpEntLimits.GetCounts().some_limit, 3); | ||||
TS_ASSERT_EQUALS(cmpEntLimits.GetMatchCounts().some_template, 3); | TS_ASSERT_EQUALS(cmpEntLimits.GetMatchCounts().some_template, 3); | ||||
} | } | ||||
function test_batch_adding() | function test_batch_adding() | ||||
{ | { | ||||
let playerEnt = 2; | let playerEnt = 2; | ||||
let playerID = 1; | let playerID = 1; | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | function test_batch_removal() | ||||
AddMock(SYSTEM_ENTITY, IID_GuiInterface, { | AddMock(SYSTEM_ENTITY, IID_GuiInterface, { | ||||
"PushNotification": () => {} | "PushNotification": () => {} | ||||
}); | }); | ||||
AddMock(SYSTEM_ENTITY, IID_Trigger, { | AddMock(SYSTEM_ENTITY, IID_Trigger, { | ||||
"CallEvent": () => {} | "CallEvent": () => {} | ||||
}); | }); | ||||
ConstructComponent(SYSTEM_ENTITY, "Timer", null); | let cmpTimer = ConstructComponent(SYSTEM_ENTITY, "Timer", null); | ||||
AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | AddMock(SYSTEM_ENTITY, IID_TemplateManager, { | ||||
"TemplateExists": () => true, | "TemplateExists": () => true, | ||||
"GetTemplate": name => ({ | "GetTemplate": name => ({ | ||||
"Cost": { | "Cost": { | ||||
"BuildTime": 0, | "BuildTime": 0, | ||||
"Population": 1, | "Population": 1, | ||||
"Resources": {} | "Resources": {} | ||||
Show All 28 Lines | function test_batch_removal() | ||||
let cmpProdQueue = ConstructComponent(testEntity, "ProductionQueue", { | let cmpProdQueue = ConstructComponent(testEntity, "ProductionQueue", { | ||||
"Entities": { "_string": "some_template" }, | "Entities": { "_string": "some_template" }, | ||||
"BatchTimeModifier": 1 | "BatchTimeModifier": 1 | ||||
}); | }); | ||||
cmpProdQueue.AddBatch("some_template", "unit", 3); | cmpProdQueue.AddBatch("some_template", "unit", 3); | ||||
TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 1); | TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 1); | ||||
cmpProdQueue.ProgressTimeout(null, 0); | cmpTimer.OnUpdate({ "turnLength": 1 }); | ||||
TS_ASSERT_EQUALS(cmpPlayerBlockSpy._called, 1); | TS_ASSERT_EQUALS(cmpPlayerBlockSpy._called, 1); | ||||
cmpProdQueue.AddBatch("some_template", "unit", 2); | cmpProdQueue.AddBatch("some_template", "unit", 2); | ||||
TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 2); | TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 2); | ||||
cmpProdQueue.RemoveBatch(1); | cmpProdQueue.RemoveItem(1); | ||||
TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 1); | TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 1); | ||||
TS_ASSERT_EQUALS(cmpPlayerUnblockSpy._called, 0); | TS_ASSERT_EQUALS(cmpPlayerUnblockSpy._called, 1); | ||||
cmpProdQueue.RemoveBatch(2); | cmpProdQueue.RemoveItem(2); | ||||
TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 0); | TS_ASSERT_EQUALS(cmpProdQueue.GetQueue().length, 0); | ||||
cmpProdQueue.ProgressTimeout(null, 0); | cmpTimer.OnUpdate({ "turnLength": 1 }); | ||||
TS_ASSERT_EQUALS(cmpPlayerUnblockSpy._called, 1); | TS_ASSERT_EQUALS(cmpPlayerUnblockSpy._called, 2); | ||||
cmpProdQueue.AddBatch("some_template", "unit", 3); | cmpProdQueue.AddBatch("some_template", "unit", 3); | ||||
cmpProdQueue.AddBatch("some_template", "unit", 3); | cmpProdQueue.AddBatch("some_template", "unit", 3); | ||||
cmpPlayer.TryReservePopulationSlots = () => false; | cmpPlayer.TryReservePopulationSlots = () => false; | ||||
cmpProdQueue.RemoveBatch(3); | cmpProdQueue.RemoveItem(3); | ||||
cmpProdQueue.ProgressTimeout(null, 0); | TS_ASSERT_EQUALS(cmpPlayerUnblockSpy._called, 3); | ||||
TS_ASSERT_EQUALS(cmpPlayerUnblockSpy._called, 2); | cmpTimer.OnUpdate({ "turnLength": 1 }); | ||||
TS_ASSERT_EQUALS(cmpPlayerUnblockSpy._called, 4); | |||||
} | } | ||||
function test_token_changes() | function test_token_changes() | ||||
{ | { | ||||
const ent = 10; | const ent = 10; | ||||
let cmpProductionQueue = ConstructComponent(10, "ProductionQueue", { | let cmpProductionQueue = ConstructComponent(10, "ProductionQueue", { | ||||
"Entities": { "_string": "units/{civ}/a " + | "Entities": { "_string": "units/{civ}/a " + | ||||
"units/{civ}/b" }, | "units/{civ}/b" }, | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator