1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

Reset randomseed before each test

This commit is contained in:
Étienne Fildadut 2024-01-02 00:32:08 +01:00
parent c2bec6f5d2
commit 7635261a3f

View file

@ -13,6 +13,9 @@ local function badrandom(a, b)
prev = (4241 * prev + 11) % 6997 prev = (4241 * prev + 11) % 6997
return a + prev % (b-a+1) return a + prev % (b-a+1)
end end
function math.randomseed()
prev = 0
end
function math.random(a, b) function math.random(a, b)
if not a and not b then if not a and not b then
return badrandom(0, 999) / 1000 return badrandom(0, 999) / 1000
@ -53,6 +56,7 @@ end
-- run a test file and return the result -- run a test file and return the result
local function run(path) local function run(path)
local out = { "--# run #--" } local out = { "--# run #--" }
math.randomseed()
local state = anselme:new() local state = anselme:new()
state:load_stdlib() state:load_stdlib()
@ -107,7 +111,7 @@ local loading = {
write = function(self, message) write = function(self, message)
self:clear() self:clear()
local str = self.loop[self.loop_pos].." "..message local str = self.loop[self.loop_pos].." "..message
self.erase_code = ("\b"):rep(#str) self.erase_code = ("\b \b"):rep(#str)
io.write(str) io.write(str)
end, end,
clear = function(self) clear = function(self)
@ -132,6 +136,10 @@ if not arg[1] or arg[1] == "update" then
local total, failure, errored, notfound = #tests, 0, 0, 0 local total, failure, errored, notfound = #tests, 0, 0, 0
for i, test in ipairs(tests) do for i, test in ipairs(tests) do
-- status
loading:write(("%s/%s tests ran; running %s"):format(i, #tests, test))
if i % 10 == 0 then loading:update() end
repeat repeat
local rerun = false local rerun = false
@ -192,10 +200,6 @@ if not arg[1] or arg[1] == "update" then
print("") print("")
end end
until not rerun until not rerun
-- status
loading:write(("%s/%s tests ran"):format(i, #tests))
if i % 10 == 0 then loading:update() end
end end
loading:clear() loading:clear()