Add tests for DUP

This commit is contained in:
Starfflame 2021-05-23 07:12:10 -05:00
parent 09e42c69d5
commit cb1214dcdb
1 changed files with 23 additions and 2 deletions

View File

@ -137,7 +137,7 @@ function buildEnvironment(testString)
return testEnv return testEnv
end end
local twoRandom = function() return math.random(100000), math.random(100000) end local twoRandom = function() return math.random(-100000, 100000), math.random(-100000, 100000) end
describe("Interpreter tests", function() describe("Interpreter tests", function()
@ -186,7 +186,7 @@ describe("Interpreter tests", function()
end) end)
it("can evaluate a arithmetic expression with multiple operations", function() it("can evaluate a arithmetic expression with multiple operations", function()
for i = 1, 1000 do for i = 1, 1000 do
operands = {math.random(100000), math.random(100000), math.random(100000), math.random(100000)} operands = {math.random(-100000,100000), math.random(-100000,100000), math.random(-100000,100000), math.random(-100000,100000)}
local operations = {math.random(4), math.random(4), math.random(4)} local operations = {math.random(4), math.random(4), math.random(4)}
local testString = ""..operands[1] local testString = ""..operands[1]
local expectedResult = operands[1] local expectedResult = operands[1]
@ -211,6 +211,27 @@ describe("Interpreter tests", function()
end end
end) end)
end) end)
describe("Core word tests", function()
describe("DUP tests", function()
it("DUPs the top item of a stack with one item on it.", function()
local testEnv = buildEnvironment("1 DUP")
interpreters.start(testEnv)
assert.are.same(1, testEnv.activeDataStack.contents[2])
end)
it("DUPs the top item of a stack with random quantities of random numbers on it.", function()
for i = 1, 1000 do
local stack_depth = math.random(100)
local stack_top = 0
for j = 1, stack_depth do
stack_top = math.random(-100000,100000)
testEnv.activeDataStack:push(stack_top)
end
local testEnv = buildEnvironment(stack_top.." DUP")
assert.are.same(stack_top, testEnv.activeDataStack.contents[j+1])
end
end)
end)
end)
end) end)