-- 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") print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) os.exit(failures == 0 and 0 or 1)