chore: auto-commit (97 archivos)
- .claude/CLAUDE.md - .claude/agents/fn-recopilador/SKILL.md - .claude/rules/INDEX.md - .claude/rules/cpp_apps.md - bash/functions/infra/build_cpp_windows.sh - cpp/CMakeLists.txt - cpp/PATTERNS.md - cpp/framework/app_base.cpp - cpp/framework/app_base.h - dev/issues/README.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package core
|
||||
|
||||
// GoldenDiff compares two byte slices and returns a similarity score in [0,1].
|
||||
// similarity = matchedBytes / max(len(actual), len(golden)).
|
||||
// matched = similarity >= (1.0 - threshold).
|
||||
// threshold=0.0 requires exact match; threshold=0.05 tolerates up to 5% divergence.
|
||||
// Returns similarity=1.0 and matched=true when both slices are empty.
|
||||
func GoldenDiff(actual, golden []byte, threshold float64) (matched bool, similarity float64) {
|
||||
maxLen := len(actual)
|
||||
if len(golden) > maxLen {
|
||||
maxLen = len(golden)
|
||||
}
|
||||
if maxLen == 0 {
|
||||
return true, 1.0
|
||||
}
|
||||
|
||||
minLen := len(actual)
|
||||
if len(golden) < minLen {
|
||||
minLen = len(golden)
|
||||
}
|
||||
|
||||
var matchedBytes int
|
||||
for i := 0; i < minLen; i++ {
|
||||
if actual[i] == golden[i] {
|
||||
matchedBytes++
|
||||
}
|
||||
}
|
||||
|
||||
similarity = float64(matchedBytes) / float64(maxLen)
|
||||
matched = similarity >= (1.0 - threshold)
|
||||
return matched, similarity
|
||||
}
|
||||
Reference in New Issue
Block a user