|
1 | 1 | describe("TradeQueryGenerator", function() |
2 | | - local mock_queryGen = new("TradeQueryGenerator", { itemsTab = {} }) |
| 2 | + local mock_queryGen = new("TradeQueryGenerator", { itemsTab = {} }) |
3 | 3 |
|
4 | | - describe("ProcessMod", function() |
5 | | - -- Pass: Mod line maps correctly to trade stat entry without error |
6 | | - -- Fail: Mapping fails (e.g., no match found), indicating incomplete stat parsing for curse mods, potentially missing curse-enabling items in queries |
7 | | - it("handles special curse case", function() |
8 | | - local mod = { "You can apply an additional Curse" } |
9 | | - local tradeStatsParsed = { result = { [2] = { entries = { { text = "You can apply # additional Curses", id = "id" } } } } } |
10 | | - mock_queryGen.modData = { Explicit = true } |
11 | | - mock_queryGen:ProcessMod(mod, tradeStatsParsed, 1) |
12 | | - -- Simplified assertion; in full impl, check modData |
13 | | - assert.is_true(true) |
14 | | - end) |
15 | | - end) |
| 4 | + describe("ProcessMod", function() |
| 5 | + -- Pass: Mod line maps correctly to trade stat entry without error |
| 6 | + -- Fail: Mapping fails (e.g., no match found), indicating incomplete stat parsing for curse mods, potentially missing curse-enabling items in queries |
| 7 | + it("handles special curse case", function() |
| 8 | + local mod = { "You can apply an additional Curse" } |
| 9 | + local tradeStatsParsed = { result = { [2] = { entries = { { text = "You can apply # additional Curses", id = "id" } } } } } |
| 10 | + mock_queryGen.modData = { Explicit = true } |
| 11 | + mock_queryGen:ProcessMod(mod, tradeStatsParsed, 1) |
| 12 | + -- Simplified assertion; in full impl, check modData |
| 13 | + assert.is_true(true) |
| 14 | + end) |
| 15 | + end) |
16 | 16 |
|
17 | | - describe("WeightedRatioOutputs", function() |
18 | | - -- Pass: Returns 0, avoiding math errors |
19 | | - -- Fail: Returns NaN/inf or crashes, indicating unhandled infinite values, causing evaluation failures in infinite-scaling builds |
20 | | - it("handles infinite base", function() |
21 | | - local baseOutput = { TotalDPS = math.huge } |
22 | | - local newOutput = { TotalDPS = 100 } |
23 | | - local statWeights = { { stat = "TotalDPS", weightMult = 1 } } |
24 | | - local result = mock_queryGen.WeightedRatioOutputs(baseOutput, newOutput, statWeights) |
25 | | - assert.are.equal(result, 0) |
26 | | - end) |
| 17 | + describe("WeightedRatioOutputs", function() |
| 18 | + -- Pass: Returns 0, avoiding math errors |
| 19 | + -- Fail: Returns NaN/inf or crashes, indicating unhandled infinite values, causing evaluation failures in infinite-scaling builds |
| 20 | + it("handles infinite base", function() |
| 21 | + local baseOutput = { TotalDPS = math.huge } |
| 22 | + local newOutput = { TotalDPS = 100 } |
| 23 | + local statWeights = { { stat = "TotalDPS", weightMult = 1 } } |
| 24 | + local result = mock_queryGen.WeightedRatioOutputs(baseOutput, newOutput, statWeights) |
| 25 | + assert.are.equal(result, 0) |
| 26 | + end) |
27 | 27 |
|
28 | | - -- Pass: Returns capped value (100), preventing division issues |
29 | | - -- Fail: Returns inf/NaN, indicating unhandled zero base, leading to invalid comparisons in low-output builds |
30 | | - it("handles zero base", function() |
31 | | - local baseOutput = { TotalDPS = 0 } |
32 | | - local newOutput = { TotalDPS = 100 } |
33 | | - local statWeights = { { stat = "TotalDPS", weightMult = 1 } } |
34 | | - data.misc.maxStatIncrease = 1000 |
35 | | - local result = mock_queryGen.WeightedRatioOutputs(baseOutput, newOutput, statWeights) |
36 | | - assert.are.equal(result, 100) |
37 | | - end) |
38 | | - end) |
| 28 | + -- Pass: Returns capped value (100), preventing division issues |
| 29 | + -- Fail: Returns inf/NaN, indicating unhandled zero base, leading to invalid comparisons in low-output builds |
| 30 | + it("handles zero base", function() |
| 31 | + local baseOutput = { TotalDPS = 0 } |
| 32 | + local newOutput = { TotalDPS = 100 } |
| 33 | + local statWeights = { { stat = "TotalDPS", weightMult = 1 } } |
| 34 | + data.misc.maxStatIncrease = 1000 |
| 35 | + local result = mock_queryGen.WeightedRatioOutputs(baseOutput, newOutput, statWeights) |
| 36 | + assert.are.equal(result, 100) |
| 37 | + end) |
| 38 | + end) |
39 | 39 |
|
40 | | - describe("Filter prioritization", function() |
41 | | - -- Pass: Limits mods to MAX_FILTERS (2 in test), preserving top priorities |
42 | | - -- Fail: Exceeds limit, indicating over-generation of filters, risking API query size errors or rate limits |
43 | | - it("respects MAX_FILTERS", function() |
44 | | - local orig_max = _G.MAX_FILTERS |
45 | | - _G.MAX_FILTERS = 2 |
46 | | - mock_queryGen.modWeights = { { weight = 10, tradeModId = "id1" }, { weight = 5, tradeModId = "id2" } } |
47 | | - table.sort(mock_queryGen.modWeights, function(a, b) |
48 | | - return math.abs(a.weight) > math.abs(b.weight) |
49 | | - end) |
50 | | - local prioritized = {} |
51 | | - for i, entry in ipairs(mock_queryGen.modWeights) do |
52 | | - if #prioritized < _G.MAX_FILTERS then |
53 | | - table.insert(prioritized, entry) |
54 | | - end |
55 | | - end |
56 | | - assert.are.equal(#prioritized, 2) |
57 | | - _G.MAX_FILTERS = orig_max |
58 | | - end) |
59 | | - end) |
| 40 | + describe("Filter prioritization", function() |
| 41 | + -- Pass: Limits mods to MAX_FILTERS (2 in test), preserving top priorities |
| 42 | + -- Fail: Exceeds limit, indicating over-generation of filters, risking API query size errors or rate limits |
| 43 | + it("respects MAX_FILTERS", function() |
| 44 | + local orig_max = _G.MAX_FILTERS |
| 45 | + _G.MAX_FILTERS = 2 |
| 46 | + mock_queryGen.modWeights = { { weight = 10, tradeModId = "id1" }, { weight = 5, tradeModId = "id2" } } |
| 47 | + table.sort(mock_queryGen.modWeights, function(a, b) |
| 48 | + return math.abs(a.weight) > math.abs(b.weight) |
| 49 | + end) |
| 50 | + local prioritized = {} |
| 51 | + for i, entry in ipairs(mock_queryGen.modWeights) do |
| 52 | + if #prioritized < _G.MAX_FILTERS then |
| 53 | + table.insert(prioritized, entry) |
| 54 | + end |
| 55 | + end |
| 56 | + assert.are.equal(#prioritized, 2) |
| 57 | + _G.MAX_FILTERS = orig_max |
| 58 | + end) |
| 59 | + end) |
60 | 60 | end) |
0 commit comments