Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 44 additions & 44 deletions spec/GenerateBuilds.lua
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
local function fetchBuilds(path, buildList)
buildList = buildList or {}
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path..'/'..file
local attr = lfs.attributes (f)
assert(type(attr) == "table")
if attr.mode == "directory" then
fetchBuilds(f, buildList)
else
if file:match("^.+(%..+)$") == ".xml" then
local fileHnd, errMsg = io.open(f, "r")
if not fileHnd then
return nil, errMsg
end
local fileText = fileHnd:read("*a")
fileHnd:close()
buildList[f] = fileText
end
end
end
end
return buildList
buildList = buildList or {}
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path..'/'..file
local attr = lfs.attributes (f)
assert(type(attr) == "table")
if attr.mode == "directory" then
fetchBuilds(f, buildList)
else
if file:match("^.+(%..+)$") == ".xml" then
local fileHnd, errMsg = io.open(f, "r")
if not fileHnd then
return nil, errMsg
end
local fileText = fileHnd:read("*a")
fileHnd:close()
buildList[f] = fileText
end
end
end
end
return buildList
end

function buildTable(tableName, values, string)
string = string or ""
string = string .. tableName .. " = {"
for key, value in pairs(values) do
if type(value) == "table" then
buildTable(key, value, string)
elseif type(value) == "boolean" then
string = string .. "[\"" .. key .. "\"] = " .. (value and "true" or "false") .. ",\n"
elseif type(value) == "string" then
string = string .. "[\"" .. key .. "\"] = \"" .. value .. "\",\n"
else
string = string .. "[\"" .. key .. "\"] = " .. round(value, 4) .. ",\n"
end
end
string = string .. "}\n"
return string
string = string or ""
string = string .. tableName .. " = {"
for key, value in pairs(values) do
if type(value) == "table" then
buildTable(key, value, string)
elseif type(value) == "boolean" then
string = string .. "[\"" .. key .. "\"] = " .. (value and "true" or "false") .. ",\n"
elseif type(value) == "string" then
string = string .. "[\"" .. key .. "\"] = \"" .. value .. "\",\n"
else
string = string .. "[\"" .. key .. "\"] = " .. round(value, 4) .. ",\n"
end
end
string = string .. "}\n"
return string
end

local buildList = fetchBuilds("../spec/TestBuilds")
for filename, testBuild in pairs(buildList) do
loadBuildFromXML(testBuild)
local fileHnd, errMsg = io.open(filename:gsub("^(.+)%..+$", "%1.lua"), "w+")
fileHnd:write("return {\n xml = [[")
fileHnd:write(testBuild)
fileHnd:write("]],\n ")
fileHnd:write(buildTable("output", build.calcsTab.mainOutput) .. "\n}")
fileHnd:close()
loadBuildFromXML(testBuild)
local fileHnd, errMsg = io.open(filename:gsub("^(.+)%..+$", "%1.lua"), "w+")
fileHnd:write("return {\n xml = [[")
fileHnd:write(testBuild)
fileHnd:write("]],\n ")
fileHnd:write(buildTable("output", build.calcsTab.mainOutput) .. "\n}")
fileHnd:close()
end
42 changes: 21 additions & 21 deletions spec/System/TestAilments_spec.lua
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
describe("TestAilments", function()
before_each(function()
newBuild()
end)
before_each(function()
newBuild()
end)

teardown(function()
-- newBuild() takes care of resetting everything in setup()
end)
teardown(function()
-- newBuild() takes care of resetting everything in setup()
end)

it("maximum shock value", function()
-- Shock Nova
build.skillsTab:PasteSocketGroup("Slot: Weapon 1\nShock Nova 4/0 Default 1\n")
runCallback("OnFrame")
assert.are.equals(round(50 + 10), build.calcsTab.mainOutput.MaximumShock)
it("maximum shock value", function()
-- Shock Nova
build.skillsTab:PasteSocketGroup("Slot: Weapon 1\nShock Nova 4/0 Default 1\n")
runCallback("OnFrame")
assert.are.equals(round(50 + 10), build.calcsTab.mainOutput.MaximumShock)

-- Voltaxic Rift
build.itemsTab:CreateDisplayItemFromRaw("New Item\nAssassin Bow\n+40% to Maximum Effect of Shock")
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")
assert.are.equals(round(50 + 10 + 40), build.calcsTab.mainOutput.MaximumShock)
end)
-- Voltaxic Rift
build.itemsTab:CreateDisplayItemFromRaw("New Item\nAssassin Bow\n+40% to Maximum Effect of Shock")
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")
assert.are.equals(round(50 + 10 + 40), build.calcsTab.mainOutput.MaximumShock)
end)

it("bleed is buffed by bleed chance", function()
build.itemsTab:CreateDisplayItemFromRaw("New Item\nKarui Chopper")
build.itemsTab:AddDisplayItem()
build.skillsTab:PasteSocketGroup("Slot: Weapon 1\nHeavy Strike 1/0 Default 1\n")
build.configTab.input.customMods = "\z
attacks have 10% chance to cause bleeding\n\z
"
attacks have 10% chance to cause bleeding\n\z
"
build.configTab:BuildModList()
runCallback("OnFrame")
local badDps = build.calcsTab.mainOutput.BleedDPS

build.configTab.input.customMods = "\z
attacks have 100% chance to cause bleeding\n\z
"
attacks have 100% chance to cause bleeding\n\z
"
build.configTab:BuildModList()
runCallback("OnFrame")
local goodDps = build.calcsTab.mainOutput.BleedDPS
Expand Down
86 changes: 43 additions & 43 deletions spec/System/TestAttacks_spec.lua
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
describe("TestAttacks", function()
before_each(function()
newBuild()
end)
before_each(function()
newBuild()
end)

teardown(function()
-- newBuild() takes care of resetting everything in setup()
end)
teardown(function()
-- newBuild() takes care of resetting everything in setup()
end)

it("creates an item and has the correct crit chance", function()
assert.are.equals(build.calcsTab.mainOutput.CritChance, 0)
build.itemsTab:CreateDisplayItemFromRaw("New Item\nMaraketh Bow\nCrafted: true\nPrefix: None\nPrefix: None\nPrefix: None\nSuffix: None\nSuffix: None\nSuffix: None\nQuality: 20\nSockets: G-G-G-G-G-G\nLevelReq: 71\nImplicits: 1\n{tags:speed}10% increased Movement Speed")
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")
assert.are.equals(build.calcsTab.mainOutput.CritChance, 5.5 * build.calcsTab.mainOutput.HitChance / 100)
end)
it("creates an item and has the correct crit chance", function()
assert.are.equals(build.calcsTab.mainOutput.CritChance, 0)
build.itemsTab:CreateDisplayItemFromRaw("New Item\nMaraketh Bow\nCrafted: true\nPrefix: None\nPrefix: None\nPrefix: None\nSuffix: None\nSuffix: None\nSuffix: None\nQuality: 20\nSockets: G-G-G-G-G-G\nLevelReq: 71\nImplicits: 1\n{tags:speed}10% increased Movement Speed")
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")
assert.are.equals(build.calcsTab.mainOutput.CritChance, 5.5 * build.calcsTab.mainOutput.HitChance / 100)
end)

it("creates an item and has the correct crit multi", function()
assert.are.equals(1.5, build.calcsTab.mainOutput.CritMultiplier)
build.itemsTab:CreateDisplayItemFromRaw("New Item\nAssassin Bow\nCrafted: true\nPrefix: None\nPrefix: None\nPrefix: None\nSuffix: None\nSuffix: None\nSuffix: None\nQuality: 20\nSockets: G-G-G-G-G-G\nLevelReq: 62\nImplicits: 1\n{tags:damage,critical}{range:0.5}+(15-25)% to Global Critical Strike Multiplier")
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")
assert.are.equals(1.5 + 0.2, build.calcsTab.mainOutput.CritMultiplier)
end)
it("creates an item and has the correct crit multi", function()
assert.are.equals(1.5, build.calcsTab.mainOutput.CritMultiplier)
build.itemsTab:CreateDisplayItemFromRaw("New Item\nAssassin Bow\nCrafted: true\nPrefix: None\nPrefix: None\nPrefix: None\nSuffix: None\nSuffix: None\nSuffix: None\nQuality: 20\nSockets: G-G-G-G-G-G\nLevelReq: 62\nImplicits: 1\n{tags:damage,critical}{range:0.5}+(15-25)% to Global Critical Strike Multiplier")
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")
assert.are.equals(1.5 + 0.2, build.calcsTab.mainOutput.CritMultiplier)
end)

it("correctly converts spell damage per stat to attack damage", function()
assert.are.equals(0, build.calcsTab.mainEnv.player.modDB:Sum("INC", { flags = ModFlag.Attack }, "Damage"))
build.itemsTab:CreateDisplayItemFromRaw([[
New Item
Coral Amulet
10% increased attack damage
10% increased spell damage
1% increased spell damage per 10 intelligence
]])
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")
assert.are.equals(10, build.calcsTab.mainEnv.player.modDB:Sum("INC", { flags = ModFlag.Attack }, "Damage"))
-- Scion starts with 20 Intelligence
assert.are.equals(12, build.calcsTab.mainEnv.player.modDB:Sum("INC", { flags = ModFlag.Spell }, "Damage"))
it("correctly converts spell damage per stat to attack damage", function()
assert.are.equals(0, build.calcsTab.mainEnv.player.modDB:Sum("INC", { flags = ModFlag.Attack }, "Damage"))
build.itemsTab:CreateDisplayItemFromRaw([[
New Item
Coral Amulet
10% increased attack damage
10% increased spell damage
1% increased spell damage per 10 intelligence
]])
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")
assert.are.equals(10, build.calcsTab.mainEnv.player.modDB:Sum("INC", { flags = ModFlag.Attack }, "Damage"))
-- Scion starts with 20 Intelligence
assert.are.equals(12, build.calcsTab.mainEnv.player.modDB:Sum("INC", { flags = ModFlag.Spell }, "Damage"))

build.itemsTab:CreateDisplayItemFromRaw([[
New Item
Coral Ring
increases and reductions to spell damage also apply to attacks
]])
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")
assert.are.equals(22, build.calcsTab.mainEnv.player.mainSkill.skillModList:Sum("INC", { flags = ModFlag.Attack }, "Damage"))
build.itemsTab:CreateDisplayItemFromRaw([[
New Item
Coral Ring
increases and reductions to spell damage also apply to attacks
]])
build.itemsTab:AddDisplayItem()
runCallback("OnFrame")
assert.are.equals(22, build.calcsTab.mainEnv.player.mainSkill.skillModList:Sum("INC", { flags = ModFlag.Attack }, "Damage"))

end)
end)
end)
60 changes: 30 additions & 30 deletions spec/System/TestBuilds_spec.lua
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
local function fetchBuilds(path, buildList)
buildList = buildList or {}
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path..'/'..file
local attr = lfs.attributes (f)
assert(type(attr) == "table")
if attr.mode == "directory" then
fetchBuilds(f, buildList)
elseif file:match("^.+(%..+)$") == ".lua" then
buildList[file] = LoadModule(f)
end
end
end
return buildList
buildList = buildList or {}
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path..'/'..file
local attr = lfs.attributes (f)
assert(type(attr) == "table")
if attr.mode == "directory" then
fetchBuilds(f, buildList)
elseif file:match("^.+(%..+)$") == ".lua" then
buildList[file] = LoadModule(f)
end
end
end
return buildList
end

expose("test all builds #builds", function()
local buildList = fetchBuilds("../spec/TestBuilds")
for buildName, testBuild in pairs(buildList) do
loadBuildFromXML(testBuild.xml, buildName)
testBuild.result = {}
for key, value in pairs(testBuild.output) do
-- Have to assign it to a temporary table here, as the tests will run later, when the 'build' isn't changing
testBuild.result[key] = build.calcsTab.mainOutput[key]
it("on build: " .. buildName .. ", key: " .. key, function()
if type(value) == "number" and type(testBuild.result[key]) == "number" then
assert.are.same(round(value, 4), round(testBuild.result[key] or 0, 4))
else
assert.are.same(value, testBuild.result[key])
end
end)
end
end
local buildList = fetchBuilds("../spec/TestBuilds")
for buildName, testBuild in pairs(buildList) do
loadBuildFromXML(testBuild.xml, buildName)
testBuild.result = {}
for key, value in pairs(testBuild.output) do
-- Have to assign it to a temporary table here, as the tests will run later, when the 'build' isn't changing
testBuild.result[key] = build.calcsTab.mainOutput[key]
it("on build: " .. buildName .. ", key: " .. key, function()
if type(value) == "number" and type(testBuild.result[key]) == "number" then
assert.are.same(round(value, 4), round(testBuild.result[key] or 0, 4))
else
assert.are.same(value, testBuild.result[key])
end
end)
end
end
end)
Loading