-- Kør: luajit tests/test_adPrices.lua (fra repo-roden) -- Prisregel: toppris fra årets prisforløb, pris-% pr. salgssted, bedste tilbud. dofile("FS25_ADSmartPickup/adPrices.lua") 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 -- P1: højeste faktor check("P1 maxFactor", ADPrices.maxFactor({EARLY_SPRING = 0.9, LATE_AUTUMN = 1.2, MID_SUMMER = 1.0}), 1.2) check("P1 uden faktorer = 1", ADPrices.maxFactor(nil), 1) -- P2: toppris = grundpris nu × (maks ÷ nu) check("P2 topPrice", ADPrices.topPrice(500, 1.0, 1.25), 625) check("P2 factorNow 0 -> grundpris", ADPrices.topPrice(500, 0, 1.25), 500) check("P2 grundpris 0 -> 0", ADPrices.topPrice(0, 1, 1.25), 0) -- P3: procent, afrundet; stor efterspørgsel > 100 check("P3 75 %", ADPrices.percentOfTop(470, 625), 75) check("P3 112 %", ADPrices.percentOfTop(700, 625), 112) check("P3 top 0 -> 0", ADPrices.percentOfTop(1, 0), 0) -- P4: spil-adapter med stationens grundpris SellingStation = {} local SUGAR = 5 g_fillTypeManager = {getFillTypeByIndex = function(_, index) if index == SUGAR then return {economy = {factors = {A = 1.0, B = 1.25}}, pricePerLiter = 400} end end} g_currentMission = {environment = {currentPeriod = "A"}, economyManager = {getPriceMultiplier = function() return 1.0 end}} local station = { fillTypePrices = {[SUGAR] = 500}, getEffectiveFillTypePrice = function(_, fillType) return 470 end, isa = function(_, class) return class == SellingStation end, isSellingPoint = true, } local quote = ADPrices.getQuote(station, SUGAR) check("P4 pris", quote.price, 470) check("P4 top (pris ved 100 %)", math.floor(quote.top + 0.5), 588) check("P4 procent = kurven alene (stationens grundpris bruges ikke: den mangler sværhedsgrad m.m.)", quote.percent, 80) check("P4 er salgssted", ADPrices.isSellingStation(station), true) check("P4 skjult = ikke salgssted", ADPrices.isSellingStation({isa = function() return true end, isSellingPoint = true, hideFromPricesMenu = true}), false) check("P4 fabrik-station = ikke salgssted", ADPrices.isSellingStation({isa = function() return true end, isSellingPoint = false}), false) -- in-game (23/9): TMR-fabrikkens indlevering er en SellingStation med isSellingPoint=true -> blev regnet som marked check("P4 fabrikkens egen station = ikke salgssted", ADPrices.isSellingStation({isa = function() return true end, isSellingPoint = true, owningPlaceable = {spec_productionPoint = {}}}), false) check("P4 staldens egen station = ikke salgssted", ADPrices.isSellingStation({isa = function() return true end, isSellingPoint = true, owningPlaceable = {getHusbandryFillLevel = function() end}}), false) -- P4b: fremmed produktion (kortets mejeri, ejer 0) køber varen = salgssted; gårdens egen fabrik er ikke check("P4b fremmed mejeri = salgssted", ADPrices.isSellingStation({isa = function() return true end, isSellingPoint = true, owningPlaceable = {spec_productionPoint = {}, getOwnerFarmId = function() return 0 end}}), true) check("P4b egen fabrik (ejer 1) = ikke salgssted", ADPrices.isSellingStation({isa = function() return true end, isSellingPoint = true, owningPlaceable = {spec_productionPoint = {}, getOwnerFarmId = function() return 1 end}}), false) check("P4b fremmed stald-felt ownerFarmId", ADPrices.isSellingStation({isa = function() return true end, isSellingPoint = true, owningPlaceable = {getHusbandryFillLevel = function() end, ownerFarmId = 0}}), true) check("P4 rigtigt salgssted med placeable", ADPrices.isSellingStation({isa = function() return true end, isSellingPoint = true, owningPlaceable = {}}), true) -- P5: uden stationens grundpris: kun kurven tæller (faktor nu ÷ faktor max) local bare = {getEffectiveFillTypePrice = function() return 470 end} local quote2 = ADPrices.getQuote(bare, SUGAR) check("P5 procent = kurven alene", quote2.percent, 80) check("P5 top = effektiv ÷ kurve", math.floor(quote2.top + 0.5), 588) -- P7: kurven er grundlaget (Distribution Redux-metoden): faktor nu ÷ årets max, uafhængigt af sværhedsgrad check("P7 curvePercent", ADPrices.curvePercent({1.0, 1.25, 0.9}, 1), 80) check("P7 curvePercent ved top", ADPrices.curvePercent({1.0, 1.25, 0.9}, 2), 100) check("P7 flad kurve = 100", ADPrices.curvePercent({1.0, 1.01, 1.0}, 3), 100) check("P7 ingen kurve = 100", ADPrices.curvePercent(nil, 1), 100) check("P7 ukendt periode = 100", ADPrices.curvePercent({1.0, 1.25}, nil), 100) -- P8: in-game (23/9): effektiv 1602 mod fillTypePrices 505 gav 317 % — stationens grundpris indeholder -- hverken sværhedsgrad eller prisskala, så forholdet er ubrugeligt. Procenten er kurven alene. local demandStation = {fillTypePrices = {[SUGAR] = 505}, getEffectiveFillTypePrice = function() return 1602 end} check("P8 procent uafhængig af stationens grundpris", ADPrices.getQuote(demandStation, SUGAR).percent, 80) check("P8 top = pris ved 100 % af kurven", math.floor(ADPrices.getQuote(demandStation, SUGAR).top + 0.5), 2003) -- P9: sværhedsgraden påvirker ikke procenten local hardStation = {getEffectiveFillTypePrice = function() return 235 end} check("P9 uafhængig af sværhedsgrad", ADPrices.getQuote(hardStation, SUGAR).percent, 80) check("P5 fejlende station -> nil", ADPrices.getQuote({getEffectiveFillTypePrice = function() error("x") end}, SUGAR), nil) -- P6: bedste tilbud = højeste procent, dernæst pris local best = ADPrices.bestQuote({{percent = 80, price = 1}, {percent = 92, price = 2}, {percent = 92, price = 3}}) check("P6 højeste procent", best.percent, 92) check("P6 ved lighed højeste pris", best.price, 3) check("P6 tom -> nil", ADPrices.bestQuote({}), nil) print(failures == 0 and "\nALLE TESTS OK" or ("\n" .. failures .. " FEJL")) os.exit(failures == 0 and 0 or 1)