Skip to content

Commit

Permalink
Place rate of fire test in a function to not repeat code
Browse files Browse the repository at this point in the history
  • Loading branch information
lL1l1 committed Apr 27, 2024
1 parent d2afb2d commit a0e68fe
Showing 1 changed file with 42 additions and 64 deletions.
106 changes: 42 additions & 64 deletions tests/blueprint/unit.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,46 @@ end

-------------------------------------------------------------------------------


-- The game runs in ticks and therefore not every rate of
-- fire is possible. The game will round the rate of fire,
-- but as a result minor changes may not always have an
-- actual impact in-game. These tests guarantee that when
-- a rate of fire is adjusted that it is always the actual
-- rate of fire that the game uses.
---@param rateOfFire number
local function rateOfFireTest(rateOfFire)
luft.expect(rateOfFire).to.be.number()

if rateOfFire > 6.6666 then
luft.expect(rateOfFire).to.be.close.to(10)
elseif rateOfFire > 4.0 then
luft.expect(rateOfFire).to.be.close.to(5)
elseif rateOfFire > 2.8571 then
luft.expect(rateOfFire).to.be.close.to(3.333)
elseif rateOfFire > 2.2222 then
luft.expect(rateOfFire).to.be.close.to(2.5)
elseif rateOfFire > 1.8182 then
luft.expect(rateOfFire).to.be.close.to(2.0)
elseif rateOfFire > 1.5384 then
luft.expect(rateOfFire).to.be.close.to(1.666)
elseif rateOfFire > 1.3333 then
luft.expect(rateOfFire).to.be.close.to(1.428)
elseif rateOfFire > 1.1765 then
luft.expect(rateOfFire).to.be.close.to(1.25)
elseif rateOfFire > 1.0526 then
luft.expect(rateOfFire).to.be.close.to(1.111)
elseif rateOfFire > 0.9524 then
luft.expect(rateOfFire).to.be.close.to(1.0)
elseif rateOfFire > 0.8696 then
luft.expect(rateOfFire).to.be.close.to(0.909)
elseif rateOfFire > 0.8 then
luft.expect(rateOfFire).to.be.close.to(0.833)
elseif rateOfFire > 0.7407 then
luft.expect(rateOfFire).to.be.close.to(0.769)
end
end

-- this file is generated by the bash script that runs the test
dofile("./tests/generated/unit-blueprint-list.lua")

Expand Down Expand Up @@ -279,38 +319,7 @@ luft.describe(
if rateOfFire then
luft.test(
"Rate of fire",
function()

luft.expect(rateOfFire).to.be.number()

if rateOfFire > 6.6666 then
luft.expect(rateOfFire).to.be.close.to(10)
elseif rateOfFire > 4.0 then
luft.expect(rateOfFire).to.be.close.to(5)
elseif rateOfFire > 2.8571 then
luft.expect(rateOfFire).to.be.close.to(3.333)
elseif rateOfFire > 2.2222 then
luft.expect(rateOfFire).to.be.close.to(2.5)
elseif rateOfFire > 1.8182 then
luft.expect(rateOfFire).to.be.close.to(2.0)
elseif rateOfFire > 1.5384 then
luft.expect(rateOfFire).to.be.close.to(1.666)
elseif rateOfFire > 1.3333 then
luft.expect(rateOfFire).to.be.close.to(1.428)
elseif rateOfFire > 1.1765 then
luft.expect(rateOfFire).to.be.close.to(1.25)
elseif rateOfFire > 1.0526 then
luft.expect(rateOfFire).to.be.close.to(1.111)
elseif rateOfFire > 0.9524 then
luft.expect(rateOfFire).to.be.close.to(1.0)
elseif rateOfFire > 0.8696 then
luft.expect(rateOfFire).to.be.close.to(0.909)
elseif rateOfFire > 0.8 then
luft.expect(rateOfFire).to.be.close.to(0.833)
elseif rateOfFire > 0.7407 then
luft.expect(rateOfFire).to.be.close.to(0.769)
end
end
rateOfFireTest(rateOfFire)
)
end

Expand Down Expand Up @@ -348,38 +357,7 @@ luft.describe(
if rateOfFire then
luft.test(
"New Rate of fire",
function()

luft.expect(rateOfFire).to.be.number()

if rateOfFire > 6.6666 then
luft.expect(rateOfFire).to.be.close.to(10)
elseif rateOfFire > 4.0 then
luft.expect(rateOfFire).to.be.close.to(5)
elseif rateOfFire > 2.8571 then
luft.expect(rateOfFire).to.be.close.to(3.333)
elseif rateOfFire > 2.2222 then
luft.expect(rateOfFire).to.be.close.to(2.5)
elseif rateOfFire > 1.8182 then
luft.expect(rateOfFire).to.be.close.to(2.0)
elseif rateOfFire > 1.5384 then
luft.expect(rateOfFire).to.be.close.to(1.666)
elseif rateOfFire > 1.3333 then
luft.expect(rateOfFire).to.be.close.to(1.428)
elseif rateOfFire > 1.1765 then
luft.expect(rateOfFire).to.be.close.to(1.25)
elseif rateOfFire > 1.0526 then
luft.expect(rateOfFire).to.be.close.to(1.111)
elseif rateOfFire > 0.9524 then
luft.expect(rateOfFire).to.be.close.to(1.0)
elseif rateOfFire > 0.8696 then
luft.expect(rateOfFire).to.be.close.to(0.909)
elseif rateOfFire > 0.8 then
luft.expect(rateOfFire).to.be.close.to(0.833)
elseif rateOfFire > 0.7407 then
luft.expect(rateOfFire).to.be.close.to(0.769)
end
end
rateOfFireTest(rateOfFire)
)
end

Expand Down

0 comments on commit a0e68fe

Please sign in to comment.