-- Kør: luajit tests/test_adFields.lua (fra repo-roden) dofile("FS25_ADSmartPickup/adFields.lua") local F = ADFields 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 -- F1/F2: markørnavne check("F1 F109", F.parseMarkerName("F109"), 109) check("F1 småt", F.parseMarkerName("f7"), 7) check("F1 mellemrum", F.parseMarkerName(" F 12 "), 12) check("F2 andet navn", F.parseMarkerName("Field 109"), nil) check("F2 tekst efter", F.parseMarkerName("F109 wait"), nil) check("F2 nil", F.parseMarkerName(nil), nil) -- F3: slåafgrøde = MOWER giver et skår som TEDDER gør til DRY…; halm udelukket local names = {[10] = "GRASS_WINDROW", [11] = "DRYGRASS_WINDROW", [20] = "STRAW", [30] = "CLOVER_WINDROW", [31] = "DRYCLOVER_WINDROW", [40] = "BEANSTRAW"} local mower = {[1] = {fillTypeIndex = 10}, [2] = {fillTypeIndex = 20}, [3] = {fillTypeIndex = 30}, [4] = {fillTypeIndex = 40}} local tedder = {[10] = {targetFillTypeIndex = 11}, [30] = {targetFillTypeIndex = 31}, [40] = {targetFillTypeIndex = 20}} local mowable = F.buildMowable(mower, tedder, function(index) return names[index] end) check("F3 græs", mowable[1] ~= nil, true) check("F3 græs skår", mowable[1].windrow, 10) check("F3 græs hø", mowable[1].hay, 11) check("F3 rug (halm) ikke", mowable[2], nil) check("F3 kløver", mowable[3].hay, 31) check("F3 bønnehalm -> halm ikke", mowable[4], nil) -- F4: markens art og om den vokser local kind, growing = F.classify(3, false, 0.4) check("F4 høstafgrøde", kind, "harvest"); check("F4 vokser", growing, true) check("F4 klar høst vokser ikke", select(2, F.classify(3, false, 0.95)), false) check("F4 slåafgrøde", (F.classify(1, true, 0.2)), "mowable") check("F4 ingen afgrøde = bar", (F.classify(nil, false, 0)), "bare") check("F4 bar vokser ikke", select(2, F.classify(nil, false, 0)), false) -- F5: jordens behov ud fra gennemsnit og spillets indstillinger local needs = F.soilNeeds({lime = 0.2, plowLevel = 0}, {limeRequired = true, plowingRequired = true}) check("F5 kalk", needs.lime, true); check("F5 pløj", needs.plow, true) local off = F.soilNeeds({lime = 0, plowLevel = 0}, {limeRequired = false, plowingRequired = false}) check("F5 kalk slået fra i spillet", off.lime, false); check("F5 pløjning slået fra", off.plow, false) check("F5 kalket jord", F.soilNeeds({lime = 2, plowLevel = 1}, {limeRequired = true, plowingRequired = true}).lime, false) check("F5 ukendt niveau = intet behov", F.soilNeeds({}, {limeRequired = true, plowingRequired = true}).plow, false) -- F6: vækststadie -> fase ud fra afgrødens egne grænser local wheat = {minHarvestingGrowthState = 6, maxHarvestingGrowthState = 7, cutState = 9, witheredState = 8} check("F6 intet", F.growthPhase(0, wheat), "none") check("F6 spirer/vokser", F.growthPhase(3, wheat), "growing") check("F6 klar", F.growthPhase(6, wheat), "ready") check("F6 visnet", F.growthPhase(8, wheat), "withered") check("F6 høstet stub", F.growthPhase(9, wheat), "cut") check("F6 ukendt stadie", F.growthPhase(nil, wheat), nil) check("F6 FS25-navne (minHarvestGrowthState)", F.growthPhase(6, {minHarvestGrowthState = 5, maxHarvestGrowthState = 6, cutState = 8}), "ready") -- F7: vokser = fase growing; ukendt fase -> voksende pixels og ikke klar check("F7 fase vinder", F.isGrowing("cut", 100, 0.1), false) check("F7 fase vokser", F.isGrowing("growing", 0, 0), true) check("F7 reserve: voksende pixels", F.isGrowing(nil, 50, 0.2), true) check("F7 reserve: ingen pixels (stub)", F.isGrowing(nil, 0, 0), false) check("F7 reserve: klar", F.isGrowing(nil, 50, 0.95), false) -- F8: slåafgrøde fuldt udvokset (Dakota-græs 3 = mellemhøjde, 4-5 = fuld) check("F8 prime græs", F.primeState({minHarvestingGrowthState = 3, maxHarvestingGrowthState = 5}), 4) check("F8 prime ét klar-stadie", F.primeState({minHarvestingGrowthState = 6, maxHarvestingGrowthState = 6}), 6) check("F8 prime ukendt", F.primeState({}), nil) check("F8 mellemhøjde tæller ikke", F.isPrime(3, 4), false) check("F8 fuld højde tæller", F.isPrime(5, 4), true) check("F8 ukendt stadie tæller", F.isPrime(nil, 4), true) check("F8 ingen krav", F.isPrime(3, nil), true) -- F9: kartofler (Dakota): 6 = klar men kun forberedelig, 10 = toppet (høstklar) local potato = {minHarvestingGrowthState = 10, maxHarvestingGrowthState = 10, minPreparingGrowthState = 6, maxPreparingGrowthState = 6, witheredState = 7, cutState = 8} check("F9 utoppet er forberedelig", F.isPreparable(6, potato), true) check("F9 voksende ikke", F.isPreparable(5, potato), false) check("F9 fase klar", F.growthPhase(6, potato), "ready") check("F9 toppet klar", F.growthPhase(10, potato), "ready") check("F9 ingen forberedelse", F.isPreparable(6, {minPreparingGrowthState = -1}), false) print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) os.exit(failures == 0 and 0 or 1)