Files
fs25-adsmartpickup/tests/test_adPrices.lua
T

66 lines
3.0 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 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", quote.top, 625)
check("P4 procent", quote.percent, 75)
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)
-- P5: uden stationens grundpris: pricePerLiter × faktor nu × sværhedsgrad
local bare = {getEffectiveFillTypePrice = function() return 470 end}
local quote2 = ADPrices.getQuote(bare, SUGAR)
check("P5 top fra pricePerLiter", quote2.top, 500)
check("P5 procent", quote2.percent, 94)
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)