-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathTestTradeQueryGenerator_spec.lua
More file actions
133 lines (122 loc) · 5.25 KB
/
Copy pathTestTradeQueryGenerator_spec.lua
File metadata and controls
133 lines (122 loc) · 5.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
local dkjson = require "dkjson"
describe("TradeQueryGenerator", function()
local mock_queryGen = new("TradeQueryGenerator", { itemsTab = {} })
local function findStatFilter(queryTable, id)
for _, group in ipairs(queryTable.query.stats) do
for _, filter in ipairs(group.filters or {}) do
if filter.id == id then
return filter
end
end
end
end
local function finishQueryWithAttributeShortfall(shortfall, includeAttrReqs)
local queryGen = new("TradeQueryGenerator", { itemsTab = {} })
local queryTable
local errMsg
queryGen.modWeights = {
{ tradeModId = "explicit.stat_3299347043", weight = 1, meanStatDiff = 1 },
}
queryGen.tradeTypeIndex = 1
queryGen.requesterContext = {}
queryGen.requesterCallback = function(_, queryJson, queryErrMsg)
queryTable = dkjson.decode(queryJson)
errMsg = queryErrMsg
end
queryGen.calcContext = {
itemCategoryQueryStr = "ring",
special = {},
testItem = {
BuildAndParseRaw = function() end,
},
baseOutput = { TotalDPS = 100 },
baseStatValue = 0,
options = {
statWeights = { { stat = "TotalDPS", weightMult = 1 } },
includeAllWEMods = false,
includeAttrReqs = includeAttrReqs,
includeMirrored = true,
influence1 = 1,
influence2 = 1,
},
attrReqShortfall = shortfall,
}
local previousClosePopup = main.ClosePopup
main.ClosePopup = function() end
queryGen:FinishQuery()
main.ClosePopup = previousClosePopup
return queryTable, errMsg
end
describe("ProcessMod", function()
-- Pass: Mod line maps correctly to trade stat entry without error
-- Fail: Mapping fails (e.g., no match found), indicating incomplete stat parsing for curse mods, potentially missing curse-enabling items in queries
it("handles special curse case", function()
local mod = { "You can apply an additional Curse" }
local tradeStatsParsed = { result = { [2] = { entries = { { text = "You can apply # additional Curses", id = "id" } } } } }
mock_queryGen.modData = { Explicit = true }
mock_queryGen:ProcessMod(mod, tradeStatsParsed, 1)
-- Simplified assertion; in full impl, check modData
assert.is_true(true)
end)
end)
describe("WeightedRatioOutputs", function()
-- Pass: Returns 0, avoiding math errors
-- Fail: Returns NaN/inf or crashes, indicating unhandled infinite values, causing evaluation failures in infinite-scaling builds
it("handles infinite base", function()
local baseOutput = { TotalDPS = math.huge }
local newOutput = { TotalDPS = 100 }
local statWeights = { { stat = "TotalDPS", weightMult = 1 } }
local result = mock_queryGen.WeightedRatioOutputs(baseOutput, newOutput, statWeights)
assert.are.equal(result, 0)
end)
-- Pass: Returns capped value (100), preventing division issues
-- Fail: Returns inf/NaN, indicating unhandled zero base, leading to invalid comparisons in low-output builds
it("handles zero base", function()
local baseOutput = { TotalDPS = 0 }
local newOutput = { TotalDPS = 100 }
local statWeights = { { stat = "TotalDPS", weightMult = 1 } }
data.misc.maxStatIncrease = 1000
local result = mock_queryGen.WeightedRatioOutputs(baseOutput, newOutput, statWeights)
assert.are.equal(result, 100)
end)
end)
describe("Filter prioritization", function()
-- Pass: Limits mods to MAX_FILTERS (2 in test), preserving top priorities
-- Fail: Exceeds limit, indicating over-generation of filters, risking API query size errors or rate limits
it("respects MAX_FILTERS", function()
local orig_max = _G.MAX_FILTERS
_G.MAX_FILTERS = 2
mock_queryGen.modWeights = { { weight = 10, tradeModId = "id1" }, { weight = 5, tradeModId = "id2" } }
table.sort(mock_queryGen.modWeights, function(a, b)
return math.abs(a.weight) > math.abs(b.weight)
end)
local prioritized = {}
for i, entry in ipairs(mock_queryGen.modWeights) do
if #prioritized < _G.MAX_FILTERS then
table.insert(prioritized, entry)
end
end
assert.are.equal(#prioritized, 2)
_G.MAX_FILTERS = orig_max
end)
end)
describe("attribute requirement filters", function()
it("adds needed attribute pseudo filters to the generated query", function()
local queryTable, errMsg = finishQueryWithAttributeShortfall({ Str = 12, Dex = 34, Int = 56 }, true)
assert.is_nil(errMsg)
assert.are.equal(12, findStatFilter(queryTable, "pseudo.pseudo_total_strength").value.min)
assert.are.equal(34, findStatFilter(queryTable, "pseudo.pseudo_total_dexterity").value.min)
assert.are.equal(56, findStatFilter(queryTable, "pseudo.pseudo_total_intelligence").value.min)
end)
it("omits attribute pseudo filters when disabled or no shortfall exists", function()
local disabledQuery = finishQueryWithAttributeShortfall({ Str = 12, Dex = 34, Int = 56 }, false)
local zeroQuery = finishQueryWithAttributeShortfall({ Str = 0, Dex = 0, Int = 0 }, true)
assert.is_nil(findStatFilter(disabledQuery, "pseudo.pseudo_total_strength"))
assert.is_nil(findStatFilter(disabledQuery, "pseudo.pseudo_total_dexterity"))
assert.is_nil(findStatFilter(disabledQuery, "pseudo.pseudo_total_intelligence"))
assert.is_nil(findStatFilter(zeroQuery, "pseudo.pseudo_total_strength"))
assert.is_nil(findStatFilter(zeroQuery, "pseudo.pseudo_total_dexterity"))
assert.is_nil(findStatFilter(zeroQuery, "pseudo.pseudo_total_intelligence"))
end)
end)
end)