80 lines
4.7 KiB
Lua
80 lines
4.7 KiB
Lua
-- Kør: luajit tests/test_adLoadSwap.lua (fra repo-roden)
|
|
-- Ren rangering af aflæsnings-siloer (lagermål for udkørsel og læs-bytte).
|
|
|
|
dofile("FS25_ADSmartPickup/adPrices.lua")
|
|
dofile("FS25_ADSmartPickup/adLoadSwap.lua")
|
|
local L = ADLoadSwap
|
|
|
|
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
|
|
|
|
-- LS1: markører et andet forløb HENTER fra (fx "Milk Storage Load") vælges sidst; ellers har-varen, så afstand
|
|
local candidates = {
|
|
{marker = {id = 1, name = "Milk Storage Load"}, hasFillType = true, distance = 100},
|
|
{marker = {id = 2, name = "Milk Storage unload"}, hasFillType = true, distance = 400},
|
|
{marker = {id = 3, name = "Silo tom"}, hasFillType = false, distance = 10},
|
|
}
|
|
local ranked = L.rankDumpCandidates(candidates, {[1] = true})
|
|
check("LS1 afhentningsmarkør undgås", ranked[1].marker.id, 2)
|
|
check("LS1 derefter tom silo før afhentning", ranked[2].marker.id, 3)
|
|
check("LS1 afhentning sidst (stadig mulig)", ranked[3].marker.id, 1)
|
|
local plain = L.rankDumpCandidates(candidates, nil)
|
|
check("LS1 uden undgå-liste: har varen + nærmest", plain[1].marker.id, 1)
|
|
|
|
-- LS2: lagermål — rene siloer altid; egne fabrikker der bruger varen som input kun når tilladt (udkørsel)
|
|
local SLURRY, MILK = 20, 21
|
|
g_currentMission = {getFarmId = function() return 1 end}
|
|
local biogas = {spec_productionPoint = {productionPoint = {productions = {{inputs = {{type = SLURRY, amount = 1}}}}}}, getOwnerFarmId = function() return 1 end}
|
|
local foreignBiogas = {spec_productionPoint = {productionPoint = {productions = {{inputs = {{type = SLURRY, amount = 1}}}}}}, getOwnerFarmId = function() return 0 end}
|
|
local silo = {spec_silo = {}}
|
|
local barn = {spec_silo = {}, getHusbandryFillLevel = function() return 0 end}
|
|
check("LS2 silo", L.isStoreTarget({owningPlaceable = silo}, SLURRY, nil, false), true)
|
|
check("LS2 stald aldrig", L.isStoreTarget({owningPlaceable = barn}, SLURRY, nil, true), false)
|
|
check("LS2 biogas kun når fabrikker tilladt", L.isStoreTarget({owningPlaceable = biogas}, SLURRY, nil, false), false)
|
|
check("LS2 biogas tager gylle", L.isStoreTarget({owningPlaceable = biogas}, SLURRY, nil, true), true)
|
|
check("LS2 biogas tager ikke mælk", L.isStoreTarget({owningPlaceable = biogas}, MILK, nil, true), false)
|
|
check("LS2 fremmed anlæg aldrig", L.isStoreTarget({owningPlaceable = foreignBiogas}, SLURRY, nil, true), false)
|
|
check("LS2 hjemmet selv aldrig", L.isStoreTarget({owningPlaceable = biogas}, SLURRY, {owningPlaceable = biogas}, true), false)
|
|
g_currentMission = nil
|
|
|
|
-- LS3: tvunget lagermål — kun de valgte markører, i rækkefølge; første der tager varen, har plads og kan nås
|
|
do
|
|
local stations = {
|
|
[101] = {accepts = {[SLURRY] = true}, free = 0}, -- BGA fuld
|
|
[102] = {accepts = {[SLURRY] = true}, free = 900000}, -- gylletank
|
|
[103] = {accepts = {[MILK] = true}, free = 900000}, -- tager ikke gylle
|
|
}
|
|
for _, st in pairs(stations) do
|
|
st.getIsFillTypeSupported = function(self, ft) return self.accepts[ft] == true end
|
|
st.getFreeCapacity = function(self) return self.free end
|
|
end
|
|
ADSmartPickup = {getFarmId = function() return 1 end, getUnloadStationAtWayPointId = function(_, id) return stations[id] end}
|
|
local adEnv = {ADGraphManager = {getMapMarkerByWayPointId = function(_, id) return {id = id, name = "m" .. id} end}}
|
|
local vehicle = {}
|
|
local all = function() return true end
|
|
check("LS3 fuld BGA springes over -> tank", L.findForcedDumpMarker(adEnv, vehicle, SLURRY, 20000, {101, 102}, all).id, 102)
|
|
stations[101].free = 500000
|
|
check("LS3 BGA med plads vælges først", L.findForcedDumpMarker(adEnv, vehicle, SLURRY, 20000, {101, 102}, all).id, 101)
|
|
local none, why = L.findForcedDumpMarker(adEnv, vehicle, SLURRY, 20000, {103}, all)
|
|
check("LS3 intet valgt mål tager varen -> nil", none, nil)
|
|
check("LS3 forklaring", why ~= nil and why:find("valgt", 1, true) ~= nil, true)
|
|
check("LS3 ikke nåelig -> næste", L.findForcedDumpMarker(adEnv, vehicle, SLURRY, 20000, {101, 102}, function(id) return id ~= 101 end).id, 102)
|
|
ADSmartPickup = nil
|
|
end
|
|
|
|
-- LQ: flydende varer lægges ikke automatisk i en fabrik (AIO-risten, in-game 26/9)
|
|
check("LQ gylle er flydende", ADLoadSwap.isLiquidName("LIQUIDMANURE"), true)
|
|
check("LQ digestat er flydende", ADLoadSwap.isLiquidName("digestate"), true)
|
|
check("LQ hvede er ikke flydende", ADLoadSwap.isLiquidName("WHEAT"), false)
|
|
check("LQ ukendt", ADLoadSwap.isLiquidName(nil), false)
|
|
|
|
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
|
|
os.exit(failures == 0 and 0 or 1)
|