|
| 1 | +describe("TradeHelpers trade hash matching", function() |
| 2 | + local tradeHelpers = LoadModule("Classes/TradeHelpers") |
| 3 | + |
| 4 | + ---@param ids number[] |
| 5 | + ---@param expected number |
| 6 | + ---@return boolean contains whether the given array contains the expected id |
| 7 | + local function contains(ids, expected) |
| 8 | + for _, id in ipairs(ids) do |
| 9 | + if id == expected then return true end |
| 10 | + end |
| 11 | + return false |
| 12 | + end |
| 13 | + |
| 14 | + describe("modLineValue", function() |
| 15 | + it("returns the single number on a line", function() |
| 16 | + assert.equal(50, tradeHelpers.modLineValue("+50 to maximum Life")) |
| 17 | + end) |
| 18 | + |
| 19 | + it("returns the midpoint of a '# to #' range", function() |
| 20 | + assert.equal(15, tradeHelpers.modLineValue("Adds 10 to 20 Fire Damage")) |
| 21 | + assert.equal(12.5, tradeHelpers.modLineValue("Adds 10 to 15 Fire Damage")) |
| 22 | + end) |
| 23 | + |
| 24 | + it("handles negative numbers", function() |
| 25 | + assert.equal(-10, tradeHelpers.modLineValue("-10% to Fire Resistance")) |
| 26 | + end) |
| 27 | + |
| 28 | + it("returns nil when onlyFromTo is set and there is no range", function() |
| 29 | + assert.is_nil(tradeHelpers.modLineValue("+50 to maximum Life", true)) |
| 30 | + end) |
| 31 | + end) |
| 32 | + |
| 33 | + describe("findTradeHash", function() |
| 34 | + it("matches a simple mod", function() |
| 35 | + local ids, value = tradeHelpers.findTradeHash("+50 to maximum Life") |
| 36 | + assert.equal(50, value) |
| 37 | + assert.is_true(contains(ids, HashStats({ "base_maximum_life" }))) |
| 38 | + end) |
| 39 | + |
| 40 | + it("matches a percentage mod", function() |
| 41 | + local ids, value = tradeHelpers.findTradeHash("25% reduced maximum Energy Shield") |
| 42 | + assert.equal(25, value) |
| 43 | + assert.is_true(contains(ids, HashStats({ "maximum_energy_shield_+%" }))) |
| 44 | + end) |
| 45 | + |
| 46 | + it("matches a # to # mod", function() |
| 47 | + local ids, value = tradeHelpers.findTradeHash("Adds 5 to 15 Fire Damage") |
| 48 | + assert.equal(10, value) |
| 49 | + assert.is_true(contains(ids, |
| 50 | + HashStats({ "local_minimum_added_fire_damage", "local_maximum_added_fire_damage" }))) |
| 51 | + end) |
| 52 | + |
| 53 | + it("is case-insensitive", function() |
| 54 | + local ids = tradeHelpers.findTradeHash( |
| 55 | + "1 aDDED PASSiVe sKilL IS ONE wITh The ShiELd") |
| 56 | + assert.is_true(contains(ids, HashStats({ "local_affliction_notable_one_with_the_shield" }))) |
| 57 | + end) |
| 58 | + |
| 59 | + it("returns no results for an unmatchable line", function() |
| 60 | + local ids = tradeHelpers.findTradeHash("+100 to IQ") |
| 61 | + assert.equal(0, #ids) |
| 62 | + end) |
| 63 | + |
| 64 | + it("works thrice in a row", function() |
| 65 | + local a = tradeHelpers.findTradeHash("+50 to maximum Life") |
| 66 | + local b = tradeHelpers.findTradeHash("+50 to maximum Life") |
| 67 | + local c = tradeHelpers.findTradeHash("+50 to maximum Life") |
| 68 | + assert.same(a, b) |
| 69 | + assert.same(b, c) |
| 70 | + end) |
| 71 | + |
| 72 | + it("detects inverted mods correctly", function() |
| 73 | + -- note that this stat is a handwrap mod and doesn't actually exist on the trade site |
| 74 | + local ids, value, shouldNegate = tradeHelpers.findTradeHash( |
| 75 | + "Debuffs on you expire 100% slower while affected by Haste") |
| 76 | + assert.equal(100, value) |
| 77 | + assert.is_true(shouldNegate) |
| 78 | + assert.equal(1, #ids) |
| 79 | + |
| 80 | + local ids, value, shouldNegate = tradeHelpers.findTradeHash("67% reduced maximum life") |
| 81 | + assert.equal(67, value) |
| 82 | + assert.is_true(shouldNegate) |
| 83 | + assert.equal(1, #ids) |
| 84 | + end) |
| 85 | + it("detects mods with lua pattern characters correctly", function() |
| 86 | + local ids, value = tradeHelpers.findTradeHash( |
| 87 | + "trigger Socketed Spells when you focus, with a 0.25 second cooldown") |
| 88 | + assert.is_true(contains(ids, HashStats({ "trigger_socketed_spells_when_you_focus_%" }))) |
| 89 | + assert.equal(100, value) |
| 90 | + |
| 91 | + local ids, value, shouldNegate = tradeHelpers.findTradeHash( |
| 92 | + "10% reduced effect of Non-Curse Auras from your Skills on your Minions") |
| 93 | + assert.is_true(contains(ids, HashStats({ "minions_have_non_curse_aura_effect_+%_from_parent_skills" }))) |
| 94 | + assert.equal(10, value) |
| 95 | + assert.is_true(shouldNegate) |
| 96 | + end) |
| 97 | + it("detects passage modline correctly", function() |
| 98 | + local ids = tradeHelpers.findTradeHash( |
| 99 | + "Passive Skills in Radius can be Allocated without being connected to your tree") |
| 100 | + assert.is_true(contains(ids, |
| 101 | + HashStats({ "local_unique_jewel_nearby_disconnected_passives_can_be_allocated", |
| 102 | + "unique_thread_of_hope_base_resist_all_elements_%" }))) |
| 103 | + end) |
| 104 | + end) |
| 105 | +end) |
0 commit comments