{"id": "999997e0574eb8d354652c3ded0ae7b5", "language": "python", "function_name": "reverse_string", "function_code": "def reverse_string(s: str) -> str:\n return s[::-1]", "edge_case_type": "palindrome_input", "edge_case_description": "reversing a palindrome returns the same string", "test_framework": "pytest", "unit_test": "def test_reverse_palindrome():\n assert reverse_string(\"racecar\") == \"racecar\"", "difficulty": "easy"} {"id": "ddc383c36c48281a65e54850561c615d", "language": "rust", "function_name": "count_vowels", "function_code": "pub fn count_vowels(s: &str) -> usize {\n s.chars().filter(|c| \"aeiouAEIOU\".contains(*c)).count()\n}", "edge_case_type": "mixed", "edge_case_description": "mixed content counted correctly", "test_framework": "rust-test", "unit_test": "#[test]\nfn test_vowels_mixed() {\n assert_eq!(count_vowels(\"Hello World\"), 3);\n}", "difficulty": "medium"} {"id": "b20c38fcc95e9e0d75d661a2aedda85f", "language": "typescript", "function_name": "retry", "function_code": "export async function retry(fn: () => Promise, times: number): Promise {\n let lastErr: unknown;\n for (let i = 0; i < times; i++) {\n try { return await fn(); } catch (e) { lastErr = e; }\n }\n throw lastErr;\n}", "edge_case_type": "exhausts_retries", "edge_case_description": "rejects after all attempts fail", "test_framework": "jest", "unit_test": "test('retry exhausted', async () => {\n const fn = jest.fn().mockRejectedValue(new Error('fail'));\n await expect(retry(fn, 3)).rejects.toThrow('fail');\n expect(fn).toHaveBeenCalledTimes(3);\n});", "difficulty": "medium"} {"id": "b7e2d78f060d99ab85df3689aafa0fa5", "language": "typescript", "function_name": "retry", "function_code": "export async function retry(fn: () => Promise, times: number): Promise {\n let lastErr: unknown;\n for (let i = 0; i < times; i++) {\n try { return await fn(); } catch (e) { lastErr = e; }\n }\n throw lastErr;\n}", "edge_case_type": "succeeds_after_fail", "edge_case_description": "retries after failure and resolves", "test_framework": "jest", "unit_test": "test('retry after fail', async () => {\n const fn = jest.fn().mockRejectedValueOnce(new Error()).mockResolvedValue('ok');\n await expect(retry(fn, 3)).resolves.toBe('ok');\n expect(fn).toHaveBeenCalledTimes(2);\n});", "difficulty": "medium"} {"id": "9b9f5bfb414221e4d1620073ea18d78a", "language": "rust", "function_name": "fibonacci", "function_code": "pub fn fibonacci(n: u64) -> u64 {\n if n <= 1 { return n; }\n let (mut a, mut b) = (0u64, 1u64);\n for _ in 2..=n {\n let c = a + b;\n a = b;\n b = c;\n }\n b\n}", "edge_case_type": "two", "edge_case_description": "fibonacci(2) is 1", "test_framework": "rust-test", "unit_test": "#[test]\nfn test_fib_two() {\n assert_eq!(fibonacci(2), 1);\n}", "difficulty": "easy"} {"id": "cabe773e9c07ceecc2cd6ced5e7dc106", "language": "java", "function_name": "binarySearch", "function_code": "public static int binarySearch(int[] arr, int target) {\n int lo = 0, hi = arr.length - 1;\n while (lo <= hi) {\n int mid = (lo + hi) >>> 1;\n if (arr[mid] == target) return mid;\n else if (arr[mid] < target) lo = mid + 1;\n else hi = mid - 1;\n }\n return -1;\n}", "edge_case_type": "single_element_not_found", "edge_case_description": "single element array, target not found", "test_framework": "junit4", "unit_test": "@Test\npublic void testBSearchSingleMiss() {\n assertEquals(-1, binarySearch(new int[]{42}, 99));\n}", "difficulty": "easy"} {"id": "ff22acc265ff16650c78afb3d67a09d6", "language": "java", "function_name": "binarySearch", "function_code": "public static int binarySearch(int[] arr, int target) {\n int lo = 0, hi = arr.length - 1;\n while (lo <= hi) {\n int mid = (lo + hi) >>> 1;\n if (arr[mid] == target) return mid;\n else if (arr[mid] < target) lo = mid + 1;\n else hi = mid - 1;\n }\n return -1;\n}", "edge_case_type": "not_found", "edge_case_description": "target not in array returns -1", "test_framework": "junit4", "unit_test": "@Test\npublic void testBSearchNotFound() {\n assertEquals(-1, binarySearch(new int[]{1,3,5,7}, 4));\n}", "difficulty": "easy"} {"id": "cf2414de6872355021839eb4386f5257", "language": "python", "function_name": "gcd", "function_code": "def gcd(a: int, b: int) -> int:\n while b:\n a, b = b, a % b\n return a", "edge_case_type": "larger_first", "edge_case_description": "gcd is commutative", "test_framework": "pytest", "unit_test": "def test_gcd_commutative():\n assert gcd(48, 18) == gcd(18, 48)", "difficulty": "medium"} {"id": "6164fabc3397cb5726f739aebcea4823", "language": "go", "function_name": "WordCount", "function_code": "func WordCount(s string) map[string]int {\n\tcounts := make(map[string]int)\n\tfor _, w := range strings.Fields(s) {\n\t\tcounts[strings.ToLower(w)]++\n\t}\n\treturn counts\n}", "edge_case_type": "case_insensitive", "edge_case_description": "counting is case-insensitive", "test_framework": "testing", "unit_test": "func TestWordCountCase(t *testing.T) {\n\tresult := WordCount(\"Hello HELLO hello\")\n\tif result[\"hello\"] != 3 {\n\t\tt.Errorf(\"expected 3, got %v\", result[\"hello\"])\n\t}\n}", "difficulty": "medium"} {"id": "9d8a9ed30d5ffaf5c93fa7cc9dd166e0", "language": "python", "function_name": "reverse_string", "function_code": "def reverse_string(s: str) -> str:\n return s[::-1]", "edge_case_type": "unicode", "edge_case_description": "unicode characters are reversed correctly", "test_framework": "pytest", "unit_test": "def test_reverse_unicode():\n assert reverse_string(\"h\u00e9llo\") == \"oll\u00e9h\"", "difficulty": "medium"} {"id": "71bd2567a9b226a1a23376e885fa27fc", "language": "python", "function_name": "word_count", "function_code": "def word_count(text: str) -> dict[str, int]:\n words = text.lower().split()\n counts: dict[str, int] = {}\n for w in words:\n counts[w] = counts.get(w, 0) + 1\n return counts", "edge_case_type": "repeated_word", "edge_case_description": "repeated word accumulates count", "test_framework": "pytest", "unit_test": "def test_word_count_repeated():\n assert word_count(\"the cat sat the cat\") == {\"the\": 2, \"cat\": 2, \"sat\": 1}", "difficulty": "medium"} {"id": "c2214e0ef09b2e26c6a275ec7530369b", "language": "typescript", "function_name": "deepEqual", "function_code": "export function deepEqual(a: unknown, b: unknown): boolean {\n return JSON.stringify(a) === JSON.stringify(b);\n}", "edge_case_type": "primitive_not_equal", "edge_case_description": "different primitives not equal", "test_framework": "jest", "unit_test": "test('deepEqual different primitives', () => {\n expect(deepEqual(1, 2)).toBe(false);\n});", "difficulty": "medium"} {"id": "ccc18d45baae8a736bb997f22be020b0", "language": "rust", "function_name": "reverse_string", "function_code": "pub fn reverse_string(s: &str) -> String {\n s.chars().rev().collect()\n}", "edge_case_type": "palindrome", "edge_case_description": "palindrome reverses to itself", "test_framework": "rust-test", "unit_test": "#[test]\nfn test_reverse_palindrome() {\n assert_eq!(reverse_string(\"racecar\"), \"racecar\");\n}", "difficulty": "easy"} {"id": "95dfc29c444fccb40083186114a79df8", "language": "typescript", "function_name": "flattenDeep", "function_code": "export function flattenDeep(arr: unknown[]): unknown[] {\n const result: unknown[] = [];\n const stack = [...arr];\n while (stack.length) {\n const item = stack.pop();\n if (Array.isArray(item)) {\n stack.push(...item);\n } else {\n result.unshift(item);\n }\n }\n return result;\n}", "edge_case_type": "empty", "edge_case_description": "empty array returns empty", "test_framework": "jest", "unit_test": "test('flattenDeep empty', () => {\n expect(flattenDeep([])).toEqual([]);\n});", "difficulty": "easy"} {"id": "0ca7318ae18f1e39358a2501ebcb49d4", "language": "python", "function_name": "truncate", "function_code": "def truncate(s: str, max_len: int) -> str:\n if len(s) <= max_len:\n return s\n return s[:max_len] + \"...\"", "edge_case_type": "max_len_one", "edge_case_description": "max_len of 1 truncates to first char plus ellipsis", "test_framework": "pytest", "unit_test": "def test_truncate_one_max():\n assert truncate(\"hello\", 1) == \"h...\"", "difficulty": "medium"} {"id": "2a4c3f64bf4a0e5daa3dbddb46302c7d", "language": "python", "function_name": "chunk_list", "function_code": "def chunk_list(lst: list, size: int) -> list[list]:\n if size <= 0:\n raise ValueError(\"size must be positive\")\n return [lst[i:i + size] for i in range(0, len(lst), size)]", "edge_case_type": "empty_list", "edge_case_description": "empty list returns empty list", "test_framework": "pytest", "unit_test": "def test_chunk_empty():\n assert chunk_list([], 3) == []", "difficulty": "easy"} {"id": "3b7045d23318848318bae40893dac3c2", "language": "python", "function_name": "levenshtein", "function_code": "def levenshtein(s: str, t: str) -> int:\n \"\"\"Compute Levenshtein (edit) distance between s and t.\"\"\"\n m, n = len(s), len(t)\n dp = list(range(n + 1))\n for i in range(1, m + 1):\n prev = dp[0]\n dp[0] = i\n for j in range(1, n + 1):\n tmp = dp[j]\n if s[i-1] == t[j-1]:\n dp[j] = prev\n else:\n dp[j] = 1 + min(prev, dp[j], dp[j-1])\n prev = tmp\n return dp[n]", "edge_case_type": "single_deletion", "edge_case_description": "one deletion has distance 1", "test_framework": "pytest", "unit_test": "def test_lev_delete():\n assert levenshtein(\"cart\", \"cat\") == 1", "difficulty": "medium"} {"id": "20094732ec7857d528e10e9995390ef5", "language": "typescript", "function_name": "retry", "function_code": "export async function retry(fn: () => Promise, times: number): Promise {\n let lastErr: unknown;\n for (let i = 0; i < times; i++) {\n try { return await fn(); } catch (e) { lastErr = e; }\n }\n throw lastErr;\n}", "edge_case_type": "zero_retries", "edge_case_description": "0 attempts immediately throws", "test_framework": "jest", "unit_test": "test('retry zero times', async () => {\n const fn = jest.fn().mockRejectedValue(new Error('err'));\n await expect(retry(fn, 0)).rejects.toThrow();\n expect(fn).not.toHaveBeenCalled();\n});", "difficulty": "hard"} {"id": "7931772393ec2c524a6196ae77b6c5e8", "language": "javascript", "function_name": "groupBy", "function_code": "function groupBy(arr, key) {\n return arr.reduce((acc, item) => {\n const k = item[key];\n if (!acc[k]) acc[k] = [];\n acc[k].push(item);\n return acc;\n }, {});\n}", "edge_case_type": "all_same_key", "edge_case_description": "all items share same key value", "test_framework": "jest", "unit_test": "test(\"groupBy all same key\", () => {\n const items = [{t: \"a\", v: 1}, {t: \"a\", v: 2}];\n expect(groupBy(items, \"t\")).toEqual({ a: [{t:\"a\",v:1},{t:\"a\",v:2}] });\n});", "difficulty": "medium"} {"id": "1f1478258417606f799298b89f185c88", "language": "typescript", "function_name": "omit", "function_code": "export function omit(obj: T, keys: K[]): Omit {\n const result = { ...obj };\n for (const k of keys) delete result[k];\n return result as Omit;\n}", "edge_case_type": "does_not_mutate", "edge_case_description": "original object is not mutated", "test_framework": "jest", "unit_test": "test('omit no mutation', () => {\n const orig = {a:1,b:2};\n omit(orig, ['a']);\n expect(orig).toEqual({a:1,b:2});\n});", "difficulty": "hard"} {"id": "68d7a50776f3cde548061a840289fb87", "language": "go", "function_name": "Divide", "function_code": "func Divide(a, b float64) (float64, error) {\n\tif b == 0 {\n\t\treturn 0, errors.New(\"division by zero\")\n\t}\n\treturn a / b, nil\n}", "edge_case_type": "both_zero", "edge_case_description": "a=0 returns 0 without error", "test_framework": "testing", "unit_test": "func TestDivideZeroNumerator(t *testing.T) {\n\tresult, err := Divide(0, 5)\n\tif err != nil || result != 0 {\n\t\tt.Errorf(\"expected 0, got %v (err %v)\", result, err)\n\t}\n}", "difficulty": "medium"} {"id": "913068a9b707936040cefb7b3b883b94", "language": "python", "function_name": "is_prime", "function_code": "def is_prime(n: int) -> bool:\n if n < 2:\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", "edge_case_type": "composite", "edge_case_description": "composite number returns False", "test_framework": "pytest", "unit_test": "def test_is_prime_composite():\n assert is_prime(9) is False", "difficulty": "easy"} {"id": "315f21f83a02441422cbe4e0ab6fc10a", "language": "javascript", "function_name": "reverseString", "function_code": "function reverseString(s) {\n return s.split('').reverse().join('');\n}", "edge_case_type": "unicode", "edge_case_description": "unicode emoji string reverses character sequence", "test_framework": "jest", "unit_test": "test(\"reverseString unicode\", () => {\n expect(reverseString(\"abc\")).toBe(\"cba\");\n});", "difficulty": "medium"} {"id": "a3b38ae5e29c4bad3a3358353acc411b", "language": "java", "function_name": "binarySearch", "function_code": "public static int binarySearch(int[] arr, int target) {\n int lo = 0, hi = arr.length - 1;\n while (lo <= hi) {\n int mid = (lo + hi) >>> 1;\n if (arr[mid] == target) return mid;\n else if (arr[mid] < target) lo = mid + 1;\n else hi = mid - 1;\n }\n return -1;\n}", "edge_case_type": "empty_array", "edge_case_description": "empty array returns -1", "test_framework": "junit4", "unit_test": "@Test\npublic void testBSearchEmpty() {\n assertEquals(-1, binarySearch(new int[]{}, 5));\n}", "difficulty": "easy"} {"id": "a6779f80735ed81693aa85f460c6bca4", "language": "javascript", "function_name": "throttle", "function_code": "function throttle(fn, interval) {\n let lastTime = 0;\n return (...args) => {\n const now = Date.now();\n if (now - lastTime >= interval) {\n lastTime = now;\n return fn(...args);\n }\n };\n}", "edge_case_type": "allows_after_interval", "edge_case_description": "call after interval fires again", "test_framework": "jest", "unit_test": "test(\"throttle allows after interval\", () => {\n jest.useFakeTimers();\n const fn = jest.fn();\n const throttled = throttle(fn, 100);\n throttled();\n jest.advanceTimersByTime(150);\n throttled();\n expect(fn).toHaveBeenCalledTimes(2);\n jest.useRealTimers();\n});", "difficulty": "hard"} {"id": "1d2ef35b8f9af7959d7fca36122c6a85", "language": "python", "function_name": "divide", "function_code": "def divide(a: float, b: float) -> float:\n \"\"\"Return a divided by b.\"\"\"\n return a / b", "edge_case_type": "zero_division", "edge_case_description": "divisor is zero raises ZeroDivisionError", "test_framework": "pytest", "unit_test": "import pytest\n\ndef test_divide_zero_divisor():\n with pytest.raises(ZeroDivisionError):\n divide(10, 0)", "difficulty": "medium"} {"id": "7ce1176558dfffb3b66aa574d1d27a31", "language": "python", "function_name": "Stack", "function_code": "class Stack:\n def __init__(self):\n self._data = []\n\n def push(self, item):\n self._data.append(item)\n\n def pop(self):\n if not self._data:\n raise IndexError(\"pop from empty stack\")\n return self._data.pop()\n\n def peek(self):\n if not self._data:\n raise IndexError(\"peek at empty stack\")\n return self._data[-1]\n\n def is_empty(self):\n return len(self._data) == 0\n\n def size(self):\n return len(self._data)", "edge_case_type": "push_pop", "edge_case_description": "pushed item is returned by pop", "test_framework": "pytest", "unit_test": "def test_stack_push_pop():\n s = Stack()\n s.push(42)\n assert s.pop() == 42", "difficulty": "easy"} {"id": "7a72375ddb4d8a618d83b94fdf4952ff", "language": "rust", "function_name": "median", "function_code": "pub fn median(mut nums: Vec) -> Option {\n if nums.is_empty() { return None; }\n nums.sort_by(|a, b| a.partial_cmp(b).unwrap());\n let mid = nums.len() / 2;\n if nums.len() % 2 == 1 {\n Some(nums[mid])\n } else {\n Some((nums[mid - 1] + nums[mid]) / 2.0)\n }\n}", "edge_case_type": "unsorted_input", "edge_case_description": "unsorted input is sorted before median computed", "test_framework": "rust-test", "unit_test": "#[test]\nfn test_median_unsorted() {\n assert_eq!(median(vec![5.0, 1.0, 3.0]), Some(3.0));\n}", "difficulty": "medium"} {"id": "7c94abc617ff163960ae988390504a05", "language": "python", "function_name": "is_prime", "function_code": "def is_prime(n: int) -> bool:\n if n < 2:\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", "edge_case_type": "zero", "edge_case_description": "0 is not prime", "test_framework": "pytest", "unit_test": "def test_is_prime_zero():\n assert is_prime(0) is False", "difficulty": "easy"} {"id": "18f1eb8d31e99da010285cb59655ddd0", "language": "python", "function_name": "merge_sorted", "function_code": "def merge_sorted(a: list[int], b: list[int]) -> list[int]:\n \"\"\"Merge two sorted lists into one sorted list.\"\"\"\n result, i, j = [], 0, 0\n while i < len(a) and j < len(b):\n if a[i] <= b[j]:\n result.append(a[i]); i += 1\n else:\n result.append(b[j]); j += 1\n result.extend(a[i:])\n result.extend(b[j:])\n return result", "edge_case_type": "both_empty", "edge_case_description": "merging two empty lists returns empty list", "test_framework": "pytest", "unit_test": "def test_merge_both_empty():\n assert merge_sorted([], []) == []", "difficulty": "easy"} {"id": "c1603768b99d39aa7c3d5cfc4510248b", "language": "javascript", "function_name": "divide", "function_code": "function divide(a, b) {\n if (b === 0) throw new Error('Division by zero');\n return a / b;\n}", "edge_case_type": "both_negative", "edge_case_description": "both operands negative yields positive", "test_framework": "jest", "unit_test": "test(\"divide both negative\", () => {\n expect(divide(-6, -3)).toBe(2);\n});", "difficulty": "medium"} {"id": "c31fae5a7a70be0e84fc0efe01d2fa6f", "language": "rust", "function_name": "find_max", "function_code": "pub fn find_max(nums: &[i64]) -> Option {\n nums.iter().copied().reduce(i64::max)\n}", "edge_case_type": "single", "edge_case_description": "single element returns Some of it", "test_framework": "rust-test", "unit_test": "#[test]\nfn test_find_max_single() {\n assert_eq!(find_max(&[42]), Some(42));\n}", "difficulty": "easy"} {"id": "3f4b2845b0061377333baa6e0f97c8e4", "language": "python", "function_name": "chunk_list", "function_code": "def chunk_list(lst: list, size: int) -> list[list]:\n if size <= 0:\n raise ValueError(\"size must be positive\")\n return [lst[i:i + size] for i in range(0, len(lst), size)]", "edge_case_type": "negative_size", "edge_case_description": "negative chunk size raises ValueError", "test_framework": "pytest", "unit_test": "import pytest\n\ndef test_chunk_negative_size():\n with pytest.raises(ValueError):\n chunk_list([1, 2, 3], -1)", "difficulty": "medium"} {"id": "1329cb4c2e0fd29378650274a303dd54", "language": "go", "function_name": "IsPrime", "function_code": "func IsPrime(n int) bool {\n\tif n < 2 {\n\t\treturn false\n\t}\n\tfor i := 2; i*i <= n; i++ {\n\t\tif n%i == 0 {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}", "edge_case_type": "composite", "edge_case_description": "composite number is not prime", "test_framework": "testing", "unit_test": "func TestIsPrimeComposite(t *testing.T) {\n\tif IsPrime(15) {\n\t\tt.Error(\"15 should not be prime\")\n\t}\n}", "difficulty": "easy"} {"id": "beb9e5ff2449f2520787f07417e8b432", "language": "python", "function_name": "string_to_int", "function_code": "def string_to_int(s: str) -> int | None:\n \"\"\"Parse s as integer, returning None on failure.\"\"\"\n try:\n return int(s.strip())\n except (ValueError, AttributeError):\n return None", "edge_case_type": "float_string", "edge_case_description": "float string returns None", "test_framework": "pytest", "unit_test": "def test_str2int_float():\n assert string_to_int('3.14') is None", "difficulty": "medium"} {"id": "3cba2399a7bd6f73af431025f94f00ec", "language": "go", "function_name": "IsPrime", "function_code": "func IsPrime(n int) bool {\n\tif n < 2 {\n\t\treturn false\n\t}\n\tfor i := 2; i*i <= n; i++ {\n\t\tif n%i == 0 {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}", "edge_case_type": "one", "edge_case_description": "1 is not prime", "test_framework": "testing", "unit_test": "func TestIsPrimeOne(t *testing.T) {\n\tif IsPrime(1) {\n\t\tt.Error(\"1 should not be prime\")\n\t}\n}", "difficulty": "easy"} {"id": "4388d84ed4a0ad7c190167a9174ef3c2", "language": "java", "function_name": "isPalindrome", "function_code": "public static boolean isPalindrome(String s) {\n String clean = s.toLowerCase().replaceAll(\"\\\\s\", \"\");\n return clean.equals(new StringBuilder(clean).reverse().toString());\n}", "edge_case_type": "empty_string", "edge_case_description": "empty string is palindrome", "test_framework": "junit4", "unit_test": "@Test\npublic void testPalindromeEmpty() {\n assertTrue(isPalindrome(\"\"));\n}", "difficulty": "easy"} {"id": "068cd42cfec33431f9fca82fe8792a5b", "language": "python", "function_name": "group_consecutive", "function_code": "def group_consecutive(nums: list[int]) -> list[list[int]]:\n \"\"\"Group consecutive integers into sublists.\"\"\"\n if not nums:\n return []\n groups, current = [[nums[0]]], [nums[0]]\n for n in nums[1:]:\n if n == current[-1] + 1:\n current.append(n)\n else:\n groups.append([n])\n current = groups[-1]\n return groups", "edge_case_type": "negative_values", "edge_case_description": "negative consecutive integers grouped correctly", "test_framework": "pytest", "unit_test": "def test_group_consec_negatives():\n assert group_consecutive([-3, -2, -1, 1]) == [[-3, -2, -1], [1]]", "difficulty": "medium"}