Commit
·
efdda4b
1
Parent(s):
dcfdf56
Fix Rust compilation
Browse files
data/rust/data/humanevalbugs.jsonl
CHANGED
@@ -7,7 +7,7 @@
|
|
7 |
{"task_id": "Rust/6", "prompt": "\n/*\n Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\n For each of the group, output the deepest level of nesting of parentheses.\n E.g. (()()) has maximum two levels of nesting while ((())) has three.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn parse_nested_parens(paren_string:String) -> Vec<i32>{\n", "canonical_solution": "\n let mut result:Vec<i32> = vec![];\n let mut depth:i32 = 0;\n let mut max_depth:i32 = 0;\n\n for splits in paren_string.split(' '){\n for c in splits.chars(){ \n if c == '('{\n depth = depth + 1;\n max_depth = max(depth, max_depth);\n }\n else{\n depth = depth - 1;\n }\n }\n \n if depth == 0 {\n result.push(max_depth);\n max_depth = 0;\n }\n }\n\n return result;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n#[test]\n fn test_parse_nested_parens() {\n assert!(\n parse_nested_parens(String::from(\"(()()) ((())) () ((())()())\")) == vec![2, 3, 1, 3]\n );\n assert!(parse_nested_parens(String::from(\"() (()) ((())) (((())))\")) == vec![1, 2, 3, 4]);\n assert!(parse_nested_parens(String::from(\"(()(())((())))\")) == vec![4]);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut result:Vec<i32> = vec![];\n let mut depth:i32 = 0;\n let mut max_depth:i32 = 0;\n\n for splits in paren_string.split(' '){\n for c in splits.chars(){ \n if c == '('{\n depth = depth + 1;\n max_depth = max(depth, max_depth);\n }\n else{\n max_depth = depth - 1;\n }\n }\n \n if depth == 0 {\n result.push(max_depth);\n max_depth = 0;\n }\n }\n\n return result;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "parse_nested_parens"}
|
8 |
{"task_id": "Rust/7", "prompt": "\n/*\n Filter an input list of strings only for ones that contain given substring\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn filter_by_substring(strings: Vec<String>, substring:String) -> Vec<String>{\n", "canonical_solution": "\n return strings.iter().filter(|x:&&String| x.contains(&substring)).map(String::from).collect();\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_filter_by_substring() {\n let v_empty: Vec<String> = vec![];\n assert!(filter_by_substring(vec![], String::from(\"john\")) == v_empty);\n assert!(\n filter_by_substring(\n vec![\n \"xxx\".to_string(),\n \"asd\".to_string(),\n \"xxy\".to_string(),\n \"john doe\".to_string(),\n \"xxxAAA\".to_string(),\n \"xxx\".to_string()\n ],\n String::from(\"xxx\")\n ) == vec![\"xxx\", \"xxxAAA\", \"xxx\"]\n );\n assert!(\n filter_by_substring(\n vec![\n \"xxx\".to_string(),\n \"asd\".to_string(),\n \"aaaxxy\".to_string(),\n \"john doe\".to_string(),\n \"xxxAAA\".to_string(),\n \"xxx\".to_string()\n ],\n String::from(\"xx\")\n ) == vec![\"xxx\", \"aaaxxy\", \"xxxAAA\", \"xxx\"]\n );\n assert!(\n filter_by_substring(\n vec![\n \"grunt\".to_string(),\n \"trumpet\".to_string(),\n \"prune\".to_string(),\n \"gruesome\".to_string()\n ],\n String::from(\"run\")\n ) == [\"grunt\", \"prune\"]\n );\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n return strings.iter().filter(|x| substring.contains(&**x)).cloned().collect();\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "filter_by_substring"}
|
9 |
{"task_id": "Rust/8", "prompt": "\n/*\n For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\n Empty sum should be equal to 0 and empty product should be equal to 1.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn sum_product(numbers:Vec<i32>) -> (i32,i32){\n", "canonical_solution": "\n let sum = |xs: &Vec<i32>| xs.iter()\n .fold(0, |mut sum, &val| { sum += val; \n sum }\n );\n let product = |xs: &Vec<i32>| xs.iter()\n .fold(1, |mut prod, &val| { prod *= val; \n prod }\n );\n return (sum(&numbers),product(&numbers));\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_sum_product() {\n assert!(sum_product(vec![]) == (0, 1));\n assert!(sum_product(vec![1, 1, 1]) == (3, 1));\n assert!(sum_product(vec![100, 0]) == (100, 0));\n assert!(sum_product(vec![3, 5, 7]) == (3 + 5 + 7, 3 * 5 * 7));\n assert!(sum_product(vec![10]) == (10, 10));\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let sum = |xs: &Vec<i32>| xs.iter()\n .fold(0, |mut sum, &val| { sum += val; \n sum }\n );\n let product = |xs: &Vec<i32>| xs.iter()\n .fold(0, |mut prod, &val| { prod *= val; \n prod }\n );\n return (sum(&numbers),product(&numbers));\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "sum_product"}
|
10 |
-
{"task_id": "Rust/9", "prompt": "\n/*\n From a given list of integers, generate a list of rolling maximum element found until given moment\n in the sequence.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn rolling_max(numbers:Vec<i32>) -> Vec<i32>{\n", "canonical_solution": "\n let mut running_max :Option<i32> = None;\n let mut result:Vec<i32> = vec![];\n\n for n in numbers{\n if running_max == None {\n running_max = Some(n);\n\n }else{\n running_max = max(running_max, Some(n));\n }\n\n result.push(running_max.unwrap());\n }\n return result;\n\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_rolling_max() {\n assert!(rolling_max(vec![]) == vec![]);\n assert!(rolling_max(vec![1, 2, 3, 4]) == vec![1, 2, 3, 4]);\n assert!(rolling_max(vec![4, 3, 2, 1]) == vec![4, 4, 4, 4]);\n assert!(rolling_max(vec![3, 2, 3, 100, 3]) == vec![3, 3, 3, 100, 100]);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut running_max :Option<i32> = None;\n let mut result:Vec<i32> = vec![];\n\n for n in numbers{\n if running_max == None {\n running_max = Some(n);\n\n }else{\n running_max = max(running_max, Some(n));\n }\n
|
11 |
{"task_id": "Rust/10", "prompt": "\n/*\n Find the shortest palindrome that begins with a supplied string.\n Algorithm idea is simple:\n - Find the longest postfix of supplied string that is a palindrome.\n - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn is_palindrome_10(str: &str) -> bool {\n", "canonical_solution": "\n let s: String = str.chars().rev().collect();\n return s==str;\n }\n \n fn make_palindrome(str: &str) -> String {\n let mut i: usize = 0;\n for i in 0..str.len() {\n let rstr: &str = &str[i..];\n if is_palindrome_10(rstr) {\n let nstr: &str = &str[0..i];\n let n2str: String = nstr.chars().rev().collect();\n return str.to_string()+&n2str;\n }\n }\n let n2str: String = str.chars().rev().collect();\n return str.to_string()+&n2str;\n }\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_make_palindrome() {\n assert_eq!(make_palindrome(\"\"), \"\");\n assert_eq!(make_palindrome(\"x\"), \"x\");\n assert_eq!(make_palindrome(\"xyz\"), \"xyzyx\");\n assert_eq!(make_palindrome(\"xyx\"), \"xyx\");\n assert_eq!(make_palindrome(\"jerry\"), \"jerryrrej\");\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let s: String = str.chars().rev().collect();\n return s==str;\n }\n \n fn make_palindrome(str: &str) -> String {\n let mut i: usize = 0;\n for i in 0..str.len() {\n let rstr: &str = &str[i..];\n if is_palindrome_10(str) {\n let nstr: &str = &str[0..i];\n let n2str: String = nstr.chars().rev().collect();\n return str.to_string()+&n2str;\n }\n }\n let n2str: String = str.chars().rev().collect();\n return str.to_string()+&n2str;\n }\n", "bug_type": "missing logic", "failure_symptoms": "stackoverflow", "entry_point": "make_palindrome"}
|
12 |
{"task_id": "Rust/11", "prompt": "\n/*\n Input are two strings a and b consisting only of 1s and 0s.\n Perform binary XOR on these inputs and return result also as a string.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn string_xor(a:String, b:String) -> String{\n", "canonical_solution": "\n\n let xor = |i:char, j:char| {if i == j{return \"0\".to_string()}else{return \"1\".to_string()}};\n return a.chars().into_iter().zip(b.chars().into_iter()).map(|(i,j)| \"\".to_string() + &xor(i,j)).collect(); \n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_string_xor() {\n assert!(string_xor(\"111000\".to_string(), \"101010\".to_string()) == \"010010\");\n assert!(string_xor(\"1\".to_string(), \"1\".to_string()) == \"0\");\n assert!(string_xor(\"0101\".to_string(), \"0000\".to_string()) == \"0101\");\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n\n let xor = |i:char, j:char| {if i == j{return \"1\".to_string()}else{return \"0\".to_string()}};\n return a.chars().into_iter().zip(b.chars().into_iter()).map(|(i,j)| \"\".to_string() + &xor(i,j)).collect(); \n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "string_xor"}
|
13 |
{"task_id": "Rust/12", "prompt": "\n/*\n Out of list of strings, return the longest one. Return the first one in case of multiple\n strings of the same length. Return None in case the input list is empty.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn longest(strings:Vec<String>) -> Option<String>{\n\n", "canonical_solution": "\n if strings.is_empty(){\n return None;\n }\n let mut max:i32 = 0;\n let mut res:String = String::new();\n\n for s in strings{\n if s.len() as i32 > max {\n res = s;\n max = res.len() as i32;\n } \n }\n return Some(res);\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n#[test]\n fn test_longest() {\n assert!(longest(vec![]) == None);\n assert!(\n longest(vec![\"x\".to_string(), \"y\".to_string(), \"z\".to_string()])\n == Some(\"x\".to_string())\n );\n assert!(\n longest(vec![\n \"x\".to_string(),\n \"yyy\".to_string(),\n \"zzzz\".to_string(),\n \"www\".to_string(),\n \"kkkk\".to_string(),\n \"abc\".to_string()\n ]) == Some(\"zzzz\".to_string())\n );\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n if strings.is_empty(){\n return None;\n }\n let mut max:i32 = 1;\n let mut res:String = String::new();\n\n for s in strings{\n if s.len() as i32 == max {\n res = s;\n max = res.len() as i32;\n } \n }\n return Some(res);\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "longest"}
|
@@ -30,7 +30,7 @@
|
|
30 |
{"task_id": "Rust/29", "prompt": "\n/*\n Filter an input list of strings only for ones that start with a given prefix.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn filter_by_prefix(strings:Vec<String>, prefix:String)-> Vec<String>{\n\n", "canonical_solution": "\n return strings.into_iter().filter(|s| s.starts_with(&prefix)).collect();\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n#[test]\n fn test_filter_by_prefix() {\n let v_empty: Vec<String> = vec![];\n assert!(filter_by_prefix(vec![], \"john\".to_string()) == v_empty);\n assert!(\n filter_by_prefix(\n vec![\n \"xxx\".to_string(),\n \"asd\".to_string(),\n \"xxy\".to_string(),\n \"john doe\".to_string(),\n \"xxxAAA\".to_string(),\n \"xxx\".to_string()\n ],\n \"xxx\".to_string()\n ) == vec![\"xxx\", \"xxxAAA\", \"xxx\"]\n );\n }\n\n\n}\n", "example_test": "None", "buggy_solution": "\n return strings.into_iter().filter(|s| s.ends_with(&prefix)).collect();\n}\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "filter_by_prefix"}
|
31 |
{"task_id": "Rust/30", "prompt": "\n/*\nReturn only positive numbers in the list.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn get_positive(numbers:Vec<i32>) -> Vec<i32>{\n\n", "canonical_solution": "\n return numbers.into_iter().filter(|n| n.is_positive()).collect();\n\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_get_positive() {\n assert!(get_positive(vec![-1, -2, 4, 5, 6]) == [4, 5, 6]);\n assert!(\n get_positive(vec![5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 3, 9, 123, 1]\n );\n assert!(get_positive(vec![-1, -2]) == []);\n assert!(get_positive(vec![]) == []);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n return numbers.into_iter().filter(|n| n.is_negative()).collect();\n\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "get_positive"}
|
32 |
{"task_id": "Rust/31", "prompt": "\n/*\nReturn true if a given number is prime, and false otherwise.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn is_prime(n:i32) -> bool{\n\n", "canonical_solution": "\n if n < 2{\n return false;\n}\nfor k in 2..n-1 {\n if n % k == 0{\n return false;\n }\n}\nreturn true;\n\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_is_prime() {\n assert!(is_prime(6) == false);\n assert!(is_prime(101) == true);\n assert!(is_prime(11) == true);\n assert!(is_prime(13441) == true);\n assert!(is_prime(61) == true);\n assert!(is_prime(4) == false);\n assert!(is_prime(1) == false);\n assert!(is_prime(5) == true);\n assert!(is_prime(11) == true);\n assert!(is_prime(17) == true);\n assert!(is_prime(5 * 17) == false);\n assert!(is_prime(11 * 7) == false);\n assert!(is_prime(13441 * 19) == false);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n if n < 1{\n return false;\n}\nfor k in 1..n-1 {\n if n % k == 0{\n return false;\n }\n}\nreturn true;\n\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_prime"}
|
33 |
-
{"task_id": "Rust/32", "prompt": "\n/*\n xs are coefficients of a polynomial.\n find_zero find x such that poly(x) = 0.\n find_zero returns only only zero point, even if there are many.\n Moreover, find_zero only takes list xs having even number of coefficients\n and largest non zero coefficient as it guarantees\n a solution.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn poly(xs: &Vec<f64>, x: f64) -> f64 {\n\n", "canonical_solution": "\n let mut sum = 0.0;\n for i in 0..xs.len() {\n sum += xs[i] * x.powi(i as i32);\n }\n sum\n }\n \n fn find_zero(xs: &Vec<f64>) -> f64 {\n let mut ans = 0.0;\n let mut value = poly(xs, ans);\n while value.abs() > 1e-6 {\n let mut driv = 0.0;\n for i in 1..xs.len() {\n driv += xs[i] * ans.powi((i - 1) as i32) * (i as f64);\n }\n ans = ans - value / driv;\n value = poly(xs, ans);\n }\n ans\n }\n", "test": "\n/*\n#[cfg(test)]\nmod tests {\n use super::*;\n\n#[test]\n fn test_poly() {\n let mut rng = rand::thread_rng();\n let mut solution: f64;\n let mut ncoeff: i32;\n for _ in 0..100 {\n ncoeff = 2 * (1 + rng.gen_range(0, 4));\n let mut coeffs = vec![];\n for _ in 0..ncoeff {\n let coeff = -10 + rng.gen_range(0, 21);\n if coeff == 0 {\n coeffs.push(1.0);\n } else {\n coeffs.push(coeff as f64);\n }\n }\n solution = find_zero(&coeffs);\n assert!(poly(&coeffs, solution).abs() < 1e-3);\n }\n }\n\n}\n*/\n", "example_test": "None", "buggy_solution": "\n let mut sum = 0.0;\n for i in 0..xs.len() {\n sum += xs[i] * x.powi(i as i32);\n }\n sum\n }\n \n fn find_zero(xs: &Vec<f64>) -> f64 {\n let mut driv = 0.0;\n let mut ans = 0.0;\n let mut value = poly(xs, ans);\n while value.abs() > 1e-6 {\n for i in 1..xs.len() {\n driv += xs[i] * ans.powi((i - 1) as i32) * (i as f64);\n }\n ans = ans - value / driv;\n value = poly(xs, ans);\n }\n
|
34 |
{"task_id": "Rust/33", "prompt": "\n/*\nThis function takes a list l and returns a list l' such that\n l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n to the values of the corresponding indicies of l, but sorted.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn sort_third(l: Vec<i32>) -> Vec<i32> {\n\n", "canonical_solution": "\n let mut third = vec![];\n let mut out:Vec<i32> = vec![];\n\n for (indx,elem) in l.iter().enumerate(){\n if indx%3 == 0 && indx != 0{\n third.push(elem)\n }\n }\n third.sort();\n let mut indx_t:usize = 0;\n\n for i in 0..l.len() {\n if i%3 == 0 && i != 0{\n if indx_t < third.len(){\n out.push(*third[indx_t]);\n indx_t += 1;\n }\n }else{\n out.push(l[i]);\n }\n \n }\n return out;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_sort_third() {\n let mut l = vec![1, 2, 3];\n assert_eq!(sort_third(l), vec![1, 2, 3]);\n l = vec![5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10];\n assert_eq!(sort_third(l), vec![5, 3, -5, 1, -3, 3, 2, 0, 123, 9, -10]);\n l = vec![5, 8, -12, 4, 23, 2, 3, 11, 12, -10];\n assert_eq!(sort_third(l), vec![5, 8, -12, -10, 23, 2, 3, 11, 12, 4]);\n l = vec![5, 6, 3, 4, 8, 9, 2];\n assert_eq!(sort_third(l), vec![5, 6, 3, 2, 8, 9, 4]);\n l = vec![5, 8, 3, 4, 6, 9, 2];\n assert_eq!(sort_third(l), vec![5, 8, 3, 2, 6, 9, 4]);\n l = vec![5, 6, 9, 4, 8, 3, 2];\n assert_eq!(sort_third(l), vec![5, 6, 9, 2, 8, 3, 4]);\n l = vec![5, 6, 3, 4, 8, 9, 2, 1];\n assert_eq!(sort_third(l), vec![5, 6, 3, 2, 8, 9, 4, 1]);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut third = vec![];\n let mut out:Vec<i32> = vec![];\n\n for (indx,elem) in l.iter().enumerate(){\n if indx%3 == 0 && indx != 0{\n third.push(elem)\n }\n }\n let mut indx_t:usize = 0;\n\n for i in 0..l.len() {\n if i%3 == 0 && i != 0{\n if indx_t < third.len(){\n out.push(*third[indx_t]);\n indx_t += 1;\n }\n }else{\n out.push(l[i]);\n }\n \n }\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sort_third"}
|
35 |
{"task_id": "Rust/34", "prompt": "\n/*\nReturn sorted unique elements in a list\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn unique(nmbs:Vec<i32>) -> Vec<i32>{\n\n", "canonical_solution": "\n let mut res:Vec<i32> = nmbs.clone();\n res.sort();\n res.dedup();\n return res;\n }\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_unique() {\n assert!(unique(vec![5, 3, 5, 2, 3, 3, 9, 0, 123]) == vec![0, 2, 3, 5, 9, 123]);\n }\n\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut res:Vec<i32> = nmbs.clone();\n res.sort();\n return res;\n }\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "unique"}
|
36 |
{"task_id": "Rust/35", "prompt": "\n/*\nReturn maximum element in the list.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn maximum(nmbs:Vec<i32>) -> i32{\n\n", "canonical_solution": "\n return *nmbs.iter().max().unwrap();\n }\n\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_maximum() {\n assert!(maximum(vec![1, 2, 3]) == 3);\n assert!(maximum(vec![5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) == 124);\n }\n\n\n}\n", "example_test": "None", "buggy_solution": "\n return *nmbs.iter().min().unwrap();\n }\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "max_element"}
|
|
|
7 |
{"task_id": "Rust/6", "prompt": "\n/*\n Input to this function is a string represented multiple groups for nested parentheses separated by spaces.\n For each of the group, output the deepest level of nesting of parentheses.\n E.g. (()()) has maximum two levels of nesting while ((())) has three.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn parse_nested_parens(paren_string:String) -> Vec<i32>{\n", "canonical_solution": "\n let mut result:Vec<i32> = vec![];\n let mut depth:i32 = 0;\n let mut max_depth:i32 = 0;\n\n for splits in paren_string.split(' '){\n for c in splits.chars(){ \n if c == '('{\n depth = depth + 1;\n max_depth = max(depth, max_depth);\n }\n else{\n depth = depth - 1;\n }\n }\n \n if depth == 0 {\n result.push(max_depth);\n max_depth = 0;\n }\n }\n\n return result;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n#[test]\n fn test_parse_nested_parens() {\n assert!(\n parse_nested_parens(String::from(\"(()()) ((())) () ((())()())\")) == vec![2, 3, 1, 3]\n );\n assert!(parse_nested_parens(String::from(\"() (()) ((())) (((())))\")) == vec![1, 2, 3, 4]);\n assert!(parse_nested_parens(String::from(\"(()(())((())))\")) == vec![4]);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut result:Vec<i32> = vec![];\n let mut depth:i32 = 0;\n let mut max_depth:i32 = 0;\n\n for splits in paren_string.split(' '){\n for c in splits.chars(){ \n if c == '('{\n depth = depth + 1;\n max_depth = max(depth, max_depth);\n }\n else{\n max_depth = depth - 1;\n }\n }\n \n if depth == 0 {\n result.push(max_depth);\n max_depth = 0;\n }\n }\n\n return result;\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "parse_nested_parens"}
|
8 |
{"task_id": "Rust/7", "prompt": "\n/*\n Filter an input list of strings only for ones that contain given substring\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn filter_by_substring(strings: Vec<String>, substring:String) -> Vec<String>{\n", "canonical_solution": "\n return strings.iter().filter(|x:&&String| x.contains(&substring)).map(String::from).collect();\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_filter_by_substring() {\n let v_empty: Vec<String> = vec![];\n assert!(filter_by_substring(vec![], String::from(\"john\")) == v_empty);\n assert!(\n filter_by_substring(\n vec![\n \"xxx\".to_string(),\n \"asd\".to_string(),\n \"xxy\".to_string(),\n \"john doe\".to_string(),\n \"xxxAAA\".to_string(),\n \"xxx\".to_string()\n ],\n String::from(\"xxx\")\n ) == vec![\"xxx\", \"xxxAAA\", \"xxx\"]\n );\n assert!(\n filter_by_substring(\n vec![\n \"xxx\".to_string(),\n \"asd\".to_string(),\n \"aaaxxy\".to_string(),\n \"john doe\".to_string(),\n \"xxxAAA\".to_string(),\n \"xxx\".to_string()\n ],\n String::from(\"xx\")\n ) == vec![\"xxx\", \"aaaxxy\", \"xxxAAA\", \"xxx\"]\n );\n assert!(\n filter_by_substring(\n vec![\n \"grunt\".to_string(),\n \"trumpet\".to_string(),\n \"prune\".to_string(),\n \"gruesome\".to_string()\n ],\n String::from(\"run\")\n ) == [\"grunt\", \"prune\"]\n );\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n return strings.iter().filter(|x| substring.contains(&**x)).cloned().collect();\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "filter_by_substring"}
|
9 |
{"task_id": "Rust/8", "prompt": "\n/*\n For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list.\n Empty sum should be equal to 0 and empty product should be equal to 1.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn sum_product(numbers:Vec<i32>) -> (i32,i32){\n", "canonical_solution": "\n let sum = |xs: &Vec<i32>| xs.iter()\n .fold(0, |mut sum, &val| { sum += val; \n sum }\n );\n let product = |xs: &Vec<i32>| xs.iter()\n .fold(1, |mut prod, &val| { prod *= val; \n prod }\n );\n return (sum(&numbers),product(&numbers));\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_sum_product() {\n assert!(sum_product(vec![]) == (0, 1));\n assert!(sum_product(vec![1, 1, 1]) == (3, 1));\n assert!(sum_product(vec![100, 0]) == (100, 0));\n assert!(sum_product(vec![3, 5, 7]) == (3 + 5 + 7, 3 * 5 * 7));\n assert!(sum_product(vec![10]) == (10, 10));\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let sum = |xs: &Vec<i32>| xs.iter()\n .fold(0, |mut sum, &val| { sum += val; \n sum }\n );\n let product = |xs: &Vec<i32>| xs.iter()\n .fold(0, |mut prod, &val| { prod *= val; \n prod }\n );\n return (sum(&numbers),product(&numbers));\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "sum_product"}
|
10 |
+
{"task_id": "Rust/9", "prompt": "\n/*\n From a given list of integers, generate a list of rolling maximum element found until given moment\n in the sequence.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn rolling_max(numbers:Vec<i32>) -> Vec<i32>{\n", "canonical_solution": "\n let mut running_max :Option<i32> = None;\n let mut result:Vec<i32> = vec![];\n\n for n in numbers{\n if running_max == None {\n running_max = Some(n);\n\n }else{\n running_max = max(running_max, Some(n));\n }\n\n result.push(running_max.unwrap());\n }\n return result;\n\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_rolling_max() {\n assert!(rolling_max(vec![]) == vec![]);\n assert!(rolling_max(vec![1, 2, 3, 4]) == vec![1, 2, 3, 4]);\n assert!(rolling_max(vec![4, 3, 2, 1]) == vec![4, 4, 4, 4]);\n assert!(rolling_max(vec![3, 2, 3, 100, 3]) == vec![3, 3, 3, 100, 100]);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut running_max :Option<i32> = None;\n let mut result:Vec<i32> = vec![];\n\n for n in numbers{\n if running_max == None {\n running_max = Some(n);\n\n }else{\n running_max = max(running_max, Some(n));\n }\n }\n return result;\n\n}\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "rolling_max"}
|
11 |
{"task_id": "Rust/10", "prompt": "\n/*\n Find the shortest palindrome that begins with a supplied string.\n Algorithm idea is simple:\n - Find the longest postfix of supplied string that is a palindrome.\n - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn is_palindrome_10(str: &str) -> bool {\n", "canonical_solution": "\n let s: String = str.chars().rev().collect();\n return s==str;\n }\n \n fn make_palindrome(str: &str) -> String {\n let mut i: usize = 0;\n for i in 0..str.len() {\n let rstr: &str = &str[i..];\n if is_palindrome_10(rstr) {\n let nstr: &str = &str[0..i];\n let n2str: String = nstr.chars().rev().collect();\n return str.to_string()+&n2str;\n }\n }\n let n2str: String = str.chars().rev().collect();\n return str.to_string()+&n2str;\n }\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_make_palindrome() {\n assert_eq!(make_palindrome(\"\"), \"\");\n assert_eq!(make_palindrome(\"x\"), \"x\");\n assert_eq!(make_palindrome(\"xyz\"), \"xyzyx\");\n assert_eq!(make_palindrome(\"xyx\"), \"xyx\");\n assert_eq!(make_palindrome(\"jerry\"), \"jerryrrej\");\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let s: String = str.chars().rev().collect();\n return s==str;\n }\n \n fn make_palindrome(str: &str) -> String {\n let mut i: usize = 0;\n for i in 0..str.len() {\n let rstr: &str = &str[i..];\n if is_palindrome_10(str) {\n let nstr: &str = &str[0..i];\n let n2str: String = nstr.chars().rev().collect();\n return str.to_string()+&n2str;\n }\n }\n let n2str: String = str.chars().rev().collect();\n return str.to_string()+&n2str;\n }\n", "bug_type": "missing logic", "failure_symptoms": "stackoverflow", "entry_point": "make_palindrome"}
|
12 |
{"task_id": "Rust/11", "prompt": "\n/*\n Input are two strings a and b consisting only of 1s and 0s.\n Perform binary XOR on these inputs and return result also as a string.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn string_xor(a:String, b:String) -> String{\n", "canonical_solution": "\n\n let xor = |i:char, j:char| {if i == j{return \"0\".to_string()}else{return \"1\".to_string()}};\n return a.chars().into_iter().zip(b.chars().into_iter()).map(|(i,j)| \"\".to_string() + &xor(i,j)).collect(); \n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_string_xor() {\n assert!(string_xor(\"111000\".to_string(), \"101010\".to_string()) == \"010010\");\n assert!(string_xor(\"1\".to_string(), \"1\".to_string()) == \"0\");\n assert!(string_xor(\"0101\".to_string(), \"0000\".to_string()) == \"0101\");\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n\n let xor = |i:char, j:char| {if i == j{return \"1\".to_string()}else{return \"0\".to_string()}};\n return a.chars().into_iter().zip(b.chars().into_iter()).map(|(i,j)| \"\".to_string() + &xor(i,j)).collect(); \n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "string_xor"}
|
13 |
{"task_id": "Rust/12", "prompt": "\n/*\n Out of list of strings, return the longest one. Return the first one in case of multiple\n strings of the same length. Return None in case the input list is empty.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn longest(strings:Vec<String>) -> Option<String>{\n\n", "canonical_solution": "\n if strings.is_empty(){\n return None;\n }\n let mut max:i32 = 0;\n let mut res:String = String::new();\n\n for s in strings{\n if s.len() as i32 > max {\n res = s;\n max = res.len() as i32;\n } \n }\n return Some(res);\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n#[test]\n fn test_longest() {\n assert!(longest(vec![]) == None);\n assert!(\n longest(vec![\"x\".to_string(), \"y\".to_string(), \"z\".to_string()])\n == Some(\"x\".to_string())\n );\n assert!(\n longest(vec![\n \"x\".to_string(),\n \"yyy\".to_string(),\n \"zzzz\".to_string(),\n \"www\".to_string(),\n \"kkkk\".to_string(),\n \"abc\".to_string()\n ]) == Some(\"zzzz\".to_string())\n );\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n if strings.is_empty(){\n return None;\n }\n let mut max:i32 = 1;\n let mut res:String = String::new();\n\n for s in strings{\n if s.len() as i32 == max {\n res = s;\n max = res.len() as i32;\n } \n }\n return Some(res);\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "longest"}
|
|
|
30 |
{"task_id": "Rust/29", "prompt": "\n/*\n Filter an input list of strings only for ones that start with a given prefix.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn filter_by_prefix(strings:Vec<String>, prefix:String)-> Vec<String>{\n\n", "canonical_solution": "\n return strings.into_iter().filter(|s| s.starts_with(&prefix)).collect();\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n#[test]\n fn test_filter_by_prefix() {\n let v_empty: Vec<String> = vec![];\n assert!(filter_by_prefix(vec![], \"john\".to_string()) == v_empty);\n assert!(\n filter_by_prefix(\n vec![\n \"xxx\".to_string(),\n \"asd\".to_string(),\n \"xxy\".to_string(),\n \"john doe\".to_string(),\n \"xxxAAA\".to_string(),\n \"xxx\".to_string()\n ],\n \"xxx\".to_string()\n ) == vec![\"xxx\", \"xxxAAA\", \"xxx\"]\n );\n }\n\n\n}\n", "example_test": "None", "buggy_solution": "\n return strings.into_iter().filter(|s| s.ends_with(&prefix)).collect();\n}\n", "bug_type": "function misuse", "failure_symptoms": "incorrect output", "entry_point": "filter_by_prefix"}
|
31 |
{"task_id": "Rust/30", "prompt": "\n/*\nReturn only positive numbers in the list.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn get_positive(numbers:Vec<i32>) -> Vec<i32>{\n\n", "canonical_solution": "\n return numbers.into_iter().filter(|n| n.is_positive()).collect();\n\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_get_positive() {\n assert!(get_positive(vec![-1, -2, 4, 5, 6]) == [4, 5, 6]);\n assert!(\n get_positive(vec![5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10]) == [5, 3, 2, 3, 3, 9, 123, 1]\n );\n assert!(get_positive(vec![-1, -2]) == []);\n assert!(get_positive(vec![]) == []);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n return numbers.into_iter().filter(|n| n.is_negative()).collect();\n\n}\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "get_positive"}
|
32 |
{"task_id": "Rust/31", "prompt": "\n/*\nReturn true if a given number is prime, and false otherwise.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn is_prime(n:i32) -> bool{\n\n", "canonical_solution": "\n if n < 2{\n return false;\n}\nfor k in 2..n-1 {\n if n % k == 0{\n return false;\n }\n}\nreturn true;\n\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_is_prime() {\n assert!(is_prime(6) == false);\n assert!(is_prime(101) == true);\n assert!(is_prime(11) == true);\n assert!(is_prime(13441) == true);\n assert!(is_prime(61) == true);\n assert!(is_prime(4) == false);\n assert!(is_prime(1) == false);\n assert!(is_prime(5) == true);\n assert!(is_prime(11) == true);\n assert!(is_prime(17) == true);\n assert!(is_prime(5 * 17) == false);\n assert!(is_prime(11 * 7) == false);\n assert!(is_prime(13441 * 19) == false);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n if n < 1{\n return false;\n}\nfor k in 1..n-1 {\n if n % k == 0{\n return false;\n }\n}\nreturn true;\n\n}\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "is_prime"}
|
33 |
+
{"task_id": "Rust/32", "prompt": "\n/*\n xs are coefficients of a polynomial.\n find_zero find x such that poly(x) = 0.\n find_zero returns only only zero point, even if there are many.\n Moreover, find_zero only takes list xs having even number of coefficients\n and largest non zero coefficient as it guarantees\n a solution.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn poly(xs: &Vec<f64>, x: f64) -> f64 {\n\n", "canonical_solution": "\n let mut sum = 0.0;\n for i in 0..xs.len() {\n sum += xs[i] * x.powi(i as i32);\n }\n sum\n }\n \n fn find_zero(xs: &Vec<f64>) -> f64 {\n let mut ans = 0.0;\n let mut value = poly(xs, ans);\n while value.abs() > 1e-6 {\n let mut driv = 0.0;\n for i in 1..xs.len() {\n driv += xs[i] * ans.powi((i - 1) as i32) * (i as f64);\n }\n ans = ans - value / driv;\n value = poly(xs, ans);\n }\n ans\n }\n", "test": "\n/*\n#[cfg(test)]\nmod tests {\n use super::*;\n\n#[test]\n fn test_poly() {\n let mut rng = rand::thread_rng();\n let mut solution: f64;\n let mut ncoeff: i32;\n for _ in 0..100 {\n ncoeff = 2 * (1 + rng.gen_range(0, 4));\n let mut coeffs = vec![];\n for _ in 0..ncoeff {\n let coeff = -10 + rng.gen_range(0, 21);\n if coeff == 0 {\n coeffs.push(1.0);\n } else {\n coeffs.push(coeff as f64);\n }\n }\n solution = find_zero(&coeffs);\n assert!(poly(&coeffs, solution).abs() < 1e-3);\n }\n }\n\n}\n*/\n", "example_test": "None", "buggy_solution": "\n let mut sum = 0.0;\n for i in 0..xs.len() {\n sum += xs[i] * x.powi(i as i32);\n }\n sum\n }\n \n fn find_zero(xs: &Vec<f64>) -> f64 {\n let mut driv = 0.0;\n let mut ans = 0.0;\n let mut value = poly(xs, ans);\n while value.abs() > 1e-6 {\n for i in 1..xs.len() {\n driv += xs[i] * ans.powi((i - 1) as i32) * (i as f64);\n }\n ans = ans - value / driv;\n value = poly(xs, ans);\n }\n 10.0\n }\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "find_zero"}
|
34 |
{"task_id": "Rust/33", "prompt": "\n/*\nThis function takes a list l and returns a list l' such that\n l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal\n to the values of the corresponding indicies of l, but sorted.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn sort_third(l: Vec<i32>) -> Vec<i32> {\n\n", "canonical_solution": "\n let mut third = vec![];\n let mut out:Vec<i32> = vec![];\n\n for (indx,elem) in l.iter().enumerate(){\n if indx%3 == 0 && indx != 0{\n third.push(elem)\n }\n }\n third.sort();\n let mut indx_t:usize = 0;\n\n for i in 0..l.len() {\n if i%3 == 0 && i != 0{\n if indx_t < third.len(){\n out.push(*third[indx_t]);\n indx_t += 1;\n }\n }else{\n out.push(l[i]);\n }\n \n }\n return out;\n}\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_sort_third() {\n let mut l = vec![1, 2, 3];\n assert_eq!(sort_third(l), vec![1, 2, 3]);\n l = vec![5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10];\n assert_eq!(sort_third(l), vec![5, 3, -5, 1, -3, 3, 2, 0, 123, 9, -10]);\n l = vec![5, 8, -12, 4, 23, 2, 3, 11, 12, -10];\n assert_eq!(sort_third(l), vec![5, 8, -12, -10, 23, 2, 3, 11, 12, 4]);\n l = vec![5, 6, 3, 4, 8, 9, 2];\n assert_eq!(sort_third(l), vec![5, 6, 3, 2, 8, 9, 4]);\n l = vec![5, 8, 3, 4, 6, 9, 2];\n assert_eq!(sort_third(l), vec![5, 8, 3, 2, 6, 9, 4]);\n l = vec![5, 6, 9, 4, 8, 3, 2];\n assert_eq!(sort_third(l), vec![5, 6, 9, 2, 8, 3, 4]);\n l = vec![5, 6, 3, 4, 8, 9, 2, 1];\n assert_eq!(sort_third(l), vec![5, 6, 3, 2, 8, 9, 4, 1]);\n }\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut third = vec![];\n let mut out:Vec<i32> = vec![];\n\n for (indx,elem) in l.iter().enumerate(){\n if indx%3 == 0 && indx != 0{\n third.push(elem)\n }\n }\n let mut indx_t:usize = 0;\n\n for i in 0..l.len() {\n if i%3 == 0 && i != 0{\n if indx_t < third.len(){\n out.push(*third[indx_t]);\n indx_t += 1;\n }\n }else{\n out.push(l[i]);\n }\n \n }\n return out;\n}\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "sort_third"}
|
35 |
{"task_id": "Rust/34", "prompt": "\n/*\nReturn sorted unique elements in a list\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn unique(nmbs:Vec<i32>) -> Vec<i32>{\n\n", "canonical_solution": "\n let mut res:Vec<i32> = nmbs.clone();\n res.sort();\n res.dedup();\n return res;\n }\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_unique() {\n assert!(unique(vec![5, 3, 5, 2, 3, 3, 9, 0, 123]) == vec![0, 2, 3, 5, 9, 123]);\n }\n\n\n}\n", "example_test": "None", "buggy_solution": "\n let mut res:Vec<i32> = nmbs.clone();\n res.sort();\n return res;\n }\n", "bug_type": "missing logic", "failure_symptoms": "incorrect output", "entry_point": "unique"}
|
36 |
{"task_id": "Rust/35", "prompt": "\n/*\nReturn maximum element in the list.\n \n*/\n", "declaration": "\nuse std::{slice::Iter, cmp::{max, self}, mem::replace, collections::{HashSet, HashMap}, ops::Index, ascii::AsciiExt};\nuse rand::Rng;\nuse regex::Regex;\nuse md5;\nuse std::any::{Any, TypeId};\n\nfn maximum(nmbs:Vec<i32>) -> i32{\n\n", "canonical_solution": "\n return *nmbs.iter().max().unwrap();\n }\n\n", "test": "\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_maximum() {\n assert!(maximum(vec![1, 2, 3]) == 3);\n assert!(maximum(vec![5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) == 124);\n }\n\n\n}\n", "example_test": "None", "buggy_solution": "\n return *nmbs.iter().min().unwrap();\n }\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "max_element"}
|