{
  "name": "quixbugs-python-find_first_in_sorted",
  "description": "Fix bug in: find first in sorted",
  "dataset": "quixbugs",
  "instruction": "There is a Python file called find_first_in_sorted.py in the current directory. It contains a buggy implementation of the find first in sorted algorithm. Find and fix the bug. The fix should be minimal - typically a single line change. Do not rewrite the entire function.",
  "setup_files": {
    "find_first_in_sorted.py": "def find_first_in_sorted(arr, x):\n    lo = 0\n    hi = len(arr)\n\n    while lo <= hi:\n        mid = (lo + hi) // 2\n\n        if x == arr[mid] and (mid == 0 or x != arr[mid - 1]):\n            return mid\n\n        elif x <= arr[mid]:\n            hi = mid\n\n        else:\n            lo = mid + 1\n\n    return -1\n\n\n\"\"\"\nFancy Binary Search\nfancy-binsearch\n\n\nInput:\n    arr: A sorted list of ints\n    x: A value to find\n\nOutput:\n    The lowest index i such that arr[i] == x, or -1 if x not in arr\n\nExample:\n    >>> find_first_in_sorted([3, 4, 5, 5, 5, 5, 6], 5)\n    2\n\"\"\"\n",
    "test_find_first_in_sorted.py": "import sys\n\nfrom find_first_in_sorted import find_first_in_sorted\n\nFUNC_NAME = \"find_first_in_sorted\"\ntest_cases = [[[[3, 4, 5, 5, 5, 5, 6], 5], 2], [[[3, 4, 5, 5, 5, 5, 6], 7], -1], [[[3, 4, 5, 5, 5, 5, 6], 2], -1], [[[3, 6, 7, 9, 9, 10, 14, 27], 14], 6], [[[0, 1, 6, 8, 13, 14, 67, 128], 80], -1], [[[0, 1, 6, 8, 13, 14, 67, 128], 67], 6], [[[0, 1, 6, 8, 13, 14, 67, 128], 128], 7]]\n\npassed = 0\nfailed = 0\nfor tc in test_cases:\n    inputs = tc[0]\n    expected = tc[1]\n    try:\n        result = find_first_in_sorted(*inputs)\n        if result == expected:\n            passed += 1\n        else:\n            print(f\"FAIL: {FUNC_NAME}({inputs}) = {result}, expected {expected}\")\n            failed += 1\n    except Exception as e:\n        print(f\"ERROR: {FUNC_NAME}({inputs}) raised {e}\")\n        failed += 1\n\nprint(f\"{passed}/{passed+failed} tests passed\")\nif failed > 0:\n    sys.exit(1)\n"
  },
  "verify": "cd $BENCH_WORK_DIR && python3 test_find_first_in_sorted.py",
  "timeout": 180000,
  "tags": [
    "quixbugs",
    "python",
    "bug-fix"
  ]
}