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
|
|
@ -21,6 +21,7 @@
|
|||
---@class PanelConfig
|
||||
---@field diff_modes string[]
|
||||
---@field max_output_lines integer
|
||||
---@field epsilon number?
|
||||
|
||||
---@class DiffGitConfig
|
||||
---@field args string[]
|
||||
|
|
@ -174,7 +175,7 @@ M.defaults = {
|
|||
add_test_key = 'ga',
|
||||
save_and_exit_key = 'q',
|
||||
},
|
||||
panel = { diff_modes = { 'side-by-side', 'git', 'vim' }, max_output_lines = 50 },
|
||||
panel = { diff_modes = { 'side-by-side', 'git', 'vim' }, max_output_lines = 50, epsilon = nil },
|
||||
diff = {
|
||||
git = {
|
||||
args = { 'diff', '--no-index', '--word-diff=plain', '--word-diff-regex=.', '--no-prefix' },
|
||||
|
|
@ -368,6 +369,13 @@ function M.setup(user_config)
|
|||
end,
|
||||
'positive integer',
|
||||
},
|
||||
epsilon = {
|
||||
cfg.ui.panel.epsilon,
|
||||
function(v)
|
||||
return v == nil or (type(v) == 'number' and v >= 0)
|
||||
end,
|
||||
'nil or non-negative number',
|
||||
},
|
||||
git = { cfg.ui.diff.git, { 'table' } },
|
||||
git_args = { cfg.ui.diff.git.args, is_string_list, 'string[]' },
|
||||
width = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue