83 lines
4.4 KiB
Lua
83 lines
4.4 KiB
Lua
-- Kør: luajit tests/test_adMonthView.lua (fra repo-roden)
|
||
dofile("FS25_ADSmartPickup/adFieldModel.lua")
|
||
dofile("FS25_ADSmartPickup/adMonthView.lua")
|
||
local V, M = ADMonthView, ADFieldModel
|
||
local failures = 0
|
||
local function check(name, actual, expected)
|
||
if actual == expected then print("OK " .. name) else
|
||
failures = failures + 1
|
||
print(string.format("FAIL %s: forventede %s, fik %s", name, tostring(expected), tostring(actual)))
|
||
end
|
||
end
|
||
|
||
-- MV1: perioder
|
||
check("MV1 næste periode", V.nextPeriod(5), 6)
|
||
check("MV1 vinter -> forår", V.nextPeriod(12), 1)
|
||
|
||
-- MV2: såvindue (hvede sås i periode 6-7)
|
||
local function plantableIn(name, period) return name == "WHEAT" and (period == 6 or period == 7) end
|
||
check("MV2 lukker", V.sowWindow(plantableIn, "WHEAT", 7), "closes")
|
||
check("MV2 åbent", V.sowWindow(plantableIn, "WHEAT", 6), "open")
|
||
check("MV2 lukket", V.sowWindow(plantableIn, "WHEAT", 8), "closed")
|
||
|
||
-- MV3: visning (Dakota-kartofler: harvestReady 6 -> dead 7 i EARLY_AUTUMN = periode 7)
|
||
local potato = {witheredState = 7, growthDataSeasonal = {periods = {[7] = {updates = {{startState = 6, endState = 7}}}}}}
|
||
check("MV3 visner næste måned", V.withersIn(potato, 7, 6), true)
|
||
check("MV3 ikke måneden før", V.withersIn(potato, 6, 6), false)
|
||
check("MV3 ukendte data", V.withersIn({witheredState = 7}, 7, 6), false)
|
||
|
||
-- MV4: fremdrift
|
||
local harvest = M.with(M.newField(15), {stage = "harvesting", kind = "harvest"})
|
||
check("MV4 CP vinder", V.progress(harvest, {readyRatio = 0.9}, 0.5), 0.5)
|
||
check("MV4 høst ud fra afgrøde", V.progress(harvest, {readyRatio = 0.25}, nil), 0.75)
|
||
check("MV4 kultivering ukendt", V.progress(M.with(harvest, {stage = "cultivating"}), {readyRatio = 0}, nil), nil)
|
||
check("MV4 tekst", V.percentText(0.504), "50 %")
|
||
check("MV4 tekst ukendt", V.percentText(nil), "–")
|
||
|
||
-- MV5: hel fane
|
||
local fields = {
|
||
[15] = M.with(harvest, {plan = {sow = true, sowFruit = "WHEAT", soil = "cultivate", straw = "chop"}}),
|
||
[16] = M.with(M.newField(16), {stage = "harvesting", kind = "harvest"}),
|
||
[18] = M.with(M.newField(18), {stage = "sowing", kind = "harvest", plan = {sow = true, sowFruit = "WHEAT"}}),
|
||
[20] = M.with(M.newField(20), {stage = "fertilizing"}),
|
||
[21] = M.newField(21),
|
||
[22] = M.with(M.newField(22), {plan = {targetFruit = "WHEAT"}}),
|
||
[23] = M.with(M.newField(23), {stage = "ready"}),
|
||
}
|
||
local infos = {
|
||
{id = 15, kind = "harvest", readyRatio = 0.5, cropTitle = "Hvede", needs = {}},
|
||
{id = 16, kind = "harvest", readyRatio = 1, cropTitle = "Kartofler", growthState = 6},
|
||
{id = 18, kind = "bare", readyRatio = 0},
|
||
{id = 20, kind = "harvest", readyRatio = 0},
|
||
{id = 21, kind = "bare"},
|
||
{id = 22, kind = "bare"},
|
||
{id = 23, kind = "harvest", readyRatio = 1},
|
||
}
|
||
local ctx = {period = 7, plantableIn = plantableIn,
|
||
withers = function(info, nextPeriod) return info.id == 16 and nextPeriod == 8 end,
|
||
cpProgress = function(id) return id == 18 and 0.1 or nil end}
|
||
local view = V.build(infos, fields, ctx)
|
||
check("MV5 aktive marker (21 venter, 22 kommer, 23 passiv klar)", #view.rows, 4)
|
||
check("MV5 kritiske", view.critical, 3)
|
||
check("MV5 høst før sidste såmåned først (id)", view.rows[1].id, 15)
|
||
check("MV5 høst -> såning senere lukker", view.rows[1].window, "lastSowMonth")
|
||
check("MV5 høst næste trin", view.rows[1].nextStage, "cultivating")
|
||
check("MV5 høst der visner", view.rows[2].id, 16)
|
||
check("MV5 vindue høst", view.rows[2].window, "harvestCloses")
|
||
check("MV5 sidste såmåned", view.rows[3].id, 18)
|
||
check("MV5 vindue såning", view.rows[3].window, "lastSowMonth")
|
||
check("MV5 såafgrøde", view.rows[3].sowFruit, "WHEAT")
|
||
check("MV5 CP-fremdrift", view.rows[3].progress, 0.1)
|
||
check("MV5 pleje sidst", view.rows[4].id, 20)
|
||
check("MV5 pleje intet næste", view.rows[4].nextStage, nil)
|
||
check("MV5 kommer: F22 hvede", view.upcoming[1] and view.upcoming[1].id, 22)
|
||
check("MV5 kommer: lukker", view.upcoming[1] and view.upcoming[1].closes, true)
|
||
|
||
-- MV6: klargøring før såning med lukkende vindue er kritisk
|
||
local cultivating = M.with(M.newField(30), {stage = "cultivating", plan = {sow = true, sowFruit = "WHEAT"}})
|
||
check("MV6 kultivering før sidste såmåned", V.window(cultivating, {kind = "bare"}, ctx), "lastSowMonth")
|
||
check("MV6 aktiv klar (auto)", V.isActive(M.with(M.newField(31), {stage = "ready", plan = {mode = "auto"}})), true)
|
||
|
||
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
|
||
os.exit(failures == 0 and 0 or 1)
|