116 lines
9.0 KiB
Lua
116 lines
9.0 KiB
Lua
-- Kør: luajit tests/test_adFieldJobs.lua (fra repo-roden)
|
|
dofile("FS25_ADSmartPickup/adFieldModel.lua")
|
|
dofile("FS25_ADSmartPickup/adFieldJobs.lua")
|
|
local J = ADFieldJobs
|
|
local M = 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
|
|
local info = {id = 109, markerId = 5, mowable = true, readyRatio = 1}
|
|
|
|
-- J1: klar auto-mark med markør -> start; uden markør -> vent
|
|
local auto = M.onReadiness(M.newField(109), 1); auto.plan.mode = "auto"
|
|
check("J1 start", J.decide(auto, info, {}, 0).action, "start")
|
|
check("J1 uden markør", J.decide(auto, {id = 109, mowable = true}, {}, 0).action, "wait")
|
|
|
|
-- J2: arbejdende trin uden sæt -> send rolle; alle sæt færdige -> næste trin
|
|
local mowing = M.start(auto)
|
|
local wanted = J.decide(mowing, info, {}, 0)
|
|
check("J2 send slåmaskine", wanted.action, "dispatch"); check("J2 rolle", wanted.role, "mower")
|
|
check("J2 sæt i gang -> ingenting", J.decide(mowing, info, {{phase = "working"}}, 0).action, "none")
|
|
local mowedInfo = {id = 109, markerId = 5, mowable = true, readyRatio = 0}
|
|
check("J2 færdig -> videre", J.decide(mowing, mowedInfo, {{phase = "finished"}}, 0).action, "advance")
|
|
-- J3: sæt frigivet (spilleren tog det) tæller ikke som færdigt
|
|
check("J3 frigivet -> send nyt", J.decide(mowing, info, {{phase = "released"}}, 0).action, "dispatch")
|
|
-- J4: slåning færdig men marken stadig klar -> ikke videre (afbrudt)
|
|
check("J4 afbrudt slåning", J.decide(mowing, {id = 109, markerId = 5, mowable = true, readyRatio = 0.8}, {{phase = "finished"}}, 0).action, "dispatch")
|
|
-- J5: opsamling efter genindlæsning uden sæt -> send læssevogn
|
|
local collecting = M.advance(mowing)
|
|
check("J5 genoptag opsamling", J.decide(collecting, info, {}, 0).role, "collector")
|
|
check("J5 to vogne maks", J.decide(collecting, info, {{phase = "working"}, {phase = "driving"}}, 0).action, "none")
|
|
|
|
-- J6: Courseplay efterlader et hjørne -> efter 2 færdige slå-ture går marken videre alligevel
|
|
local standing = {id = 109, markerId = 5, mowable = true, readyRatio = 0.8}
|
|
check("J6 én tur -> slå igen", J.decide(mowing, standing, {{phase = "finished"}}, 0).action, "dispatch")
|
|
check("J6 to ture -> videre", J.decide(mowing, standing, {{phase = "finished"}, {phase = "finished"}}, 0).action, "advance")
|
|
|
|
-- J7: slået mark uden sæt (fx sluppet undervejs) -> videre til opsamling, ikke en ny slå-tur
|
|
check("J7 slået uden sæt -> videre", J.decide(mowing, {id = 109, markerId = 5, mowable = true, readyRatio = 0.1}, {}, 0).action, "advance")
|
|
check("J7 stående uden sæt -> slå", J.decide(mowing, info, {}, 0).action, "dispatch")
|
|
check("J7 slået men sæt i gang -> vent", J.decide(mowing, {id = 109, markerId = 5, mowable = true, readyRatio = 0.1}, {{phase = "working"}}, 0).action, "none")
|
|
|
|
-- J8: høst — høster først (hovedrolle), aflæsningsvogne kun mens høsteren arbejder
|
|
local harvestInfo = {id = 50, markerId = 7, kind = "harvest", readyRatio = 1, fruitIndex = 3}
|
|
local harvesting = M.start(M.onReadiness(M.newField(50), 1), "harvest", {})
|
|
local d = J.decide(harvesting, harvestInfo, {}, 0)
|
|
check("J8 send høster", d.role, "harvester"); check("J8 ikke hjælper", d.helper, false)
|
|
local withHarvester = {{phase = "working", stage = "harvesting", helper = false}}
|
|
local dHelper = J.decide(harvesting, harvestInfo, withHarvester, 0)
|
|
check("J8 så aflæsningsvogn", dHelper.role, "unloader"); check("J8 hjælper", dHelper.helper, true)
|
|
check("J8 vogn på plads -> intet", J.decide(harvesting, harvestInfo, {withHarvester[1], {phase = "working", stage = "harvesting", helper = true}}, 0).action, "none")
|
|
-- høsteren færdig, afgrøden væk (marken er nu bar) -> videre, selv om vognen stadig kører
|
|
local afterInfo = {id = 50, markerId = 7, kind = "bare", readyRatio = 0}
|
|
check("J8 høst færdig -> videre", J.decide(harvesting, afterInfo, {{phase = "finished", stage = "harvesting"}, {phase = "working", stage = "harvesting", helper = true}}, 0).action, "advance")
|
|
-- sæt fra et tidligere trin (vogn på vej hjem) tæller ikke på det nye trin
|
|
local cultivating = M.advance(harvesting, {})
|
|
check("J8 gammel vogn tæller ikke", J.decide(cultivating, afterInfo, {{phase = "working", stage = "harvesting", helper = true}}, 0).role, "cultivator")
|
|
|
|
-- J9: multi-tool — hele holdet sendes samlet; mens nogen kører, sendes ingen nye hovedsæt
|
|
local multiMow = M.with(mowing, {plan = {rigs = 3}})
|
|
local dMulti = J.decide(multiMow, info, {}, 0)
|
|
check("J9 tre slåmaskiner", dMulti.count, 3)
|
|
check("J9 én kører stadig -> ingen nye", J.decide(multiMow, info, {{phase = "working"}, {phase = "finished"}}, 0).action, "none")
|
|
|
|
-- J10: pleje under vækst — Auto starter, Manuel viser behovet
|
|
local growingInfo = {id = 60, markerId = 8, kind = "harvest", growing = true, fert = 0, fertMax = 2, lime = 2, weed = 0, readyRatio = 0.2}
|
|
local autoField = M.with(M.newField(60), {plan = {mode = "auto"}})
|
|
local care = J.decide(autoField, growingInfo, {}, 0)
|
|
check("J10 auto -> pleje", care.action, "care"); check("J10 gødning", care.stage, "fertilizing")
|
|
local manualCare = J.decide(M.newField(60), growingInfo, {}, 0)
|
|
check("J10 manuel -> intet, men behov vist", manualCare.action, "none"); check("J10 behov", manualCare.care, "fertilizing")
|
|
check("J10 Start nu -> pleje", J.decide(M.with(M.newField(60), {startRequested = true}), growingInfo, {}, 0).action, "care")
|
|
check("J10 uden markør -> vent", J.decide(autoField, {id = 60, kind = "harvest", growing = true, fert = 0, fertMax = 2}, {}, 0).action, "wait")
|
|
|
|
-- J11: regn — vejrfølsomme trin sendes ikke ud (kørende sæt fortsætter); klargøring/pleje kører videre
|
|
local rain = {raining = true}
|
|
local dRain = J.decide(mowing, info, {}, 0, rain)
|
|
check("J11 slåning venter i regn", dRain.action, "wait"); check("J11 grund", dRain.reason, "rain")
|
|
check("J11 kørende slåmaskine fortsætter", J.decide(mowing, info, {{phase = "working"}}, 0, rain).action, "none")
|
|
check("J11 høst venter", J.decide(harvesting, harvestInfo, {}, 0, rain).reason, "rain")
|
|
check("J11 kultivering kører i regn", J.decide(cultivating, afterInfo, {}, 0, rain).role, "cultivator")
|
|
check("J11 start af høst venter", J.decide(M.with(M.onReadiness(M.newField(51), 1), {startRequested = true, kind = "harvest"}), harvestInfo, {}, 0, rain).reason, "rain")
|
|
local silageCollect = M.advance(mowing)
|
|
check("J11 ensilage-opsamling kører i regn", J.decide(silageCollect, info, {}, 0, rain).action, "dispatch")
|
|
local hayCollect = M.with(silageCollect, {plan = {product = "hay"}})
|
|
check("J11 hø-opsamling venter", J.decide(hayCollect, info, {}, 0, rain).reason, "rain")
|
|
check("J11 tørvejr", J.decide(mowing, info, {}, 0, {raining = false}).action, "dispatch")
|
|
|
|
-- J12: bar mark med mål-afgrøde starter selv når målet kan sås; ellers venter den
|
|
local bareInfo = {id = 90, markerId = 9, kind = "bare", readyRatio = 0, needs = {}}
|
|
local bareTarget = M.with(M.newField(90), {plan = {targetFruit = "WHEAT", mode = "auto"}})
|
|
local canSow = {plantable = function(name) return name == "WHEAT" end}
|
|
check("J12 bar + såtid -> start", J.decide(bareTarget, bareInfo, {}, 0, canSow).action, "start")
|
|
check("J12 bar + ikke såtid -> intet", J.decide(bareTarget, bareInfo, {}, 0, {plantable = function() return false end}).action, "none")
|
|
check("J12 bar uden markør -> vent", J.decide(bareTarget, {id = 90, kind = "bare"}, {}, 0, canSow).action, "wait")
|
|
check("J12 voksende mark med mål -> lad den vokse", J.decide(bareTarget, {id = 90, markerId = 9, kind = "harvest", growing = true, readyRatio = 0.3}, {}, 0, canSow).action, "none")
|
|
|
|
-- J13: afbrudt slåning efter genindlæsning (in-game 27/9 F90): genvækst i mellemhøjde -> vent; hjørne efter en tur -> slå straks
|
|
local regrowing = {id = 90, markerId = 9, mowable = true, readyRatio = 0.5, immatureRatio = 0.5}
|
|
local dRegrow = J.decide(mowing, regrowing, {}, 0)
|
|
check("J13 genvækst -> vent", dRegrow.action, "wait"); check("J13 grund", dRegrow.reason, "regrowing")
|
|
check("J13 genvækst men tur færdig -> slå hjørnet", J.decide(mowing, regrowing, {{phase = "finished"}}, 0).action, "dispatch")
|
|
check("J13 halvt slået uden genvækst -> slå resten", J.decide(mowing, {id = 90, markerId = 9, mowable = true, readyRatio = 0.6, immatureRatio = 0}, {}, 0).action, "dispatch")
|
|
|
|
-- J14: kultivering på en mark med uhøstede kartofler (in-game 27/9 F16) -> tilbage til klar; rest efter høst -> ikke
|
|
local cultivatingField = M.with(auto, {stage = "cultivating", kind = "harvest"})
|
|
check("J14 uhøstet -> spol tilbage", J.decide(cultivatingField, {id = 16, markerId = 9, kind = "harvest", phase = "ready", readyRatio = 1}, {}, 0).action, "rewind")
|
|
check("J14 høstrest 30 % -> kultiver", J.decide(cultivatingField, {id = 16, markerId = 9, kind = "harvest", phase = "ready", readyRatio = 0.3}, {}, 0).action ~= "rewind", true)
|
|
check("J14 stub -> kultiver", J.decide(cultivatingField, {id = 16, markerId = 9, kind = "bare", phase = "cut", readyRatio = 0}, {}, 0).action ~= "rewind", true)
|
|
|
|
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
|
|
os.exit(failures == 0 and 0 or 1)
|