Commit
·
ca63504
1
Parent(s):
78e747a
Update
Browse files
data/go/data/humanevalbugs.jsonl
CHANGED
@@ -48,7 +48,7 @@
|
|
48 |
{"task_id": "Go/47", "prompt": "import (\n\t\"sort\"\n)\n\n// Return Median of elements in the list l.\n// >>> Median([3, 1, 2, 4, 5])\n// 3.0\n// >>> Median([-10, 4, 6, 1000, 10, 20])\n// 15.0\nfunc Median(l []int) float64 {\n", "import": "import (\n\t\"sort\"\n)", "docstring": "// Return Median of elements in the list l.\n// >>> Median([3, 1, 2, 4, 5])\n// 3\n// >>> Median([-10, 4, 6, 1000, 10, 20])\n// 15.0\n", "declaration": "\nfunc Median(l []int) float64 {\n", "canonical_solution": " sort.Ints(l)\n\tif len(l)%2==1{\n\t\treturn float64(l[len(l)/2])\n\t}else{\n\t\treturn float64(l[len(l)/2-1]+l[len(l)/2])/2.0\n\t}\n}\n\n", "test": "func TestMedian(t *testing.T) {\n\tassert := assert.New(t)\n\tassert.Equal(3.0, Median([]int{3, 1, 2, 4, 5}))\n\tassert.Equal(8.0, Median([]int{-10, 4, 6, 1000, 10, 20}))\n\tassert.Equal(5.0, Median([]int{5}))\n\tassert.Equal(5.5, Median([]int{6, 5}))\n\tassert.Equal(7.0, Median([]int{8, 1, 3, 9, 9, 2, 7}))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestMedian(t *testing.T) {\n\tassert := assert.New(t)\n\tassert.Equal(3.0, Median([]int{3, 1, 2, 4, 5}))\n\tassert.Equal(8.0, Median([]int{-10, 4, 6, 1000, 10, 20}))\n}\n", "buggy_solution": " sort.Ints(l)\n\tif len(l)%2==1{\n\t\treturn float64(l[len(l)/2])\n\t}else{\n\t\treturn float64(l[len(l)-1/2]+l[len(l)/2])/2.0\n\t}\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Median"}
|
49 |
{"task_id": "Go/48", "prompt": "\n// Checks if given string is a palindrome\n// >>> IsPalindrome('')\n// true\n// >>> IsPalindrome('aba')\n// true\n// >>> IsPalindrome('aaaaa')\n// true\n// >>> IsPalindrome('zbcd')\n// false\nfunc IsPalindrome(text string) bool {\n", "import": "", "docstring": "// Checks if given string is a palindrome\n// >>> IsPalindrome('')\n// true\n// >>> IsPalindrome('aba')\n// true\n// >>> IsPalindrome('aaaaa')\n// true\n// >>> IsPalindrome('zbcd')\n// false\n", "declaration": "\nfunc IsPalindrome(text string) bool {\n", "canonical_solution": " runes := []rune(text)\n result := make([]rune, 0)\n for i := len(runes) - 1; i >= 0; i-- {\n result = append(result, runes[i])\n }\n return text == string(result)\n}\n\n", "test": "func TestIsPalindrome(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, IsPalindrome(\"\"))\n assert.Equal(true, IsPalindrome(\"aba\"))\n assert.Equal(true, IsPalindrome(\"aaaaa\"))\n assert.Equal(false, IsPalindrome(\"zbcd\"))\n assert.Equal(true, IsPalindrome(\"xywyx\"))\n assert.Equal(false, IsPalindrome(\"xywyz\"))\n assert.Equal(false, IsPalindrome(\"xywzx\"))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestIsPalindrome(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, IsPalindrome(\"\"))\n assert.Equal(true, IsPalindrome(\"aba\"))\n assert.Equal(true, IsPalindrome(\"aaaaa\"))\n assert.Equal(false, IsPalindrome(\"zbcd\"))\n}\n", "buggy_solution": " runes := []rune(text)\n result := make([]rune, 0)\n for i := len(runes) - 1; i > 0; i-- {\n result = append(result, runes[i])\n }\n return text == string(result)\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsPalindrome"}
|
50 |
{"task_id": "Go/49", "prompt": "\n// Return 2^n modulo p (be aware of numerics).\n// >>> Modp(3, 5)\n// 3\n// >>> Modp(1101, 101)\n// 2\n// >>> Modp(0, 101)\n// 1\n// >>> Modp(3, 11)\n// 8\n// >>> Modp(100, 101)\n// 1\nfunc Modp(n int,p int) int {\n", "import": "", "docstring": "// Return 2^n modulo p (be aware of numerics).\n// >>> Modp(3, 5)\n// 3\n// >>> Modp(1101, 101)\n// 2\n// >>> Modp(0, 101)\n// 1\n// >>> Modp(3, 11)\n// 8\n// >>> Modp(100, 101)\n// 1\n", "declaration": "\nfunc Modp(n int,p int) int {\n", "canonical_solution": " ret := 1\n for i:= 0; i < n; i++ {\n\t\tret = (2 * ret) % p\n\t}\n return ret\n}\n\n", "test": "func TestModp(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, Modp(3, 5))\n assert.Equal(2, Modp(1101, 101))\n assert.Equal(1, Modp(0, 101))\n assert.Equal(8, Modp(3, 11))\n assert.Equal(1, Modp(100, 101))\n assert.Equal(4, Modp(30, 5))\n assert.Equal(3, Modp(31, 5))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestModp(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, Modp(3, 5))\n assert.Equal(2, Modp(1101, 101))\n assert.Equal(1, Modp(0, 101))\n assert.Equal(8, Modp(3, 11))\n assert.Equal(1, Modp(100, 101))\n}\n", "buggy_solution": " ret := 0\n for i:= 0; i < n; i++ {\n\t\tret = (2 * ret) % p\n\t}\n return ret\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Modp"}
|
51 |
-
{"task_id": "Go/50", "prompt": "// returns encoded string by shifting every character by 5 in the alphabet.\nfunc EncodeShift(s string) string {\n runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes, (ch+5-'a')%26+'a')\n }\n return string(runes)\n}\n\n// takes as input string encoded with EncodeShift function. Returns decoded string.\nfunc DecodeShift(s string) string {\n", "import": "", "docstring": "// returns encoded string by shifting every character by 5 in the alphabet.\n// takes as input string encoded with encode_shift function. Returns decoded string.\n", "declaration": "\nfunc DecodeShift(s string) string {\n", "canonical_solution": " runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes, (ch-5-'a')%26+'a')\n }\n return string(runes)\n}\n\n", "test": "func TestDecodeShift(t *testing.T) {\n assert := assert.New(t)\n randInt := func(min, max int) int {\n rng := rand.New(rand.NewSource(time.Now().UnixNano()))\n if min >= max || min == 0 || max == 0 {\n return max\n }\n return rng.Intn(max-min) + min\n }\n for i := 0; i <100 ; i++ {\n runes := make([]rune, 0)\n for j := 0; j < randInt(10,20); j++ {\n runes = append(runes, int32(randInt('a','z')))\n }\n encoded_str := EncodeShift(string(runes))\n assert.Equal(DecodeShift(encoded_str), string(runes))\n }\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"math/rand\"\n \"time\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "", "buggy_solution": " runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes, 'a'
|
52 |
{"task_id": "Go/51", "prompt": "import (\n \"regexp\"\n)\n\n// RemoveVowels is a function that takes string and returns string without vowels.\n// >>> RemoveVowels('')\n// ''\n// >>> RemoveVowels(\"abcdef\\nghijklm\")\n// 'bcdf\\nghjklm'\n// >>> RemoveVowels('abcdef')\n// 'bcdf'\n// >>> RemoveVowels('aaaaa')\n// ''\n// >>> RemoveVowels('aaBAA')\n// 'B'\n// >>> RemoveVowels('zbcd')\n// 'zbcd'\nfunc RemoveVowels(text string) string {\n", "import": "import (\n \"regexp\"\n)", "docstring": "// RemoveVowels is a function that takes string and returns string without vowels.\n// >>> RemoveVowels('')\n// ''\n// >>> RemoveVowels(\"abcdef\\nghijklm\")\n// 'bcdf\\nghjklm'\n// >>> RemoveVowels('abcdef')\n// 'bcdf'\n// >>> RemoveVowels('aaaaa')\n// ''\n// >>> RemoveVowels('aaBAA')\n// 'B'\n// >>> RemoveVowels('zbcd')\n// 'zbcd'\n", "declaration": "\nfunc RemoveVowels(text string) string {\n ", "canonical_solution": " var re = regexp.MustCompile(\"[aeiouAEIOU]\")\n\ttext = re.ReplaceAllString(text, \"\")\n\treturn text\n}\n\n", "test": "func TestRemoveVowels(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(\"\", RemoveVowels(\"\"))\n assert.Equal(\"bcdf\\nghjklm\", RemoveVowels(\"abcdef\\nghijklm\"))\n assert.Equal(\"fdcb\", RemoveVowels(\"fedcba\"))\n assert.Equal(\"\", RemoveVowels(\"eeeee\"))\n assert.Equal(\"cB\", RemoveVowels(\"acBAA\"))\n assert.Equal(\"cB\", RemoveVowels(\"EcBOO\"))\n assert.Equal(\"ybcd\", RemoveVowels(\"ybcd\"))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestRemoveVowels(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(\"\", RemoveVowels(\"\"))\n assert.Equal(\"bcdf\\nghjklm\", RemoveVowels(\"abcdef\\nghijklm\"))\n assert.Equal(\"bcdf\", RemoveVowels(\"abcdef\"))\n assert.Equal(\"\", RemoveVowels(\"aaaaa\"))\n assert.Equal(\"B\", RemoveVowels(\"aaBAA\"))\n assert.Equal(\"zbcd\", RemoveVowels(\"zbcd\"))\n}\n", "buggy_solution": " var re = regexp.MustCompile(\"[aeiouwyAEIOUWY]\")\n\ttext = re.ReplaceAllString(text, \"\")\n\treturn text\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "RemoveVowels"}
|
53 |
{"task_id": "Go/52", "prompt": "\n// Return true if all numbers in the list l are below threshold t.\n// >>> BelowThreshold([1, 2, 4, 10], 100)\n// true\n// >>> BelowThreshold([1, 20, 4, 10], 5)\n// false\nfunc BelowThreshold(l []int,t int) bool {\n", "import": "", "docstring": "// Return true if all numbers in the list l are below threshold t.\n// >>> BelowThreshold([1, 2, 4, 10], 100)\n// true\n// >>> BelowThreshold([1, 20, 4, 10], 5)\n// false\n", "declaration": "\nfunc BelowThreshold(l []int,t int) bool {\n", "canonical_solution": " for _, n := range l {\n\t\tif n >= t {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n", "test": "func TestBelowThreshold(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, BelowThreshold([]int{1, 2, 4, 10}, 100))\n assert.Equal(false, BelowThreshold([]int{1, 20, 4, 10}, 5))\n assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 21))\n assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 22))\n assert.Equal(true, BelowThreshold([]int{1, 8, 4, 10}, 11))\n assert.Equal(false, BelowThreshold([]int{1, 8, 4, 10}, 10))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestBelowThreshold(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, BelowThreshold([]int{1, 2, 4, 10}, 100))\n assert.Equal(false, BelowThreshold([]int{1, 20, 4, 10}, 5))\n}\n", "buggy_solution": " for _, n := range l {\n\t\tif n >= t {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "BelowThreshold"}
|
54 |
{"task_id": "Go/53", "prompt": "\n// Add two numbers x and y\n// >>> Add(2, 3)\n// 5\n// >>> Add(5, 7)\n// 12\nfunc Add(x int, y int) int {\n", "import": "", "docstring": "// Add two numbers x and y\n// >>> Add(2, 3)\n// 5\n// >>> Add(5, 7)\n// 12\n", "declaration": "\nfunc Add(x int, y int) int {\n", "canonical_solution": " return x + y\n}\n\n", "test": "func TestAdd(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(1, Add(0, 1))\n assert.Equal(1, Add(1, 0))\n assert.Equal(5, Add(2, 3))\n assert.Equal(12, Add(5, 7))\n assert.Equal(12, Add(7, 5))\n for i := 0; i < 100; i++ {\n x := rand.Int31n(1000)\n y := rand.Int31n(1000)\n assert.Equal(int(x+y), Add(int(x), int(y)))\n }\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"math/rand\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestAdd(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(5, Add(2, 3+rand.Intn(1000)*0))\n assert.Equal(12, Add(5, 7))\n}\n", "buggy_solution": " return x + y + y + x\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Add"}
|
|
|
48 |
{"task_id": "Go/47", "prompt": "import (\n\t\"sort\"\n)\n\n// Return Median of elements in the list l.\n// >>> Median([3, 1, 2, 4, 5])\n// 3.0\n// >>> Median([-10, 4, 6, 1000, 10, 20])\n// 15.0\nfunc Median(l []int) float64 {\n", "import": "import (\n\t\"sort\"\n)", "docstring": "// Return Median of elements in the list l.\n// >>> Median([3, 1, 2, 4, 5])\n// 3\n// >>> Median([-10, 4, 6, 1000, 10, 20])\n// 15.0\n", "declaration": "\nfunc Median(l []int) float64 {\n", "canonical_solution": " sort.Ints(l)\n\tif len(l)%2==1{\n\t\treturn float64(l[len(l)/2])\n\t}else{\n\t\treturn float64(l[len(l)/2-1]+l[len(l)/2])/2.0\n\t}\n}\n\n", "test": "func TestMedian(t *testing.T) {\n\tassert := assert.New(t)\n\tassert.Equal(3.0, Median([]int{3, 1, 2, 4, 5}))\n\tassert.Equal(8.0, Median([]int{-10, 4, 6, 1000, 10, 20}))\n\tassert.Equal(5.0, Median([]int{5}))\n\tassert.Equal(5.5, Median([]int{6, 5}))\n\tassert.Equal(7.0, Median([]int{8, 1, 3, 9, 9, 2, 7}))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestMedian(t *testing.T) {\n\tassert := assert.New(t)\n\tassert.Equal(3.0, Median([]int{3, 1, 2, 4, 5}))\n\tassert.Equal(8.0, Median([]int{-10, 4, 6, 1000, 10, 20}))\n}\n", "buggy_solution": " sort.Ints(l)\n\tif len(l)%2==1{\n\t\treturn float64(l[len(l)/2])\n\t}else{\n\t\treturn float64(l[len(l)-1/2]+l[len(l)/2])/2.0\n\t}\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Median"}
|
49 |
{"task_id": "Go/48", "prompt": "\n// Checks if given string is a palindrome\n// >>> IsPalindrome('')\n// true\n// >>> IsPalindrome('aba')\n// true\n// >>> IsPalindrome('aaaaa')\n// true\n// >>> IsPalindrome('zbcd')\n// false\nfunc IsPalindrome(text string) bool {\n", "import": "", "docstring": "// Checks if given string is a palindrome\n// >>> IsPalindrome('')\n// true\n// >>> IsPalindrome('aba')\n// true\n// >>> IsPalindrome('aaaaa')\n// true\n// >>> IsPalindrome('zbcd')\n// false\n", "declaration": "\nfunc IsPalindrome(text string) bool {\n", "canonical_solution": " runes := []rune(text)\n result := make([]rune, 0)\n for i := len(runes) - 1; i >= 0; i-- {\n result = append(result, runes[i])\n }\n return text == string(result)\n}\n\n", "test": "func TestIsPalindrome(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, IsPalindrome(\"\"))\n assert.Equal(true, IsPalindrome(\"aba\"))\n assert.Equal(true, IsPalindrome(\"aaaaa\"))\n assert.Equal(false, IsPalindrome(\"zbcd\"))\n assert.Equal(true, IsPalindrome(\"xywyx\"))\n assert.Equal(false, IsPalindrome(\"xywyz\"))\n assert.Equal(false, IsPalindrome(\"xywzx\"))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestIsPalindrome(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, IsPalindrome(\"\"))\n assert.Equal(true, IsPalindrome(\"aba\"))\n assert.Equal(true, IsPalindrome(\"aaaaa\"))\n assert.Equal(false, IsPalindrome(\"zbcd\"))\n}\n", "buggy_solution": " runes := []rune(text)\n result := make([]rune, 0)\n for i := len(runes) - 1; i > 0; i-- {\n result = append(result, runes[i])\n }\n return text == string(result)\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "IsPalindrome"}
|
50 |
{"task_id": "Go/49", "prompt": "\n// Return 2^n modulo p (be aware of numerics).\n// >>> Modp(3, 5)\n// 3\n// >>> Modp(1101, 101)\n// 2\n// >>> Modp(0, 101)\n// 1\n// >>> Modp(3, 11)\n// 8\n// >>> Modp(100, 101)\n// 1\nfunc Modp(n int,p int) int {\n", "import": "", "docstring": "// Return 2^n modulo p (be aware of numerics).\n// >>> Modp(3, 5)\n// 3\n// >>> Modp(1101, 101)\n// 2\n// >>> Modp(0, 101)\n// 1\n// >>> Modp(3, 11)\n// 8\n// >>> Modp(100, 101)\n// 1\n", "declaration": "\nfunc Modp(n int,p int) int {\n", "canonical_solution": " ret := 1\n for i:= 0; i < n; i++ {\n\t\tret = (2 * ret) % p\n\t}\n return ret\n}\n\n", "test": "func TestModp(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, Modp(3, 5))\n assert.Equal(2, Modp(1101, 101))\n assert.Equal(1, Modp(0, 101))\n assert.Equal(8, Modp(3, 11))\n assert.Equal(1, Modp(100, 101))\n assert.Equal(4, Modp(30, 5))\n assert.Equal(3, Modp(31, 5))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestModp(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(3, Modp(3, 5))\n assert.Equal(2, Modp(1101, 101))\n assert.Equal(1, Modp(0, 101))\n assert.Equal(8, Modp(3, 11))\n assert.Equal(1, Modp(100, 101))\n}\n", "buggy_solution": " ret := 0\n for i:= 0; i < n; i++ {\n\t\tret = (2 * ret) % p\n\t}\n return ret\n}\n\n", "bug_type": "value misuse", "failure_symptoms": "incorrect output", "entry_point": "Modp"}
|
51 |
+
{"task_id": "Go/50", "prompt": "// returns encoded string by shifting every character by 5 in the alphabet.\nfunc EncodeShift(s string) string {\n runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes, (ch+5-'a')%26+'a')\n }\n return string(runes)\n}\n\n// takes as input string encoded with EncodeShift function. Returns decoded string.\nfunc DecodeShift(s string) string {\n", "import": "", "docstring": "// returns encoded string by shifting every character by 5 in the alphabet.\n// takes as input string encoded with encode_shift function. Returns decoded string.\n", "declaration": "\nfunc DecodeShift(s string) string {\n", "canonical_solution": " runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes, (ch-5-'a')%26+'a')\n }\n return string(runes)\n}\n\n", "test": "func TestDecodeShift(t *testing.T) {\n assert := assert.New(t)\n randInt := func(min, max int) int {\n rng := rand.New(rand.NewSource(time.Now().UnixNano()))\n if min >= max || min == 0 || max == 0 {\n return max\n }\n return rng.Intn(max-min) + min\n }\n for i := 0; i <100 ; i++ {\n runes := make([]rune, 0)\n for j := 0; j < randInt(10,20); j++ {\n runes = append(runes, int32(randInt('a','z')))\n }\n encoded_str := EncodeShift(string(runes))\n assert.Equal(DecodeShift(encoded_str), string(runes))\n }\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"math/rand\"\n \"time\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "", "buggy_solution": " runes := []rune(s)\n newRunes := make([]rune, 0)\n for _, ch := range runes {\n newRunes = append(newRunes, (ch-5-'a')%26+'a')\n }\n return EncodeShift(string(runes))\n}\n\n", "bug_type": "variable misuse", "failure_symptoms": "incorrect output", "entry_point": "DecodeShift"}
|
52 |
{"task_id": "Go/51", "prompt": "import (\n \"regexp\"\n)\n\n// RemoveVowels is a function that takes string and returns string without vowels.\n// >>> RemoveVowels('')\n// ''\n// >>> RemoveVowels(\"abcdef\\nghijklm\")\n// 'bcdf\\nghjklm'\n// >>> RemoveVowels('abcdef')\n// 'bcdf'\n// >>> RemoveVowels('aaaaa')\n// ''\n// >>> RemoveVowels('aaBAA')\n// 'B'\n// >>> RemoveVowels('zbcd')\n// 'zbcd'\nfunc RemoveVowels(text string) string {\n", "import": "import (\n \"regexp\"\n)", "docstring": "// RemoveVowels is a function that takes string and returns string without vowels.\n// >>> RemoveVowels('')\n// ''\n// >>> RemoveVowels(\"abcdef\\nghijklm\")\n// 'bcdf\\nghjklm'\n// >>> RemoveVowels('abcdef')\n// 'bcdf'\n// >>> RemoveVowels('aaaaa')\n// ''\n// >>> RemoveVowels('aaBAA')\n// 'B'\n// >>> RemoveVowels('zbcd')\n// 'zbcd'\n", "declaration": "\nfunc RemoveVowels(text string) string {\n ", "canonical_solution": " var re = regexp.MustCompile(\"[aeiouAEIOU]\")\n\ttext = re.ReplaceAllString(text, \"\")\n\treturn text\n}\n\n", "test": "func TestRemoveVowels(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(\"\", RemoveVowels(\"\"))\n assert.Equal(\"bcdf\\nghjklm\", RemoveVowels(\"abcdef\\nghijklm\"))\n assert.Equal(\"fdcb\", RemoveVowels(\"fedcba\"))\n assert.Equal(\"\", RemoveVowels(\"eeeee\"))\n assert.Equal(\"cB\", RemoveVowels(\"acBAA\"))\n assert.Equal(\"cB\", RemoveVowels(\"EcBOO\"))\n assert.Equal(\"ybcd\", RemoveVowels(\"ybcd\"))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestRemoveVowels(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(\"\", RemoveVowels(\"\"))\n assert.Equal(\"bcdf\\nghjklm\", RemoveVowels(\"abcdef\\nghijklm\"))\n assert.Equal(\"bcdf\", RemoveVowels(\"abcdef\"))\n assert.Equal(\"\", RemoveVowels(\"aaaaa\"))\n assert.Equal(\"B\", RemoveVowels(\"aaBAA\"))\n assert.Equal(\"zbcd\", RemoveVowels(\"zbcd\"))\n}\n", "buggy_solution": " var re = regexp.MustCompile(\"[aeiouwyAEIOUWY]\")\n\ttext = re.ReplaceAllString(text, \"\")\n\treturn text\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "RemoveVowels"}
|
53 |
{"task_id": "Go/52", "prompt": "\n// Return true if all numbers in the list l are below threshold t.\n// >>> BelowThreshold([1, 2, 4, 10], 100)\n// true\n// >>> BelowThreshold([1, 20, 4, 10], 5)\n// false\nfunc BelowThreshold(l []int,t int) bool {\n", "import": "", "docstring": "// Return true if all numbers in the list l are below threshold t.\n// >>> BelowThreshold([1, 2, 4, 10], 100)\n// true\n// >>> BelowThreshold([1, 20, 4, 10], 5)\n// false\n", "declaration": "\nfunc BelowThreshold(l []int,t int) bool {\n", "canonical_solution": " for _, n := range l {\n\t\tif n >= t {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n", "test": "func TestBelowThreshold(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, BelowThreshold([]int{1, 2, 4, 10}, 100))\n assert.Equal(false, BelowThreshold([]int{1, 20, 4, 10}, 5))\n assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 21))\n assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 22))\n assert.Equal(true, BelowThreshold([]int{1, 8, 4, 10}, 11))\n assert.Equal(false, BelowThreshold([]int{1, 8, 4, 10}, 10))\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestBelowThreshold(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(true, BelowThreshold([]int{1, 2, 4, 10}, 100))\n assert.Equal(false, BelowThreshold([]int{1, 20, 4, 10}, 5))\n}\n", "buggy_solution": " for _, n := range l {\n\t\tif n >= t {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n", "bug_type": "operator misuse", "failure_symptoms": "incorrect output", "entry_point": "BelowThreshold"}
|
54 |
{"task_id": "Go/53", "prompt": "\n// Add two numbers x and y\n// >>> Add(2, 3)\n// 5\n// >>> Add(5, 7)\n// 12\nfunc Add(x int, y int) int {\n", "import": "", "docstring": "// Add two numbers x and y\n// >>> Add(2, 3)\n// 5\n// >>> Add(5, 7)\n// 12\n", "declaration": "\nfunc Add(x int, y int) int {\n", "canonical_solution": " return x + y\n}\n\n", "test": "func TestAdd(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(1, Add(0, 1))\n assert.Equal(1, Add(1, 0))\n assert.Equal(5, Add(2, 3))\n assert.Equal(12, Add(5, 7))\n assert.Equal(12, Add(7, 5))\n for i := 0; i < 100; i++ {\n x := rand.Int31n(1000)\n y := rand.Int31n(1000)\n assert.Equal(int(x+y), Add(int(x), int(y)))\n }\n}\n", "test_setup": "package main\n\nimport (\n \"testing\"\n \"math/rand\"\n \"github.com/stretchr/testify/assert\"\n)\n", "example_test": "func TestAdd(t *testing.T) {\n assert := assert.New(t)\n assert.Equal(5, Add(2, 3+rand.Intn(1000)*0))\n assert.Equal(12, Add(5, 7))\n}\n", "buggy_solution": " return x + y + y + x\n}\n\n", "bug_type": "excess logic", "failure_symptoms": "incorrect output", "entry_point": "Add"}
|
data/rust/data/humanevalbugs.jsonl
CHANGED
@@ -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 =
|
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"}
|
|
|
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 = value - driv / ans;\n value = poly(xs, ans);\n }\n ans\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"}
|