Files
fs25-adsmartpickup/tests/test_adFlowView.lua

70 lines
3.3 KiB
Lua

-- Kør: luajit tests/test_adFlowView.lua (fra repo-roden)
-- Ren oprydning af Flows-fanen: tavlens rækkefølge, hvilke traktorer og bygninger der vises.
dofile("FS25_ADSmartPickup/adFlowView.lua")
local V = ADFlowView
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 function ids(list, field)
local out = {}
for _, item in ipairs(list) do table.insert(out, tostring(item[field or "id"])) end
return table.concat(out, ",")
end
-- FV1: tavlen — forsyning (Ind) først, så udkørsel (Ud); hver gruppe sorteret efter navn (naturligt)
local runs = {
{id = 1, name = "Pig Food", kind = "supply"},
{id = 2, name = "Milk Sale", kind = "outbound"},
{id = 3, name = "Cow Food", kind = "supply"},
{id = 4, name = "Biogas 10", kind = "supply"},
{id = 5, name = "Biogas 9", kind = "supply"},
{id = 6, name = "Digestate", kind = "outbound"},
}
local groups = V.boardGroups(runs)
check("FV1 to grupper", #groups, 2)
check("FV1 Ind først", groups[1].kind, "supply")
check("FV1 Ind sorteret (Biogas 9 før 10)", ids(groups[1].runs), "5,4,3,1")
check("FV1 Ud sorteret", ids(groups[2].runs), "6,2")
check("FV1 samlet rækkefølge til vælgeren", ids(V.orderedRuns(runs)), "5,4,3,1,6,2")
check("FV1 tom gruppe udelades", #V.boardGroups({{id = 1, name = "A", kind = "supply"}}), 1)
-- FV2: traktorer — egne først, så ledige brugbare; andre flows og låste kun med "vis alle"
local vehicles = {
{id = "a", label = "Zetor", state = "free"},
{id = "b", label = "Fendt", state = "in"},
{id = "c", label = "Case", state = "other"},
{id = "d", label = "Claas", state = "blocked"},
{id = "e", label = "Deutz", state = "free"},
}
check("FV2 standard: egne + ledige, sorteret", ids(V.vehicleRows(vehicles, false)), "b,e,a")
check("FV2 vis alle: + andre flows + låste til sidst", ids(V.vehicleRows(vehicles, true)), "b,e,a,c,d")
check("FV2 antal skjulte", V.hiddenCount(vehicles, V.vehicleRows(vehicles, false)), 2)
-- FV3: bygninger — valgte først; uden markør skjult medmindre valgt eller "vis alle"
local buildings = {
{id = "s2", name = "Silo 2", hasMarker = true},
{id = "s10", name = "Silo 10", hasMarker = true},
{id = "x", name = "Gammel lade", hasMarker = false},
{id = "y", name = "Anden uden", hasMarker = false},
{id = "a", name = "Anlæg", hasMarker = true},
}
local chosen = {s10 = true, y = true}
check("FV3 standard: valgte først, så med markør", ids(V.buildingRows(buildings, chosen, false)), "y,s10,a,s2")
check("FV3 vis alle: uden markør til sidst", ids(V.buildingRows(buildings, chosen, true)), "y,s10,a,s2,x")
-- FV4: ens navne slås sammen med antal ("Chicken Coop x5"), rækkefølge efter første forekomst
check("FV4 sammenlæg", V.joinCounted({"Chicken Coop", "Chicken Coop", "Cow Barn", "Chicken Coop"}, " + ", "-"), "Chicken Coop x3 + Cow Barn")
check("FV4 ingen dubletter", V.joinCounted({"A", "B"}, " + ", "-"), "A + B")
check("FV4 tom -> tekst", V.joinCounted({}, " + ", "(ingen)"), "(ingen)")
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
os.exit(failures == 0 and 0 or 1)