feat: add epsilon tolerance for floating-point output comparison
Problem: output comparison used exact string equality after whitespace normalisation, causing correct solutions to fail on problems where floating-point answers are accepted within a tolerance (e.g. 1e-6). Solution: add an optional ui.panel.epsilon config value. When set, actual and expected output are compared token-by-token: numeric tokens are compared with math.abs(a - b) <= epsilon, non-numeric tokens fall back to exact string equality. Per-problem epsilon can also be stored in the cache and takes precedence over the global default.
This commit is contained in:
parent
84d12758c2
commit
e685a8089f
3 changed files with 87 additions and 3 deletions
|
|
@ -27,6 +27,7 @@
|
|||
---@field multi_test? boolean
|
||||
---@field memory_mb? number
|
||||
---@field timeout_ms? number
|
||||
---@field epsilon? number
|
||||
---@field combined_test? CombinedTest
|
||||
---@field test_cases TestCase[]
|
||||
|
||||
|
|
@ -273,6 +274,34 @@ function M.get_constraints(platform, contest_id, problem_id)
|
|||
return problem_data.timeout_ms, problem_data.memory_mb
|
||||
end
|
||||
|
||||
---@param platform string
|
||||
---@param contest_id string
|
||||
---@param problem_id? string
|
||||
---@return number?
|
||||
function M.get_epsilon(platform, contest_id, problem_id)
|
||||
vim.validate({
|
||||
platform = { platform, 'string' },
|
||||
contest_id = { contest_id, 'string' },
|
||||
problem_id = { problem_id, { 'string', 'nil' }, true },
|
||||
})
|
||||
|
||||
if
|
||||
not cache_data[platform]
|
||||
or not cache_data[platform][contest_id]
|
||||
or not cache_data[platform][contest_id].index_map
|
||||
then
|
||||
return nil
|
||||
end
|
||||
|
||||
local index = cache_data[platform][contest_id].index_map[problem_id]
|
||||
if not index then
|
||||
return nil
|
||||
end
|
||||
|
||||
local problem_data = cache_data[platform][contest_id].problems[index]
|
||||
return problem_data and problem_data.epsilon or nil
|
||||
end
|
||||
|
||||
---@param file_path string
|
||||
---@return FileState|nil
|
||||
function M.get_file_state(file_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue