FAILURE MAP
← Case archive

FA-3981 / Text processing / Open access

Text edit distance counts only length difference · case 01

Text edit distance counts only length difference.

Verified by executionVariant 1 · 4 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The implementation applies an operation whose text or grammar semantics violate this contract: Return Levenshtein distance for two strings, unit insertion/deletion/substitution.

VERIFIED REPAIR

Implement the complete stated contract, including the boundary fixtures: Return Levenshtein distance for two strings, unit insertion/deletion/substitution.

Unsuccessful approach: The attempted repair handles the primary example but still violates a separate boundary of the same contract.

Case contract

Return Levenshtein distance for two strings, unit insertion/deletion/substitution.

Why this case matters

A local executable model for consumers of structured text; oracle values are authored literals, not outputs copied from the repaired implementation.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return abs(len(x[0])-len(x[1]))
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve(['cat', 'cut']), 1)
check('boundary 2', solve(['abc', 'bca']), 2)
check('boundary 3', solve(['', 'ab']), 2)
check('boundary 4', solve(['same', 'same']), 0)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
boundary 101Failed
boundary 202Failed
boundary 322Passed
boundary 400Passed

SHA-256 / beb0785252c98a7b73f9419e133e90a9cbfbfb54e5101f3e71029329d6ac64ac

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return sum(a!=b for a,b in zip(*x))+abs(len(x[0])-len(x[1]))
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve(['cat', 'cut']), 1)
check('boundary 2', solve(['abc', 'bca']), 2)
check('boundary 3', solve(['', 'ab']), 2)
check('boundary 4', solve(['same', 'same']), 0)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
boundary 111Passed
boundary 232Failed
boundary 322Passed
boundary 400Passed

SHA-256 / 6dd42b11da3f2ee525ba2426838b2d29dc6e14c0be1504514f24fea85e2ae4d2

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        a,b=x
        row=list(range(len(b)+1))
        for i,ca in enumerate(a,1):
            nxt=[i]
            for j,cb in enumerate(b,1): nxt.append(min(nxt[-1]+1,row[j]+1,row[j-1]+(ca!=cb)))
            row=nxt
        return row[-1]
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve(['cat', 'cut']), 1)
check('boundary 2', solve(['abc', 'bca']), 2)
check('boundary 3', solve(['', 'ab']), 2)
check('boundary 4', solve(['same', 'same']), 0)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
boundary 111Passed
boundary 222Passed
boundary 322Passed
boundary 400Passed

SHA-256 / 348c7c3af922f8051f041e6e73676908337a07a4d4282613616370ba60e974f5

Verification & scope

This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:37:33.632899+00:00.

Case digest / 020082370294d1c8524a488260b70d80fc204b7ced2d37ef8af674e91f9ab7ab