code-debug-env / server /tasks /task_medium.py
luciferai-devil's picture
Upload folder using huggingface_hub
cacd58c verified
# server/tasks/task_medium.py
TASK_MEDIUM = {
"task_id": "task_medium",
"difficulty": "medium",
"num_tests": 6,
"description": (
"Fix two independent bugs in the `parse_key_value` function. "
"It should parse a string of 'key=value' pairs separated by semicolons "
"into a dictionary. Bug 1: it splits on the wrong delimiter for pairs. "
"Bug 2: it doesn't strip whitespace from keys and values."
),
# The broken version the agent sees
"buggy_code": """\
def parse_key_value(s: str) -> dict[str, str]:
\"\"\"Parse 'key1=val1;key2=val2' into {'key1': 'val1', 'key2': 'val2'}.
Handles whitespace around keys/values. Returns empty dict for empty string.\"\"\"
if not s or not s.strip():
return {}
result = {}
# BUG 1: splits on ',' instead of ';'
pairs = s.split(',')
for pair in pairs:
if '=' not in pair:
continue
key, value = pair.split('=', 1)
# BUG 2: missing .strip() on key and value
result[key] = value
return result
""",
"clean_code": """\
def parse_key_value(s: str) -> dict[str, str]:
\"\"\"Parse 'key1=val1;key2=val2' into {'key1': 'val1', 'key2': 'val2'}.
Handles whitespace around keys/values. Returns empty dict for empty string.\"\"\"
if not s or not s.strip():
return {}
result = {}
pairs = s.split(';')
for pair in pairs:
if '=' not in pair:
continue
key, value = pair.split('=', 1)
result[key.strip()] = value.strip()
return result
""",
"test_suite": """\
def test_basic():
assert parse_key_value("name=Alice;age=30") == {"name": "Alice", "age": "30"}
def test_whitespace():
assert parse_key_value(" name = Alice ; age = 30 ") == {"name": "Alice", "age": "30"}
def test_empty():
assert parse_key_value("") == {}
def test_single_pair():
assert parse_key_value("key=value") == {"key": "value"}
def test_value_with_equals():
assert parse_key_value("expr=a=b;other=c") == {"expr": "a=b", "other": "c"}
def test_whitespace_only():
assert parse_key_value(" ") == {}
""",
}