47fac22230
- .claude/CLAUDE.md - .claude/commands/subagentes.md - .claude/rules/INDEX.md - .mcp.json - bash/functions/cybersecurity/analyze_dns.md - bash/functions/cybersecurity/audit_http_headers.md - bash/functions/cybersecurity/audit_ssh_config.md - bash/functions/cybersecurity/check_firewall.md - bash/functions/cybersecurity/detect_suspicious_users.md - bash/functions/cybersecurity/encrypt_file.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2.2 KiB
2.2 KiB
name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path, params, output
| name | kind | lang | domain | version | purity | signature | description | tags | uses_functions | uses_types | returns | returns_optional | error_type | imports | tested | tests | test_file_path | file_path | params | output | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| golden_diff | function | go | core | 1.0.0 | pure | func GoldenDiff(actual, golden []byte, threshold float64) (matched bool, similarity float64) | Compara dos buffers byte-a-byte y retorna una puntuacion de similitud en [0,1]. similarity = matchedBytes / max(len(actual), len(golden)). matched = similarity >= (1.0 - threshold). threshold=0.0 exige match exacto; threshold=0.05 tolera hasta 5% de divergencia. |
|
false | true |
|
functions/core/golden_diff_test.go | functions/core/golden_diff.go |
|
matched indica si la similitud supera el umbral. similarity es la fraccion de bytes que coinciden respecto al mayor de los dos buffers. |
Ejemplo
actual := []byte("hello world")
golden := []byte("hello world")
matched, sim := GoldenDiff(actual, golden, 0.0)
// matched=true, sim=1.0
actual2 := []byte("hello wrold") // typo
matched2, sim2 := GoldenDiff(actual2, golden, 0.05)
// sim2 = 9/11 ≈ 0.818, matched2=true (dentro del 5% de tolerancia)
Notas
Funcion pura, sin I/O. Usa comparacion posicional byte-a-byte: dos buffers del mismo contenido pero con bytes insertados/eliminados en el centro daran una similitud baja aunque el contenido sea logicamente similar. Para comparaciones de texto estructurado (JSON, YAML) considerar normalizar antes de llamar a GoldenDiff.
El denominador es max(len(actual), len(golden)), lo que penaliza diferencias de longitud ademas de diferencias de contenido.