Spaces:
Sleeping
Sleeping
File size: 2,138 Bytes
cacd58c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | # 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(" ") == {}
""",
}
|