47 lines
2.6 KiB
Lua
47 lines
2.6 KiB
Lua
-- Kør: luajit tests/test_adFieldSiloConfig.lua (fra repo-roden)
|
|
dofile("FS25_ADSmartPickup/adFieldSiloConfig.lua")
|
|
local C = ADFieldSiloConfig
|
|
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 cfg = C.new()
|
|
check("standard fra", cfg.enabled, false)
|
|
check("standard x=2", cfg.maxVehicles, 2)
|
|
check("standard tærskel 10000", cfg.minLiters, 10000)
|
|
check("x under 1 -> 1", C.with(cfg, {maxVehicles = 0}).maxVehicles, 1)
|
|
check("x over 10 -> 10", C.with(cfg, {maxVehicles = 99}).maxVehicles, 10)
|
|
check("tærskel snappes til nærmeste valg", C.with(cfg, {minLiters = 12000}).minLiters, 10000)
|
|
check("tærskel 40000 -> 50000", C.with(cfg, {minLiters = 40000}).minLiters, 50000)
|
|
check("with muterer ikke", cfg.maxVehicles, 2)
|
|
local on = C.toggleStore(cfg, "silo1")
|
|
check("toggle til", C.hasStore(on, "silo1"), true)
|
|
check("toggle muterer ikke", C.hasStore(cfg, "silo1"), false)
|
|
check("toggle fra", C.hasStore(C.toggleStore(on, "silo1"), "silo1"), false)
|
|
local full = C.with(C.toggleStore(C.toggleStore(cfg, "a"), "b"), {enabled = true, maxVehicles = 4, minLiters = 25000})
|
|
local back = C.fromRecord(C.toRecord(full))
|
|
check("record: enabled", back.enabled, true)
|
|
check("record: lagre", table.concat(back.storeIds, " "), "a b")
|
|
check("record: x", back.maxVehicles, 4)
|
|
check("record: tærskel", back.minLiters, 25000)
|
|
check("tom record -> standard", C.fromRecord(nil).maxVehicles, 2)
|
|
check("record uden tal -> standard tærskel", C.fromRecord({enabled = 1}).minLiters, 10000)
|
|
-- kør til produktion + foderreserve
|
|
check("standard: ikke til produktion", cfg.toProduction, false)
|
|
check("standard foderreserve 7 døgn", cfg.reserveDays, 7)
|
|
check("reserve snappes (10 -> 7)", C.with(cfg, {reserveDays = 10}).reserveDays, 7)
|
|
check("reserve 40 -> 30", C.with(cfg, {reserveDays = 40}).reserveDays, 30)
|
|
local prod = C.with(C.toggleStore(cfg, "a"), {toProduction = true, reserveDays = 14})
|
|
check("with bevarer lagre", C.hasStore(prod, "a"), true)
|
|
check("with muterer ikke (produktion)", cfg.toProduction, false)
|
|
local prodBack = C.fromRecord(C.toRecord(prod))
|
|
check("record: til produktion", prodBack.toProduction, true)
|
|
check("record: foderreserve", prodBack.reserveDays, 14)
|
|
check("gammel record uden felter -> standard", C.fromRecord({enabled = 1}).reserveDays, 7)
|
|
check("toggleStore bevarer produktion", C.toggleStore(prod, "b").toProduction, true)
|
|
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
|
|
os.exit(failures == 0 and 0 or 1)
|