feat(lagre): vælg bygning -> statistik pr. vare: værdi nu/ved toppris, gårdens beholdning i døgn, forbrug og produktion pr. døgn (v1.15.0.0)
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
-- Kør: luajit tests/test_adStorageStats.lua (fra repo-roden)
|
||||
-- Lagerstatistik pr. vare: fyldning, værdi nu / ved toppris, gårdens samlede beholdning, dage tilbage.
|
||||
|
||||
dofile("FS25_ADSmartPickup/adStorageStats.lua")
|
||||
local S = ADStorageStats
|
||||
|
||||
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
|
||||
|
||||
-- ST1: fuld beregning
|
||||
local st = S.itemStats({fillType = 5, level = 150000, capacity = 180000}, 412000, {consumption = 130000, production = 48000}, {price = 1.6, top = 2.0})
|
||||
check("ST1 procent", st.percent, 83)
|
||||
check("ST1 værdi nu", st.valueNow, 240000)
|
||||
check("ST1 værdi top", st.valueTop, 300000)
|
||||
check("ST1 gårdens beholdning", st.farmTotal, 412000)
|
||||
check("ST1 dage", math.floor(st.days * 10 + 0.5) / 10, 3.2)
|
||||
check("ST1 netto pr. døgn", st.net, -82000)
|
||||
|
||||
-- ST2: ingen salgssted, intet forbrug, ingen kapacitet
|
||||
local st2 = S.itemStats({fillType = 6, level = 5000, capacity = 0}, 5000, nil, nil)
|
||||
check("ST2 ingen pris -> nil", st2.valueNow, nil)
|
||||
check("ST2 intet forbrug -> dage nil", st2.days, nil)
|
||||
check("ST2 kapacitet 0 -> procent nil", st2.percent, nil)
|
||||
|
||||
-- ST3: bygningens samlede værdi (kun varer med pris)
|
||||
local total = S.buildingTotals({st, st2, S.itemStats({fillType = 7, level = 1000, capacity = 2000}, 1000, nil, {price = 2, top = 3})})
|
||||
check("ST3 samlet nu", total.valueNow, 242000)
|
||||
check("ST3 samlet top", total.valueTop, 303000)
|
||||
|
||||
-- ST4: gårdens totaler fra inventar
|
||||
local totals = S.farmTotals({{entries = {{fillType = 5, level = 100}, {fillType = 6, level = 5}}}, {entries = {{fillType = 5, level = 50}}}})
|
||||
check("ST4 sum pr. vare", totals[5], 150)
|
||||
check("ST4 anden vare", totals[6], 5)
|
||||
|
||||
-- ST5: foder-forbrug i et fælles trug fordeles efter truget indhold; tomt trug -> bedste foder
|
||||
local split = S.splitTroughConsumption(2400, {[116] = 3000, [7] = 1000}, {[116] = 1.0, [7] = 0.8})
|
||||
check("ST5 TMR 75 %", split[116], 1800)
|
||||
check("ST5 ensilage 25 %", split[7], 600)
|
||||
local empty = S.splitTroughConsumption(2400, {}, {[116] = 1.0, [7] = 0.8})
|
||||
check("ST5 tomt trug -> bedste foder", empty[116], 2400)
|
||||
check("ST5 tomt trug -> intet på ensilage", empty[7], nil)
|
||||
|
||||
print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL"))
|
||||
os.exit(failures == 0 and 0 or 1)
|
||||
Reference in New Issue
Block a user