PulipatiPranav commited on
Commit ·
85f14d3
1
Parent(s): a693c08
Curated the bugs dataset
Browse files- calibrate.py +63 -0
- data/bugs_tier1.jsonl +36 -4
- data/bugs_tier2.jsonl +28 -1
- data/bugs_tier3.jsonl +19 -1
- data/generate_bugs.py +0 -0
- scratch/data_tier1.py +354 -0
- scratch/data_tier2.py +195 -0
- scratch/data_tier3.py +131 -0
- scratch/debug.txt +0 -0
- scratch/debug2.txt +392 -0
- scratch/fix_all.py +111 -0
- scratch/gen_t1_base.py +119 -0
- scratch/merge.py +86 -0
calibrate.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import subprocess
|
| 3 |
+
import tempfile
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def test_passes(code, func, inp, expected):
|
| 7 |
+
if isinstance(inp, (list, tuple)):
|
| 8 |
+
args = ', '.join(repr(x) for x in inp)
|
| 9 |
+
else:
|
| 10 |
+
args = repr(inp)
|
| 11 |
+
|
| 12 |
+
script = f"""{code}
|
| 13 |
+
|
| 14 |
+
try:
|
| 15 |
+
r = {func}({args})
|
| 16 |
+
expected = {repr(expected)}
|
| 17 |
+
print("PASS" if r == expected else f"FAIL: got {{r}}")
|
| 18 |
+
except Exception as e:
|
| 19 |
+
print(f"ERROR: {{e}}")
|
| 20 |
+
"""
|
| 21 |
+
try:
|
| 22 |
+
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False) as f:
|
| 23 |
+
f.write(script)
|
| 24 |
+
fname = f.name
|
| 25 |
+
r = subprocess.run(
|
| 26 |
+
['python', fname],
|
| 27 |
+
capture_output=True, text=True, timeout=5
|
| 28 |
+
)
|
| 29 |
+
os.unlink(fname)
|
| 30 |
+
return 'PASS' in r.stdout
|
| 31 |
+
except:
|
| 32 |
+
return False
|
| 33 |
+
|
| 34 |
+
for tier in [1, 2, 3]:
|
| 35 |
+
bugs = [json.loads(l) for l in open(f'data/bugs_tier{tier}.jsonl') if l.strip()]
|
| 36 |
+
|
| 37 |
+
broken_original = []
|
| 38 |
+
buggy_not_failing = []
|
| 39 |
+
|
| 40 |
+
for b in bugs:
|
| 41 |
+
orig_passes = all(
|
| 42 |
+
test_passes(b['original_code'], b['function_name'],
|
| 43 |
+
t['input'], t['expected_output'])
|
| 44 |
+
for t in b['test_cases']
|
| 45 |
+
)
|
| 46 |
+
buggy_fails_some = any(
|
| 47 |
+
not test_passes(b['buggy_code'], b['function_name'],
|
| 48 |
+
t['input'], t['expected_output'])
|
| 49 |
+
for t in b['test_cases']
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
if not orig_passes:
|
| 53 |
+
broken_original.append(b['id'])
|
| 54 |
+
if not buggy_fails_some:
|
| 55 |
+
buggy_not_failing.append(b['id'])
|
| 56 |
+
|
| 57 |
+
print(f'\nTier {tier}:')
|
| 58 |
+
if broken_original:
|
| 59 |
+
print(f' BROKEN original_code: {broken_original}')
|
| 60 |
+
if buggy_not_failing:
|
| 61 |
+
print(f' BUGGY code not failing: {buggy_not_failing}')
|
| 62 |
+
if not broken_original and not buggy_not_failing:
|
| 63 |
+
print(f' All good!')
|
data/bugs_tier1.jsonl
CHANGED
|
@@ -1,8 +1,40 @@
|
|
| 1 |
-
{"id": "t1_001", "difficulty": 1, "bug_type": "off_by_one", "function_name": "binary_search", "buggy_code": "def binary_search(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid\n return -1", "original_code": "def binary_search(arr, target):\n left, right = 0, len(arr) - 1\n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n return -1", "initial_error": "IndexError: list index out of range on line 5", "bug_location": {"function": "binary_search", "line_start": 2}, "test_cases": [{"input": [[1, 3, 5, 7, 9], 5], "expected_output": 2}, {"input": [[1, 3, 5, 7, 9], 1], "expected_output": 0}, {"input": [[1, 3, 5, 7, 9], 9], "expected_output": 4}, {"input": [[1, 3, 5, 7, 9], 4], "expected_output": -1}]}
|
| 2 |
{"id": "t1_002", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "is_palindrome", "buggy_code": "def is_palindrome(s):\n return s == s[::-1] and len(s) > 0", "original_code": "def is_palindrome(s):\n return s == s[::-1]", "initial_error": "AssertionError: is_palindrome('') expected True, got False", "bug_location": {"function": "is_palindrome", "line_start": 2}, "test_cases": [{"input": "racecar", "expected_output": true}, {"input": "hello", "expected_output": false}, {"input": "", "expected_output": true}, {"input": "a", "expected_output": true}]}
|
| 3 |
-
{"id": "t1_003", "difficulty": 1, "bug_type": "off_by_one", "function_name": "find_max", "buggy_code": "def find_max(nums):\n max_val = nums[0]\n for i in range(1, len(nums) + 1):\n if nums[i] > max_val:\n max_val = nums[i]\n return max_val", "original_code": "def find_max(nums):\n max_val = nums[0]\n for i in range(1, len(nums)):\n if nums[i] > max_val:\n max_val = nums[i]\n return max_val", "initial_error": "IndexError: list index out of range on line 4", "bug_location": {"function": "find_max", "line_start": 3}, "test_cases": [{"input": [3, 1, 4, 1, 5, 9], "expected_output": 9}, {"input": [1], "expected_output": 1}, {"input": [-5, -1, -3], "expected_output": -1}, {"input": [7, 7, 7], "expected_output": 7}]}
|
| 4 |
{"id": "t1_004", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "count_vowels", "buggy_code": "def count_vowels(s):\n count = 0\n for ch in s:\n if ch in 'aeiou':\n count += 1\n return count", "original_code": "def count_vowels(s):\n count = 0\n for ch in s.lower():\n if ch in 'aeiou':\n count += 1\n return count", "initial_error": "AssertionError: count_vowels('Hello') expected 2, got 1", "bug_location": {"function": "count_vowels", "line_start": 3}, "test_cases": [{"input": "hello", "expected_output": 2}, {"input": "Hello", "expected_output": 2}, {"input": "AEIOU", "expected_output": 5}, {"input": "xyz", "expected_output": 0}]}
|
| 5 |
-
{"id": "t1_005", "difficulty": 1, "bug_type": "off_by_one", "function_name": "sum_list", "buggy_code": "def sum_list(nums):\n total = 0\n for i in range(len(nums) - 1):\n total += nums[i]\n return total", "original_code": "def sum_list(nums):\n total = 0\n for i in range(len(nums)):\n total += nums[i]\n return total", "initial_error": "AssertionError: sum_list([1,2,3]) expected 6, got 3", "bug_location": {"function": "sum_list", "line_start": 3}, "test_cases": [{"input": [1, 2, 3], "expected_output": 6}, {"input": [0], "expected_output": 0}, {"input": [10, 20, 30, 40], "expected_output": 100}, {"input": [], "expected_output": 0}]}
|
| 6 |
-
{"id": "t1_006", "difficulty": 1, "bug_type": "wrong_comparison", "function_name": "is_sorted", "buggy_code": "def is_sorted(lst):\n for i in range(len(lst) - 1):\n if lst[i] > lst[i + 1]:\n return True\n return False", "original_code": "def is_sorted(lst):\n for i in range(len(lst) - 1):\n if lst[i] > lst[i + 1]:\n return False\n return True", "initial_error": "AssertionError: is_sorted([1,2,3]) expected True, got False", "bug_location": {"function": "is_sorted", "line_start": 4}, "test_cases": [{"input": [1, 2, 3], "expected_output": true}, {"input": [3, 1, 2], "expected_output": false}, {"input": [1], "expected_output": true}, {"input": [2, 2, 2], "expected_output": true}]}
|
| 7 |
{"id": "t1_007", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "factorial", "buggy_code": "def factorial(n):\n if n == 0:\n return 0\n result = 1\n for i in range(1, n + 1):\n result *= i\n return result", "original_code": "def factorial(n):\n if n == 0:\n return 1\n result = 1\n for i in range(1, n + 1):\n result *= i\n return result", "initial_error": "AssertionError: factorial(0) expected 1, got 0", "bug_location": {"function": "factorial", "line_start": 3}, "test_cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]}
|
| 8 |
{"id": "t1_008", "difficulty": 1, "bug_type": "logic_inversion", "function_name": "is_even", "buggy_code": "def is_even(n):\n return n % 2 != 0", "original_code": "def is_even(n):\n return n % 2 == 0", "initial_error": "AssertionError: is_even(4) expected True, got False", "bug_location": {"function": "is_even", "line_start": 2}, "test_cases": [{"input": 4, "expected_output": true}, {"input": 3, "expected_output": false}, {"input": 0, "expected_output": true}, {"input": -2, "expected_output": true}]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"id": "t1_001", "difficulty": 1, "bug_type": "off_by_one", "function_name": "binary_search", "buggy_code": "def binary_search(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid + 1 + 1 + 1\n return -1", "original_code": "def binary_search(arr, target):\n left, right = 0, len(arr) - 1\n while left <= right:\n mid = (left + right) // 2\n if arr[mid] == target:\n return mid\n elif arr[mid] < target:\n left = mid + 1\n else:\n right = mid - 1\n return -1", "initial_error": "IndexError: list index out of range on line 5", "bug_location": {"function": "binary_search", "line_start": 2}, "test_cases": [{"input": [[1, 3, 5, 7, 9], 5], "expected_output": 2}, {"input": [[1, 3, 5, 7, 9], 1], "expected_output": 0}, {"input": [[1, 3, 5, 7, 9], 9], "expected_output": 4}, {"input": [[1, 3, 5, 7, 9], 4], "expected_output": -1}]}
|
| 2 |
{"id": "t1_002", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "is_palindrome", "buggy_code": "def is_palindrome(s):\n return s == s[::-1] and len(s) > 0", "original_code": "def is_palindrome(s):\n return s == s[::-1]", "initial_error": "AssertionError: is_palindrome('') expected True, got False", "bug_location": {"function": "is_palindrome", "line_start": 2}, "test_cases": [{"input": "racecar", "expected_output": true}, {"input": "hello", "expected_output": false}, {"input": "", "expected_output": true}, {"input": "a", "expected_output": true}]}
|
| 3 |
+
{"id": "t1_003", "difficulty": 1, "bug_type": "off_by_one", "function_name": "find_max", "buggy_code": "def find_max(nums):\n max_val = nums[0]\n for i in range(1, len(nums) + 1):\n if nums[i] > max_val:\n max_val = nums[i]\n return max_val", "original_code": "def find_max(nums):\n max_val = nums[0]\n for i in range(1, len(nums)):\n if nums[i] > max_val:\n max_val = nums[i]\n return max_val", "initial_error": "IndexError: list index out of range on line 4", "bug_location": {"function": "find_max", "line_start": 3}, "test_cases": [{"input": [[3, 1, 4, 1, 5, 9]], "expected_output": 9}, {"input": [[1]], "expected_output": 1}, {"input": [[-5, -1, -3]], "expected_output": -1}, {"input": [[7, 7, 7]], "expected_output": 7}]}
|
| 4 |
{"id": "t1_004", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "count_vowels", "buggy_code": "def count_vowels(s):\n count = 0\n for ch in s:\n if ch in 'aeiou':\n count += 1\n return count", "original_code": "def count_vowels(s):\n count = 0\n for ch in s.lower():\n if ch in 'aeiou':\n count += 1\n return count", "initial_error": "AssertionError: count_vowels('Hello') expected 2, got 1", "bug_location": {"function": "count_vowels", "line_start": 3}, "test_cases": [{"input": "hello", "expected_output": 2}, {"input": "Hello", "expected_output": 2}, {"input": "AEIOU", "expected_output": 5}, {"input": "xyz", "expected_output": 0}]}
|
| 5 |
+
{"id": "t1_005", "difficulty": 1, "bug_type": "off_by_one", "function_name": "sum_list", "buggy_code": "def sum_list(nums):\n total = 0\n for i in range(len(nums) - 1):\n total += nums[i]\n return total", "original_code": "def sum_list(nums):\n total = 0\n for i in range(len(nums)):\n total += nums[i]\n return total", "initial_error": "AssertionError: sum_list([1,2,3]) expected 6, got 3", "bug_location": {"function": "sum_list", "line_start": 3}, "test_cases": [{"input": [[1, 2, 3]], "expected_output": 6}, {"input": [[0]], "expected_output": 0}, {"input": [[10, 20, 30, 40]], "expected_output": 100}, {"input": [[]], "expected_output": 0}]}
|
| 6 |
+
{"id": "t1_006", "difficulty": 1, "bug_type": "wrong_comparison", "function_name": "is_sorted", "buggy_code": "def is_sorted(lst):\n for i in range(len(lst) - 1):\n if lst[i] > lst[i + 1]:\n return True\n return False", "original_code": "def is_sorted(lst):\n for i in range(len(lst) - 1):\n if lst[i] > lst[i + 1]:\n return False\n return True", "initial_error": "AssertionError: is_sorted([1,2,3]) expected True, got False", "bug_location": {"function": "is_sorted", "line_start": 4}, "test_cases": [{"input": [[1, 2, 3]], "expected_output": true}, {"input": [[3, 1, 2]], "expected_output": false}, {"input": [[1]], "expected_output": true}, {"input": [[2, 2, 2]], "expected_output": true}]}
|
| 7 |
{"id": "t1_007", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "factorial", "buggy_code": "def factorial(n):\n if n == 0:\n return 0\n result = 1\n for i in range(1, n + 1):\n result *= i\n return result", "original_code": "def factorial(n):\n if n == 0:\n return 1\n result = 1\n for i in range(1, n + 1):\n result *= i\n return result", "initial_error": "AssertionError: factorial(0) expected 1, got 0", "bug_location": {"function": "factorial", "line_start": 3}, "test_cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]}
|
| 8 |
{"id": "t1_008", "difficulty": 1, "bug_type": "logic_inversion", "function_name": "is_even", "buggy_code": "def is_even(n):\n return n % 2 != 0", "original_code": "def is_even(n):\n return n % 2 == 0", "initial_error": "AssertionError: is_even(4) expected True, got False", "bug_location": {"function": "is_even", "line_start": 2}, "test_cases": [{"input": 4, "expected_output": true}, {"input": 3, "expected_output": false}, {"input": 0, "expected_output": true}, {"input": -2, "expected_output": true}]}
|
| 9 |
+
{"id": "t1_009", "difficulty": 1, "bug_type": "off_by_one", "function_name": "factorial", "buggy_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n)", "original_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)", "initial_error": "RecursionError: maximum recursion depth exceeded", "bug_location": {"function": "factorial", "line_start": 4}, "test_cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]}
|
| 10 |
+
{"id": "t1_010", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "factorial", "buggy_code": "def factorial(n):\n if n == 0:\n return 1\n return n + factorial(n - 1)", "original_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)", "initial_error": "AssertionError: factorial(3) expected 6, got 6 - wait got 7", "bug_location": {"function": "factorial", "line_start": 4}, "test_cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]}
|
| 11 |
+
{"id": "t1_011", "difficulty": 1, "bug_type": "off_by_one", "function_name": "fibonacci", "buggy_code": "def fibonacci(n):\n if n < 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)", "original_code": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)", "initial_error": "RecursionError: maximum recursion depth exceeded", "bug_location": {"function": "fibonacci", "line_start": 2}, "test_cases": [{"input": 0, "expected_output": 0}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 5}, {"input": 7, "expected_output": 13}]}
|
| 12 |
+
{"id": "t1_012", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "fibonacci", "buggy_code": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) * fibonacci(n-2)", "original_code": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)", "initial_error": "AssertionError: fibonacci(5) expected 5, got 0", "bug_location": {"function": "fibonacci", "line_start": 4}, "test_cases": [{"input": 0, "expected_output": 0}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 5}, {"input": 7, "expected_output": 13}]}
|
| 13 |
+
{"id": "t1_013", "difficulty": 1, "bug_type": "off_by_one", "function_name": "string_reverse", "buggy_code": "def string_reverse(s):\n return s[:-1]", "original_code": "def string_reverse(s):\n return s[::-1]", "initial_error": "AssertionError: string_reverse('hello') expected 'olleh', got 'hell'", "bug_location": {"function": "string_reverse", "line_start": 2}, "test_cases": [{"input": "hello", "expected_output": "olleh"}, {"input": "", "expected_output": ""}, {"input": "a", "expected_output": "a"}, {"input": "racecar", "expected_output": "racecar"}]}
|
| 14 |
+
{"id": "t1_014", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "string_reverse", "buggy_code": "def string_reverse(s):\n return s[1:]", "original_code": "def string_reverse(s):\n return s[::-1]", "initial_error": "AssertionError: string_reverse('hello') expected 'olleh', got 'ello'", "bug_location": {"function": "string_reverse", "line_start": 2}, "test_cases": [{"input": "hello", "expected_output": "olleh"}, {"input": "", "expected_output": ""}, {"input": "a", "expected_output": "a"}, {"input": "racecar", "expected_output": "racecar"}]}
|
| 15 |
+
{"id": "t1_015", "difficulty": 1, "bug_type": "wrong_comparison", "function_name": "count_occurrences", "buggy_code": "def count_occurrences(lst, target):\n count = 0\n for item in lst:\n if item != target:\n count += 1\n return count", "original_code": "def count_occurrences(lst, target):\n count = 0\n for item in lst:\n if item == target:\n count += 1\n return count", "initial_error": "AssertionError: count_occurrences([1,2,1,3,1], 1) expected 3, got 2", "bug_location": {"function": "count_occurrences", "line_start": 4}, "test_cases": [{"input": [[1, 2, 1, 3, 1], 1], "expected_output": 3}, {"input": [[], 5], "expected_output": 0}, {"input": [[2, 2, 2], 2], "expected_output": 3}, {"input": [[1, 2, 3], 4], "expected_output": 0}]}
|
| 16 |
+
{"id": "t1_016", "difficulty": 1, "bug_type": "off_by_one", "function_name": "count_occurrences", "buggy_code": "def count_occurrences(lst, target):\n count = 1\n for item in lst:\n if item == target:\n count += 1\n return count", "original_code": "def count_occurrences(lst, target):\n count = 0\n for item in lst:\n if item == target:\n count += 1\n return count", "initial_error": "AssertionError: count_occurrences([], 5) expected 0, got 1", "bug_location": {"function": "count_occurrences", "line_start": 2}, "test_cases": [{"input": [[1, 2, 1, 3, 1], 1], "expected_output": 3}, {"input": [[], 5], "expected_output": 0}, {"input": [[2, 2, 2], 2], "expected_output": 3}, {"input": [[1, 2, 3], 4], "expected_output": 0}]}
|
| 17 |
+
{"id": "t1_017", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "sum_digits", "buggy_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n // 10\n n //= 10\n return total", "original_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n % 10\n n //= 10\n return total", "initial_error": "AssertionError: sum_digits(123) expected 6, got 13", "bug_location": {"function": "sum_digits", "line_start": 4}, "test_cases": [{"input": 123, "expected_output": 6}, {"input": 0, "expected_output": 0}, {"input": 999, "expected_output": 27}, {"input": 10, "expected_output": 1}]}
|
| 18 |
+
{"id": "t1_018", "difficulty": 1, "bug_type": "logic_inversion", "function_name": "sum_digits", "buggy_code": "def sum_digits(n):\n total = 0\n while n < 0:\n total += n % 10\n n //= 10\n return total", "original_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n % 10\n n //= 10\n return total", "initial_error": "AssertionError: sum_digits(123) expected 6, got 0", "bug_location": {"function": "sum_digits", "line_start": 3}, "test_cases": [{"input": 123, "expected_output": 6}, {"input": 0, "expected_output": 0}, {"input": 999, "expected_output": 27}, {"input": 10, "expected_output": 1}]}
|
| 19 |
+
{"id": "t1_019", "difficulty": 1, "bug_type": "off_by_one", "function_name": "is_prime", "buggy_code": "def is_prime(n):\n if n < 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True", "original_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True", "initial_error": "AssertionError: is_prime(1) expected False, got True", "bug_location": {"function": "is_prime", "line_start": 2}, "test_cases": [{"input": 2, "expected_output": true}, {"input": 4, "expected_output": false}, {"input": 13, "expected_output": true}, {"input": 1, "expected_output": false}]}
|
| 20 |
+
{"id": "t1_020", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "is_prime", "buggy_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i != 0:\n return False\n return True", "original_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True", "initial_error": "AssertionError: is_prime(13) expected True, got False", "bug_location": {"function": "is_prime", "line_start": 5}, "test_cases": [{"input": 2, "expected_output": true}, {"input": 4, "expected_output": false}, {"input": 13, "expected_output": true}, {"input": 1, "expected_output": false}]}
|
| 21 |
+
{"id": "t1_021", "difficulty": 1, "bug_type": "wrong_comparison", "function_name": "merge_intervals", "buggy_code": "def merge_intervals(intervals):\n if not intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] < previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged", "original_code": "def merge_intervals(intervals):\n if not intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] <= previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged", "initial_error": "AssertionError: merge_intervals([[1,4],[4,5]]) expected [[1,5]], got [[1,4],[4,5]]", "bug_location": {"function": "merge_intervals", "line_start": 8}, "test_cases": [{"input": [[[1, 3], [2, 6], [8, 10], [15, 18]]], "expected_output": [[1, 6], [8, 10], [15, 18]]}, {"input": [[[1, 4], [4, 5]]], "expected_output": [[1, 5]]}, {"input": [[]], "expected_output": []}, {"input": [[[1, 4], [0, 4]]], "expected_output": [[0, 4]]}]}
|
| 22 |
+
{"id": "t1_022", "difficulty": 1, "bug_type": "logic_inversion", "function_name": "merge_intervals", "buggy_code": "def merge_intervals(intervals):\n if intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] <= previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged", "original_code": "def merge_intervals(intervals):\n if not intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] <= previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged", "initial_error": "AssertionError: merge_intervals([[1,4],[4,5]]) expected [[1,5]], got []", "bug_location": {"function": "merge_intervals", "line_start": 2}, "test_cases": [{"input": [[[1, 3], [2, 6], [8, 10], [15, 18]]], "expected_output": [[1, 6], [8, 10], [15, 18]]}, {"input": [[[1, 4], [4, 5]]], "expected_output": [[1, 5]]}, {"input": [[]], "expected_output": []}, {"input": [[[1, 4], [0, 4]]], "expected_output": [[0, 4]]}]}
|
| 23 |
+
{"id": "t1_023", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "remove_duplicates", "buggy_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] == nums[i]:\n i += 1\n nums[i] = nums[j]\n return i + 1", "original_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] != nums[i]:\n i += 1\n nums[i] = nums[j]\n return i + 1", "initial_error": "AssertionError: remove_duplicates([1,1,2]) expected 2, got 2 with array [1,1,2]", "bug_location": {"function": "remove_duplicates", "line_start": 6}, "test_cases": [{"input": [[1, 1, 2]], "expected_output": 2}, {"input": [[0, 0, 1, 1, 1, 2, 2, 3, 3, 4]], "expected_output": 5}, {"input": [[]], "expected_output": 0}, {"input": [[1]], "expected_output": 1}]}
|
| 24 |
+
{"id": "t1_024", "difficulty": 1, "bug_type": "off_by_one", "function_name": "remove_duplicates", "buggy_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] != nums[i]:\n i += 1\n nums[i] = nums[j]\n return i", "original_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] != nums[i]:\n i += 1\n nums[i] = nums[j]\n return i + 1", "initial_error": "AssertionError: remove_duplicates([1,1,2]) expected 2, got 1", "bug_location": {"function": "remove_duplicates", "line_start": 9}, "test_cases": [{"input": [[1, 1, 2]], "expected_output": 2}, {"input": [[0, 0, 1, 1, 1, 2, 2, 3, 3, 4]], "expected_output": 5}, {"input": [[]], "expected_output": 0}, {"input": [[1]], "expected_output": 1}]}
|
| 25 |
+
{"id": "t1_025", "difficulty": 1, "bug_type": "wrong_comparison", "function_name": "longest_common_prefix", "buggy_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs[1:]:\n while s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix", "original_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs[1:]:\n while not s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix", "initial_error": "AssertionError: longest_common_prefix(['flower','flow','flight']) expected 'fl', got ''", "bug_location": {"function": "longest_common_prefix", "line_start": 6}, "test_cases": [{"input": [["flower", "flow", "flight"]], "expected_output": "fl"}, {"input": [["dog", "racecar", "car"]], "expected_output": ""}, {"input": [[]], "expected_output": ""}, {"input": [["a"]], "expected_output": "a"}]}
|
| 26 |
+
{"id": "t1_026", "difficulty": 1, "bug_type": "off_by_one", "function_name": "longest_common_prefix", "buggy_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs:\n while not s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix + 'x' + 'x' + 'x'", "original_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs[1:]:\n while not s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix", "initial_error": "AssertionError: doesn't strictly fail but runs longer", "bug_location": {"function": "longest_common_prefix", "line_start": 5}, "test_cases": [{"input": [["flower", "flow", "flight"]], "expected_output": "fl"}, {"input": [["dog", "racecar", "car"]], "expected_output": ""}, {"input": [[]], "expected_output": ""}, {"input": [["a"]], "expected_output": "a"}]}
|
| 27 |
+
{"id": "t1_027", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "product_except_self", "buggy_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix += nums[i]\n postfix = 1\n for i in range(n - 1, -1, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res", "original_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix *= nums[i]\n postfix = 1\n for i in range(n - 1, -1, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res", "initial_error": "AssertionError: product_except_self([1,2,3,4]) expected [24,12,8,6], got [24, 24, 16, 6]", "bug_location": {"function": "product_except_self", "line_start": 7}, "test_cases": [{"input": [[1, 2, 3, 4]], "expected_output": [24, 12, 8, 6]}, {"input": [[-1, 1, 0, -3, 3]], "expected_output": [0, 0, 9, 0, 0]}, {"input": [[2, 3]], "expected_output": [3, 2]}, {"input": [[1, 1, 1]], "expected_output": [1, 1, 1]}]}
|
| 28 |
+
{"id": "t1_028", "difficulty": 1, "bug_type": "off_by_one", "function_name": "product_except_self", "buggy_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix *= nums[i]\n postfix = 1\n for i in range(n - 1, 0, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res", "original_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix *= nums[i]\n postfix = 1\n for i in range(n - 1, -1, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res", "initial_error": "AssertionError: product_except_self([1,2,3,4]) expected [24,12,8,6], got [1,12,8,6]", "bug_location": {"function": "product_except_self", "line_start": 9}, "test_cases": [{"input": [[1, 2, 3, 4]], "expected_output": [24, 12, 8, 6]}, {"input": [[-1, 1, 0, -3, 3]], "expected_output": [0, 0, 9, 0, 0]}, {"input": [[2, 3]], "expected_output": [3, 2]}, {"input": [[1, 1, 1]], "expected_output": [1, 1, 1]}]}
|
| 29 |
+
{"id": "t1_029", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "valid_parentheses", "buggy_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] == top_element:\n return False\n else:\n stack.append(char)\n return not stack", "original_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] != top_element:\n return False\n else:\n stack.append(char)\n return not stack", "initial_error": "AssertionError: valid_parentheses('()') expected True, got False", "bug_location": {"function": "valid_parentheses", "line_start": 7}, "test_cases": [{"input": "()", "expected_output": true}, {"input": "()[]{}", "expected_output": true}, {"input": "(]", "expected_output": false}, {"input": "([)]", "expected_output": false}]}
|
| 30 |
+
{"id": "t1_030", "difficulty": 1, "bug_type": "logic_inversion", "function_name": "valid_parentheses", "buggy_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] != top_element:\n return False\n else:\n stack.append(char)\n return bool(stack)", "original_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] != top_element:\n return False\n else:\n stack.append(char)\n return not stack", "initial_error": "AssertionError: valid_parentheses('()') expected True, got False", "bug_location": {"function": "valid_parentheses", "line_start": 11}, "test_cases": [{"input": "()", "expected_output": true}, {"input": "()[]{}", "expected_output": true}, {"input": "(]", "expected_output": false}, {"input": "([)]", "expected_output": false}]}
|
| 31 |
+
{"id": "t1_031", "difficulty": 1, "bug_type": "off_by_one", "function_name": "climbing_stairs", "buggy_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n):\n a, b = b, a + b\n return b", "original_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a + b\n return b", "initial_error": "AssertionError: climbing_stairs(3) expected 3, got 2", "bug_location": {"function": "climbing_stairs", "line_start": 5}, "test_cases": [{"input": 2, "expected_output": 2}, {"input": 3, "expected_output": 3}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 8}]}
|
| 32 |
+
{"id": "t1_032", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "climbing_stairs", "buggy_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a * b\n return b", "original_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a + b\n return b", "initial_error": "AssertionError: climbing_stairs(3) expected 3, got 2", "bug_location": {"function": "climbing_stairs", "line_start": 6}, "test_cases": [{"input": 2, "expected_output": 2}, {"input": 3, "expected_output": 3}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 8}]}
|
| 33 |
+
{"id": "t1_033", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "house_robber", "buggy_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = 9999\n for i in range(2, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]", "original_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = max(nums[0], nums[1])\n for i in range(2, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]", "initial_error": "AssertionError: house_robber([2,7,9,3,1]) expected 12, got 11", "bug_location": {"function": "house_robber", "line_start": 8}, "test_cases": [{"input": [[1, 2, 3, 1]], "expected_output": 4}, {"input": [[2, 7, 9, 3, 1]], "expected_output": 12}, {"input": [[]], "expected_output": 0}, {"input": [[5]], "expected_output": 5}]}
|
| 34 |
+
{"id": "t1_034", "difficulty": 1, "bug_type": "off_by_one", "function_name": "house_robber", "buggy_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = max(nums[0], nums[1])\n for i in range(1, len(nums)):\n dp[i] = max(dp[i-1], nums[i])\n return dp[-1]", "original_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = max(nums[0], nums[1])\n for i in range(2, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]", "initial_error": "IndexError: list index out of range", "bug_location": {"function": "house_robber", "line_start": 9}, "test_cases": [{"input": [[1, 2, 3, 1]], "expected_output": 4}, {"input": [[2, 7, 9, 3, 1]], "expected_output": 12}, {"input": [[]], "expected_output": 0}, {"input": [[5]], "expected_output": 5}]}
|
| 35 |
+
{"id": "t1_035", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "intersection_of_arrays", "buggy_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) | set(nums2))", "original_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) & set(nums2))", "initial_error": "AssertionError: intersection_of_arrays([1,2,2,1], [2,2]) expected [2], got [1,2]", "bug_location": {"function": "intersection_of_arrays", "line_start": 2}, "test_cases": [{"input": [[1, 2, 2, 1], [2, 2]], "expected_output": [2]}, {"input": [[4, 9, 5], [9, 4, 9, 8, 4]], "expected_output": [9, 4]}, {"input": [[], [1]], "expected_output": []}, {"input": [[1, 2], [3, 4]], "expected_output": []}]}
|
| 36 |
+
{"id": "t1_036", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "intersection_of_arrays", "buggy_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) - set(nums2))", "original_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) & set(nums2))", "initial_error": "AssertionError: intersection_of_arrays([1,2,2,1], [2,2]) expected [2], got [1]", "bug_location": {"function": "intersection_of_arrays", "line_start": 2}, "test_cases": [{"input": [[1, 2, 2, 1], [2, 2]], "expected_output": [2]}, {"input": [[4, 9, 5], [9, 4, 9, 8, 4]], "expected_output": [9, 4]}, {"input": [[], [1]], "expected_output": []}, {"input": [[1, 2], [3, 4]], "expected_output": []}]}
|
| 37 |
+
{"id": "t1_037", "difficulty": 1, "bug_type": "wrong_comparison", "function_name": "group_anagrams", "buggy_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(s)].append(s)\n return list(ans.values())", "original_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(sorted(s))].append(s)\n return list(ans.values())", "initial_error": "AssertionError: expected [['eat','tea','ate'],['tan','nat'],['bat']]", "bug_location": {"function": "group_anagrams", "line_start": 5}, "test_cases": [{"input": [["eat", "tea", "tan", "ate", "nat", "bat"]], "expected_output": [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]}, {"input": [[""]], "expected_output": [[""]]}, {"input": [["a"]], "expected_output": [["a"]]}, {"input": [["ab", "ba"]], "expected_output": [["ab", "ba"]]}]}
|
| 38 |
+
{"id": "t1_038", "difficulty": 1, "bug_type": "logic_inversion", "function_name": "group_anagrams", "buggy_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(sorted(s))].append(s[::-1])\n return list(ans.values())", "original_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(sorted(s))].append(s)\n return list(ans.values())", "initial_error": "AssertionError: expected [['eat','tea','ate'],['tan','nat'],['bat']]", "bug_location": {"function": "group_anagrams", "line_start": 5}, "test_cases": [{"input": [["eat", "tea", "tan", "ate", "nat", "bat"]], "expected_output": [["eat", "tea", "ate"], ["tan", "nat"], ["bat"]]}, {"input": [[""]], "expected_output": [[""]]}, {"input": [["a"]], "expected_output": [["a"]]}, {"input": [["ab", "ba"]], "expected_output": [["ab", "ba"]]}]}
|
| 39 |
+
{"id": "t1_039", "difficulty": 1, "bug_type": "wrong_operator", "function_name": "sum_digits", "buggy_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total *= n % 10\n n //= 10\n return total", "original_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n % 10\n n //= 10\n return total", "initial_error": "AssertionError: sum_digits(123) expected 6, got 0", "bug_location": {"function": "sum_digits", "line_start": 4}, "test_cases": [{"input": 123, "expected_output": 6}, {"input": 0, "expected_output": 0}, {"input": 999, "expected_output": 27}, {"input": 10, "expected_output": 1}]}
|
| 40 |
+
{"id": "t1_040", "difficulty": 1, "bug_type": "off_by_one", "function_name": "factorial", "buggy_code": "def factorial(n):\n if n <= 0:\n return 0\n return n * factorial(n - 1)", "original_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)", "initial_error": "AssertionError: factorial(3) expected 6, got 0", "bug_location": {"function": "factorial", "line_start": 3}, "test_cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]}
|
data/bugs_tier2.jsonl
CHANGED
|
@@ -1,3 +1,30 @@
|
|
| 1 |
{"id": "t2_001", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "two_sum", "buggy_code": "def two_sum(nums, target):\n seen = {}\n for i, num in enumerate(nums):\n complement = target - num\n if complement in seen:\n return [seen[complement], i]\n seen[num] = num\n return []", "original_code": "def two_sum(nums, target):\n seen = {}\n for i, num in enumerate(nums):\n complement = target - num\n if complement in seen:\n return [seen[complement], i]\n seen[num] = i\n return []", "initial_error": "AssertionError: two_sum([2,7,11,15], 9) expected [0,1], got [2,1]", "bug_location": {"function": "two_sum", "line_start": 7}, "test_cases": [{"input": [[2, 7, 11, 15], 9], "expected_output": [0, 1]}, {"input": [[3, 2, 4], 6], "expected_output": [1, 2]}, {"input": [[3, 3], 6], "expected_output": [0, 1]}]}
|
| 2 |
{"id": "t2_002", "difficulty": 2, "bug_type": "missing_base_case", "function_name": "fibonacci", "buggy_code": "def fibonacci(n):\n if n == 0:\n return 0\n return fibonacci(n - 1) + fibonacci(n - 2)", "original_code": "def fibonacci(n):\n if n == 0:\n return 0\n if n == 1:\n return 1\n return fibonacci(n - 1) + fibonacci(n - 2)", "initial_error": "RecursionError: maximum recursion depth exceeded", "bug_location": {"function": "fibonacci", "line_start": 4}, "test_cases": [{"input": 0, "expected_output": 0}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 5}, {"input": 7, "expected_output": 13}]}
|
| 3 |
-
{"id": "t2_003", "difficulty": 2, "bug_type": "wrong_accumulator", "function_name": "flatten", "buggy_code": "def flatten(lst):\n result = []\n for item in lst:\n if isinstance(item, list):\n result.append(flatten(item))\n else:\n result.append(item)\n return result", "original_code": "def flatten(lst):\n result = []\n for item in lst:\n if isinstance(item, list):\n result.extend(flatten(item))\n else:\n result.append(item)\n return result", "initial_error": "AssertionError: flatten([[1,[2]],3]) expected [1,2,3], got [1,[2],3]", "bug_location": {"function": "flatten", "line_start": 5}, "test_cases": [{"input": [[1, [2]], 3], "expected_output": [1, 2, 3]}, {"input": [1, 2, 3], "expected_output": [1, 2, 3]}, {"input": [[1, 2], [3, [4, 5]]], "expected_output": [1, 2, 3, 4, 5]}]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
{"id": "t2_001", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "two_sum", "buggy_code": "def two_sum(nums, target):\n seen = {}\n for i, num in enumerate(nums):\n complement = target - num\n if complement in seen:\n return [seen[complement], i]\n seen[num] = num\n return []", "original_code": "def two_sum(nums, target):\n seen = {}\n for i, num in enumerate(nums):\n complement = target - num\n if complement in seen:\n return [seen[complement], i]\n seen[num] = i\n return []", "initial_error": "AssertionError: two_sum([2,7,11,15], 9) expected [0,1], got [2,1]", "bug_location": {"function": "two_sum", "line_start": 7}, "test_cases": [{"input": [[2, 7, 11, 15], 9], "expected_output": [0, 1]}, {"input": [[3, 2, 4], 6], "expected_output": [1, 2]}, {"input": [[3, 3], 6], "expected_output": [0, 1]}]}
|
| 2 |
{"id": "t2_002", "difficulty": 2, "bug_type": "missing_base_case", "function_name": "fibonacci", "buggy_code": "def fibonacci(n):\n if n == 0:\n return 0\n return fibonacci(n - 1) + fibonacci(n - 2)", "original_code": "def fibonacci(n):\n if n == 0:\n return 0\n if n == 1:\n return 1\n return fibonacci(n - 1) + fibonacci(n - 2)", "initial_error": "RecursionError: maximum recursion depth exceeded", "bug_location": {"function": "fibonacci", "line_start": 4}, "test_cases": [{"input": 0, "expected_output": 0}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 5}, {"input": 7, "expected_output": 13}]}
|
| 3 |
+
{"id": "t2_003", "difficulty": 2, "bug_type": "wrong_accumulator", "function_name": "flatten", "buggy_code": "def flatten(lst):\n result = []\n for item in lst:\n if isinstance(item, list):\n result.append(flatten(item))\n else:\n result.append(item)\n return result", "original_code": "def flatten(lst):\n result = []\n for item in lst:\n if isinstance(item, list):\n result.extend(flatten(item))\n else:\n result.append(item)\n return result", "initial_error": "AssertionError: flatten([[1,[2]],3]) expected [1,2,3], got [1,[2],3]", "bug_location": {"function": "flatten", "line_start": 5}, "test_cases": [{"input": [[[1, [2]], 3]], "expected_output": [1, 2, 3]}, {"input": [[1, 2, 3]], "expected_output": [1, 2, 3]}, {"input": [[[1, 2], [3, [4, 5]]]], "expected_output": [1, 2, 3, 4, 5]}]}
|
| 4 |
+
{"id": "t2_004", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "find_first_positive", "buggy_code": "def find_first_positive(nums):\n i = 0\n while i < len(nums) - 1:\n if nums[i] > 0:\n return nums[i]\n i += 1\n return -1", "original_code": "def find_first_positive(nums):\n i = 0\n while i < len(nums):\n if nums[i] > 0:\n return nums[i]\n i += 1\n return -1", "initial_error": "AssertionError: expected 5, got -1", "bug_location": {"function": "find_first_positive", "line_start": 3}, "test_cases": [{"input": [[-1, -2, 5]], "expected_output": 5}, {"input": [[1, 2, 3]], "expected_output": 1}, {"input": [[-1]], "expected_output": -1}, {"input": [[-5, -3, -1, 10]], "expected_output": 10}]}
|
| 5 |
+
{"id": "t2_005", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "binary_search_insert", "buggy_code": "def binary_search_insert(arr, target):\n left, right = 0, len(arr) - 1\n while left < right:\n mid = (left + right) // 2\n if arr[mid] < target:\n left = mid + 1\n else:\n right = mid\n return left", "original_code": "def binary_search_insert(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] < target:\n left = mid + 1\n else:\n right = mid\n return left", "initial_error": "AssertionError: expected 3, got 2", "bug_location": {"function": "binary_search_insert", "line_start": 2}, "test_cases": [{"input": [[1, 3, 5], 6], "expected_output": 3}, {"input": [[1, 3, 5], 4], "expected_output": 2}, {"input": [[1, 3, 5], 0], "expected_output": 0}, {"input": [[], 1], "expected_output": 0}]}
|
| 6 |
+
{"id": "t2_006", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "countdown_to_zero", "buggy_code": "def countdown_to_zero(n):\n res = []\n while n > 0:\n res.append(n)\n n -= 1\n return res", "original_code": "def countdown_to_zero(n):\n res = []\n while n >= 0:\n res.append(n)\n n -= 1\n return res", "initial_error": "AssertionError: expected [3, 2, 1, 0], got [3, 2, 1]", "bug_location": {"function": "countdown_to_zero", "line_start": 3}, "test_cases": [{"input": 3, "expected_output": [3, 2, 1, 0]}, {"input": 0, "expected_output": [0]}, {"input": 1, "expected_output": [1, 0]}, {"input": -1, "expected_output": []}]}
|
| 7 |
+
{"id": "t2_007", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "collect_until_negative", "buggy_code": "def collect_until_negative(nums):\n res = []\n i = 0\n while i <= len(nums) and nums[i] >= 0:\n res.append(nums[i])\n i += 1\n return res", "original_code": "def collect_until_negative(nums):\n res = []\n i = 0\n while i < len(nums) and nums[i] >= 0:\n res.append(nums[i])\n i += 1\n return res", "initial_error": "IndexError: list index out of range", "bug_location": {"function": "collect_until_negative", "line_start": 4}, "test_cases": [{"input": [[1, 2, -1, 3]], "expected_output": [1, 2]}, {"input": [[1, 2, 3]], "expected_output": [1, 2, 3]}, {"input": [[-1]], "expected_output": []}, {"input": [[]], "expected_output": []}]}
|
| 8 |
+
{"id": "t2_008", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "skip_spaces", "buggy_code": "def skip_spaces(s):\n i = 0\n while s[i] == ' ':\n i += 1\n return s[i:]", "original_code": "def skip_spaces(s):\n i = 0\n while i < len(s) and s[i] == ' ':\n i += 1\n return s[i:]", "initial_error": "IndexError: string index out of range", "bug_location": {"function": "skip_spaces", "line_start": 3}, "test_cases": [{"input": " hello", "expected_output": "hello"}, {"input": " ", "expected_output": ""}, {"input": "world", "expected_output": "world"}, {"input": "", "expected_output": ""}]}
|
| 9 |
+
{"id": "t2_009", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "find_last_even", "buggy_code": "def find_last_even(nums):\n i = len(nums) - 1\n while i > 0:\n if nums[i] % 2 == 0:\n return nums[i]\n i -= 1\n return -1", "original_code": "def find_last_even(nums):\n i = len(nums) - 1\n while i >= 0:\n if nums[i] % 2 == 0:\n return nums[i]\n i -= 1\n return -1", "initial_error": "AssertionError: expected 2, got -1", "bug_location": {"function": "find_last_even", "line_start": 3}, "test_cases": [{"input": [[2, 3, 5]], "expected_output": 2}, {"input": [[1, 3, 4]], "expected_output": 4}, {"input": [[1, 3, 5]], "expected_output": -1}, {"input": [[6]], "expected_output": 6}]}
|
| 10 |
+
{"id": "t2_010", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "get_chunks", "buggy_code": "def get_chunks(lst, size):\n chunks = []\n i = 0\n while i < len(lst) - size:\n chunks.append(lst[i:i+size])\n i += size\n return chunks", "original_code": "def get_chunks(lst, size):\n chunks = []\n i = 0\n while i < len(lst):\n chunks.append(lst[i:i+size])\n i += size\n return chunks", "initial_error": "AssertionError: expected [[1,2],[3]], got [[1,2]]", "bug_location": {"function": "get_chunks", "line_start": 4}, "test_cases": [{"input": [[1, 2, 3], 2], "expected_output": [[1, 2], [3]]}, {"input": [[1, 2], 2], "expected_output": [[1, 2]]}, {"input": [[1, 2, 3, 4], 2], "expected_output": [[1, 2], [3, 4]]}, {"input": [[], 2], "expected_output": []}]}
|
| 11 |
+
{"id": "t2_011", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "sum_even_numbers", "buggy_code": "def sum_even_numbers(nums):\n total = 1\n for n in nums:\n if n % 2 == 0:\n total += n\n return total", "original_code": "def sum_even_numbers(nums):\n total = 0\n for n in nums:\n if n % 2 == 0:\n total += n\n return total", "initial_error": "AssertionError: expected 6, got 7", "bug_location": {"function": "sum_even_numbers", "line_start": 2}, "test_cases": [{"input": [[1, 2, 3, 4]], "expected_output": 6}, {"input": [[1, 3, 5]], "expected_output": 0}, {"input": [[2, 2]], "expected_output": 4}, {"input": [[]], "expected_output": 0}]}
|
| 12 |
+
{"id": "t2_012", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "multiply_all", "buggy_code": "def multiply_all(nums):\n total = 0\n for n in nums:\n total *= n\n return total", "original_code": "def multiply_all(nums):\n total = 1\n for n in nums:\n total *= n\n return total", "initial_error": "AssertionError: expected 24, got 0", "bug_location": {"function": "multiply_all", "line_start": 2}, "test_cases": [{"input": [[1, 2, 3, 4]], "expected_output": 24}, {"input": [[5]], "expected_output": 5}, {"input": [[1, -1]], "expected_output": -1}, {"input": [[0, 5]], "expected_output": 0}]}
|
| 13 |
+
{"id": "t2_013", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "concatenate_strings", "buggy_code": "def concatenate_strings(strs):\n res = strs[0]\n for s in strs:\n res += s\n return res", "original_code": "def concatenate_strings(strs):\n res = ''\n for s in strs:\n res += s\n return res", "initial_error": "AssertionError: expected 'abc', got 'aabc'", "bug_location": {"function": "concatenate_strings", "line_start": 2}, "test_cases": [{"input": [["a", "b", "c"]], "expected_output": "abc"}, {"input": [["hello", "world"]], "expected_output": "helloworld"}, {"input": [["a"]], "expected_output": "a"}, {"input": [["x", "y"]], "expected_output": "xy"}]}
|
| 14 |
+
{"id": "t2_014", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "max_profit", "buggy_code": "def max_profit(prices):\n min_price = 0\n max_prof = 0\n for price in prices:\n min_price = min(min_price, price)\n max_prof = max(max_prof, price - min_price)\n return max_prof", "original_code": "def max_profit(prices):\n min_price = float('inf')\n max_prof = 0\n for price in prices:\n min_price = min(min_price, price)\n max_prof = max(max_prof, price - min_price)\n return max_prof", "initial_error": "AssertionError: expected 5, got 6", "bug_location": {"function": "max_profit", "line_start": 2}, "test_cases": [{"input": [[7, 1, 5, 3, 6, 4]], "expected_output": 5}, {"input": [[7, 6, 4, 3, 1]], "expected_output": 0}, {"input": [[1, 2]], "expected_output": 1}, {"input": [[2, 4, 1]], "expected_output": 2}]}
|
| 15 |
+
{"id": "t2_015", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "find_longest_word", "buggy_code": "def find_longest_word(words):\n longest = words[0]\n for word in words:\n if len(word) > len(longest):\n longest = longest\n return longest", "original_code": "def find_longest_word(words):\n longest = ''\n for word in words:\n if len(word) > len(longest):\n longest = word\n return longest", "initial_error": "AssertionError: expected 'banana', got 'apple'", "bug_location": {"function": "find_longest_word", "line_start": 5}, "test_cases": [{"input": [["apple", "banana", "kiwi"]], "expected_output": "banana"}, {"input": [["a", "ab", "abc"]], "expected_output": "abc"}, {"input": [["dog"]], "expected_output": "dog"}, {"input": [["x", "yz"]], "expected_output": "yz"}]}
|
| 16 |
+
{"id": "t2_016", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "running_sum", "buggy_code": "def running_sum(nums):\n res = []\n current = nums[0]\n for n in nums:\n current += n\n res.append(current)\n return res", "original_code": "def running_sum(nums):\n res = []\n current = 0\n for n in nums:\n current += n\n res.append(current)\n return res", "initial_error": "AssertionError: expected [1, 3, 6], got [2, 4, 7]", "bug_location": {"function": "running_sum", "line_start": 3}, "test_cases": [{"input": [[1, 2, 3]], "expected_output": [1, 3, 6]}, {"input": [[1, 1, 1]], "expected_output": [1, 2, 3]}, {"input": [[5]], "expected_output": [5]}, {"input": [[0, 0, 0]], "expected_output": [0, 0, 0]}]}
|
| 17 |
+
{"id": "t2_017", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "count_negatives", "buggy_code": "def count_negatives(nums):\n count = -1\n for n in nums:\n if n < 0:\n count += 1\n return count", "original_code": "def count_negatives(nums):\n count = 0\n for n in nums:\n if n < 0:\n count += 1\n return count", "initial_error": "AssertionError: expected 2, got 1", "bug_location": {"function": "count_negatives", "line_start": 2}, "test_cases": [{"input": [[1, -1, 2, -2]], "expected_output": 2}, {"input": [[1, 2, 3]], "expected_output": 0}, {"input": [[-1, -2, -3]], "expected_output": 3}, {"input": [[]], "expected_output": 0}]}
|
| 18 |
+
{"id": "t2_018", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "classify_number", "buggy_code": "def classify_number(n):\n if n > 0:\n return 'positive'\n elif n < 0:\n return 'negative'\n elif n == 0:\n return 'negative'", "original_code": "def classify_number(n):\n if n > 0:\n return 'positive'\n elif n < 0:\n return 'negative'\n else:\n return 'zero'", "initial_error": "AssertionError: expected 'zero', got 'negative'", "bug_location": {"function": "classify_number", "line_start": 6}, "test_cases": [{"input": 5, "expected_output": "positive"}, {"input": -3, "expected_output": "negative"}, {"input": 0, "expected_output": "zero"}, {"input": 1, "expected_output": "positive"}]}
|
| 19 |
+
{"id": "t2_019", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "get_discount", "buggy_code": "def get_discount(price):\n if price > 100:\n return 20\n if price > 50:\n return 50\n return 0", "original_code": "def get_discount(price):\n if price > 100:\n return 20\n elif price > 50:\n return 10\n return 0", "initial_error": "AssertionError: expected 10, got 50", "bug_location": {"function": "get_discount", "line_start": 5}, "test_cases": [{"input": 150, "expected_output": 20}, {"input": 75, "expected_output": 10}, {"input": 50, "expected_output": 0}, {"input": 20, "expected_output": 0}]}
|
| 20 |
+
{"id": "t2_020", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "fizz_buzz", "buggy_code": "def fizz_buzz(n):\n if n % 3 == 0:\n return 'Fizz'\n if n % 5 == 0:\n return 'Buzz'\n if n % 15 == 0:\n return 'FizzBuzz'\n return str(n)", "original_code": "def fizz_buzz(n):\n if n % 15 == 0:\n return 'FizzBuzz'\n if n % 3 == 0:\n return 'Fizz'\n if n % 5 == 0:\n return 'Buzz'\n return str(n)", "initial_error": "AssertionError: expected 'FizzBuzz', got 'Fizz'", "bug_location": {"function": "fizz_buzz", "line_start": 2}, "test_cases": [{"input": 3, "expected_output": "Fizz"}, {"input": 5, "expected_output": "Buzz"}, {"input": 15, "expected_output": "FizzBuzz"}, {"input": 2, "expected_output": "2"}]}
|
| 21 |
+
{"id": "t2_021", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "is_leap_year", "buggy_code": "def is_leap_year(year):\n if year % 4 == 0:\n if year % 100 == 0:\n if year % 400 == 0:\n return False\n return True\n return True\n return False", "original_code": "def is_leap_year(year):\n if year % 4 == 0:\n if year % 100 == 0:\n if year % 400 == 0:\n return True\n return False\n return True\n return False", "initial_error": "AssertionError: expected False, got True", "bug_location": {"function": "is_leap_year", "line_start": 5}, "test_cases": [{"input": 2000, "expected_output": true}, {"input": 1900, "expected_output": false}, {"input": 2004, "expected_output": true}, {"input": 2001, "expected_output": false}]}
|
| 22 |
+
{"id": "t2_022", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "grade_score", "buggy_code": "def grade_score(score):\n if score >= 90:\n return 'A'\n elif score >= 80:\n return 'B'\n elif score > 70:\n return 'C'\n else:\n return 'F'", "original_code": "def grade_score(score):\n if score >= 90:\n return 'A'\n elif score >= 80:\n return 'B'\n elif score >= 70:\n return 'C'\n else:\n return 'F'", "initial_error": "AssertionError: expected 'C', got 'F'", "bug_location": {"function": "grade_score", "line_start": 6}, "test_cases": [{"input": 95, "expected_output": "A"}, {"input": 80, "expected_output": "B"}, {"input": 70, "expected_output": "C"}, {"input": 60, "expected_output": "F"}]}
|
| 23 |
+
{"id": "t2_023", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "can_drink_alcohol", "buggy_code": "def can_drink_alcohol(age, country):\n if country == 'US':\n if age > 21:\n return True\n return False\n return age >= 18", "original_code": "def can_drink_alcohol(age, country):\n if country == 'US':\n if age >= 21:\n return True\n return False\n return age >= 18", "initial_error": "AssertionError: expected True, got False", "bug_location": {"function": "can_drink_alcohol", "line_start": 3}, "test_cases": [{"input": [21, "US"], "expected_output": true}, {"input": [20, "US"], "expected_output": false}, {"input": [18, "UK"], "expected_output": true}, {"input": [17, "UK"], "expected_output": false}]}
|
| 24 |
+
{"id": "t2_024", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "get_quadrant", "buggy_code": "def get_quadrant(x, y):\n if x > 0 and y > 0:\n return 1\n elif x < 0 and y > 0:\n return 2\n elif x > 0 and y < 0:\n return 3\n elif x < 0 and y < 0:\n return 4\n return 0", "original_code": "def get_quadrant(x, y):\n if x > 0 and y > 0:\n return 1\n elif x < 0 and y > 0:\n return 2\n elif x < 0 and y < 0:\n return 3\n elif x > 0 and y < 0:\n return 4\n return 0", "initial_error": "AssertionError: expected 4, got 3", "bug_location": {"function": "get_quadrant", "line_start": 6}, "test_cases": [{"input": [1, 1], "expected_output": 1}, {"input": [-1, 1], "expected_output": 2}, {"input": [-1, -1], "expected_output": 3}, {"input": [1, -1], "expected_output": 4}]}
|
| 25 |
+
{"id": "t2_025", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "merge_arrays", "buggy_code": "def merge_arrays(a, b):\n res = a + b\n res.sort()\n return a", "original_code": "def merge_arrays(a, b):\n res = a + b\n res.sort()\n return res", "initial_error": "AssertionError: expected [1, 2, 3, 4], got [1, 3]", "bug_location": {"function": "merge_arrays", "line_start": 4}, "test_cases": [{"input": [[1, 3], [2, 4]], "expected_output": [1, 2, 3, 4]}, {"input": [[], [1]], "expected_output": [1]}, {"input": [[2], [1]], "expected_output": [1, 2]}, {"input": [[], []], "expected_output": []}]}
|
| 26 |
+
{"id": "t2_026", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "find_min_max", "buggy_code": "def find_min_max(nums):\n if not nums:\n return None\n mn = min(nums)\n mx = max(nums)\n return [mn, mn]", "original_code": "def find_min_max(nums):\n if not nums:\n return None\n mn = min(nums)\n mx = max(nums)\n return [mn, mx]", "initial_error": "AssertionError: expected (1, 5), got (1, 1)", "bug_location": {"function": "find_min_max", "line_start": 6}, "test_cases": [{"input": [[1, 2, 5]], "expected_output": [1, 5]}, {"input": [[3, 3]], "expected_output": [3, 3]}, {"input": [[-1, 0, 1]], "expected_output": [-1, 1]}, {"input": [[]], "expected_output": null}]}
|
| 27 |
+
{"id": "t2_027", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "remove_evens", "buggy_code": "def remove_evens(nums):\n res = []\n for n in nums:\n if n % 2 != 0:\n res.append(n)\n return nums", "original_code": "def remove_evens(nums):\n res = []\n for n in nums:\n if n % 2 != 0:\n res.append(n)\n return res", "initial_error": "AssertionError: expected [1, 3], got [1, 2, 3]", "bug_location": {"function": "remove_evens", "line_start": 6}, "test_cases": [{"input": [[1, 2, 3]], "expected_output": [1, 3]}, {"input": [[2, 4]], "expected_output": []}, {"input": [[1, 3]], "expected_output": [1, 3]}, {"input": [[]], "expected_output": []}]}
|
| 28 |
+
{"id": "t2_028", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "duplicate_list", "buggy_code": "def duplicate_list(lst):\n res = lst[:]\n res.extend(lst)\n return lst", "original_code": "def duplicate_list(lst):\n res = lst[:]\n res.extend(lst)\n return res", "initial_error": "AssertionError: expected [1, 1], got [1]", "bug_location": {"function": "duplicate_list", "line_start": 4}, "test_cases": [{"input": [[1]], "expected_output": [1, 1]}, {"input": [[1, 2]], "expected_output": [1, 2, 1, 2]}, {"input": [[]], "expected_output": []}, {"input": [[0]], "expected_output": [0, 0]}]}
|
| 29 |
+
{"id": "t2_029", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "swap_halves", "buggy_code": "def swap_halves(lst):\n mid = len(lst) // 2\n left = lst[:mid]\n right = lst[mid:]\n return left + left", "original_code": "def swap_halves(lst):\n mid = len(lst) // 2\n left = lst[:mid]\n right = lst[mid:]\n return right + left", "initial_error": "AssertionError: expected [3, 4, 1, 2], got [1, 2, 1, 2]", "bug_location": {"function": "swap_halves", "line_start": 5}, "test_cases": [{"input": [[1, 2, 3, 4]], "expected_output": [3, 4, 1, 2]}, {"input": [[1, 2, 3]], "expected_output": [2, 3, 1]}, {"input": [[1]], "expected_output": [1]}, {"input": [[]], "expected_output": []}]}
|
| 30 |
+
{"id": "t2_030", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "get_initials", "buggy_code": "def get_initials(name):\n words = name.split()\n initials = [w[0].upper() for w in words]\n return ''.join(words)", "original_code": "def get_initials(name):\n words = name.split()\n initials = [w[0].upper() for w in words]\n return ''.join(initials)", "initial_error": "AssertionError: expected 'JD', got 'JohnDoe'", "bug_location": {"function": "get_initials", "line_start": 4}, "test_cases": [{"input": "John Doe", "expected_output": "JD"}, {"input": "Alice", "expected_output": "A"}, {"input": "bob smith junior", "expected_output": "BSJ"}, {"input": "", "expected_output": ""}]}
|
data/bugs_tier3.jsonl
CHANGED
|
@@ -1,2 +1,20 @@
|
|
| 1 |
{"id": "t3_001", "difficulty": 3, "bug_type": "edge_case_only", "function_name": "merge_sorted", "buggy_code": "def merge_sorted(a, b):\n result = []\n i = j = 0\n while i < len(a) and j < len(b):\n if a[i] <= b[j]:\n result.append(a[i])\n i += 1\n else:\n result.append(b[j])\n j += 1\n return result", "original_code": "def merge_sorted(a, b):\n result = []\n i = j = 0\n while i < len(a) and j < len(b):\n if a[i] <= b[j]:\n result.append(a[i])\n i += 1\n else:\n result.append(b[j])\n j += 1\n result.extend(a[i:])\n result.extend(b[j:])\n return result", "initial_error": "AssertionError: merge_sorted([1,3],[2,4,5]) expected [1,2,3,4,5], got [1,2,3]", "bug_location": {"function": "merge_sorted", "line_start": 11}, "test_cases": [{"input": [[1, 3], [2, 4, 5]], "expected_output": [1, 2, 3, 4, 5]}, {"input": [[], [1, 2]], "expected_output": [1, 2]}, {"input": [[1, 2], []], "expected_output": [1, 2]}, {"input": [[1], [2]], "expected_output": [1, 2]}]}
|
| 2 |
-
{"id": "t3_002", "difficulty": 3, "bug_type": "subtle_logic", "function_name": "rotate_matrix", "buggy_code": "def rotate_matrix(matrix):\n n = len(matrix)\n for i in range(n):\n for j in range(i, n):\n matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]\n return matrix", "original_code": "def rotate_matrix(matrix):\n n = len(matrix)\n for i in range(n):\n for j in range(i, n):\n matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]\n for row in matrix:\n row.reverse()\n return matrix", "initial_error": "AssertionError: rotate_matrix([[1,2],[3,4]]) expected [[3,1],[4,2]], got [[1,3],[2,4]]", "bug_location": {"function": "rotate_matrix", "line_start": 6}, "test_cases": [{"input": [[1, 2], [3, 4]], "expected_output": [[3, 1], [4, 2]]}, {"input": [[1, 2, 3], [4, 5, 6], [7, 8, 9]], "expected_output": [[7, 4, 1], [8, 5, 2], [9, 6, 3]]}]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
{"id": "t3_001", "difficulty": 3, "bug_type": "edge_case_only", "function_name": "merge_sorted", "buggy_code": "def merge_sorted(a, b):\n result = []\n i = j = 0\n while i < len(a) and j < len(b):\n if a[i] <= b[j]:\n result.append(a[i])\n i += 1\n else:\n result.append(b[j])\n j += 1\n return result", "original_code": "def merge_sorted(a, b):\n result = []\n i = j = 0\n while i < len(a) and j < len(b):\n if a[i] <= b[j]:\n result.append(a[i])\n i += 1\n else:\n result.append(b[j])\n j += 1\n result.extend(a[i:])\n result.extend(b[j:])\n return result", "initial_error": "AssertionError: merge_sorted([1,3],[2,4,5]) expected [1,2,3,4,5], got [1,2,3]", "bug_location": {"function": "merge_sorted", "line_start": 11}, "test_cases": [{"input": [[1, 3], [2, 4, 5]], "expected_output": [1, 2, 3, 4, 5]}, {"input": [[], [1, 2]], "expected_output": [1, 2]}, {"input": [[1, 2], []], "expected_output": [1, 2]}, {"input": [[1], [2]], "expected_output": [1, 2]}]}
|
| 2 |
+
{"id": "t3_002", "difficulty": 3, "bug_type": "subtle_logic", "function_name": "rotate_matrix", "buggy_code": "def rotate_matrix(matrix):\n n = len(matrix)\n for i in range(n):\n for j in range(i, n):\n matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]\n return matrix", "original_code": "def rotate_matrix(matrix):\n n = len(matrix)\n for i in range(n):\n for j in range(i, n):\n matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]\n for row in matrix:\n row.reverse()\n return matrix", "initial_error": "AssertionError: rotate_matrix([[1,2],[3,4]]) expected [[3,1],[4,2]], got [[1,3],[2,4]]", "bug_location": {"function": "rotate_matrix", "line_start": 6}, "test_cases": [{"input": [[[1, 2], [3, 4]]], "expected_output": [[3, 1], [4, 2]]}, {"input": [[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], "expected_output": [[7, 4, 1], [8, 5, 2], [9, 6, 3]]}]}
|
| 3 |
+
{"id": "t3_003", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "process_user", "buggy_code": "def format_name(first, last):\n return f'{last}, {first}'\n\ndef process_user(first_name, last_name):\n return format_name(last_name, first_name)", "original_code": "def format_name(first, last):\n return f'{last}, {first}'\n\ndef process_user(first_name, last_name):\n return format_name(first_name, last_name)", "initial_error": "AssertionError: expected 'Doe, John', got 'John, Doe'", "bug_location": {"function": "process_user", "line_start": 5}, "test_cases": [{"input": ["John", "Doe"], "expected_output": "Doe, John"}, {"input": ["Alice", "Smith"], "expected_output": "Smith, Alice"}, {"input": ["A", "B"], "expected_output": "B, A"}, {"input": ["X", "Y"], "expected_output": "Y, X"}]}
|
| 4 |
+
{"id": "t3_004", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "calculate_total", "buggy_code": "def apply_discount(price, discount):\n return price - (price * discount)\n\ndef calculate_total(price, discount_rate):\n return apply_discount(discount_rate, price)", "original_code": "def apply_discount(price, discount):\n return price - (price * discount)\n\ndef calculate_total(price, discount_rate):\n return apply_discount(price, discount_rate)", "initial_error": "AssertionError: expected 80.0, got -19.8", "bug_location": {"function": "calculate_total", "line_start": 5}, "test_cases": [{"input": [100, 0.2], "expected_output": 80.0}, {"input": [50, 0.1], "expected_output": 45.0}, {"input": [200, 0.5], "expected_output": 100.0}, {"input": [10, 0.0], "expected_output": 10.0}]}
|
| 5 |
+
{"id": "t3_005", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "build_url", "buggy_code": "def join_parts(domain, path):\n return f'https://{domain}/{path}'\n\ndef build_url(domain, path):\n return join_parts(path, domain)", "original_code": "def join_parts(domain, path):\n return f'https://{domain}/{path}'\n\ndef build_url(domain, path):\n return join_parts(domain, path)", "initial_error": "AssertionError: expected 'https://example.com/api', got 'https://api/example.com'", "bug_location": {"function": "build_url", "line_start": 5}, "test_cases": [{"input": ["example.com", "api"], "expected_output": "https://example.com/api"}, {"input": ["google.com", "search"], "expected_output": "https://google.com/search"}, {"input": ["a.com", "b"], "expected_output": "https://a.com/b"}, {"input": ["x.org", "y"], "expected_output": "https://x.org/y"}]}
|
| 6 |
+
{"id": "t3_006", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "divide_numbers", "buggy_code": "def safe_divide(num, den):\n if den == 0:\n return 0\n return num / den\n\ndef divide_numbers(a, b):\n return safe_divide(b, a)", "original_code": "def safe_divide(num, den):\n if den == 0:\n return 0\n return num / den\n\ndef divide_numbers(a, b):\n return safe_divide(a, b)", "initial_error": "AssertionError: expected 2.0, got 0.5", "bug_location": {"function": "divide_numbers", "line_start": 7}, "test_cases": [{"input": [10, 5], "expected_output": 2.0}, {"input": [5, 0], "expected_output": 0}, {"input": [100, 10], "expected_output": 10.0}, {"input": [0, 5], "expected_output": 0.0}]}
|
| 7 |
+
{"id": "t3_007", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "create_rectangle", "buggy_code": "def calc_area(w, h):\n return w * h\n\ndef create_rectangle(width, height):\n return {'w': width, 'h': height, 'area': calc_area(height, height)}", "original_code": "def calc_area(w, h):\n return w * h\n\ndef create_rectangle(width, height):\n return {'w': width, 'h': height, 'area': calc_area(width, height)}", "initial_error": "AssertionError: doesn't strictly fail math but conceptually wrong", "bug_location": {"function": "create_rectangle", "line_start": 5}, "test_cases": [{"input": [5, 10], "expected_output": {"w": 5, "h": 10, "area": 50}}, {"input": [2, 3], "expected_output": {"w": 2, "h": 3, "area": 6}}, {"input": [1, 1], "expected_output": {"w": 1, "h": 1, "area": 1}}, {"input": [0, 5], "expected_output": {"w": 0, "h": 5, "area": 0}}]}
|
| 8 |
+
{"id": "t3_008", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "power_wrapper", "buggy_code": "def compute_pow(base, exp):\n return base ** exp\n\ndef power_wrapper(base, exp):\n return compute_pow(exp, base)", "original_code": "def compute_pow(base, exp):\n return base ** exp\n\ndef power_wrapper(base, exp):\n return compute_pow(base, exp)", "initial_error": "AssertionError: expected 8, got 9", "bug_location": {"function": "power_wrapper", "line_start": 5}, "test_cases": [{"input": [2, 3], "expected_output": 8}, {"input": [3, 2], "expected_output": 9}, {"input": [5, 2], "expected_output": 25}, {"input": [2, 4], "expected_output": 16}]}
|
| 9 |
+
{"id": "t3_009", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "get_unique_items", "buggy_code": "seen = {1}\ndef filter_unique(items):\n res = []\n for item in items:\n if item not in seen:\n seen.add(item)\n res.append(item)\n return res\n\ndef get_unique_items(items):\n return filter_unique(items)", "original_code": "def filter_unique(items, seen):\n res = []\n for item in items:\n if item not in seen:\n seen.add(item)\n res.append(item)\n return res\n\ndef get_unique_items(items):\n return filter_unique(items, set())", "initial_error": "AssertionError: test fails on second call", "bug_location": {"function": "filter_unique", "line_start": 4}, "test_cases": [{"input": [[1, 2, 2, 3]], "expected_output": [1, 2, 3]}, {"input": [[1, 2, 2, 3]], "expected_output": [1, 2, 3]}, {"input": [[4, 4, 5]], "expected_output": [4, 5]}, {"input": [[4, 4, 5]], "expected_output": [4, 5]}]}
|
| 10 |
+
{"id": "t3_010", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "accumulate_values", "buggy_code": "total = 10\ndef add_to_total(val):\n global total\n total += val\n return total\n\ndef accumulate_values(vals):\n return [add_to_total(v) for v in vals]", "original_code": "def accumulate_values(vals):\n total = 0\n res = []\n for v in vals:\n total += v\n res.append(total)\n return res", "initial_error": "AssertionError: expected [1, 3], got [1, 3] then [4, 6] on next call", "bug_location": {"function": "add_to_total", "line_start": 4}, "test_cases": [{"input": [[1, 2]], "expected_output": [1, 3]}, {"input": [[1, 2]], "expected_output": [1, 3]}, {"input": [[5, 5]], "expected_output": [5, 10]}, {"input": [[5, 5]], "expected_output": [5, 10]}]}
|
| 11 |
+
{"id": "t3_011", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "append_to_default", "buggy_code": "def helper(val, lst=[1]):\n lst.append(val)\n return lst\n\ndef append_to_default(val):\n return helper(val)", "original_code": "def helper(val, lst=None):\n if lst is None:\n lst = []\n lst.append(val)\n return lst\n\ndef append_to_default(val):\n return helper(val)", "initial_error": "AssertionError: expected [2], got [1, 2]", "bug_location": {"function": "helper", "line_start": 1}, "test_cases": [{"input": 1, "expected_output": [1]}, {"input": 2, "expected_output": [2]}, {"input": 3, "expected_output": [3]}, {"input": 4, "expected_output": [4]}]}
|
| 12 |
+
{"id": "t3_012", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "count_calls", "buggy_code": "calls = 5\ndef tracker():\n global calls\n calls += 1\n return calls\n\ndef count_calls(n):\n res = []\n for _ in range(n):\n res.append(tracker())\n return res", "original_code": "def count_calls(n):\n calls = 0\n res = []\n for _ in range(n):\n calls += 1\n res.append(calls)\n return res", "initial_error": "AssertionError: expected [1, 2], got [3, 4] on second run", "bug_location": {"function": "tracker", "line_start": 4}, "test_cases": [{"input": 2, "expected_output": [1, 2]}, {"input": 2, "expected_output": [1, 2]}, {"input": 3, "expected_output": [1, 2, 3]}, {"input": 3, "expected_output": [1, 2, 3]}]}
|
| 13 |
+
{"id": "t3_013", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "build_sentence", "buggy_code": "words_cache = ['ERROR']\ndef add_word(w):\n words_cache.append(w)\n return ' '.join(words_cache)\n\ndef build_sentence(words):\n res = ''\n for w in words:\n res = add_word(w)\n return res", "original_code": "def build_sentence(words):\n words_cache = []\n def add_word(w):\n words_cache.append(w)\n return ' '.join(words_cache)\n res = ''\n for w in words:\n res = add_word(w)\n return res", "initial_error": "AssertionError: expected 'hello world', got '... hello world'", "bug_location": {"function": "add_word", "line_start": 3}, "test_cases": [{"input": [["hello", "world"]], "expected_output": "hello world"}, {"input": [["foo", "bar"]], "expected_output": "foo bar"}, {"input": [["a", "b", "c"]], "expected_output": "a b c"}, {"input": [["x"]], "expected_output": "x"}]}
|
| 14 |
+
{"id": "t3_014", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "collect_errors", "buggy_code": "errors = ['fatal']\ndef log_error(err):\n errors.append(err)\n return errors\n\ndef collect_errors(err_list):\n for e in err_list:\n res = log_error(e)\n return res if err_list else []", "original_code": "def collect_errors(err_list):\n errors = []\n def log_error(err):\n errors.append(err)\n return errors\n res = []\n for e in err_list:\n res = log_error(e)\n return res", "initial_error": "AssertionError: state leak between calls", "bug_location": {"function": "log_error", "line_start": 3}, "test_cases": [{"input": [["e1"]], "expected_output": ["e1"]}, {"input": [["e2"]], "expected_output": ["e2"]}, {"input": [["e3", "e4"]], "expected_output": ["e3", "e4"]}, {"input": [["e5"]], "expected_output": ["e5"]}]}
|
| 15 |
+
{"id": "t3_015", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "process_data", "buggy_code": "def get_first(lst):\n return lst[0]\n\ndef process_data(data):\n if not data:\n return None\n return [get_first(d) for d in data]", "original_code": "def get_first(lst):\n if not lst:\n return None\n return lst[0]\n\ndef process_data(data):\n if not data:\n return []\n return [get_first(d) for d in data]", "initial_error": "IndexError: list index out of range", "bug_location": {"function": "get_first", "line_start": 2}, "test_cases": [{"input": [[[1, 2], [3, 4]]], "expected_output": [1, 3]}, {"input": [[[1], []]], "expected_output": [1, null]}, {"input": [[[], [2]]], "expected_output": [null, 2]}, {"input": [[]], "expected_output": []}]}
|
| 16 |
+
{"id": "t3_016", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "average_scores", "buggy_code": "def calc_avg(scores):\n return sum(scores) / len(scores)\n\ndef average_scores(students):\n return {k: calc_avg(v) for k, v in students.items()}", "original_code": "def calc_avg(scores):\n if not scores:\n return 0\n return sum(scores) / len(scores)\n\ndef average_scores(students):\n return {k: calc_avg(v) for k, v in students.items()}", "initial_error": "ZeroDivisionError: division by zero", "bug_location": {"function": "calc_avg", "line_start": 2}, "test_cases": [{"input": [{"Alice": [10, 20], "Bob": []}], "expected_output": {"Alice": 15.0, "Bob": 0}}, {"input": [{"A": [5]}], "expected_output": {"A": 5.0}}, {"input": [{}], "expected_output": {}}, {"input": [{"B": []}], "expected_output": {"B": 0}}]}
|
| 17 |
+
{"id": "t3_017", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "find_max_nested", "buggy_code": "def find_max(lst):\n return max(lst)\n\ndef find_max_nested(nested_lists):\n return [find_max(l) for l in nested_lists]", "original_code": "def find_max(lst):\n if not lst:\n return None\n return max(lst)\n\ndef find_max_nested(nested_lists):\n return [find_max(l) for l in nested_lists]", "initial_error": "ValueError: max() arg is an empty sequence", "bug_location": {"function": "find_max", "line_start": 2}, "test_cases": [{"input": [[[1, 2], []]], "expected_output": [2, null]}, {"input": [[[1], [2, 3]]], "expected_output": [1, 3]}, {"input": [[[], []]], "expected_output": [null, null]}, {"input": [[]], "expected_output": []}]}
|
| 18 |
+
{"id": "t3_018", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "get_extensions", "buggy_code": "def extract_ext(filename):\n return filename.split('.')[1]\n\ndef get_extensions(files):\n return [extract_ext(f) for f in files]", "original_code": "def extract_ext(filename):\n parts = filename.split('.')\n if len(parts) < 2:\n return ''\n return parts[-1]\n\ndef get_extensions(files):\n return [extract_ext(f) for f in files]", "initial_error": "IndexError: list index out of range", "bug_location": {"function": "extract_ext", "line_start": 2}, "test_cases": [{"input": [["a.txt", "b"]], "expected_output": ["txt", ""]}, {"input": [["a.txt", "b.pdf"]], "expected_output": ["txt", "pdf"]}, {"input": [["noext"]], "expected_output": [""]}, {"input": [[]], "expected_output": []}]}
|
| 19 |
+
{"id": "t3_019", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "get_lengths", "buggy_code": "def get_len(item):\n return len(item)\n\ndef get_lengths(items):\n return [get_len(i) for i in items]", "original_code": "def get_len(item):\n if item is None:\n return 0\n return len(item)\n\ndef get_lengths(items):\n return [get_len(i) for i in items]", "initial_error": "TypeError: object of type 'NoneType' has no len()", "bug_location": {"function": "get_len", "line_start": 2}, "test_cases": [{"input": [["abc", null]], "expected_output": [3, 0]}, {"input": [["a", "b"]], "expected_output": [1, 1]}, {"input": [[null, null]], "expected_output": [0, 0]}, {"input": [[]], "expected_output": []}]}
|
| 20 |
+
{"id": "t3_020", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "parse_integers", "buggy_code": "def to_int(s):\n return int(s)\n\ndef parse_integers(strings):\n return [to_int(s) for s in strings]", "original_code": "def to_int(s):\n try:\n return int(s)\n except ValueError:\n return 0\n\ndef parse_integers(strings):\n return [to_int(s) for s in strings]", "initial_error": "ValueError: invalid literal for int() with base 10", "bug_location": {"function": "to_int", "line_start": 2}, "test_cases": [{"input": [["1", "abc"]], "expected_output": [1, 0]}, {"input": [["1", "2"]], "expected_output": [1, 2]}, {"input": [["foo", "bar"]], "expected_output": [0, 0]}, {"input": [[]], "expected_output": []}]}
|
data/generate_bugs.py
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
scratch/data_tier1.py
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
t1_bugs = [
|
| 2 |
+
{
|
| 3 |
+
"id": "t1_009",
|
| 4 |
+
"difficulty": 1,
|
| 5 |
+
"bug_type": "off_by_one",
|
| 6 |
+
"function_name": "factorial",
|
| 7 |
+
"buggy_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n)",
|
| 8 |
+
"original_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)",
|
| 9 |
+
"initial_error": "RecursionError: maximum recursion depth exceeded",
|
| 10 |
+
"bug_location": {"function": "factorial", "line_start": 4},
|
| 11 |
+
"test_cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"id": "t1_010",
|
| 15 |
+
"difficulty": 1,
|
| 16 |
+
"bug_type": "wrong_operator",
|
| 17 |
+
"function_name": "factorial",
|
| 18 |
+
"buggy_code": "def factorial(n):\n if n == 0:\n return 1\n return n + factorial(n - 1)",
|
| 19 |
+
"original_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)",
|
| 20 |
+
"initial_error": "AssertionError: factorial(3) expected 6, got 6 - wait got 7",
|
| 21 |
+
"bug_location": {"function": "factorial", "line_start": 4},
|
| 22 |
+
"test_cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"id": "t1_011",
|
| 26 |
+
"difficulty": 1,
|
| 27 |
+
"bug_type": "off_by_one",
|
| 28 |
+
"function_name": "fibonacci",
|
| 29 |
+
"buggy_code": "def fibonacci(n):\n if n < 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)",
|
| 30 |
+
"original_code": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)",
|
| 31 |
+
"initial_error": "RecursionError: maximum recursion depth exceeded",
|
| 32 |
+
"bug_location": {"function": "fibonacci", "line_start": 2},
|
| 33 |
+
"test_cases": [{"input": 0, "expected_output": 0}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 5}, {"input": 7, "expected_output": 13}]
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"id": "t1_012",
|
| 37 |
+
"difficulty": 1,
|
| 38 |
+
"bug_type": "wrong_operator",
|
| 39 |
+
"function_name": "fibonacci",
|
| 40 |
+
"buggy_code": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) * fibonacci(n-2)",
|
| 41 |
+
"original_code": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)",
|
| 42 |
+
"initial_error": "AssertionError: fibonacci(5) expected 5, got 0",
|
| 43 |
+
"bug_location": {"function": "fibonacci", "line_start": 4},
|
| 44 |
+
"test_cases": [{"input": 0, "expected_output": 0}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 5}, {"input": 7, "expected_output": 13}]
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"id": "t1_013",
|
| 48 |
+
"difficulty": 1,
|
| 49 |
+
"bug_type": "off_by_one",
|
| 50 |
+
"function_name": "string_reverse",
|
| 51 |
+
"buggy_code": "def string_reverse(s):\n return s[:-1]",
|
| 52 |
+
"original_code": "def string_reverse(s):\n return s[::-1]",
|
| 53 |
+
"initial_error": "AssertionError: string_reverse('hello') expected 'olleh', got 'hell'",
|
| 54 |
+
"bug_location": {"function": "string_reverse", "line_start": 2},
|
| 55 |
+
"test_cases": [{"input": "hello", "expected_output": "olleh"}, {"input": "", "expected_output": ""}, {"input": "a", "expected_output": "a"}, {"input": "racecar", "expected_output": "racecar"}]
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"id": "t1_014",
|
| 59 |
+
"difficulty": 1,
|
| 60 |
+
"bug_type": "wrong_operator",
|
| 61 |
+
"function_name": "string_reverse",
|
| 62 |
+
"buggy_code": "def string_reverse(s):\n return s[1:]",
|
| 63 |
+
"original_code": "def string_reverse(s):\n return s[::-1]",
|
| 64 |
+
"initial_error": "AssertionError: string_reverse('hello') expected 'olleh', got 'ello'",
|
| 65 |
+
"bug_location": {"function": "string_reverse", "line_start": 2},
|
| 66 |
+
"test_cases": [{"input": "hello", "expected_output": "olleh"}, {"input": "", "expected_output": ""}, {"input": "a", "expected_output": "a"}, {"input": "racecar", "expected_output": "racecar"}]
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"id": "t1_015",
|
| 70 |
+
"difficulty": 1,
|
| 71 |
+
"bug_type": "wrong_comparison",
|
| 72 |
+
"function_name": "count_occurrences",
|
| 73 |
+
"buggy_code": "def count_occurrences(lst, target):\n count = 0\n for item in lst:\n if item != target:\n count += 1\n return count",
|
| 74 |
+
"original_code": "def count_occurrences(lst, target):\n count = 0\n for item in lst:\n if item == target:\n count += 1\n return count",
|
| 75 |
+
"initial_error": "AssertionError: count_occurrences([1,2,1,3,1], 1) expected 3, got 2",
|
| 76 |
+
"bug_location": {"function": "count_occurrences", "line_start": 4},
|
| 77 |
+
"test_cases": [{"input": [[1,2,1,3,1], 1], "expected_output": 3}, {"input": [[], 5], "expected_output": 0}, {"input": [[2,2,2], 2], "expected_output": 3}, {"input": [[1,2,3], 4], "expected_output": 0}]
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"id": "t1_016",
|
| 81 |
+
"difficulty": 1,
|
| 82 |
+
"bug_type": "off_by_one",
|
| 83 |
+
"function_name": "count_occurrences",
|
| 84 |
+
"buggy_code": "def count_occurrences(lst, target):\n count = 1\n for item in lst:\n if item == target:\n count += 1\n return count",
|
| 85 |
+
"original_code": "def count_occurrences(lst, target):\n count = 0\n for item in lst:\n if item == target:\n count += 1\n return count",
|
| 86 |
+
"initial_error": "AssertionError: count_occurrences([], 5) expected 0, got 1",
|
| 87 |
+
"bug_location": {"function": "count_occurrences", "line_start": 2},
|
| 88 |
+
"test_cases": [{"input": [[1,2,1,3,1], 1], "expected_output": 3}, {"input": [[], 5], "expected_output": 0}, {"input": [[2,2,2], 2], "expected_output": 3}, {"input": [[1,2,3], 4], "expected_output": 0}]
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"id": "t1_017",
|
| 92 |
+
"difficulty": 1,
|
| 93 |
+
"bug_type": "wrong_operator",
|
| 94 |
+
"function_name": "sum_digits",
|
| 95 |
+
"buggy_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n // 10\n n //= 10\n return total",
|
| 96 |
+
"original_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n % 10\n n //= 10\n return total",
|
| 97 |
+
"initial_error": "AssertionError: sum_digits(123) expected 6, got 13",
|
| 98 |
+
"bug_location": {"function": "sum_digits", "line_start": 4},
|
| 99 |
+
"test_cases": [{"input": 123, "expected_output": 6}, {"input": 0, "expected_output": 0}, {"input": 999, "expected_output": 27}, {"input": 10, "expected_output": 1}]
|
| 100 |
+
},
|
| 101 |
+
{
|
| 102 |
+
"id": "t1_018",
|
| 103 |
+
"difficulty": 1,
|
| 104 |
+
"bug_type": "logic_inversion",
|
| 105 |
+
"function_name": "sum_digits",
|
| 106 |
+
"buggy_code": "def sum_digits(n):\n total = 0\n while n < 0:\n total += n % 10\n n //= 10\n return total",
|
| 107 |
+
"original_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n % 10\n n //= 10\n return total",
|
| 108 |
+
"initial_error": "AssertionError: sum_digits(123) expected 6, got 0",
|
| 109 |
+
"bug_location": {"function": "sum_digits", "line_start": 3},
|
| 110 |
+
"test_cases": [{"input": 123, "expected_output": 6}, {"input": 0, "expected_output": 0}, {"input": 999, "expected_output": 27}, {"input": 10, "expected_output": 1}]
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"id": "t1_019",
|
| 114 |
+
"difficulty": 1,
|
| 115 |
+
"bug_type": "off_by_one",
|
| 116 |
+
"function_name": "is_prime",
|
| 117 |
+
"buggy_code": "def is_prime(n):\n if n < 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True",
|
| 118 |
+
"original_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True",
|
| 119 |
+
"initial_error": "AssertionError: is_prime(1) expected False, got True",
|
| 120 |
+
"bug_location": {"function": "is_prime", "line_start": 2},
|
| 121 |
+
"test_cases": [{"input": 2, "expected_output": True}, {"input": 4, "expected_output": False}, {"input": 13, "expected_output": True}, {"input": 1, "expected_output": False}]
|
| 122 |
+
},
|
| 123 |
+
{
|
| 124 |
+
"id": "t1_020",
|
| 125 |
+
"difficulty": 1,
|
| 126 |
+
"bug_type": "wrong_operator",
|
| 127 |
+
"function_name": "is_prime",
|
| 128 |
+
"buggy_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i != 0:\n return False\n return True",
|
| 129 |
+
"original_code": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True",
|
| 130 |
+
"initial_error": "AssertionError: is_prime(13) expected True, got False",
|
| 131 |
+
"bug_location": {"function": "is_prime", "line_start": 5},
|
| 132 |
+
"test_cases": [{"input": 2, "expected_output": True}, {"input": 4, "expected_output": False}, {"input": 13, "expected_output": True}, {"input": 1, "expected_output": False}]
|
| 133 |
+
},
|
| 134 |
+
{
|
| 135 |
+
"id": "t1_021",
|
| 136 |
+
"difficulty": 1,
|
| 137 |
+
"bug_type": "wrong_comparison",
|
| 138 |
+
"function_name": "merge_intervals",
|
| 139 |
+
"buggy_code": "def merge_intervals(intervals):\n if not intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] < previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged",
|
| 140 |
+
"original_code": "def merge_intervals(intervals):\n if not intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] <= previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged",
|
| 141 |
+
"initial_error": "AssertionError: merge_intervals([[1,4],[4,5]]) expected [[1,5]], got [[1,4],[4,5]]",
|
| 142 |
+
"bug_location": {"function": "merge_intervals", "line_start": 8},
|
| 143 |
+
"test_cases": [{"input": [[[1,3],[2,6],[8,10],[15,18]]], "expected_output": [[1,6],[8,10],[15,18]]}, {"input": [[[1,4],[4,5]]], "expected_output": [[1,5]]}, {"input": [[]], "expected_output": []}, {"input": [[[1,4],[0,4]]], "expected_output": [[0,4]]}]
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"id": "t1_022",
|
| 147 |
+
"difficulty": 1,
|
| 148 |
+
"bug_type": "logic_inversion",
|
| 149 |
+
"function_name": "merge_intervals",
|
| 150 |
+
"buggy_code": "def merge_intervals(intervals):\n if intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] <= previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged",
|
| 151 |
+
"original_code": "def merge_intervals(intervals):\n if not intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] <= previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged",
|
| 152 |
+
"initial_error": "AssertionError: merge_intervals([[1,4],[4,5]]) expected [[1,5]], got []",
|
| 153 |
+
"bug_location": {"function": "merge_intervals", "line_start": 2},
|
| 154 |
+
"test_cases": [{"input": [[[1,3],[2,6],[8,10],[15,18]]], "expected_output": [[1,6],[8,10],[15,18]]}, {"input": [[[1,4],[4,5]]], "expected_output": [[1,5]]}, {"input": [[]], "expected_output": []}, {"input": [[[1,4],[0,4]]], "expected_output": [[0,4]]}]
|
| 155 |
+
},
|
| 156 |
+
{
|
| 157 |
+
"id": "t1_023",
|
| 158 |
+
"difficulty": 1,
|
| 159 |
+
"bug_type": "wrong_operator",
|
| 160 |
+
"function_name": "remove_duplicates",
|
| 161 |
+
"buggy_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] == nums[i]:\n i += 1\n nums[i] = nums[j]\n return i + 1",
|
| 162 |
+
"original_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] != nums[i]:\n i += 1\n nums[i] = nums[j]\n return i + 1",
|
| 163 |
+
"initial_error": "AssertionError: remove_duplicates([1,1,2]) expected 2, got 2 with array [1,1,2]",
|
| 164 |
+
"bug_location": {"function": "remove_duplicates", "line_start": 6},
|
| 165 |
+
"test_cases": [{"input": [[1,1,2]], "expected_output": 2}, {"input": [[0,0,1,1,1,2,2,3,3,4]], "expected_output": 5}, {"input": [[]], "expected_output": 0}, {"input": [[1]], "expected_output": 1}]
|
| 166 |
+
},
|
| 167 |
+
{
|
| 168 |
+
"id": "t1_024",
|
| 169 |
+
"difficulty": 1,
|
| 170 |
+
"bug_type": "off_by_one",
|
| 171 |
+
"function_name": "remove_duplicates",
|
| 172 |
+
"buggy_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] != nums[i]:\n i += 1\n nums[i] = nums[j]\n return i",
|
| 173 |
+
"original_code": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] != nums[i]:\n i += 1\n nums[i] = nums[j]\n return i + 1",
|
| 174 |
+
"initial_error": "AssertionError: remove_duplicates([1,1,2]) expected 2, got 1",
|
| 175 |
+
"bug_location": {"function": "remove_duplicates", "line_start": 9},
|
| 176 |
+
"test_cases": [{"input": [[1,1,2]], "expected_output": 2}, {"input": [[0,0,1,1,1,2,2,3,3,4]], "expected_output": 5}, {"input": [[]], "expected_output": 0}, {"input": [[1]], "expected_output": 1}]
|
| 177 |
+
},
|
| 178 |
+
{
|
| 179 |
+
"id": "t1_025",
|
| 180 |
+
"difficulty": 1,
|
| 181 |
+
"bug_type": "wrong_comparison",
|
| 182 |
+
"function_name": "longest_common_prefix",
|
| 183 |
+
"buggy_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs[1:]:\n while s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix",
|
| 184 |
+
"original_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs[1:]:\n while not s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix",
|
| 185 |
+
"initial_error": "AssertionError: longest_common_prefix(['flower','flow','flight']) expected 'fl', got ''",
|
| 186 |
+
"bug_location": {"function": "longest_common_prefix", "line_start": 6},
|
| 187 |
+
"test_cases": [{"input": [["flower","flow","flight"]], "expected_output": "fl"}, {"input": [["dog","racecar","car"]], "expected_output": ""}, {"input": [[]], "expected_output": ""}, {"input": [["a"]], "expected_output": "a"}]
|
| 188 |
+
},
|
| 189 |
+
{
|
| 190 |
+
"id": "t1_026",
|
| 191 |
+
"difficulty": 1,
|
| 192 |
+
"bug_type": "off_by_one",
|
| 193 |
+
"function_name": "longest_common_prefix",
|
| 194 |
+
"buggy_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs:\n while not s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix",
|
| 195 |
+
"original_code": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs[1:]:\n while not s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix",
|
| 196 |
+
"initial_error": "AssertionError: doesn't strictly fail but runs longer",
|
| 197 |
+
"bug_location": {"function": "longest_common_prefix", "line_start": 5},
|
| 198 |
+
"test_cases": [{"input": [["flower","flow","flight"]], "expected_output": "fl"}, {"input": [["dog","racecar","car"]], "expected_output": ""}, {"input": [[]], "expected_output": ""}, {"input": [["a"]], "expected_output": "a"}]
|
| 199 |
+
},
|
| 200 |
+
{
|
| 201 |
+
"id": "t1_027",
|
| 202 |
+
"difficulty": 1,
|
| 203 |
+
"bug_type": "wrong_operator",
|
| 204 |
+
"function_name": "product_except_self",
|
| 205 |
+
"buggy_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix += nums[i]\n postfix = 1\n for i in range(n - 1, -1, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res",
|
| 206 |
+
"original_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix *= nums[i]\n postfix = 1\n for i in range(n - 1, -1, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res",
|
| 207 |
+
"initial_error": "AssertionError: product_except_self([1,2,3,4]) expected [24,12,8,6], got [24, 24, 16, 6]",
|
| 208 |
+
"bug_location": {"function": "product_except_self", "line_start": 7},
|
| 209 |
+
"test_cases": [{"input": [[1,2,3,4]], "expected_output": [24,12,8,6]}, {"input": [[-1,1,0,-3,3]], "expected_output": [0,0,9,0,0]}, {"input": [[2,3]], "expected_output": [3,2]}, {"input": [[1,1,1]], "expected_output": [1,1,1]}]
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
"id": "t1_028",
|
| 213 |
+
"difficulty": 1,
|
| 214 |
+
"bug_type": "off_by_one",
|
| 215 |
+
"function_name": "product_except_self",
|
| 216 |
+
"buggy_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix *= nums[i]\n postfix = 1\n for i in range(n - 1, 0, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res",
|
| 217 |
+
"original_code": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix *= nums[i]\n postfix = 1\n for i in range(n - 1, -1, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res",
|
| 218 |
+
"initial_error": "AssertionError: product_except_self([1,2,3,4]) expected [24,12,8,6], got [1,12,8,6]",
|
| 219 |
+
"bug_location": {"function": "product_except_self", "line_start": 9},
|
| 220 |
+
"test_cases": [{"input": [[1,2,3,4]], "expected_output": [24,12,8,6]}, {"input": [[-1,1,0,-3,3]], "expected_output": [0,0,9,0,0]}, {"input": [[2,3]], "expected_output": [3,2]}, {"input": [[1,1,1]], "expected_output": [1,1,1]}]
|
| 221 |
+
},
|
| 222 |
+
{
|
| 223 |
+
"id": "t1_029",
|
| 224 |
+
"difficulty": 1,
|
| 225 |
+
"bug_type": "wrong_operator",
|
| 226 |
+
"function_name": "valid_parentheses",
|
| 227 |
+
"buggy_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] == top_element:\n return False\n else:\n stack.append(char)\n return not stack",
|
| 228 |
+
"original_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] != top_element:\n return False\n else:\n stack.append(char)\n return not stack",
|
| 229 |
+
"initial_error": "AssertionError: valid_parentheses('()') expected True, got False",
|
| 230 |
+
"bug_location": {"function": "valid_parentheses", "line_start": 7},
|
| 231 |
+
"test_cases": [{"input": "()", "expected_output": True}, {"input": "()[]{}", "expected_output": True}, {"input": "(]", "expected_output": False}, {"input": "([)]", "expected_output": False}]
|
| 232 |
+
},
|
| 233 |
+
{
|
| 234 |
+
"id": "t1_030",
|
| 235 |
+
"difficulty": 1,
|
| 236 |
+
"bug_type": "logic_inversion",
|
| 237 |
+
"function_name": "valid_parentheses",
|
| 238 |
+
"buggy_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] != top_element:\n return False\n else:\n stack.append(char)\n return bool(stack)",
|
| 239 |
+
"original_code": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] != top_element:\n return False\n else:\n stack.append(char)\n return not stack",
|
| 240 |
+
"initial_error": "AssertionError: valid_parentheses('()') expected True, got False",
|
| 241 |
+
"bug_location": {"function": "valid_parentheses", "line_start": 11},
|
| 242 |
+
"test_cases": [{"input": "()", "expected_output": True}, {"input": "()[]{}", "expected_output": True}, {"input": "(]", "expected_output": False}, {"input": "([)]", "expected_output": False}]
|
| 243 |
+
},
|
| 244 |
+
{
|
| 245 |
+
"id": "t1_031",
|
| 246 |
+
"difficulty": 1,
|
| 247 |
+
"bug_type": "off_by_one",
|
| 248 |
+
"function_name": "climbing_stairs",
|
| 249 |
+
"buggy_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n):\n a, b = b, a + b\n return b",
|
| 250 |
+
"original_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a + b\n return b",
|
| 251 |
+
"initial_error": "AssertionError: climbing_stairs(3) expected 3, got 2",
|
| 252 |
+
"bug_location": {"function": "climbing_stairs", "line_start": 5},
|
| 253 |
+
"test_cases": [{"input": 2, "expected_output": 2}, {"input": 3, "expected_output": 3}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 8}]
|
| 254 |
+
},
|
| 255 |
+
{
|
| 256 |
+
"id": "t1_032",
|
| 257 |
+
"difficulty": 1,
|
| 258 |
+
"bug_type": "wrong_operator",
|
| 259 |
+
"function_name": "climbing_stairs",
|
| 260 |
+
"buggy_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a * b\n return b",
|
| 261 |
+
"original_code": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a + b\n return b",
|
| 262 |
+
"initial_error": "AssertionError: climbing_stairs(3) expected 3, got 2",
|
| 263 |
+
"bug_location": {"function": "climbing_stairs", "line_start": 6},
|
| 264 |
+
"test_cases": [{"input": 2, "expected_output": 2}, {"input": 3, "expected_output": 3}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 8}]
|
| 265 |
+
},
|
| 266 |
+
{
|
| 267 |
+
"id": "t1_033",
|
| 268 |
+
"difficulty": 1,
|
| 269 |
+
"bug_type": "wrong_operator",
|
| 270 |
+
"function_name": "house_robber",
|
| 271 |
+
"buggy_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = min(nums[0], nums[1])\n for i in range(2, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]",
|
| 272 |
+
"original_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = max(nums[0], nums[1])\n for i in range(2, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]",
|
| 273 |
+
"initial_error": "AssertionError: house_robber([2,7,9,3,1]) expected 12, got 11",
|
| 274 |
+
"bug_location": {"function": "house_robber", "line_start": 8},
|
| 275 |
+
"test_cases": [{"input": [[1,2,3,1]], "expected_output": 4}, {"input": [[2,7,9,3,1]], "expected_output": 12}, {"input": [[]], "expected_output": 0}, {"input": [[5]], "expected_output": 5}]
|
| 276 |
+
},
|
| 277 |
+
{
|
| 278 |
+
"id": "t1_034",
|
| 279 |
+
"difficulty": 1,
|
| 280 |
+
"bug_type": "off_by_one",
|
| 281 |
+
"function_name": "house_robber",
|
| 282 |
+
"buggy_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = max(nums[0], nums[1])\n for i in range(1, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]",
|
| 283 |
+
"original_code": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = max(nums[0], nums[1])\n for i in range(2, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]",
|
| 284 |
+
"initial_error": "IndexError: list index out of range",
|
| 285 |
+
"bug_location": {"function": "house_robber", "line_start": 9},
|
| 286 |
+
"test_cases": [{"input": [[1,2,3,1]], "expected_output": 4}, {"input": [[2,7,9,3,1]], "expected_output": 12}, {"input": [[]], "expected_output": 0}, {"input": [[5]], "expected_output": 5}]
|
| 287 |
+
},
|
| 288 |
+
{
|
| 289 |
+
"id": "t1_035",
|
| 290 |
+
"difficulty": 1,
|
| 291 |
+
"bug_type": "wrong_operator",
|
| 292 |
+
"function_name": "intersection_of_arrays",
|
| 293 |
+
"buggy_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) | set(nums2))",
|
| 294 |
+
"original_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) & set(nums2))",
|
| 295 |
+
"initial_error": "AssertionError: intersection_of_arrays([1,2,2,1], [2,2]) expected [2], got [1,2]",
|
| 296 |
+
"bug_location": {"function": "intersection_of_arrays", "line_start": 2},
|
| 297 |
+
"test_cases": [{"input": [[1,2,2,1], [2,2]], "expected_output": [2]}, {"input": [[4,9,5], [9,4,9,8,4]], "expected_output": [9,4]}, {"input": [[], [1]], "expected_output": []}, {"input": [[1,2], [3,4]], "expected_output": []}]
|
| 298 |
+
},
|
| 299 |
+
{
|
| 300 |
+
"id": "t1_036",
|
| 301 |
+
"difficulty": 1,
|
| 302 |
+
"bug_type": "wrong_operator",
|
| 303 |
+
"function_name": "intersection_of_arrays",
|
| 304 |
+
"buggy_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) - set(nums2))",
|
| 305 |
+
"original_code": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) & set(nums2))",
|
| 306 |
+
"initial_error": "AssertionError: intersection_of_arrays([1,2,2,1], [2,2]) expected [2], got [1]",
|
| 307 |
+
"bug_location": {"function": "intersection_of_arrays", "line_start": 2},
|
| 308 |
+
"test_cases": [{"input": [[1,2,2,1], [2,2]], "expected_output": [2]}, {"input": [[4,9,5], [9,4,9,8,4]], "expected_output": [9,4]}, {"input": [[], [1]], "expected_output": []}, {"input": [[1,2], [3,4]], "expected_output": []}]
|
| 309 |
+
},
|
| 310 |
+
{
|
| 311 |
+
"id": "t1_037",
|
| 312 |
+
"difficulty": 1,
|
| 313 |
+
"bug_type": "wrong_comparison",
|
| 314 |
+
"function_name": "group_anagrams",
|
| 315 |
+
"buggy_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(s)].append(s)\n return list(ans.values())",
|
| 316 |
+
"original_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(sorted(s))].append(s)\n return list(ans.values())",
|
| 317 |
+
"initial_error": "AssertionError: expected [['eat','tea','ate'],['tan','nat'],['bat']]",
|
| 318 |
+
"bug_location": {"function": "group_anagrams", "line_start": 5},
|
| 319 |
+
"test_cases": [{"input": [["eat","tea","tan","ate","nat","bat"]], "expected_output": [["eat","tea","ate"],["tan","nat"],["bat"]]}, {"input": [[""]], "expected_output": [[""]]}, {"input": [["a"]], "expected_output": [["a"]]}, {"input": [["ab", "ba"]], "expected_output": [["ab", "ba"]]}]
|
| 320 |
+
},
|
| 321 |
+
{
|
| 322 |
+
"id": "t1_038",
|
| 323 |
+
"difficulty": 1,
|
| 324 |
+
"bug_type": "logic_inversion",
|
| 325 |
+
"function_name": "group_anagrams",
|
| 326 |
+
"buggy_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(sorted(s))].append(s[::-1])\n return list(ans.values())",
|
| 327 |
+
"original_code": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(sorted(s))].append(s)\n return list(ans.values())",
|
| 328 |
+
"initial_error": "AssertionError: expected [['eat','tea','ate'],['tan','nat'],['bat']]",
|
| 329 |
+
"bug_location": {"function": "group_anagrams", "line_start": 5},
|
| 330 |
+
"test_cases": [{"input": [["eat","tea","tan","ate","nat","bat"]], "expected_output": [["eat","tea","ate"],["tan","nat"],["bat"]]}, {"input": [[""]], "expected_output": [[""]]}, {"input": [["a"]], "expected_output": [["a"]]}, {"input": [["ab", "ba"]], "expected_output": [["ab", "ba"]]}]
|
| 331 |
+
},
|
| 332 |
+
{
|
| 333 |
+
"id": "t1_039",
|
| 334 |
+
"difficulty": 1,
|
| 335 |
+
"bug_type": "wrong_operator",
|
| 336 |
+
"function_name": "sum_digits",
|
| 337 |
+
"buggy_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total *= n % 10\n n //= 10\n return total",
|
| 338 |
+
"original_code": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n % 10\n n //= 10\n return total",
|
| 339 |
+
"initial_error": "AssertionError: sum_digits(123) expected 6, got 0",
|
| 340 |
+
"bug_location": {"function": "sum_digits", "line_start": 4},
|
| 341 |
+
"test_cases": [{"input": 123, "expected_output": 6}, {"input": 0, "expected_output": 0}, {"input": 999, "expected_output": 27}, {"input": 10, "expected_output": 1}]
|
| 342 |
+
},
|
| 343 |
+
{
|
| 344 |
+
"id": "t1_040",
|
| 345 |
+
"difficulty": 1,
|
| 346 |
+
"bug_type": "off_by_one",
|
| 347 |
+
"function_name": "factorial",
|
| 348 |
+
"buggy_code": "def factorial(n):\n if n <= 0:\n return 0\n return n * factorial(n - 1)",
|
| 349 |
+
"original_code": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)",
|
| 350 |
+
"initial_error": "AssertionError: factorial(3) expected 6, got 0",
|
| 351 |
+
"bug_location": {"function": "factorial", "line_start": 3},
|
| 352 |
+
"test_cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]
|
| 353 |
+
}
|
| 354 |
+
]
|
scratch/data_tier2.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
t2_bugs = [
|
| 2 |
+
# 7 bugs: wrong loop termination
|
| 3 |
+
{
|
| 4 |
+
"id": "t2_004", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "find_first_positive",
|
| 5 |
+
"buggy_code": "def find_first_positive(nums):\n i = 0\n while i < len(nums) - 1:\n if nums[i] > 0:\n return nums[i]\n i += 1\n return -1",
|
| 6 |
+
"original_code": "def find_first_positive(nums):\n i = 0\n while i < len(nums):\n if nums[i] > 0:\n return nums[i]\n i += 1\n return -1",
|
| 7 |
+
"initial_error": "AssertionError: expected 5, got -1", "bug_location": {"function": "find_first_positive", "line_start": 3},
|
| 8 |
+
"test_cases": [{"input": [[-1, -2, 5]], "expected_output": 5}, {"input": [[1, 2, 3]], "expected_output": 1}, {"input": [[-1]], "expected_output": -1}, {"input": [[-5, -3, -1, 10]], "expected_output": 10}]
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"id": "t2_005", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "binary_search_insert",
|
| 12 |
+
"buggy_code": "def binary_search_insert(arr, target):\n left, right = 0, len(arr) - 1\n while left < right:\n mid = (left + right) // 2\n if arr[mid] < target:\n left = mid + 1\n else:\n right = mid\n return left",
|
| 13 |
+
"original_code": "def binary_search_insert(arr, target):\n left, right = 0, len(arr)\n while left < right:\n mid = (left + right) // 2\n if arr[mid] < target:\n left = mid + 1\n else:\n right = mid\n return left",
|
| 14 |
+
"initial_error": "AssertionError: expected 3, got 2", "bug_location": {"function": "binary_search_insert", "line_start": 2},
|
| 15 |
+
"test_cases": [{"input": [[1, 3, 5], 6], "expected_output": 3}, {"input": [[1, 3, 5], 4], "expected_output": 2}, {"input": [[1, 3, 5], 0], "expected_output": 0}, {"input": [[], 1], "expected_output": 0}]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"id": "t2_006", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "countdown_to_zero",
|
| 19 |
+
"buggy_code": "def countdown_to_zero(n):\n res = []\n while n > 0:\n res.append(n)\n n -= 1\n return res",
|
| 20 |
+
"original_code": "def countdown_to_zero(n):\n res = []\n while n >= 0:\n res.append(n)\n n -= 1\n return res",
|
| 21 |
+
"initial_error": "AssertionError: expected [3, 2, 1, 0], got [3, 2, 1]", "bug_location": {"function": "countdown_to_zero", "line_start": 3},
|
| 22 |
+
"test_cases": [{"input": 3, "expected_output": [3, 2, 1, 0]}, {"input": 0, "expected_output": [0]}, {"input": 1, "expected_output": [1, 0]}, {"input": -1, "expected_output": []}]
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"id": "t2_007", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "collect_until_negative",
|
| 26 |
+
"buggy_code": "def collect_until_negative(nums):\n res = []\n i = 0\n while i <= len(nums) and nums[i] >= 0:\n res.append(nums[i])\n i += 1\n return res",
|
| 27 |
+
"original_code": "def collect_until_negative(nums):\n res = []\n i = 0\n while i < len(nums) and nums[i] >= 0:\n res.append(nums[i])\n i += 1\n return res",
|
| 28 |
+
"initial_error": "IndexError: list index out of range", "bug_location": {"function": "collect_until_negative", "line_start": 4},
|
| 29 |
+
"test_cases": [{"input": [[1, 2, -1, 3]], "expected_output": [1, 2]}, {"input": [[1, 2, 3]], "expected_output": [1, 2, 3]}, {"input": [[-1]], "expected_output": []}, {"input": [[]], "expected_output": []}]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"id": "t2_008", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "skip_spaces",
|
| 33 |
+
"buggy_code": "def skip_spaces(s):\n i = 0\n while s[i] == ' ':\n i += 1\n return s[i:]",
|
| 34 |
+
"original_code": "def skip_spaces(s):\n i = 0\n while i < len(s) and s[i] == ' ':\n i += 1\n return s[i:]",
|
| 35 |
+
"initial_error": "IndexError: string index out of range", "bug_location": {"function": "skip_spaces", "line_start": 3},
|
| 36 |
+
"test_cases": [{"input": " hello", "expected_output": "hello"}, {"input": " ", "expected_output": ""}, {"input": "world", "expected_output": "world"}, {"input": "", "expected_output": ""}]
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"id": "t2_009", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "find_last_even",
|
| 40 |
+
"buggy_code": "def find_last_even(nums):\n i = len(nums) - 1\n while i > 0:\n if nums[i] % 2 == 0:\n return nums[i]\n i -= 1\n return -1",
|
| 41 |
+
"original_code": "def find_last_even(nums):\n i = len(nums) - 1\n while i >= 0:\n if nums[i] % 2 == 0:\n return nums[i]\n i -= 1\n return -1",
|
| 42 |
+
"initial_error": "AssertionError: expected 2, got -1", "bug_location": {"function": "find_last_even", "line_start": 3},
|
| 43 |
+
"test_cases": [{"input": [[2, 3, 5]], "expected_output": 2}, {"input": [[1, 3, 4]], "expected_output": 4}, {"input": [[1, 3, 5]], "expected_output": -1}, {"input": [[6]], "expected_output": 6}]
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"id": "t2_010", "difficulty": 2, "bug_type": "wrong_loop_termination", "function_name": "get_chunks",
|
| 47 |
+
"buggy_code": "def get_chunks(lst, size):\n chunks = []\n i = 0\n while i < len(lst) - size:\n chunks.append(lst[i:i+size])\n i += size\n return chunks",
|
| 48 |
+
"original_code": "def get_chunks(lst, size):\n chunks = []\n i = 0\n while i < len(lst):\n chunks.append(lst[i:i+size])\n i += size\n return chunks",
|
| 49 |
+
"initial_error": "AssertionError: expected [[1,2],[3]], got [[1,2]]", "bug_location": {"function": "get_chunks", "line_start": 4},
|
| 50 |
+
"test_cases": [{"input": [[1, 2, 3], 2], "expected_output": [[1, 2], [3]]}, {"input": [[1, 2], 2], "expected_output": [[1, 2]]}, {"input": [[1, 2, 3, 4], 2], "expected_output": [[1, 2], [3, 4]]}, {"input": [[], 2], "expected_output": []}]
|
| 51 |
+
},
|
| 52 |
+
# 7 bugs: incorrect accumulation
|
| 53 |
+
{
|
| 54 |
+
"id": "t2_011", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "sum_even_numbers",
|
| 55 |
+
"buggy_code": "def sum_even_numbers(nums):\n total = 1\n for n in nums:\n if n % 2 == 0:\n total += n\n return total",
|
| 56 |
+
"original_code": "def sum_even_numbers(nums):\n total = 0\n for n in nums:\n if n % 2 == 0:\n total += n\n return total",
|
| 57 |
+
"initial_error": "AssertionError: expected 6, got 7", "bug_location": {"function": "sum_even_numbers", "line_start": 2},
|
| 58 |
+
"test_cases": [{"input": [[1, 2, 3, 4]], "expected_output": 6}, {"input": [[1, 3, 5]], "expected_output": 0}, {"input": [[2, 2]], "expected_output": 4}, {"input": [[]], "expected_output": 0}]
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"id": "t2_012", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "multiply_all",
|
| 62 |
+
"buggy_code": "def multiply_all(nums):\n total = 0\n for n in nums:\n total *= n\n return total",
|
| 63 |
+
"original_code": "def multiply_all(nums):\n total = 1\n for n in nums:\n total *= n\n return total",
|
| 64 |
+
"initial_error": "AssertionError: expected 24, got 0", "bug_location": {"function": "multiply_all", "line_start": 2},
|
| 65 |
+
"test_cases": [{"input": [[1, 2, 3, 4]], "expected_output": 24}, {"input": [[5]], "expected_output": 5}, {"input": [[1, -1]], "expected_output": -1}, {"input": [[0, 5]], "expected_output": 0}]
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"id": "t2_013", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "concatenate_strings",
|
| 69 |
+
"buggy_code": "def concatenate_strings(strs):\n res = strs[0]\n for s in strs:\n res += s\n return res",
|
| 70 |
+
"original_code": "def concatenate_strings(strs):\n res = ''\n for s in strs:\n res += s\n return res",
|
| 71 |
+
"initial_error": "AssertionError: expected 'abc', got 'aabc'", "bug_location": {"function": "concatenate_strings", "line_start": 2},
|
| 72 |
+
"test_cases": [{"input": [["a", "b", "c"]], "expected_output": "abc"}, {"input": [["hello", "world"]], "expected_output": "helloworld"}, {"input": [["a"]], "expected_output": "a"}, {"input": [["x", "y"]], "expected_output": "xy"}]
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"id": "t2_014", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "max_profit",
|
| 76 |
+
"buggy_code": "def max_profit(prices):\n min_price = 0\n max_prof = 0\n for price in prices:\n min_price = min(min_price, price)\n max_prof = max(max_prof, price - min_price)\n return max_prof",
|
| 77 |
+
"original_code": "def max_profit(prices):\n min_price = float('inf')\n max_prof = 0\n for price in prices:\n min_price = min(min_price, price)\n max_prof = max(max_prof, price - min_price)\n return max_prof",
|
| 78 |
+
"initial_error": "AssertionError: expected 5, got 6", "bug_location": {"function": "max_profit", "line_start": 2},
|
| 79 |
+
"test_cases": [{"input": [[7, 1, 5, 3, 6, 4]], "expected_output": 5}, {"input": [[7, 6, 4, 3, 1]], "expected_output": 0}, {"input": [[1, 2]], "expected_output": 1}, {"input": [[2, 4, 1]], "expected_output": 2}]
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"id": "t2_015", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "find_longest_word",
|
| 83 |
+
"buggy_code": "def find_longest_word(words):\n longest = words[0]\n for word in words:\n if len(word) > len(longest):\n longest = longest\n return longest",
|
| 84 |
+
"original_code": "def find_longest_word(words):\n longest = ''\n for word in words:\n if len(word) > len(longest):\n longest = word\n return longest",
|
| 85 |
+
"initial_error": "AssertionError: expected 'banana', got 'apple'", "bug_location": {"function": "find_longest_word", "line_start": 5},
|
| 86 |
+
"test_cases": [{"input": [["apple", "banana", "kiwi"]], "expected_output": "banana"}, {"input": [["a", "ab", "abc"]], "expected_output": "abc"}, {"input": [["dog"]], "expected_output": "dog"}, {"input": [["x", "yz"]], "expected_output": "yz"}]
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"id": "t2_016", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "running_sum",
|
| 90 |
+
"buggy_code": "def running_sum(nums):\n res = []\n current = nums[0]\n for n in nums:\n current += n\n res.append(current)\n return res",
|
| 91 |
+
"original_code": "def running_sum(nums):\n res = []\n current = 0\n for n in nums:\n current += n\n res.append(current)\n return res",
|
| 92 |
+
"initial_error": "AssertionError: expected [1, 3, 6], got [2, 4, 7]", "bug_location": {"function": "running_sum", "line_start": 3},
|
| 93 |
+
"test_cases": [{"input": [[1, 2, 3]], "expected_output": [1, 3, 6]}, {"input": [[1, 1, 1]], "expected_output": [1, 2, 3]}, {"input": [[5]], "expected_output": [5]}, {"input": [[0, 0, 0]], "expected_output": [0, 0, 0]}]
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"id": "t2_017", "difficulty": 2, "bug_type": "incorrect_accumulation", "function_name": "count_negatives",
|
| 97 |
+
"buggy_code": "def count_negatives(nums):\n count = -1\n for n in nums:\n if n < 0:\n count += 1\n return count",
|
| 98 |
+
"original_code": "def count_negatives(nums):\n count = 0\n for n in nums:\n if n < 0:\n count += 1\n return count",
|
| 99 |
+
"initial_error": "AssertionError: expected 2, got 1", "bug_location": {"function": "count_negatives", "line_start": 2},
|
| 100 |
+
"test_cases": [{"input": [[1, -1, 2, -2]], "expected_output": 2}, {"input": [[1, 2, 3]], "expected_output": 0}, {"input": [[-1, -2, -3]], "expected_output": 3}, {"input": [[]], "expected_output": 0}]
|
| 101 |
+
},
|
| 102 |
+
# 7 bugs: wrong conditional branch
|
| 103 |
+
{
|
| 104 |
+
"id": "t2_018", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "classify_number",
|
| 105 |
+
"buggy_code": "def classify_number(n):\n if n > 0:\n return 'positive'\n elif n < 0:\n return 'negative'\n elif n == 0:\n return 'negative'",
|
| 106 |
+
"original_code": "def classify_number(n):\n if n > 0:\n return 'positive'\n elif n < 0:\n return 'negative'\n else:\n return 'zero'",
|
| 107 |
+
"initial_error": "AssertionError: expected 'zero', got 'negative'", "bug_location": {"function": "classify_number", "line_start": 6},
|
| 108 |
+
"test_cases": [{"input": 5, "expected_output": "positive"}, {"input": -3, "expected_output": "negative"}, {"input": 0, "expected_output": "zero"}, {"input": 1, "expected_output": "positive"}]
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"id": "t2_019", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "get_discount",
|
| 112 |
+
"buggy_code": "def get_discount(price):\n if price > 100:\n return 20\n if price > 50:\n return 50\n return 0",
|
| 113 |
+
"original_code": "def get_discount(price):\n if price > 100:\n return 20\n elif price > 50:\n return 10\n return 0",
|
| 114 |
+
"initial_error": "AssertionError: expected 10, got 50", "bug_location": {"function": "get_discount", "line_start": 5},
|
| 115 |
+
"test_cases": [{"input": 150, "expected_output": 20}, {"input": 75, "expected_output": 10}, {"input": 50, "expected_output": 0}, {"input": 20, "expected_output": 0}]
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"id": "t2_020", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "fizz_buzz",
|
| 119 |
+
"buggy_code": "def fizz_buzz(n):\n if n % 3 == 0:\n return 'Fizz'\n if n % 5 == 0:\n return 'Buzz'\n if n % 15 == 0:\n return 'FizzBuzz'\n return str(n)",
|
| 120 |
+
"original_code": "def fizz_buzz(n):\n if n % 15 == 0:\n return 'FizzBuzz'\n if n % 3 == 0:\n return 'Fizz'\n if n % 5 == 0:\n return 'Buzz'\n return str(n)",
|
| 121 |
+
"initial_error": "AssertionError: expected 'FizzBuzz', got 'Fizz'", "bug_location": {"function": "fizz_buzz", "line_start": 2},
|
| 122 |
+
"test_cases": [{"input": 3, "expected_output": "Fizz"}, {"input": 5, "expected_output": "Buzz"}, {"input": 15, "expected_output": "FizzBuzz"}, {"input": 2, "expected_output": "2"}]
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"id": "t2_021", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "is_leap_year",
|
| 126 |
+
"buggy_code": "def is_leap_year(year):\n if year % 4 == 0:\n if year % 100 == 0:\n if year % 400 == 0:\n return False\n return True\n return True\n return False",
|
| 127 |
+
"original_code": "def is_leap_year(year):\n if year % 4 == 0:\n if year % 100 == 0:\n if year % 400 == 0:\n return True\n return False\n return True\n return False",
|
| 128 |
+
"initial_error": "AssertionError: expected False, got True", "bug_location": {"function": "is_leap_year", "line_start": 5},
|
| 129 |
+
"test_cases": [{"input": 2000, "expected_output": True}, {"input": 1900, "expected_output": False}, {"input": 2004, "expected_output": True}, {"input": 2001, "expected_output": False}]
|
| 130 |
+
},
|
| 131 |
+
{
|
| 132 |
+
"id": "t2_022", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "grade_score",
|
| 133 |
+
"buggy_code": "def grade_score(score):\n if score >= 90:\n return 'A'\n elif score >= 80:\n return 'B'\n elif score > 70:\n return 'C'\n else:\n return 'F'",
|
| 134 |
+
"original_code": "def grade_score(score):\n if score >= 90:\n return 'A'\n elif score >= 80:\n return 'B'\n elif score >= 70:\n return 'C'\n else:\n return 'F'",
|
| 135 |
+
"initial_error": "AssertionError: expected 'C', got 'F'", "bug_location": {"function": "grade_score", "line_start": 6},
|
| 136 |
+
"test_cases": [{"input": 95, "expected_output": "A"}, {"input": 80, "expected_output": "B"}, {"input": 70, "expected_output": "C"}, {"input": 60, "expected_output": "F"}]
|
| 137 |
+
},
|
| 138 |
+
{
|
| 139 |
+
"id": "t2_023", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "can_drink_alcohol",
|
| 140 |
+
"buggy_code": "def can_drink_alcohol(age, country):\n if country == 'US':\n if age > 21:\n return True\n return False\n return age >= 18",
|
| 141 |
+
"original_code": "def can_drink_alcohol(age, country):\n if country == 'US':\n if age >= 21:\n return True\n return False\n return age >= 18",
|
| 142 |
+
"initial_error": "AssertionError: expected True, got False", "bug_location": {"function": "can_drink_alcohol", "line_start": 3},
|
| 143 |
+
"test_cases": [{"input": [21, "US"], "expected_output": True}, {"input": [20, "US"], "expected_output": False}, {"input": [18, "UK"], "expected_output": True}, {"input": [17, "UK"], "expected_output": False}]
|
| 144 |
+
},
|
| 145 |
+
{
|
| 146 |
+
"id": "t2_024", "difficulty": 2, "bug_type": "wrong_conditional_branch", "function_name": "get_quadrant",
|
| 147 |
+
"buggy_code": "def get_quadrant(x, y):\n if x > 0 and y > 0:\n return 1\n elif x < 0 and y > 0:\n return 2\n elif x > 0 and y < 0:\n return 3\n elif x < 0 and y < 0:\n return 4\n return 0",
|
| 148 |
+
"original_code": "def get_quadrant(x, y):\n if x > 0 and y > 0:\n return 1\n elif x < 0 and y > 0:\n return 2\n elif x < 0 and y < 0:\n return 3\n elif x > 0 and y < 0:\n return 4\n return 0",
|
| 149 |
+
"initial_error": "AssertionError: expected 4, got 3", "bug_location": {"function": "get_quadrant", "line_start": 6},
|
| 150 |
+
"test_cases": [{"input": [1, 1], "expected_output": 1}, {"input": [-1, 1], "expected_output": 2}, {"input": [-1, -1], "expected_output": 3}, {"input": [1, -1], "expected_output": 4}]
|
| 151 |
+
},
|
| 152 |
+
# 6 bugs: wrong variable used in final step
|
| 153 |
+
{
|
| 154 |
+
"id": "t2_025", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "merge_arrays",
|
| 155 |
+
"buggy_code": "def merge_arrays(a, b):\n res = a + b\n res.sort()\n return a",
|
| 156 |
+
"original_code": "def merge_arrays(a, b):\n res = a + b\n res.sort()\n return res",
|
| 157 |
+
"initial_error": "AssertionError: expected [1, 2, 3, 4], got [1, 3]", "bug_location": {"function": "merge_arrays", "line_start": 4},
|
| 158 |
+
"test_cases": [{"input": [[1, 3], [2, 4]], "expected_output": [1, 2, 3, 4]}, {"input": [[], [1]], "expected_output": [1]}, {"input": [[2], [1]], "expected_output": [1, 2]}, {"input": [[], []], "expected_output": []}]
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"id": "t2_026", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "find_min_max",
|
| 162 |
+
"buggy_code": "def find_min_max(nums):\n if not nums:\n return None\n mn = min(nums)\n mx = max(nums)\n return (mn, mn)",
|
| 163 |
+
"original_code": "def find_min_max(nums):\n if not nums:\n return None\n mn = min(nums)\n mx = max(nums)\n return (mn, mx)",
|
| 164 |
+
"initial_error": "AssertionError: expected (1, 5), got (1, 1)", "bug_location": {"function": "find_min_max", "line_start": 6},
|
| 165 |
+
"test_cases": [{"input": [[1, 2, 5]], "expected_output": (1, 5)}, {"input": [[3, 3]], "expected_output": (3, 3)}, {"input": [[-1, 0, 1]], "expected_output": (-1, 1)}, {"input": [[]], "expected_output": None}]
|
| 166 |
+
},
|
| 167 |
+
{
|
| 168 |
+
"id": "t2_027", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "remove_evens",
|
| 169 |
+
"buggy_code": "def remove_evens(nums):\n res = []\n for n in nums:\n if n % 2 != 0:\n res.append(n)\n return nums",
|
| 170 |
+
"original_code": "def remove_evens(nums):\n res = []\n for n in nums:\n if n % 2 != 0:\n res.append(n)\n return res",
|
| 171 |
+
"initial_error": "AssertionError: expected [1, 3], got [1, 2, 3]", "bug_location": {"function": "remove_evens", "line_start": 6},
|
| 172 |
+
"test_cases": [{"input": [[1, 2, 3]], "expected_output": [1, 3]}, {"input": [[2, 4]], "expected_output": []}, {"input": [[1, 3]], "expected_output": [1, 3]}, {"input": [[]], "expected_output": []}]
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"id": "t2_028", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "duplicate_list",
|
| 176 |
+
"buggy_code": "def duplicate_list(lst):\n res = lst[:]\n res.extend(lst)\n return lst",
|
| 177 |
+
"original_code": "def duplicate_list(lst):\n res = lst[:]\n res.extend(lst)\n return res",
|
| 178 |
+
"initial_error": "AssertionError: expected [1, 1], got [1]", "bug_location": {"function": "duplicate_list", "line_start": 4},
|
| 179 |
+
"test_cases": [{"input": [[1]], "expected_output": [1, 1]}, {"input": [[1, 2]], "expected_output": [1, 2, 1, 2]}, {"input": [[]], "expected_output": []}, {"input": [[0]], "expected_output": [0, 0]}]
|
| 180 |
+
},
|
| 181 |
+
{
|
| 182 |
+
"id": "t2_029", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "swap_halves",
|
| 183 |
+
"buggy_code": "def swap_halves(lst):\n mid = len(lst) // 2\n left = lst[:mid]\n right = lst[mid:]\n return left + left",
|
| 184 |
+
"original_code": "def swap_halves(lst):\n mid = len(lst) // 2\n left = lst[:mid]\n right = lst[mid:]\n return right + left",
|
| 185 |
+
"initial_error": "AssertionError: expected [3, 4, 1, 2], got [1, 2, 1, 2]", "bug_location": {"function": "swap_halves", "line_start": 5},
|
| 186 |
+
"test_cases": [{"input": [[1, 2, 3, 4]], "expected_output": [3, 4, 1, 2]}, {"input": [[1, 2, 3]], "expected_output": [3, 1, 2]}, {"input": [[1]], "expected_output": [1]}, {"input": [[]], "expected_output": []}]
|
| 187 |
+
},
|
| 188 |
+
{
|
| 189 |
+
"id": "t2_030", "difficulty": 2, "bug_type": "wrong_variable", "function_name": "get_initials",
|
| 190 |
+
"buggy_code": "def get_initials(name):\n words = name.split()\n initials = [w[0].upper() for w in words]\n return ''.join(words)",
|
| 191 |
+
"original_code": "def get_initials(name):\n words = name.split()\n initials = [w[0].upper() for w in words]\n return ''.join(initials)",
|
| 192 |
+
"initial_error": "AssertionError: expected 'JD', got 'JohnDoe'", "bug_location": {"function": "get_initials", "line_start": 4},
|
| 193 |
+
"test_cases": [{"input": "John Doe", "expected_output": "JD"}, {"input": "Alice", "expected_output": "A"}, {"input": "bob smith junior", "expected_output": "BSJ"}, {"input": "", "expected_output": ""}]
|
| 194 |
+
}
|
| 195 |
+
]
|
scratch/data_tier3.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
t3_bugs = [
|
| 2 |
+
# 6 bugs: wrong argument order
|
| 3 |
+
{
|
| 4 |
+
"id": "t3_003", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "process_user",
|
| 5 |
+
"buggy_code": "def format_name(first, last):\n return f'{last}, {first}'\n\ndef process_user(first_name, last_name):\n return format_name(last_name, first_name)",
|
| 6 |
+
"original_code": "def format_name(first, last):\n return f'{last}, {first}'\n\ndef process_user(first_name, last_name):\n return format_name(first_name, last_name)",
|
| 7 |
+
"initial_error": "AssertionError: expected 'Doe, John', got 'John, Doe'", "bug_location": {"function": "process_user", "line_start": 5},
|
| 8 |
+
"test_cases": [{"input": ["John", "Doe"], "expected_output": "Doe, John"}, {"input": ["Alice", "Smith"], "expected_output": "Smith, Alice"}, {"input": ["A", "B"], "expected_output": "B, A"}, {"input": ["X", "Y"], "expected_output": "Y, X"}]
|
| 9 |
+
},
|
| 10 |
+
{
|
| 11 |
+
"id": "t3_004", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "calculate_total",
|
| 12 |
+
"buggy_code": "def apply_discount(price, discount):\n return price - (price * discount)\n\ndef calculate_total(price, discount_rate):\n return apply_discount(discount_rate, price)",
|
| 13 |
+
"original_code": "def apply_discount(price, discount):\n return price - (price * discount)\n\ndef calculate_total(price, discount_rate):\n return apply_discount(price, discount_rate)",
|
| 14 |
+
"initial_error": "AssertionError: expected 80.0, got -19.8", "bug_location": {"function": "calculate_total", "line_start": 5},
|
| 15 |
+
"test_cases": [{"input": [100, 0.2], "expected_output": 80.0}, {"input": [50, 0.1], "expected_output": 45.0}, {"input": [200, 0.5], "expected_output": 100.0}, {"input": [10, 0.0], "expected_output": 10.0}]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"id": "t3_005", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "build_url",
|
| 19 |
+
"buggy_code": "def join_parts(domain, path):\n return f'https://{domain}/{path}'\n\ndef build_url(domain, path):\n return join_parts(path, domain)",
|
| 20 |
+
"original_code": "def join_parts(domain, path):\n return f'https://{domain}/{path}'\n\ndef build_url(domain, path):\n return join_parts(domain, path)",
|
| 21 |
+
"initial_error": "AssertionError: expected 'https://example.com/api', got 'https://api/example.com'", "bug_location": {"function": "build_url", "line_start": 5},
|
| 22 |
+
"test_cases": [{"input": ["example.com", "api"], "expected_output": "https://example.com/api"}, {"input": ["google.com", "search"], "expected_output": "https://google.com/search"}, {"input": ["a.com", "b"], "expected_output": "https://a.com/b"}, {"input": ["x.org", "y"], "expected_output": "https://x.org/y"}]
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"id": "t3_006", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "divide_numbers",
|
| 26 |
+
"buggy_code": "def safe_divide(num, den):\n if den == 0:\n return 0\n return num / den\n\ndef divide_numbers(a, b):\n return safe_divide(b, a)",
|
| 27 |
+
"original_code": "def safe_divide(num, den):\n if den == 0:\n return 0\n return num / den\n\ndef divide_numbers(a, b):\n return safe_divide(a, b)",
|
| 28 |
+
"initial_error": "AssertionError: expected 2.0, got 0.5", "bug_location": {"function": "divide_numbers", "line_start": 7},
|
| 29 |
+
"test_cases": [{"input": [10, 5], "expected_output": 2.0}, {"input": [5, 0], "expected_output": 0}, {"input": [100, 10], "expected_output": 10.0}, {"input": [0, 5], "expected_output": 0.0}]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"id": "t3_007", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "create_rectangle",
|
| 33 |
+
"buggy_code": "def calc_area(w, h):\n return w * h\n\ndef create_rectangle(width, height):\n return {'w': width, 'h': height, 'area': calc_area(height, width)}",
|
| 34 |
+
"original_code": "def calc_area(w, h):\n return w * h\n\ndef create_rectangle(width, height):\n return {'w': width, 'h': height, 'area': calc_area(width, height)}",
|
| 35 |
+
"initial_error": "AssertionError: doesn't strictly fail math but conceptually wrong", "bug_location": {"function": "create_rectangle", "line_start": 5},
|
| 36 |
+
"test_cases": [{"input": [5, 10], "expected_output": {'w': 5, 'h': 10, 'area': 50}}, {"input": [2, 3], "expected_output": {'w': 2, 'h': 3, 'area': 6}}, {"input": [1, 1], "expected_output": {'w': 1, 'h': 1, 'area': 1}}, {"input": [0, 5], "expected_output": {'w': 0, 'h': 5, 'area': 0}}]
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"id": "t3_008", "difficulty": 3, "bug_type": "wrong_argument_order", "function_name": "power_wrapper",
|
| 40 |
+
"buggy_code": "def compute_pow(base, exp):\n return base ** exp\n\ndef power_wrapper(base, exp):\n return compute_pow(exp, base)",
|
| 41 |
+
"original_code": "def compute_pow(base, exp):\n return base ** exp\n\ndef power_wrapper(base, exp):\n return compute_pow(base, exp)",
|
| 42 |
+
"initial_error": "AssertionError: expected 8, got 9", "bug_location": {"function": "power_wrapper", "line_start": 5},
|
| 43 |
+
"test_cases": [{"input": [2, 3], "expected_output": 8}, {"input": [3, 2], "expected_output": 9}, {"input": [5, 2], "expected_output": 25}, {"input": [2, 4], "expected_output": 16}]
|
| 44 |
+
},
|
| 45 |
+
# 6 bugs: state not reset
|
| 46 |
+
{
|
| 47 |
+
"id": "t3_009", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "get_unique_items",
|
| 48 |
+
"buggy_code": "seen = set()\ndef filter_unique(items):\n res = []\n for item in items:\n if item not in seen:\n seen.add(item)\n res.append(item)\n return res\n\ndef get_unique_items(items):\n return filter_unique(items)",
|
| 49 |
+
"original_code": "def filter_unique(items, seen):\n res = []\n for item in items:\n if item not in seen:\n seen.add(item)\n res.append(item)\n return res\n\ndef get_unique_items(items):\n return filter_unique(items, set())",
|
| 50 |
+
"initial_error": "AssertionError: test fails on second call", "bug_location": {"function": "filter_unique", "line_start": 4},
|
| 51 |
+
"test_cases": [{"input": [[1, 2, 2, 3]], "expected_output": [1, 2, 3]}, {"input": [[1, 2, 2, 3]], "expected_output": [1, 2, 3]}, {"input": [[4, 4, 5]], "expected_output": [4, 5]}, {"input": [[4, 4, 5]], "expected_output": [4, 5]}]
|
| 52 |
+
},
|
| 53 |
+
{
|
| 54 |
+
"id": "t3_010", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "accumulate_values",
|
| 55 |
+
"buggy_code": "total = 0\ndef add_to_total(val):\n global total\n total += val\n return total\n\ndef accumulate_values(vals):\n return [add_to_total(v) for v in vals]",
|
| 56 |
+
"original_code": "def accumulate_values(vals):\n total = 0\n res = []\n for v in vals:\n total += v\n res.append(total)\n return res",
|
| 57 |
+
"initial_error": "AssertionError: expected [1, 3], got [1, 3] then [4, 6] on next call", "bug_location": {"function": "add_to_total", "line_start": 4},
|
| 58 |
+
"test_cases": [{"input": [[1, 2]], "expected_output": [1, 3]}, {"input": [[1, 2]], "expected_output": [1, 3]}, {"input": [[5, 5]], "expected_output": [5, 10]}, {"input": [[5, 5]], "expected_output": [5, 10]}]
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"id": "t3_011", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "append_to_default",
|
| 62 |
+
"buggy_code": "def helper(val, lst=[]):\n lst.append(val)\n return lst\n\ndef append_to_default(val):\n return helper(val)",
|
| 63 |
+
"original_code": "def helper(val, lst=None):\n if lst is None:\n lst = []\n lst.append(val)\n return lst\n\ndef append_to_default(val):\n return helper(val)",
|
| 64 |
+
"initial_error": "AssertionError: expected [2], got [1, 2]", "bug_location": {"function": "helper", "line_start": 1},
|
| 65 |
+
"test_cases": [{"input": 1, "expected_output": [1]}, {"input": 2, "expected_output": [2]}, {"input": 3, "expected_output": [3]}, {"input": 4, "expected_output": [4]}]
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"id": "t3_012", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "count_calls",
|
| 69 |
+
"buggy_code": "calls = 0\ndef tracker():\n global calls\n calls += 1\n return calls\n\ndef count_calls(n):\n res = []\n for _ in range(n):\n res.append(tracker())\n return res",
|
| 70 |
+
"original_code": "def count_calls(n):\n calls = 0\n res = []\n for _ in range(n):\n calls += 1\n res.append(calls)\n return res",
|
| 71 |
+
"initial_error": "AssertionError: expected [1, 2], got [3, 4] on second run", "bug_location": {"function": "tracker", "line_start": 4},
|
| 72 |
+
"test_cases": [{"input": 2, "expected_output": [1, 2]}, {"input": 2, "expected_output": [1, 2]}, {"input": 3, "expected_output": [1, 2, 3]}, {"input": 3, "expected_output": [1, 2, 3]}]
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"id": "t3_013", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "build_sentence",
|
| 76 |
+
"buggy_code": "words_cache = []\ndef add_word(w):\n words_cache.append(w)\n return ' '.join(words_cache)\n\ndef build_sentence(words):\n res = ''\n for w in words:\n res = add_word(w)\n return res",
|
| 77 |
+
"original_code": "def build_sentence(words):\n words_cache = []\n def add_word(w):\n words_cache.append(w)\n return ' '.join(words_cache)\n res = ''\n for w in words:\n res = add_word(w)\n return res",
|
| 78 |
+
"initial_error": "AssertionError: expected 'hello world', got '... hello world'", "bug_location": {"function": "add_word", "line_start": 3},
|
| 79 |
+
"test_cases": [{"input": [["hello", "world"]], "expected_output": "hello world"}, {"input": [["foo", "bar"]], "expected_output": "foo bar"}, {"input": [["a", "b", "c"]], "expected_output": "a b c"}, {"input": [["x"]], "expected_output": "x"}]
|
| 80 |
+
},
|
| 81 |
+
{
|
| 82 |
+
"id": "t3_014", "difficulty": 3, "bug_type": "state_not_reset", "function_name": "collect_errors",
|
| 83 |
+
"buggy_code": "errors = []\ndef log_error(err):\n errors.append(err)\n return errors\n\ndef collect_errors(err_list):\n for e in err_list:\n res = log_error(e)\n return res if err_list else []",
|
| 84 |
+
"original_code": "def collect_errors(err_list):\n errors = []\n def log_error(err):\n errors.append(err)\n return errors\n res = []\n for e in err_list:\n res = log_error(e)\n return res",
|
| 85 |
+
"initial_error": "AssertionError: state leak between calls", "bug_location": {"function": "log_error", "line_start": 3},
|
| 86 |
+
"test_cases": [{"input": [["e1"]], "expected_output": ["e1"]}, {"input": [["e2"]], "expected_output": ["e2"]}, {"input": [["e3", "e4"]], "expected_output": ["e3", "e4"]}, {"input": [["e5"]], "expected_output": ["e5"]}]
|
| 87 |
+
},
|
| 88 |
+
# 6 bugs: missing edge case in helper
|
| 89 |
+
{
|
| 90 |
+
"id": "t3_015", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "process_data",
|
| 91 |
+
"buggy_code": "def get_first(lst):\n return lst[0]\n\ndef process_data(data):\n if not data:\n return None\n return [get_first(d) for d in data]",
|
| 92 |
+
"original_code": "def get_first(lst):\n if not lst:\n return None\n return lst[0]\n\ndef process_data(data):\n if not data:\n return []\n return [get_first(d) for d in data]",
|
| 93 |
+
"initial_error": "IndexError: list index out of range", "bug_location": {"function": "get_first", "line_start": 2},
|
| 94 |
+
"test_cases": [{"input": [[[1, 2], [3, 4]]], "expected_output": [1, 3]}, {"input": [[[1], []]], "expected_output": [1, None]}, {"input": [[[], [2]]], "expected_output": [None, 2]}, {"input": [[]], "expected_output": []}]
|
| 95 |
+
},
|
| 96 |
+
{
|
| 97 |
+
"id": "t3_016", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "average_scores",
|
| 98 |
+
"buggy_code": "def calc_avg(scores):\n return sum(scores) / len(scores)\n\ndef average_scores(students):\n return {k: calc_avg(v) for k, v in students.items()}",
|
| 99 |
+
"original_code": "def calc_avg(scores):\n if not scores:\n return 0\n return sum(scores) / len(scores)\n\ndef average_scores(students):\n return {k: calc_avg(v) for k, v in students.items()}",
|
| 100 |
+
"initial_error": "ZeroDivisionError: division by zero", "bug_location": {"function": "calc_avg", "line_start": 2},
|
| 101 |
+
"test_cases": [{"input": [{"Alice": [10, 20], "Bob": []}], "expected_output": {"Alice": 15.0, "Bob": 0}}, {"input": [{"A": [5]}], "expected_output": {"A": 5.0}}, {"input": [{}], "expected_output": {}}, {"input": [{"B": []}], "expected_output": {"B": 0}}]
|
| 102 |
+
},
|
| 103 |
+
{
|
| 104 |
+
"id": "t3_017", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "find_max_nested",
|
| 105 |
+
"buggy_code": "def find_max(lst):\n return max(lst)\n\ndef find_max_nested(nested_lists):\n return [find_max(l) for l in nested_lists]",
|
| 106 |
+
"original_code": "def find_max(lst):\n if not lst:\n return None\n return max(lst)\n\ndef find_max_nested(nested_lists):\n return [find_max(l) for l in nested_lists]",
|
| 107 |
+
"initial_error": "ValueError: max() arg is an empty sequence", "bug_location": {"function": "find_max", "line_start": 2},
|
| 108 |
+
"test_cases": [{"input": [[[1, 2], []]], "expected_output": [2, None]}, {"input": [[[1], [2, 3]]], "expected_output": [1, 3]}, {"input": [[[], []]], "expected_output": [None, None]}, {"input": [[]], "expected_output": []}]
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"id": "t3_018", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "get_extensions",
|
| 112 |
+
"buggy_code": "def extract_ext(filename):\n return filename.split('.')[1]\n\ndef get_extensions(files):\n return [extract_ext(f) for f in files]",
|
| 113 |
+
"original_code": "def extract_ext(filename):\n parts = filename.split('.')\n if len(parts) < 2:\n return ''\n return parts[-1]\n\ndef get_extensions(files):\n return [extract_ext(f) for f in files]",
|
| 114 |
+
"initial_error": "IndexError: list index out of range", "bug_location": {"function": "extract_ext", "line_start": 2},
|
| 115 |
+
"test_cases": [{"input": [["a.txt", "b"]], "expected_output": ["txt", ""]}, {"input": [["a.txt", "b.pdf"]], "expected_output": ["txt", "pdf"]}, {"input": [["noext"]], "expected_output": [""]}, {"input": [[]], "expected_output": []}]
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"id": "t3_019", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "get_lengths",
|
| 119 |
+
"buggy_code": "def get_len(item):\n return len(item)\n\ndef get_lengths(items):\n return [get_len(i) for i in items]",
|
| 120 |
+
"original_code": "def get_len(item):\n if item is None:\n return 0\n return len(item)\n\ndef get_lengths(items):\n return [get_len(i) for i in items]",
|
| 121 |
+
"initial_error": "TypeError: object of type 'NoneType' has no len()", "bug_location": {"function": "get_len", "line_start": 2},
|
| 122 |
+
"test_cases": [{"input": [["abc", None]], "expected_output": [3, 0]}, {"input": [["a", "b"]], "expected_output": [1, 1]}, {"input": [[None, None]], "expected_output": [0, 0]}, {"input": [[]], "expected_output": []}]
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"id": "t3_020", "difficulty": 3, "bug_type": "missing_edge_case", "function_name": "parse_integers",
|
| 126 |
+
"buggy_code": "def to_int(s):\n return int(s)\n\ndef parse_integers(strings):\n return [to_int(s) for s in strings]",
|
| 127 |
+
"original_code": "def to_int(s):\n try:\n return int(s)\n except ValueError:\n return 0\n\ndef parse_integers(strings):\n return [to_int(s) for s in strings]",
|
| 128 |
+
"initial_error": "ValueError: invalid literal for int() with base 10", "bug_location": {"function": "to_int", "line_start": 2},
|
| 129 |
+
"test_cases": [{"input": [["1", "abc"]], "expected_output": [1, 0]}, {"input": [["1", "2"]], "expected_output": [1, 2]}, {"input": [["foo", "bar"]], "expected_output": [0, 0]}, {"input": [[]], "expected_output": []}]
|
| 130 |
+
}
|
| 131 |
+
]
|
scratch/debug.txt
ADDED
|
Binary file (22.5 kB). View file
|
|
|
scratch/debug2.txt
ADDED
|
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
t1_001
|
| 2 |
+
ORIG:
|
| 3 |
+
def binary_search(arr, target):
|
| 4 |
+
left, right = 0, len(arr) - 1
|
| 5 |
+
while left <= right:
|
| 6 |
+
mid = (left + right) // 2
|
| 7 |
+
if arr[mid] == target:
|
| 8 |
+
return mid
|
| 9 |
+
elif arr[mid] < target:
|
| 10 |
+
left = mid + 1
|
| 11 |
+
else:
|
| 12 |
+
right = mid - 1
|
| 13 |
+
return -1
|
| 14 |
+
BUGGY:
|
| 15 |
+
def binary_search(arr, target):
|
| 16 |
+
left, right = 0, len(arr)
|
| 17 |
+
while left < right:
|
| 18 |
+
mid = (left + right) // 2
|
| 19 |
+
if arr[mid] == target:
|
| 20 |
+
return mid
|
| 21 |
+
elif arr[mid] < target:
|
| 22 |
+
left = mid + 1
|
| 23 |
+
else:
|
| 24 |
+
right = mid
|
| 25 |
+
return -1
|
| 26 |
+
TESTS:
|
| 27 |
+
[{'input': [[1, 3, 5, 7, 9], 5], 'expected_output': 2}, {'input': [[1, 3, 5, 7, 9], 1], 'expected_output': 0}, {'input': [[1, 3, 5, 7, 9], 9], 'expected_output': 4}, {'input': [[1, 3, 5, 7, 9], 4], 'expected_output': -1}]
|
| 28 |
+
|
| 29 |
+
t1_003
|
| 30 |
+
ORIG:
|
| 31 |
+
def find_max(nums):
|
| 32 |
+
max_val = nums[0]
|
| 33 |
+
for i in range(1, len(nums)):
|
| 34 |
+
if nums[i] > max_val:
|
| 35 |
+
max_val = nums[i]
|
| 36 |
+
return max_val
|
| 37 |
+
BUGGY:
|
| 38 |
+
def find_max(nums):
|
| 39 |
+
max_val = nums[0]
|
| 40 |
+
for i in range(1, len(nums) + 1):
|
| 41 |
+
if nums[i] > max_val:
|
| 42 |
+
max_val = nums[i]
|
| 43 |
+
return max_val
|
| 44 |
+
TESTS:
|
| 45 |
+
[{'input': [3, 1, 4, 1, 5, 9], 'expected_output': 9}, {'input': [1], 'expected_output': 1}, {'input': [-5, -1, -3], 'expected_output': -1}, {'input': [7, 7, 7], 'expected_output': 7}]
|
| 46 |
+
|
| 47 |
+
t1_005
|
| 48 |
+
ORIG:
|
| 49 |
+
def sum_list(nums):
|
| 50 |
+
total = 0
|
| 51 |
+
for i in range(len(nums)):
|
| 52 |
+
total += nums[i]
|
| 53 |
+
return total
|
| 54 |
+
BUGGY:
|
| 55 |
+
def sum_list(nums):
|
| 56 |
+
total = 0
|
| 57 |
+
for i in range(len(nums) - 1):
|
| 58 |
+
total += nums[i]
|
| 59 |
+
return total
|
| 60 |
+
TESTS:
|
| 61 |
+
[{'input': [1, 2, 3], 'expected_output': 6}, {'input': [0], 'expected_output': 0}, {'input': [10, 20, 30, 40], 'expected_output': 100}, {'input': [], 'expected_output': 0}]
|
| 62 |
+
|
| 63 |
+
t1_006
|
| 64 |
+
ORIG:
|
| 65 |
+
def is_sorted(lst):
|
| 66 |
+
for i in range(len(lst) - 1):
|
| 67 |
+
if lst[i] > lst[i + 1]:
|
| 68 |
+
return False
|
| 69 |
+
return True
|
| 70 |
+
BUGGY:
|
| 71 |
+
def is_sorted(lst):
|
| 72 |
+
for i in range(len(lst) - 1):
|
| 73 |
+
if lst[i] > lst[i + 1]:
|
| 74 |
+
return True
|
| 75 |
+
return False
|
| 76 |
+
TESTS:
|
| 77 |
+
[{'input': [1, 2, 3], 'expected_output': True}, {'input': [3, 1, 2], 'expected_output': False}, {'input': [1], 'expected_output': True}, {'input': [2, 2, 2], 'expected_output': True}]
|
| 78 |
+
|
| 79 |
+
t1_026
|
| 80 |
+
ORIG:
|
| 81 |
+
def longest_common_prefix(strs):
|
| 82 |
+
if not strs:
|
| 83 |
+
return ""
|
| 84 |
+
prefix = strs[0]
|
| 85 |
+
for s in strs[1:]:
|
| 86 |
+
while not s.startswith(prefix):
|
| 87 |
+
prefix = prefix[:-1]
|
| 88 |
+
if not prefix:
|
| 89 |
+
return ""
|
| 90 |
+
return prefix
|
| 91 |
+
BUGGY:
|
| 92 |
+
def longest_common_prefix(strs):
|
| 93 |
+
if not strs:
|
| 94 |
+
return ""
|
| 95 |
+
prefix = strs[0]
|
| 96 |
+
for s in strs:
|
| 97 |
+
while not s.startswith(prefix):
|
| 98 |
+
prefix = prefix[:-1]
|
| 99 |
+
if not prefix:
|
| 100 |
+
return ""
|
| 101 |
+
return prefix
|
| 102 |
+
TESTS:
|
| 103 |
+
[{'input': [['flower', 'flow', 'flight']], 'expected_output': 'fl'}, {'input': [['dog', 'racecar', 'car']], 'expected_output': ''}, {'input': [[]], 'expected_output': ''}, {'input': [['a']], 'expected_output': 'a'}]
|
| 104 |
+
|
| 105 |
+
t1_033
|
| 106 |
+
ORIG:
|
| 107 |
+
def house_robber(nums):
|
| 108 |
+
if not nums:
|
| 109 |
+
return 0
|
| 110 |
+
if len(nums) == 1:
|
| 111 |
+
return nums[0]
|
| 112 |
+
dp = [0] * len(nums)
|
| 113 |
+
dp[0] = nums[0]
|
| 114 |
+
dp[1] = max(nums[0], nums[1])
|
| 115 |
+
for i in range(2, len(nums)):
|
| 116 |
+
dp[i] = max(dp[i-1], dp[i-2] + nums[i])
|
| 117 |
+
return dp[-1]
|
| 118 |
+
BUGGY:
|
| 119 |
+
def house_robber(nums):
|
| 120 |
+
if not nums:
|
| 121 |
+
return 0
|
| 122 |
+
if len(nums) == 1:
|
| 123 |
+
return nums[0]
|
| 124 |
+
dp = [0] * len(nums)
|
| 125 |
+
dp[0] = nums[0]
|
| 126 |
+
dp[1] = min(nums[0], nums[1])
|
| 127 |
+
for i in range(2, len(nums)):
|
| 128 |
+
dp[i] = max(dp[i-1], dp[i-2] + nums[i])
|
| 129 |
+
return dp[-1]
|
| 130 |
+
TESTS:
|
| 131 |
+
[{'input': [[1, 2, 3, 1]], 'expected_output': 4}, {'input': [[2, 7, 9, 3, 1]], 'expected_output': 12}, {'input': [[]], 'expected_output': 0}, {'input': [[5]], 'expected_output': 5}]
|
| 132 |
+
|
| 133 |
+
t1_034
|
| 134 |
+
ORIG:
|
| 135 |
+
def house_robber(nums):
|
| 136 |
+
if not nums:
|
| 137 |
+
return 0
|
| 138 |
+
if len(nums) == 1:
|
| 139 |
+
return nums[0]
|
| 140 |
+
dp = [0] * len(nums)
|
| 141 |
+
dp[0] = nums[0]
|
| 142 |
+
dp[1] = max(nums[0], nums[1])
|
| 143 |
+
for i in range(2, len(nums)):
|
| 144 |
+
dp[i] = max(dp[i-1], dp[i-2] + nums[i])
|
| 145 |
+
return dp[-1]
|
| 146 |
+
BUGGY:
|
| 147 |
+
def house_robber(nums):
|
| 148 |
+
if not nums:
|
| 149 |
+
return 0
|
| 150 |
+
if len(nums) == 1:
|
| 151 |
+
return nums[0]
|
| 152 |
+
dp = [0] * len(nums)
|
| 153 |
+
dp[0] = nums[0]
|
| 154 |
+
dp[1] = max(nums[0], nums[1])
|
| 155 |
+
for i in range(1, len(nums)):
|
| 156 |
+
dp[i] = max(dp[i-1], dp[i-2] + nums[i])
|
| 157 |
+
return dp[-1]
|
| 158 |
+
TESTS:
|
| 159 |
+
[{'input': [[1, 2, 3, 1]], 'expected_output': 4}, {'input': [[2, 7, 9, 3, 1]], 'expected_output': 12}, {'input': [[]], 'expected_output': 0}, {'input': [[5]], 'expected_output': 5}]
|
| 160 |
+
|
| 161 |
+
t2_003
|
| 162 |
+
ORIG:
|
| 163 |
+
def flatten(lst):
|
| 164 |
+
result = []
|
| 165 |
+
for item in lst:
|
| 166 |
+
if isinstance(item, list):
|
| 167 |
+
result.extend(flatten(item))
|
| 168 |
+
else:
|
| 169 |
+
result.append(item)
|
| 170 |
+
return result
|
| 171 |
+
BUGGY:
|
| 172 |
+
def flatten(lst):
|
| 173 |
+
result = []
|
| 174 |
+
for item in lst:
|
| 175 |
+
if isinstance(item, list):
|
| 176 |
+
result.append(flatten(item))
|
| 177 |
+
else:
|
| 178 |
+
result.append(item)
|
| 179 |
+
return result
|
| 180 |
+
TESTS:
|
| 181 |
+
[{'input': [[1, [2]], 3], 'expected_output': [1, 2, 3]}, {'input': [1, 2, 3], 'expected_output': [1, 2, 3]}, {'input': [[1, 2], [3, [4, 5]]], 'expected_output': [1, 2, 3, 4, 5]}]
|
| 182 |
+
|
| 183 |
+
t2_026
|
| 184 |
+
ORIG:
|
| 185 |
+
def find_min_max(nums):
|
| 186 |
+
if not nums:
|
| 187 |
+
return None
|
| 188 |
+
mn = min(nums)
|
| 189 |
+
mx = max(nums)
|
| 190 |
+
return (mn, mx)
|
| 191 |
+
BUGGY:
|
| 192 |
+
def find_min_max(nums):
|
| 193 |
+
if not nums:
|
| 194 |
+
return None
|
| 195 |
+
mn = min(nums)
|
| 196 |
+
mx = max(nums)
|
| 197 |
+
return (mn, mn)
|
| 198 |
+
TESTS:
|
| 199 |
+
[{'input': [[1, 2, 5]], 'expected_output': (1, 5)}, {'input': [[3, 3]], 'expected_output': (3, 3)}, {'input': [[-1, 0, 1]], 'expected_output': (-1, 1)}, {'input': [[]], 'expected_output': None}]
|
| 200 |
+
|
| 201 |
+
t2_029
|
| 202 |
+
ORIG:
|
| 203 |
+
def swap_halves(lst):
|
| 204 |
+
mid = len(lst) // 2
|
| 205 |
+
left = lst[:mid]
|
| 206 |
+
right = lst[mid:]
|
| 207 |
+
return right + left
|
| 208 |
+
BUGGY:
|
| 209 |
+
def swap_halves(lst):
|
| 210 |
+
mid = len(lst) // 2
|
| 211 |
+
left = lst[:mid]
|
| 212 |
+
right = lst[mid:]
|
| 213 |
+
return left + left
|
| 214 |
+
TESTS:
|
| 215 |
+
[{'input': [[1, 2, 3, 4]], 'expected_output': [3, 4, 1, 2]}, {'input': [[1, 2, 3]], 'expected_output': [3, 1, 2]}, {'input': [[1]], 'expected_output': [1]}, {'input': [[]], 'expected_output': []}]
|
| 216 |
+
|
| 217 |
+
t3_002
|
| 218 |
+
ORIG:
|
| 219 |
+
def rotate_matrix(matrix):
|
| 220 |
+
n = len(matrix)
|
| 221 |
+
for i in range(n):
|
| 222 |
+
for j in range(i, n):
|
| 223 |
+
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
|
| 224 |
+
for row in matrix:
|
| 225 |
+
row.reverse()
|
| 226 |
+
return matrix
|
| 227 |
+
BUGGY:
|
| 228 |
+
def rotate_matrix(matrix):
|
| 229 |
+
n = len(matrix)
|
| 230 |
+
for i in range(n):
|
| 231 |
+
for j in range(i, n):
|
| 232 |
+
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
|
| 233 |
+
return matrix
|
| 234 |
+
TESTS:
|
| 235 |
+
[{'input': [[1, 2], [3, 4]], 'expected_output': [[3, 1], [4, 2]]}, {'input': [[1, 2, 3], [4, 5, 6], [7, 8, 9]], 'expected_output': [[7, 4, 1], [8, 5, 2], [9, 6, 3]]}]
|
| 236 |
+
|
| 237 |
+
t3_007
|
| 238 |
+
ORIG:
|
| 239 |
+
def calc_area(w, h):
|
| 240 |
+
return w * h
|
| 241 |
+
|
| 242 |
+
def create_rectangle(width, height):
|
| 243 |
+
return {'w': width, 'h': height, 'area': calc_area(width, height)}
|
| 244 |
+
BUGGY:
|
| 245 |
+
def calc_area(w, h):
|
| 246 |
+
return w * h
|
| 247 |
+
|
| 248 |
+
def create_rectangle(width, height):
|
| 249 |
+
return {'w': width, 'h': height, 'area': calc_area(height, width)}
|
| 250 |
+
TESTS:
|
| 251 |
+
[{'input': [5, 10], 'expected_output': {'w': 5, 'h': 10, 'area': 50}}, {'input': [2, 3], 'expected_output': {'w': 2, 'h': 3, 'area': 6}}, {'input': [1, 1], 'expected_output': {'w': 1, 'h': 1, 'area': 1}}, {'input': [0, 5], 'expected_output': {'w': 0, 'h': 5, 'area': 0}}]
|
| 252 |
+
|
| 253 |
+
t3_009
|
| 254 |
+
ORIG:
|
| 255 |
+
def filter_unique(items, seen):
|
| 256 |
+
res = []
|
| 257 |
+
for item in items:
|
| 258 |
+
if item not in seen:
|
| 259 |
+
seen.add(item)
|
| 260 |
+
res.append(item)
|
| 261 |
+
return res
|
| 262 |
+
|
| 263 |
+
def get_unique_items(items):
|
| 264 |
+
return filter_unique(items, set())
|
| 265 |
+
BUGGY:
|
| 266 |
+
seen = set()
|
| 267 |
+
def filter_unique(items):
|
| 268 |
+
res = []
|
| 269 |
+
for item in items:
|
| 270 |
+
if item not in seen:
|
| 271 |
+
seen.add(item)
|
| 272 |
+
res.append(item)
|
| 273 |
+
return res
|
| 274 |
+
|
| 275 |
+
def get_unique_items(items):
|
| 276 |
+
return filter_unique(items)
|
| 277 |
+
TESTS:
|
| 278 |
+
[{'input': [[1, 2, 2, 3]], 'expected_output': [1, 2, 3]}, {'input': [[1, 2, 2, 3]], 'expected_output': [1, 2, 3]}, {'input': [[4, 4, 5]], 'expected_output': [4, 5]}, {'input': [[4, 4, 5]], 'expected_output': [4, 5]}]
|
| 279 |
+
|
| 280 |
+
t3_010
|
| 281 |
+
ORIG:
|
| 282 |
+
def accumulate_values(vals):
|
| 283 |
+
total = 0
|
| 284 |
+
res = []
|
| 285 |
+
for v in vals:
|
| 286 |
+
total += v
|
| 287 |
+
res.append(total)
|
| 288 |
+
return res
|
| 289 |
+
BUGGY:
|
| 290 |
+
total = 0
|
| 291 |
+
def add_to_total(val):
|
| 292 |
+
global total
|
| 293 |
+
total += val
|
| 294 |
+
return total
|
| 295 |
+
|
| 296 |
+
def accumulate_values(vals):
|
| 297 |
+
return [add_to_total(v) for v in vals]
|
| 298 |
+
TESTS:
|
| 299 |
+
[{'input': [[1, 2]], 'expected_output': [1, 3]}, {'input': [[1, 2]], 'expected_output': [1, 3]}, {'input': [[5, 5]], 'expected_output': [5, 10]}, {'input': [[5, 5]], 'expected_output': [5, 10]}]
|
| 300 |
+
|
| 301 |
+
t3_011
|
| 302 |
+
ORIG:
|
| 303 |
+
def helper(val, lst=None):
|
| 304 |
+
if lst is None:
|
| 305 |
+
lst = []
|
| 306 |
+
lst.append(val)
|
| 307 |
+
return lst
|
| 308 |
+
|
| 309 |
+
def append_to_default(val):
|
| 310 |
+
return helper(val)
|
| 311 |
+
BUGGY:
|
| 312 |
+
def helper(val, lst=[]):
|
| 313 |
+
lst.append(val)
|
| 314 |
+
return lst
|
| 315 |
+
|
| 316 |
+
def append_to_default(val):
|
| 317 |
+
return helper(val)
|
| 318 |
+
TESTS:
|
| 319 |
+
[{'input': 1, 'expected_output': [1]}, {'input': 2, 'expected_output': [2]}, {'input': 3, 'expected_output': [3]}, {'input': 4, 'expected_output': [4]}]
|
| 320 |
+
|
| 321 |
+
t3_012
|
| 322 |
+
ORIG:
|
| 323 |
+
def count_calls(n):
|
| 324 |
+
calls = 0
|
| 325 |
+
res = []
|
| 326 |
+
for _ in range(n):
|
| 327 |
+
calls += 1
|
| 328 |
+
res.append(calls)
|
| 329 |
+
return res
|
| 330 |
+
BUGGY:
|
| 331 |
+
calls = 0
|
| 332 |
+
def tracker():
|
| 333 |
+
global calls
|
| 334 |
+
calls += 1
|
| 335 |
+
return calls
|
| 336 |
+
|
| 337 |
+
def count_calls(n):
|
| 338 |
+
res = []
|
| 339 |
+
for _ in range(n):
|
| 340 |
+
res.append(tracker())
|
| 341 |
+
return res
|
| 342 |
+
TESTS:
|
| 343 |
+
[{'input': 2, 'expected_output': [1, 2]}, {'input': 2, 'expected_output': [1, 2]}, {'input': 3, 'expected_output': [1, 2, 3]}, {'input': 3, 'expected_output': [1, 2, 3]}]
|
| 344 |
+
|
| 345 |
+
t3_013
|
| 346 |
+
ORIG:
|
| 347 |
+
def build_sentence(words):
|
| 348 |
+
words_cache = []
|
| 349 |
+
def add_word(w):
|
| 350 |
+
words_cache.append(w)
|
| 351 |
+
return ' '.join(words_cache)
|
| 352 |
+
res = ''
|
| 353 |
+
for w in words:
|
| 354 |
+
res = add_word(w)
|
| 355 |
+
return res
|
| 356 |
+
BUGGY:
|
| 357 |
+
words_cache = []
|
| 358 |
+
def add_word(w):
|
| 359 |
+
words_cache.append(w)
|
| 360 |
+
return ' '.join(words_cache)
|
| 361 |
+
|
| 362 |
+
def build_sentence(words):
|
| 363 |
+
res = ''
|
| 364 |
+
for w in words:
|
| 365 |
+
res = add_word(w)
|
| 366 |
+
return res
|
| 367 |
+
TESTS:
|
| 368 |
+
[{'input': [['hello', 'world']], 'expected_output': 'hello world'}, {'input': [['foo', 'bar']], 'expected_output': 'foo bar'}, {'input': [['a', 'b', 'c']], 'expected_output': 'a b c'}, {'input': [['x']], 'expected_output': 'x'}]
|
| 369 |
+
|
| 370 |
+
t3_014
|
| 371 |
+
ORIG:
|
| 372 |
+
def collect_errors(err_list):
|
| 373 |
+
errors = []
|
| 374 |
+
def log_error(err):
|
| 375 |
+
errors.append(err)
|
| 376 |
+
return errors
|
| 377 |
+
res = []
|
| 378 |
+
for e in err_list:
|
| 379 |
+
res = log_error(e)
|
| 380 |
+
return res
|
| 381 |
+
BUGGY:
|
| 382 |
+
errors = []
|
| 383 |
+
def log_error(err):
|
| 384 |
+
errors.append(err)
|
| 385 |
+
return errors
|
| 386 |
+
|
| 387 |
+
def collect_errors(err_list):
|
| 388 |
+
for e in err_list:
|
| 389 |
+
res = log_error(e)
|
| 390 |
+
return res if err_list else []
|
| 391 |
+
TESTS:
|
| 392 |
+
[{'input': [['e1']], 'expected_output': ['e1']}, {'input': [['e2']], 'expected_output': ['e2']}, {'input': [['e3', 'e4']], 'expected_output': ['e3', 'e4']}, {'input': [['e5']], 'expected_output': ['e5']}]
|
scratch/fix_all.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
# ensure data is importable
|
| 5 |
+
sys.path.append(os.path.abspath('.'))
|
| 6 |
+
|
| 7 |
+
from data.generate_bugs import TIER1_BUGS, TIER2_BUGS, TIER3_BUGS
|
| 8 |
+
|
| 9 |
+
for b in TIER1_BUGS:
|
| 10 |
+
if b["id"] == "t1_003":
|
| 11 |
+
for t in b["test_cases"]:
|
| 12 |
+
while len(t["input"]) == 1 and isinstance(t["input"][0], list):
|
| 13 |
+
t["input"] = t["input"][0]
|
| 14 |
+
t["input"] = [t["input"]]
|
| 15 |
+
elif b["id"] == "t1_005":
|
| 16 |
+
for t in b["test_cases"]:
|
| 17 |
+
while len(t["input"]) == 1 and isinstance(t["input"][0], list):
|
| 18 |
+
t["input"] = t["input"][0]
|
| 19 |
+
t["input"] = [t["input"]]
|
| 20 |
+
elif b["id"] == "t1_006":
|
| 21 |
+
for t in b["test_cases"]:
|
| 22 |
+
while len(t["input"]) == 1 and isinstance(t["input"][0], list):
|
| 23 |
+
t["input"] = t["input"][0]
|
| 24 |
+
t["input"] = [t["input"]]
|
| 25 |
+
elif b["id"] == "t1_001":
|
| 26 |
+
b["buggy_code"] = b["buggy_code"].replace("right = mid", "right = mid + 1")
|
| 27 |
+
elif b["id"] == "t1_026":
|
| 28 |
+
b["buggy_code"] = b["buggy_code"].replace("return prefix", "return prefix + 'x'")
|
| 29 |
+
elif b["id"] == "t1_033":
|
| 30 |
+
b["buggy_code"] = b["buggy_code"].replace("dp[1] = 0", "dp[1] = 9999")
|
| 31 |
+
elif b["id"] == "t1_034":
|
| 32 |
+
b["buggy_code"] = b["buggy_code"].replace("dp[i] = max(dp[i-1], dp[i-2] + nums[i])", "dp[i] = max(dp[i-1], nums[i])")
|
| 33 |
+
|
| 34 |
+
for b in TIER2_BUGS:
|
| 35 |
+
if b["id"] == "t2_003":
|
| 36 |
+
for t in b["test_cases"]:
|
| 37 |
+
# If t["input"] is nested too deep, unpack it first.
|
| 38 |
+
while len(t["input"]) == 1 and isinstance(t["input"][0], list) and len(t["input"][0]) == 2:
|
| 39 |
+
t["input"] = t["input"][0]
|
| 40 |
+
if len(t["input"]) == 2 and not isinstance(t["input"][0], list) and not isinstance(t["input"], tuple):
|
| 41 |
+
t["input"] = [t["input"]]
|
| 42 |
+
elif len(t["input"]) >= 2:
|
| 43 |
+
t["input"] = [t["input"]]
|
| 44 |
+
elif b["id"] == "t2_026":
|
| 45 |
+
b["original_code"] = b["original_code"].replace("return (mn, mx)", "return [mn, mx]")
|
| 46 |
+
b["buggy_code"] = b["buggy_code"].replace("return (mn, mn)", "return [mn, mn]")
|
| 47 |
+
for t in b["test_cases"]:
|
| 48 |
+
if isinstance(t["expected_output"], tuple):
|
| 49 |
+
t["expected_output"] = list(t["expected_output"])
|
| 50 |
+
elif b["id"] == "t2_029":
|
| 51 |
+
for t in b["test_cases"]:
|
| 52 |
+
if t["input"] == [[1, 2, 3]]:
|
| 53 |
+
t["expected_output"] = [2, 3, 1]
|
| 54 |
+
|
| 55 |
+
for b in TIER3_BUGS:
|
| 56 |
+
if b["id"] == "t3_002":
|
| 57 |
+
for t in b["test_cases"]:
|
| 58 |
+
# Unpack completely
|
| 59 |
+
while len(t["input"]) == 1 and isinstance(t["input"][0], list):
|
| 60 |
+
t["input"] = t["input"][0]
|
| 61 |
+
# Wrap once
|
| 62 |
+
t["input"] = [t["input"]]
|
| 63 |
+
elif b["id"] == "t3_007":
|
| 64 |
+
b["buggy_code"] = b["buggy_code"].replace("calc_area(height, width)", "calc_area(height, height)")
|
| 65 |
+
elif b["id"] == "t3_009":
|
| 66 |
+
b["buggy_code"] = b["buggy_code"].replace("seen = set()", "seen = {1}")
|
| 67 |
+
elif b["id"] == "t3_010":
|
| 68 |
+
b["buggy_code"] = b["buggy_code"].replace("total = 0", "total = 10")
|
| 69 |
+
elif b["id"] == "t3_011":
|
| 70 |
+
b["buggy_code"] = b["buggy_code"].replace("def helper(val, lst=[]):", "def helper(val, lst=[1]):")
|
| 71 |
+
elif b["id"] == "t3_012":
|
| 72 |
+
b["buggy_code"] = b["buggy_code"].replace("calls = 0", "calls = 5")
|
| 73 |
+
elif b["id"] == "t3_013":
|
| 74 |
+
b["buggy_code"] = b["buggy_code"].replace("words_cache = []", "words_cache = ['ERROR']")
|
| 75 |
+
elif b["id"] == "t3_014":
|
| 76 |
+
b["buggy_code"] = b["buggy_code"].replace("errors = []", "errors = ['fatal']")
|
| 77 |
+
|
| 78 |
+
import pprint
|
| 79 |
+
|
| 80 |
+
def dump_var(f, name, val):
|
| 81 |
+
f.write(f'{name} = ')
|
| 82 |
+
f.write(pprint.pformat(val, sort_dicts=False, width=120))
|
| 83 |
+
f.write('\n\n')
|
| 84 |
+
|
| 85 |
+
with open("data/generate_bugs.py", "w", encoding="utf-8") as f:
|
| 86 |
+
f.write('"""\nAgentDebuggerEnv - Bug Dataset Generator\n\n')
|
| 87 |
+
f.write('Generates three tiers of buggy Python functions for curriculum learning:\n')
|
| 88 |
+
f.write(' Tier 1 (easy): Off-by-one errors, wrong operators, simple logic inversions\n')
|
| 89 |
+
f.write(' Tier 2 (medium): Incorrect algorithm logic, wrong variable references, subtle type errors\n')
|
| 90 |
+
f.write(' Tier 3 (hard): Multi-bug interactions, concurrency, edge-case-only failures\n\n')
|
| 91 |
+
f.write('Usage:\n python data/generate_bugs.py\n\n')
|
| 92 |
+
f.write('Outputs:\n data/bugs_tier1.jsonl (~40 bugs)\n data/bugs_tier2.jsonl (~30 bugs)\n data/bugs_tier3.jsonl (~20 bugs)\n"""\n\n')
|
| 93 |
+
f.write('import json\nimport os\n\n')
|
| 94 |
+
|
| 95 |
+
dump_var(f, 'TIER1_BUGS', TIER1_BUGS)
|
| 96 |
+
dump_var(f, 'TIER2_BUGS', TIER2_BUGS)
|
| 97 |
+
dump_var(f, 'TIER3_BUGS', TIER3_BUGS)
|
| 98 |
+
|
| 99 |
+
f.write('def write_jsonl(bugs: list, path: str):\n')
|
| 100 |
+
f.write(' with open(path, "w") as f:\n')
|
| 101 |
+
f.write(' for bug in bugs:\n')
|
| 102 |
+
f.write(' f.write(json.dumps(bug) + "\\n")\n\n')
|
| 103 |
+
f.write('if __name__ == "__main__":\n')
|
| 104 |
+
f.write(' os.makedirs("data", exist_ok=True)\n')
|
| 105 |
+
f.write(' write_jsonl(TIER1_BUGS, "data/bugs_tier1.jsonl")\n')
|
| 106 |
+
f.write(' write_jsonl(TIER2_BUGS, "data/bugs_tier2.jsonl")\n')
|
| 107 |
+
f.write(' write_jsonl(TIER3_BUGS, "data/bugs_tier3.jsonl")\n')
|
| 108 |
+
f.write(' print(f"Tier 1: {len(TIER1_BUGS)}, Tier 2: {len(TIER2_BUGS)}, Tier 3: {len(TIER3_BUGS)}")\n')
|
| 109 |
+
f.write(' print("\\nDone. Run training/train_grpo.py to start training.")\n')
|
| 110 |
+
|
| 111 |
+
print("Fix applied successfully.")
|
scratch/gen_t1_base.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
|
| 3 |
+
t1_bugs = []
|
| 4 |
+
|
| 5 |
+
funcs = [
|
| 6 |
+
{
|
| 7 |
+
"name": "factorial",
|
| 8 |
+
"orig": "def factorial(n):\n if n == 0:\n return 1\n return n * factorial(n - 1)",
|
| 9 |
+
"cases": [{"input": 0, "expected_output": 1}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 120}, {"input": 3, "expected_output": 6}]
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"name": "fibonacci",
|
| 13 |
+
"orig": "def fibonacci(n):\n if n <= 1:\n return n\n return fibonacci(n-1) + fibonacci(n-2)",
|
| 14 |
+
"cases": [{"input": 0, "expected_output": 0}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 5}, {"input": 7, "expected_output": 13}]
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"name": "string_reverse",
|
| 18 |
+
"orig": "def string_reverse(s):\n return s[::-1]",
|
| 19 |
+
"cases": [{"input": "hello", "expected_output": "olleh"}, {"input": "", "expected_output": ""}, {"input": "a", "expected_output": "a"}, {"input": "racecar", "expected_output": "racecar"}]
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"name": "count_occurrences",
|
| 23 |
+
"orig": "def count_occurrences(lst, target):\n count = 0\n for item in lst:\n if item == target:\n count += 1\n return count",
|
| 24 |
+
"cases": [{"input": [[1,2,1,3,1], 1], "expected_output": 3}, {"input": [[], 5], "expected_output": 0}, {"input": [[2,2,2], 2], "expected_output": 3}, {"input": [[1,2,3], 4], "expected_output": 0}]
|
| 25 |
+
},
|
| 26 |
+
{
|
| 27 |
+
"name": "sum_digits",
|
| 28 |
+
"orig": "def sum_digits(n):\n total = 0\n while n > 0:\n total += n % 10\n n //= 10\n return total",
|
| 29 |
+
"cases": [{"input": 123, "expected_output": 6}, {"input": 0, "expected_output": 0}, {"input": 999, "expected_output": 27}, {"input": 10, "expected_output": 1}]
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"name": "is_prime",
|
| 33 |
+
"orig": "def is_prime(n):\n if n <= 1:\n return False\n for i in range(2, int(n**0.5) + 1):\n if n % i == 0:\n return False\n return True",
|
| 34 |
+
"cases": [{"input": 2, "expected_output": True}, {"input": 4, "expected_output": False}, {"input": 13, "expected_output": True}, {"input": 1, "expected_output": False}]
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"name": "merge_intervals",
|
| 38 |
+
"orig": "def merge_intervals(intervals):\n if not intervals:\n return []\n intervals.sort(key=lambda x: x[0])\n merged = [intervals[0]]\n for current in intervals:\n previous = merged[-1]\n if current[0] <= previous[1]:\n previous[1] = max(previous[1], current[1])\n else:\n merged.append(current)\n return merged",
|
| 39 |
+
"cases": [{"input": [[[1,3],[2,6],[8,10],[15,18]]], "expected_output": [[1,6],[8,10],[15,18]]}, {"input": [[[1,4],[4,5]]], "expected_output": [[1,5]]}, {"input": [[]], "expected_output": []}, {"input": [[[1,4],[0,4]]], "expected_output": [[0,4]]}]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"name": "remove_duplicates",
|
| 43 |
+
"orig": "def remove_duplicates(nums):\n if not nums:\n return 0\n i = 0\n for j in range(1, len(nums)):\n if nums[j] != nums[i]:\n i += 1\n nums[i] = nums[j]\n return i + 1",
|
| 44 |
+
"cases": [{"input": [[1,1,2]], "expected_output": 2}, {"input": [[0,0,1,1,1,2,2,3,3,4]], "expected_output": 5}, {"input": [[]], "expected_output": 0}, {"input": [[1]], "expected_output": 1}]
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"name": "longest_common_prefix",
|
| 48 |
+
"orig": "def longest_common_prefix(strs):\n if not strs:\n return \"\"\n prefix = strs[0]\n for s in strs[1:]:\n while not s.startswith(prefix):\n prefix = prefix[:-1]\n if not prefix:\n return \"\"\n return prefix",
|
| 49 |
+
"cases": [{"input": [["flower","flow","flight"]], "expected_output": "fl"}, {"input": [["dog","racecar","car"]], "expected_output": ""}, {"input": [[]], "expected_output": ""}, {"input": [["a"]], "expected_output": "a"}]
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"name": "product_except_self",
|
| 53 |
+
"orig": "def product_except_self(nums):\n n = len(nums)\n res = [1] * n\n prefix = 1\n for i in range(n):\n res[i] = prefix\n prefix *= nums[i]\n postfix = 1\n for i in range(n - 1, -1, -1):\n res[i] *= postfix\n postfix *= nums[i]\n return res",
|
| 54 |
+
"cases": [{"input": [[1,2,3,4]], "expected_output": [24,12,8,6]}, {"input": [[-1,1,0,-3,3]], "expected_output": [0,0,9,0,0]}, {"input": [[2,3]], "expected_output": [3,2]}, {"input": [[1,1,1]], "expected_output": [1,1,1]}]
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
"name": "valid_parentheses",
|
| 58 |
+
"orig": "def valid_parentheses(s):\n stack = []\n mapping = {')': '(', '}': '{', ']': '['}\n for char in s:\n if char in mapping:\n top_element = stack.pop() if stack else '#'\n if mapping[char] != top_element:\n return False\n else:\n stack.append(char)\n return not stack",
|
| 59 |
+
"cases": [{"input": "()", "expected_output": True}, {"input": "()[]{}", "expected_output": True}, {"input": "(]", "expected_output": False}, {"input": "([)]", "expected_output": False}]
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"name": "climbing_stairs",
|
| 63 |
+
"orig": "def climbing_stairs(n):\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a + b\n return b",
|
| 64 |
+
"cases": [{"input": 2, "expected_output": 2}, {"input": 3, "expected_output": 3}, {"input": 1, "expected_output": 1}, {"input": 5, "expected_output": 8}]
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"name": "house_robber",
|
| 68 |
+
"orig": "def house_robber(nums):\n if not nums:\n return 0\n if len(nums) == 1:\n return nums[0]\n dp = [0] * len(nums)\n dp[0] = nums[0]\n dp[1] = max(nums[0], nums[1])\n for i in range(2, len(nums)):\n dp[i] = max(dp[i-1], dp[i-2] + nums[i])\n return dp[-1]",
|
| 69 |
+
"cases": [{"input": [[1,2,3,1]], "expected_output": 4}, {"input": [[2,7,9,3,1]], "expected_output": 12}, {"input": [[]], "expected_output": 0}, {"input": [[5]], "expected_output": 5}]
|
| 70 |
+
},
|
| 71 |
+
{
|
| 72 |
+
"name": "intersection_of_arrays",
|
| 73 |
+
"orig": "def intersection_of_arrays(nums1, nums2):\n return list(set(nums1) & set(nums2))",
|
| 74 |
+
"cases": [{"input": [[1,2,2,1], [2,2]], "expected_output": [2]}, {"input": [[4,9,5], [9,4,9,8,4]], "expected_output": [9,4]}, {"input": [[], [1]], "expected_output": []}, {"input": [[1,2], [3,4]], "expected_output": []}]
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"name": "group_anagrams",
|
| 78 |
+
"orig": "def group_anagrams(strs):\n from collections import defaultdict\n ans = defaultdict(list)\n for s in strs:\n ans[tuple(sorted(s))].append(s)\n return list(ans.values())",
|
| 79 |
+
"cases": [{"input": [["eat","tea","tan","ate","nat","bat"]], "expected_output": [["eat","tea","ate"],["tan","nat"],["bat"]]}, {"input": [[""]], "expected_output": [[""]]}, {"input": [["a"]], "expected_output": [["a"]]}, {"input": [["ab", "ba"]], "expected_output": [["ab", "ba"]]}]
|
| 80 |
+
}
|
| 81 |
+
]
|
| 82 |
+
|
| 83 |
+
# Create 2 bugs per function, plus 2 more for the first function = 32 bugs.
|
| 84 |
+
bug_id_counter = 9
|
| 85 |
+
for f in funcs:
|
| 86 |
+
for i in range(2):
|
| 87 |
+
bug = {
|
| 88 |
+
"id": f"t1_{bug_id_counter:03d}",
|
| 89 |
+
"difficulty": 1,
|
| 90 |
+
"bug_type": "logic_error",
|
| 91 |
+
"function_name": f["name"],
|
| 92 |
+
"original_code": f["orig"],
|
| 93 |
+
"test_cases": f["cases"],
|
| 94 |
+
"initial_error": "AssertionError: function failed",
|
| 95 |
+
"bug_location": {"function": f["name"], "line_start": 2}
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
# We need to create a bug. Simple mutations based on function name and index.
|
| 99 |
+
# This will be done dynamically by the script we run.
|
| 100 |
+
t1_bugs.append(bug)
|
| 101 |
+
bug_id_counter += 1
|
| 102 |
+
|
| 103 |
+
# Let's add 2 more to reach 32.
|
| 104 |
+
for i in range(2):
|
| 105 |
+
bug = {
|
| 106 |
+
"id": f"t1_{bug_id_counter:03d}",
|
| 107 |
+
"difficulty": 1,
|
| 108 |
+
"bug_type": "logic_error",
|
| 109 |
+
"function_name": funcs[0]["name"],
|
| 110 |
+
"original_code": funcs[0]["orig"],
|
| 111 |
+
"test_cases": funcs[0]["cases"],
|
| 112 |
+
"initial_error": "AssertionError: function failed",
|
| 113 |
+
"bug_location": {"function": funcs[0]["name"], "line_start": 2}
|
| 114 |
+
}
|
| 115 |
+
t1_bugs.append(bug)
|
| 116 |
+
bug_id_counter += 1
|
| 117 |
+
|
| 118 |
+
with open("scratch/t1_base.json", "w") as f:
|
| 119 |
+
json.dump(t1_bugs, f, indent=4)
|
scratch/merge.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# add parent dir to path so we can import data.generate_bugs
|
| 5 |
+
sys.path.append(os.path.abspath('.'))
|
| 6 |
+
|
| 7 |
+
from data.generate_bugs import TIER1_BUGS as T1_OLD
|
| 8 |
+
from data.generate_bugs import TIER2_BUGS as T2_OLD
|
| 9 |
+
from data.generate_bugs import TIER3_BUGS as T3_OLD
|
| 10 |
+
|
| 11 |
+
from scratch.data_tier1 import t1_bugs
|
| 12 |
+
from scratch.data_tier2 import t2_bugs
|
| 13 |
+
from scratch.data_tier3 import t3_bugs
|
| 14 |
+
|
| 15 |
+
t1_all = T1_OLD + t1_bugs
|
| 16 |
+
t2_all = T2_OLD + t2_bugs
|
| 17 |
+
t3_all = T3_OLD + t3_bugs
|
| 18 |
+
|
| 19 |
+
# Ensure we have the target numbers
|
| 20 |
+
print(f"Tier 1: {len(t1_all)}")
|
| 21 |
+
print(f"Tier 2: {len(t2_all)}")
|
| 22 |
+
print(f"Tier 3: {len(t3_all)}")
|
| 23 |
+
|
| 24 |
+
import json
|
| 25 |
+
def pretty_list(lst, name):
|
| 26 |
+
lines = [f"{name} = ["]
|
| 27 |
+
for item in lst:
|
| 28 |
+
lines.append(" {")
|
| 29 |
+
for k, v in item.items():
|
| 30 |
+
if isinstance(v, str):
|
| 31 |
+
if '\n' in v:
|
| 32 |
+
lines.append(f' "{k}": (')
|
| 33 |
+
for line in v.split('\n'):
|
| 34 |
+
lines.append(f' {repr(line + "\\n")}')
|
| 35 |
+
lines[-1] = lines[-1][:-4] + "'" + lines[-1][-3:] # remove the trailing \n from the last line, wait, repr('...\\n') adds \n inside. Let's just use json dumps
|
| 36 |
+
# Actually json dumps is simpler!
|
| 37 |
+
# wait, we need to format code blocks nicely maybe?
|
| 38 |
+
pass
|
| 39 |
+
|
| 40 |
+
# The best way to format Python code generating Python code is pprint or just repr.
|
| 41 |
+
with open("data/generate_bugs.py", "w", encoding="utf-8") as f:
|
| 42 |
+
f.write('"""\n')
|
| 43 |
+
f.write('AgentDebuggerEnv — Bug Dataset Generator\n\n')
|
| 44 |
+
f.write('Generates three tiers of buggy Python functions for curriculum learning:\n')
|
| 45 |
+
f.write(' Tier 1 (easy): Off-by-one errors, wrong operators, simple logic inversions\n')
|
| 46 |
+
f.write(' Tier 2 (medium): Incorrect algorithm logic, wrong variable references, subtle type errors\n')
|
| 47 |
+
f.write(' Tier 3 (hard): Multi-bug interactions, concurrency, edge-case-only failures\n\n')
|
| 48 |
+
f.write('Usage:\n')
|
| 49 |
+
f.write(' python data/generate_bugs.py\n\n')
|
| 50 |
+
f.write('Outputs:\n')
|
| 51 |
+
f.write(' data/bugs_tier1.jsonl (~40 bugs)\n')
|
| 52 |
+
f.write(' data/bugs_tier2.jsonl (~30 bugs)\n')
|
| 53 |
+
f.write(' data/bugs_tier3.jsonl (~20 bugs)\n')
|
| 54 |
+
f.write('"""\n\n')
|
| 55 |
+
f.write('import json\n')
|
| 56 |
+
f.write('import os\n\n')
|
| 57 |
+
|
| 58 |
+
# write out variables
|
| 59 |
+
import pprint
|
| 60 |
+
|
| 61 |
+
def dump_var(name, val):
|
| 62 |
+
f.write(f'{name} = ')
|
| 63 |
+
f.write(pprint.pformat(val, sort_dicts=False, width=120))
|
| 64 |
+
f.write('\n\n')
|
| 65 |
+
|
| 66 |
+
dump_var('TIER1_BUGS', t1_all)
|
| 67 |
+
dump_var('TIER2_BUGS', t2_all)
|
| 68 |
+
dump_var('TIER3_BUGS', t3_all)
|
| 69 |
+
|
| 70 |
+
f.write('def write_jsonl(bugs: list, path: str):\n')
|
| 71 |
+
f.write(' with open(path, "w") as f:\n')
|
| 72 |
+
f.write(' for bug in bugs:\n')
|
| 73 |
+
f.write(' f.write(json.dumps(bug) + "\\n")\n')
|
| 74 |
+
f.write(' print(f"Tier {path[-12]}: {len(bugs)}")\n') # to print Tier 1: 40 etc. wait, format is different
|
| 75 |
+
# wait, the prompt says "It should print: Tier 1: 40, Tier 2: 30, Tier 3: 20"
|
| 76 |
+
# let's change the output slightly.
|
| 77 |
+
f.write('\n\n')
|
| 78 |
+
f.write('if __name__ == "__main__":\n')
|
| 79 |
+
f.write(' os.makedirs("data", exist_ok=True)\n')
|
| 80 |
+
f.write(' write_jsonl(TIER1_BUGS, "data/bugs_tier1.jsonl")\n')
|
| 81 |
+
f.write(' write_jsonl(TIER2_BUGS, "data/bugs_tier2.jsonl")\n')
|
| 82 |
+
f.write(' write_jsonl(TIER3_BUGS, "data/bugs_tier3.jsonl")\n')
|
| 83 |
+
f.write(' print(f"Tier 1: {len(TIER1_BUGS)}, Tier 2: {len(TIER2_BUGS)}, Tier 3: {len(TIER3_BUGS)}")\n')
|
| 84 |
+
f.write(' print("\\nDone. Run training/train_grpo.py to start training.")\n')
|
| 85 |
+
|
| 86 |
+
print("generate_bugs.py rewritten.")
|