Skip to content

Commit

Permalink
fix some logic errors, run slow last
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Sep 9, 2024
1 parent 49444b7 commit 1fa2251
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lua/src/p0076.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ return {

if sum >= 100
then
answer = answer + (100 + counts[2] - sum) / 2
answer = answer + math.floor((100 + counts[2] - sum) / 2)
idx = 2

repeat
Expand Down
41 changes: 25 additions & 16 deletions lua/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ local function load_problem(file_name)
end

-- Timing and result check function
local function check_problem(problem_func, expected_answer, timeout_seconds, problem_name)
local function check_problem(file_name, expected_answer, is_slow, problem_name)
local problem_func = load_problem("src/" .. file_name)
local start_time = os.clock()
local success, result = pcall(problem_func)
local elapsed_time = os.clock() - start_time
Expand All @@ -32,7 +33,7 @@ local function check_problem(problem_func, expected_answer, timeout_seconds, pro
)
end

if elapsed_time > timeout_seconds then
if not is_slow and elapsed_time > timeout_seconds then
error(
"Problem " .. problem_name .. " took " .. tostring(elapsed_time) ..
"s, exceeding the expected time limit of " .. tostring(timeout_seconds) .. "s."
Expand All @@ -42,22 +43,30 @@ local function check_problem(problem_func, expected_answer, timeout_seconds, pro
print("Problem " .. problem_name .. " passed.")
end

-- Problems configuration: filename -> {expected_answer, timeout_seconds}
-- Problems configuration: filename -> {expected_answer, is_slow}
local problems = {
["p0001.lua"] = {233168, 60},
["p0002.lua"] = {4613732, 60},
["p0004.lua"] = {906609, 60},
["p0006.lua"] = {25164150, 60},
["p0009.lua"] = {31875000, 60},
["p0017.lua"] = {21124, 60},
["p0028.lua"] = {669171001, 60},
["p0034.lua"] = {40730, 60},
["p0076.lua"] = {190569291, 60},
["p0836.lua"] = {"aprilfoolsjoke", 60},
["p0001.lua"] = {233168, false},
["p0002.lua"] = {4613732, false},
["p0004.lua"] = {906609, false},
["p0006.lua"] = {25164150, false},
["p0009.lua"] = {31875000, false},
["p0017.lua"] = {21124, false},
["p0028.lua"] = {669171001, false},
["p0034.lua"] = {40730, false},
["p0836.lua"] = {"aprilfoolsjoke", false},
["p0076.lua"] = {190569291, true},
}

-- Main testing loop
-- Fast testing loop
for file_name, config in pairs(problems) do
local problem_func = load_problem("src/" .. file_name)
check_problem(problem_func, config[1], config[2], file_name:match("(%d+)"))
if not config[2] then
check_problem(file_name, config[1], config[2], file_name:match("(%d+)"))
end
end

-- Slow testing loop
for file_name, config in pairs(problems) do
if config[2] then
check_problem(file_name, config[1], config[2], file_name:match("(%d+)"))
end
end

0 comments on commit 1fa2251

Please sign in to comment.