ID stringlengths 1 3 | Language stringclasses 1 value | Repository Name stringclasses 1 value | File Name stringlengths 4 6 | File Path in Repository stringlengths 7 9 | File Path for Unit Test stringlengths 12 14 | Code stringlengths 43 1.2k | Unit Test - (Ground Truth) stringlengths 148 1.94k | Code Url stringlengths 61 63 | Test Code Url stringlengths 61 63 |
|---|---|---|---|---|---|---|---|---|---|
0 | go | THUDM/humaneval-x | Go_0 | Go_0.go | Go_0_test.go | func HasCloseElements(numbers []float64, threshold float64) bool {
for i := 0; i < len(numbers); i++ {
for j := i + 1; j < len(numbers); j++ {
var distance float64 = math.Abs(numbers[i] - numbers[j])
if distance < threshold {
return true
}
}
}
return false
} | func TestHasCloseElements(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, HasCloseElements([]float64{11.0, 2.0, 3.9, 4.0, 5.0, 2.2}, 0.3))
assert.Equal(false, HasCloseElements([]float64{1.0, 2.0, 3.9, 4.0, 5.0, 2.2}, 0.05))
assert.Equal(true, HasCloseElements([]float64{1.0, 2.0, 5.9, 4.0, 5.0}, 0.95))
assert.Equal(false, HasCloseElements([]float64{1.0, 2.0, 5.9, 4.0, 5.0}, 0.8))
assert.Equal(true, HasCloseElements([]float64{1.0, 2.0, 3.0, 4.0, 5.0, 2.0}, 0.1))
assert.Equal(true, HasCloseElements([]float64{1.1, 2.2, 3.1, 4.1, 5.1}, 1.0))
assert.Equal(false, HasCloseElements([]float64{1.1, 2.2, 3.1, 4.1, 5.1}, 0.5))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/0 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/0 |
1 | go | THUDM/humaneval-x | Go_1 | Go_1.go | Go_1_test.go | func SeparateParenGroups(paren_string string) []string {
result := make([]string, 0)
current_string := make([]rune, 0)
current_depth := 0
for _, c := range paren_string {
if c == '(' {
current_depth += 1
current_string = append(current_string, c)
}else if c== ')'{
current_depth -= 1
current_string = append(current_string, c)
if current_depth == 0{
result = append(result, string(current_string))
current_string = make([]rune, 0)
}
}
}
return result
} | func TestSeparateParenGroups(t *testing.T) {
assert := assert.New(t)
assert.Equal([]string{"(()())", "((()))", "()", "((())()())"}, SeparateParenGroups("(()()) ((())) () ((())()())"))
assert.Equal([]string{"()", "(())", "((()))", "(((())))"}, SeparateParenGroups("() (()) ((())) (((())))"))
assert.Equal([]string{"(()(())((())))"}, SeparateParenGroups("(()(())((())))"))
assert.Equal([]string{"()", "(())", "(()())"}, SeparateParenGroups("( ) (( )) (( )( ))"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/1 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/1 |
2 | go | THUDM/humaneval-x | Go_2 | Go_2.go | Go_2_test.go | func TruncateNumber(number float64) float64 {
return math.Mod(number,1)
} | func TestTruncateNumber(t *testing.T) {
assert := assert.New(t)
assert.Equal(0.5, TruncateNumber(3.5))
assert.Equal(true, math.Abs(TruncateNumber(1.33)-0.33) < 1e-6)
assert.Equal(true, math.Abs(TruncateNumber(123.456)-0.456) < 1e-6)
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/2 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/2 |
3 | go | THUDM/humaneval-x | Go_3 | Go_3.go | Go_3_test.go | func BelowZero(operations []int) bool {
balance := 0
for _, op := range operations {
balance += op
if balance < 0 {
return true
}
}
return false
} | func TestBelowZero(t *testing.T) {
assert := assert.New(t)
assert.Equal(false, BelowZero([]int{}))
assert.Equal(false, BelowZero([]int{1, 2, -3, 1, 2, -3}))
assert.Equal(true, BelowZero([]int{1, 2, -4, 5, 6}))
assert.Equal(false, BelowZero([]int{1, -1, 2, -2, 5, -5, 4, -4}))
assert.Equal(true, BelowZero([]int{1, -1, 2, -2, 5, -5, 4, -5}))
assert.Equal(true, BelowZero([]int{1, -2, 2, -2, 5, -5, 4, -4}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/3 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/3 |
4 | go | THUDM/humaneval-x | Go_4 | Go_4.go | Go_4_test.go | func MeanAbsoluteDeviation(numbers []float64) float64 {
sum := func(numbers []float64) float64 {
sum := 0.0
for _, num := range numbers {
sum += num
}
return sum
}
mean := sum(numbers) / float64(len(numbers))
numList := make([]float64, 0)
for _, x := range numbers {
numList = append(numList, math.Abs(x-mean))
}
return sum(numList) / float64(len(numbers))
} | func TestMeanAbsoluteDeviation(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, math.Abs(MeanAbsoluteDeviation([]float64{1.0, 2.0, 3.0})-2.0/3.0) < 1e-6)
assert.Equal(true, math.Abs(MeanAbsoluteDeviation([]float64{1.0, 2.0, 3.0, 4.0})-1.0) < 1e-6)
assert.Equal(true, math.Abs(MeanAbsoluteDeviation([]float64{1.0, 2.0, 3.0, 4.0, 5.0})-6.0/5.0) < 1e-6)
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/4 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/4 |
5 | go | THUDM/humaneval-x | Go_5 | Go_5.go | Go_5_test.go | func Intersperse(numbers []int, delimeter int) []int {
result := make([]int, 0)
if len(numbers) == 0 {
return result
}
for i := 0; i < len(numbers)-1; i++ {
n := numbers[i]
result = append(result, n)
result = append(result, delimeter)
}
result = append(result, numbers[len(numbers)-1])
return result
} | func TestIntersperse(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{}, Intersperse([]int{}, 7))
assert.Equal([]int{5, 8, 6, 8, 3, 8, 2}, Intersperse([]int{5, 6, 3, 2}, 8))
assert.Equal([]int{2, 2, 2, 2, 2}, Intersperse([]int{2, 2, 2}, 2))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/5 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/5 |
6 | go | THUDM/humaneval-x | Go_6 | Go_6.go | Go_6_test.go | func ParseNestedParens(paren_string string) []int {
parse_paren_group := func(s string) int {
depth := 0
max_depth := 0
for _, c := range s {
if c == '(' {
depth += 1
max_depth = int(math.Max(float64(depth), float64(max_depth)))
} else {
depth -= 1
}
}
return max_depth
}
result := make([]int, 0)
for _, x := range strings.Split(paren_string, " ") {
result = append(result, parse_paren_group(x))
}
return result
} | func TestParseNestedParens(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{2, 3, 1, 3}, ParseNestedParens("(()()) ((())) () ((())()())"))
assert.Equal([]int{1, 2, 3, 4}, ParseNestedParens("() (()) ((())) (((())))"))
assert.Equal([]int{4}, ParseNestedParens("(()(())((())))"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/6 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/6 |
7 | go | THUDM/humaneval-x | Go_7 | Go_7.go | Go_7_test.go | func FilterBySubstring(stringList []string, substring string) []string {
result := make([]string, 0)
for _, x := range stringList {
if strings.Index(x, substring) != -1 {
result = append(result, x)
}
}
return result
} | func TestFilterBySubstring(t *testing.T) {
assert := assert.New(t)
assert.Equal([]string{}, FilterBySubstring([]string{}, "john"))
assert.Equal([]string{"xxx", "xxxAAA", "xxx"}, FilterBySubstring([]string{"xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"}, "xxx"))
assert.Equal([]string{"xxx", "aaaxxy", "xxxAAA", "xxx"}, FilterBySubstring([]string{"xxx", "asd", "aaaxxy", "john doe", "xxxAAA", "xxx"}, "xx"))
assert.Equal([]string{"grunt", "prune"}, FilterBySubstring([]string{"grunt", "trumpet", "prune", "gruesome"}, "run"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/7 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/7 |
8 | go | THUDM/humaneval-x | Go_8 | Go_8.go | Go_8_test.go | func SumProduct(numbers []int) [2]int {
sum_value := 0
prod_value := 1
for _, n := range numbers {
sum_value += n
prod_value *= n
}
return [2]int{sum_value, prod_value}
} | func TestSumProduct(t *testing.T) {
assert := assert.New(t)
assert.Equal([2]int{0, 1}, SumProduct([]int{}))
assert.Equal([2]int{3, 1}, SumProduct([]int{1, 1, 1}))
assert.Equal([2]int{100, 0}, SumProduct([]int{100, 0}))
assert.Equal([2]int{3 + 5 + 7, 3 * 5 * 7}, SumProduct([]int{3, 5, 7}))
assert.Equal([2]int{10, 10}, SumProduct([]int{10}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/8 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/8 |
9 | go | THUDM/humaneval-x | Go_9 | Go_9.go | Go_9_test.go | func RollingMax(numbers []int) []int {
running_max := math.MinInt32
result := make([]int, 0)
for _, n := range numbers {
if running_max == math.MinInt32 {
running_max = n
} else {
running_max = int(math.Max(float64(running_max), float64(n)))
}
result = append(result, running_max)
}
return result
} | func TestRollingMax(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{}, RollingMax([]int{}))
assert.Equal([]int{1, 2, 3, 4}, RollingMax([]int{1, 2, 3, 4}))
assert.Equal([]int{4, 4, 4, 4}, RollingMax([]int{4, 3, 2, 1}))
assert.Equal([]int{3, 3, 3, 100, 100}, RollingMax([]int{3, 2, 3, 100, 3}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/9 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/9 |
10 | go | THUDM/humaneval-x | Go_10 | Go_10.go | Go_10_test.go | func MakePalindrome(str string) string {
if strings.TrimSpace(str) == "" {
return ""
}
beginning_of_suffix := 0
runes := []rune(str)
for !IsPalindrome(string(runes[beginning_of_suffix:])) {
beginning_of_suffix += 1
}
result := make([]rune, 0)
for i := len(str[:beginning_of_suffix]) - 1; i >= 0; i-- {
result = append(result, runes[i])
}
return str + string(result)
} | func TestMakePalindrome(t *testing.T) {
assert := assert.New(t)
assert.Equal("", MakePalindrome(""))
assert.Equal("x", MakePalindrome("x"))
assert.Equal("xyzyx", MakePalindrome("xyz"))
assert.Equal("xyx", MakePalindrome("xyx"))
assert.Equal("jerryrrej", MakePalindrome("jerry"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/10 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/10 |
11 | go | THUDM/humaneval-x | Go_11 | Go_11.go | Go_11_test.go | func StringXor(a string, b string) string {
s2b := func(bs string) int32 {
result := int32(0)
runes := []rune(bs)
for _, r := range runes {
result = result << 1
temp := r - rune('0')
result += temp
}
return result
}
ab := s2b(a)
bb := s2b(b)
res := ab ^ bb
sprint := fmt.Sprintf("%b", res)
for i := 0; i < len(a)-len(sprint); i++ {
sprint = "0" + sprint
}
return sprint
} | func TestStringXor(t *testing.T) {
assert := assert.New(t)
assert.Equal("010010", StringXor("111000", "101010"))
assert.Equal("0", StringXor("1", "1"))
assert.Equal("0101", StringXor("0101", "0000"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/11 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/11 |
12 | go | THUDM/humaneval-x | Go_12 | Go_12.go | Go_12_test.go | func Longest(strings []string) interface{}{
if strings == nil || len(strings) == 0 {
return nil
}
maxlen := 0
maxi := 0
for i, s := range strings {
if maxlen < len(s) {
maxlen = len(s)
maxi = i
}
}
return strings[maxi]
} | func TestLongest(t *testing.T) {
assert := assert.New(t)
assert.Equal(nil, Longest([]string{}))
assert.Equal("x", Longest([]string{"x", "y", "z"}))
assert.Equal("zzzz", Longest([]string{"x", "yyy", "zzzz", "www", "kkkk", "abc"}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/12 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/12 |
13 | go | THUDM/humaneval-x | Go_13 | Go_13.go | Go_13_test.go | func GreatestCommonDivisor(a int,b int) int{
if b < 2 {
return b
}
var gcd int = 1
for i := 2; i < b; i++ {
if a%i == 0 && b%i == 0 {
gcd = i
}
}
return gcd
} | func TestGreatestCommonDivisor(t *testing.T) {
assert := assert.New(t)
assert.Equal(1, GreatestCommonDivisor(3, 7))
assert.Equal(5, GreatestCommonDivisor(10, 15))
assert.Equal(7, GreatestCommonDivisor(49, 14))
assert.Equal(12, GreatestCommonDivisor(144, 60))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/13 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/13 |
14 | go | THUDM/humaneval-x | Go_14 | Go_14.go | Go_14_test.go | func AllPrefixes(str string) []string{
prefixes := make([]string, 0, len(str))
for i := 0; i < len(str); i++ {
prefixes = append(prefixes, str[:i+1])
}
return prefixes
} | func TestAllPrefixes(t *testing.T) {
assert := assert.New(t)
assert.Equal([]string{}, AllPrefixes(""))
assert.Equal([]string{"a", "as", "asd", "asdf", "asdfg", "asdfgh"}, AllPrefixes("asdfgh"))
assert.Equal([]string{"W", "WW", "WWW"}, AllPrefixes("WWW"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/14 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/14 |
15 | go | THUDM/humaneval-x | Go_15 | Go_15.go | Go_15_test.go | func StringSequence(n int) string{
var seq string
for i := 0; i <= n; i++ {
seq += strconv.Itoa(i)
if i != n {
seq += " "
}
}
return seq
} | func TestStringSequence(t *testing.T) {
assert := assert.New(t)
assert.Equal("0", StringSequence(0))
assert.Equal("0 1 2 3", StringSequence(3))
assert.Equal("0 1 2 3 4 5 6 7 8 9 10", StringSequence(10))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/15 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/15 |
16 | go | THUDM/humaneval-x | Go_16 | Go_16.go | Go_16_test.go | func CountDistinctCharacters(str string) int{
lower := strings.ToLower(str)
count := 0
set := make(map[rune]bool)
for _, i := range lower {
if set[i] == true {
continue
} else {
set[i] = true
count++
}
}
return count
} | func TestCountDistinctCharacters(t *testing.T) {
assert := assert.New(t)
assert.Equal(0, CountDistinctCharacters(""))
assert.Equal(5, CountDistinctCharacters("abcde"))
assert.Equal(5, CountDistinctCharacters("abcde" + "cade" + "CADE"))
assert.Equal(1, CountDistinctCharacters("aaaaAAAAaaaa"))
assert.Equal(5, CountDistinctCharacters("Jerry jERRY JeRRRY"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/16 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/16 |
17 | go | THUDM/humaneval-x | Go_17 | Go_17.go | Go_17_test.go | func ParseMusic(music_string string) []int{
note_map := map[string]int{"o": 4, "o|": 2, ".|": 1}
split := strings.Split(music_string, " ")
result := make([]int, 0)
for _, x := range split {
if i, ok := note_map[x]; ok {
result = append(result, i)
}
}
return result
} | func TestParseMusic(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{}, ParseMusic(""))
assert.Equal([]int{4, 4, 4, 4}, ParseMusic("o o o o"))
assert.Equal([]int{1, 1, 1, 1}, ParseMusic(".| .| .| .|"))
assert.Equal([]int{2, 2, 1, 1, 4, 4, 4, 4}, ParseMusic("o| o| .| .| o o o o"))
assert.Equal([]int{2, 1, 2, 1, 4, 2, 4, 2}, ParseMusic("o| .| o| .| o o| o o|"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/17 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/17 |
18 | go | THUDM/humaneval-x | Go_18 | Go_18.go | Go_18_test.go | func HowManyTimes(str string,substring string) int{
times := 0
for i := 0; i < (len(str) - len(substring) + 1); i++ {
if str[i:i+len(substring)] == substring {
times += 1
}
}
return times
} | func TestHowManyTimes(t *testing.T) {
assert := assert.New(t)
assert.Equal(0, HowManyTimes("", "x"))
assert.Equal(4, HowManyTimes("xyxyxyx", "x"))
assert.Equal(4, HowManyTimes("cacacacac", "cac"))
assert.Equal(1, HowManyTimes("john doe", "john"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/18 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/18 |
19 | go | THUDM/humaneval-x | Go_19 | Go_19.go | Go_19_test.go | func SortNumbers(numbers string) string{
valueMap := map[string]int{
"zero": 0,
"one": 1,
"two": 2,
"three": 3,
"four": 4,
"five": 5,
"six": 6,
"seven": 7,
"eight": 8,
"nine": 9,
}
stringMap := make(map[int]string)
for s, i := range valueMap {
stringMap[i] = s
}
split := strings.Split(numbers, " ")
temp := make([]int, 0)
for _, s := range split {
if i, ok := valueMap[s]; ok {
temp = append(temp, i)
}
}
sort.Ints(temp)
result := make([]string, 0)
for _, i := range temp {
result = append(result, stringMap[i])
}
return strings.Join(result, " ")
} | func TestSortNumbers(t *testing.T) {
assert := assert.New(t)
assert.Equal("", SortNumbers(""))
assert.Equal("three", SortNumbers("three"))
assert.Equal("three five nine", SortNumbers("three five nine"))
assert.Equal("zero four five seven eight nine", SortNumbers("five zero four seven nine eight"))
assert.Equal("zero one two three four five six", SortNumbers("six five four three two one zero"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/19 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/19 |
20 | go | THUDM/humaneval-x | Go_20 | Go_20.go | Go_20_test.go | func FindClosestElements(numbers []float64) [2]float64 {
distance := math.MaxFloat64
var closestPair [2]float64
for idx, elem := range numbers {
for idx2, elem2 := range numbers {
if idx != idx2 {
if distance == math.MinInt64 {
distance = math.Abs(elem - elem2)
float64s := []float64{elem, elem2}
sort.Float64s(float64s)
closestPair = [2]float64{float64s[0], float64s[1]}
} else {
newDistance := math.Abs(elem - elem2)
if newDistance < distance{
distance = newDistance
float64s := []float64{elem, elem2}
sort.Float64s(float64s)
closestPair = [2]float64{float64s[0], float64s[1]}
}
}
}
}
}
return closestPair
} | func TestFindClosestElements(t *testing.T) {
assert := assert.New(t)
assert.Equal([2]float64{3.9, 4.0}, FindClosestElements([]float64{1.0, 2.0, 3.9, 4.0, 5.0, 2.2}))
assert.Equal([2]float64{5.0, 5.9}, FindClosestElements([]float64{1.0, 2.0, 5.9, 4.0, 5.0}))
assert.Equal([2]float64{2.0, 2.2}, FindClosestElements([]float64{1.0, 2.0, 3.0, 4.0, 5.0, 2.2}))
assert.Equal([2]float64{2.0, 2.0}, FindClosestElements([]float64{1.0, 2.0, 3.0, 4.0, 5.0, 2.0}))
assert.Equal([2]float64{2.2, 3.1}, FindClosestElements([]float64{1.1, 2.2, 3.1, 4.1, 5.1}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/20 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/20 |
21 | go | THUDM/humaneval-x | Go_21 | Go_21.go | Go_21_test.go | func RescaleToUnit(numbers []float64) []float64 {
smallest := numbers[0]
largest := smallest
for _, n := range numbers {
if smallest > n {
smallest = n
}
if largest < n {
largest = n
}
}
if smallest == largest {
return numbers
}
for i, n := range numbers {
numbers[i] = (n - smallest) / (largest - smallest)
}
return numbers
} | func TestRescaleToUnit(t *testing.T) {
assert := assert.New(t)
assert.Equal([]float64{0.0, 1.0}, RescaleToUnit([]float64{2.0, 49.9}))
assert.Equal([]float64{1.0, 0.0}, RescaleToUnit([]float64{100.0, 49.9}))
assert.Equal([]float64{0.0, 0.25, 0.5, 0.75, 1.0}, RescaleToUnit([]float64{1.0, 2.0, 3.0, 4.0, 5.0}))
assert.Equal([]float64{0.25, 0.0, 1.0, 0.5, 0.75}, RescaleToUnit([]float64{2.0, 1.0, 5.0, 3.0, 4.0}))
assert.Equal([]float64{0.25, 0.0, 1.0, 0.5, 0.75}, RescaleToUnit([]float64{12.0, 11.0, 15.0, 13.0, 14.0}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/21 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/21 |
22 | go | THUDM/humaneval-x | Go_22 | Go_22.go | Go_22_test.go | func FilterIntegers(values []interface{}) []int {
result := make([]int, 0)
for _, val := range values {
switch i := val.(type) {
case int:
result = append(result, i)
}
}
return result
} | func TestFilterIntegers(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{}, FilterIntegers([]interface{}{}))
assert.Equal([]int{4, 9}, FilterIntegers([]interface{}{4, nil, []interface{}{}, 23.2, 9, "adasd"}))
assert.Equal([]int{3, 3, 3}, FilterIntegers([]interface{}{3, 'c', 3, 3, 'a', 'b'}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/22 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/22 |
23 | go | THUDM/humaneval-x | Go_23 | Go_23.go | Go_23_test.go | func Strlen(str string) int {
return len(str)
} | func TestStrlen(t *testing.T) {
assert := assert.New(t)
assert.Equal(0, Strlen(""))
assert.Equal(1, Strlen("x"))
assert.Equal(9, Strlen("asdasnakj"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/23 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/23 |
24 | go | THUDM/humaneval-x | Go_24 | Go_24.go | Go_24_test.go | func LargestDivisor(n int) int {
for i := n - 1; i > 0; i-- {
if n % i == 0 {
return i
}
}
return 0
} | func TestLargestDivisor(t *testing.T) {
assert := assert.New(t)
assert.Equal(1, LargestDivisor(3))
assert.Equal(1, LargestDivisor(7))
assert.Equal(5, LargestDivisor(10))
assert.Equal(50, LargestDivisor(100))
assert.Equal(7, LargestDivisor(49))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/24 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/24 |
25 | go | THUDM/humaneval-x | Go_25 | Go_25.go | Go_25_test.go | func Factorize(n int) []int {
fact := make([]int, 0)
for i := 2; i <= int(math.Sqrt(float64(n))+1); {
if n%i == 0 {
fact = append(fact, i)
n = n / i
} else {
i++
}
}
if n > 1 {
fact = append(fact, n)
}
return fact
} | func TestFactorize(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{2}, Factorize(2))
assert.Equal([]int{2, 2}, Factorize(4))
assert.Equal([]int{2, 2, 2}, Factorize(8))
assert.Equal([]int{3, 19}, Factorize(3 * 19))
assert.Equal([]int{3, 3, 19, 19}, Factorize(3 * 19 * 3 * 19))
assert.Equal([]int{3, 3, 3, 19, 19, 19}, Factorize(3 * 19 * 3 * 19 * 3 * 19))
assert.Equal([]int{3, 19, 19, 19}, Factorize(3 * 19 * 19 * 19))
assert.Equal([]int{2, 3, 3}, Factorize(3 * 2 * 3))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/25 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/25 |
26 | go | THUDM/humaneval-x | Go_26 | Go_26.go | Go_26_test.go | func RemoveDuplicates(numbers []int) []int {
c := make(map[int] int)
for _, number := range numbers {
if i, ok := c[number]; ok {
c[number] = i + 1
} else {
c[number] = 1
}
}
result := make([]int, 0)
for _, number := range numbers {
if c[number] <= 1 {
result = append(result, number)
}
}
return result
} | func TestRemoveDuplicates(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{}, RemoveDuplicates([]int{}))
assert.Equal([]int{1, 2, 3, 4}, RemoveDuplicates([]int{1, 2, 3,4}))
assert.Equal([]int{1, 4, 5}, RemoveDuplicates([]int{1, 2, 3, 2,4, 3, 5}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/26 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/26 |
27 | go | THUDM/humaneval-x | Go_27 | Go_27.go | Go_27_test.go | func FlipCase(str string) string {
result := []rune{}
for _, c := range str {
if c >= 'A' && c <= 'Z' {
result = append(result, 'a' + ((c - 'A' + 26) % 26))
} else if c >= 'a' && c <= 'z' {
result = append(result, 'A' + ((c - 'a' + 26) % 26))
} else {
result = append(result, c)
}
}
return string(result)
} | func TestFlipCase(t *testing.T) {
assert := assert.New(t)
assert.Equal("", FlipCase(""))
assert.Equal("hELLO!", FlipCase("Hello!"))
assert.Equal("tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS",FlipCase("These violent delights have violent ends"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/27 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/27 |
28 | go | THUDM/humaneval-x | Go_28 | Go_28.go | Go_28_test.go | func Concatenate(strings []string) string {
if len(strings) == 0 {
return ""
}
return strings[0] + Concatenate(strings[1:])
} | func TestConcatenate(t *testing.T) {
assert := assert.New(t)
assert.Equal("", Concatenate([]string{}))
assert.Equal("xyz", Concatenate([]string{"x", "y", "z"}))
assert.Equal("xyzwk", Concatenate([]string{"x", "y","z", "w", "k"}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/28 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/28 |
29 | go | THUDM/humaneval-x | Go_29 | Go_29.go | Go_29_test.go | func FilterByPrefix(strings []string,prefix string) []string {
if len(strings) == 0 {
return []string{}
}
res := make([]string, 0, len(strings))
for _, s := range strings {
if s[:len(prefix)] == prefix {
res = append(res, s)
}
}
return res
} | func TestFilterByPrefix(t *testing.T) {
assert := assert.New(t)
assert.Equal([]string{}, FilterByPrefix([]string{}, "john"))
assert.Equal([]string{"xxx", "xxxAAA", "xxx"}, FilterByPrefix([]string{"xxx", "asd", "xxy", "john doe", "xxxAAA", "xxx"}, "xxx"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/29 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/29 |
30 | go | THUDM/humaneval-x | Go_30 | Go_30.go | Go_30_test.go | func GetPositive(l []int) []int {
res := make([]int, 0)
for _, x := range l {
if x > 0 {
res = append(res, x)
}
}
return res
} | func TestGetPositive(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{4, 5, 6}, GetPositive([]int{-1, -2, 4,5, 6}))
assert.Equal([]int{5, 3, 2, 3, 3, 9, 123, 1}, GetPositive([]int{5, 3, -5, 2, 3, 3, 9, 0, 123, 1, -10}))
assert.Equal([]int{}, GetPositive([]int{-1, -2}))
assert.Equal([]int{}, GetPositive([]int{}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/30 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/30 |
31 | go | THUDM/humaneval-x | Go_31 | Go_31.go | Go_31_test.go | func IsPrime(n int) bool {
if n <= 1 {
return false
}
if n == 2 {
return true
}
if n%2 == 0 {
return false
}
for i := 3; i*i <= n; i += 2 {
if n%i == 0 {
return false
}
}
return true
} | func TestIsPrime(t *testing.T) {
assert := assert.New(t)
assert.Equal(false, IsPrime(6))
assert.Equal(true, IsPrime(101))
assert.Equal(true, IsPrime(11))
assert.Equal(true, IsPrime(13441))
assert.Equal(true, IsPrime(61))
assert.Equal(false, IsPrime(4))
assert.Equal(false, IsPrime(1))
assert.Equal(true, IsPrime(5))
assert.Equal(true, IsPrime(11))
assert.Equal(true, IsPrime(17))
assert.Equal(false, IsPrime(5 * 17))
assert.Equal(false, IsPrime(11 * 7))
assert.Equal(false, IsPrime(13441 * 19))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/31 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/31 |
32 | go | THUDM/humaneval-x | Go_32 | Go_32.go | Go_32_test.go | func FindZero(xs []int) float64 {
begin := -1.0
end := 1.0
for Poly(xs, begin)*Poly(xs, end) > 0 {
begin *= 2
end *= 2
}
for end-begin > 1e-10 {
center := (begin + end) / 2
if Poly(xs, center)*Poly(xs, begin) > 0 {
begin = center
} else {
end = center
}
}
return begin
} | func TestFindZero(t *testing.T) {
assert := assert.New(t)
randInt := func(min, max int) int {
rng := rand.New(rand.NewSource(42))
if min >= max || min == 0 || max == 0 {
return max
}
return rng.Intn(max-min) + min
}
copyInts := func(src []int) []int {
ints := make([]int, 0)
for _, i := range src {
ints = append(ints, i)
}
return ints
}
for i := 0; i < 100; i++ {
ncoeff := 2 * randInt(1, 4)
coeffs := make([]int, 0)
for j := 0; j < ncoeff; j++ {
coeff := randInt(-10, 10)
if coeff == 0 {
coeff = 1
}
coeffs = append(coeffs, coeff)
}
solution := FindZero(copyInts(coeffs))
assert.Equal(true, math.Abs(Poly(coeffs,solution))<1e-4)
}
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/32 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/32 |
33 | go | THUDM/humaneval-x | Go_33 | Go_33.go | Go_33_test.go | func SortThird(l []int) []int {
temp := make([]int, 0)
for i := 0; i < len(l); i = i + 3 {
temp = append(temp, l[i])
}
sort.Ints(temp)
j := 0
for i := 0; i < len(l); i = i + 3 {
l[i] = temp[j]
j++
}
return l
} | func TestSortThird(t *testing.T) {
assert := assert.New(t)
same := func(src []int, target []int) bool {
for i := 0; i < len(src); i++ {
if src[i] != target[i] {
return false
}
}
return true
}
assert.Equal(true, same([]int{1, 2, 3}, SortThird([]int{1, 2, 3})))
assert.Equal(true, same([]int{1, 3, -5, 2, -3, 3, 5, 0, 123, 9, -10}, SortThird([]int{5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10})))
assert.Equal(true, same([]int{-10, 8, -12,3, 23, 2, 4, 11, 12, 5}, SortThird([]int{5, 8, -12, 4, 23, 2, 3, 11, 12, -10})))
assert.Equal(true, same([]int{2, 6, 3, 4, 8, 9, 5}, SortThird([]int{5, 6, 3, 4, 8, 9, 2})))
assert.Equal(true, same([]int{2, 8, 3, 4, 6, 9, 5}, SortThird([]int{5, 8, 3, 4, 6, 9, 2})))
assert.Equal(true, same([]int{2, 6, 9, 4, 8, 3, 5}, SortThird([]int{5, 6, 9, 4, 8, 3, 2})))
assert.Equal(true, same([]int{2, 6, 3, 4, 8, 9, 5, 1}, SortThird([]int{5, 6, 3, 4, 8, 9, 2, 1})))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/33 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/33 |
34 | go | THUDM/humaneval-x | Go_34 | Go_34.go | Go_34_test.go | func Unique(l []int) []int {
set := make(map[int]interface{})
for _, i := range l {
set[i]=nil
}
l = make([]int,0)
for i, _ := range set {
l = append(l, i)
}
sort.Ints(l)
return l
} | func TestUnique(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{0, 2, 3, 5, 9, 123}, Unique([]int{5, 3,5, 2, 3, 3, 9, 0, 123}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/34 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/34 |
35 | go | THUDM/humaneval-x | Go_35 | Go_35.go | Go_35_test.go | func MaxElement(l []int) int {
max := l[0]
for _, x := range l {
if x > max {
max = x
}
}
return max
} | func TestMaxElement(t *testing.T) {
assert := assert.New(t)
assert.Equal(3, MaxElement([]int{1, 2, 3}))
assert.Equal(124, MaxElement([]int{5, 3, -5, 2, -3, 3, 9,0, 124, 1, -10}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/35 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/35 |
36 | go | THUDM/humaneval-x | Go_36 | Go_36.go | Go_36_test.go | func FizzBuzz(n int) int {
ns := make([]int, 0)
for i := 0; i < n; i++ {
if i%11 == 0 || i%13 == 0 {
ns = append(ns, i)
}
}
temp := make([]string, 0)
for _, i := range ns {
temp = append(temp, strconv.Itoa(i))
}
join := strings.Join(temp, "")
ans := 0
for _, c := range join {
if c == '7' {
ans++
}
}
return ans
} | func TestFizzBuzz(t *testing.T) {
assert := assert.New(t)
assert.Equal(0, FizzBuzz(50))
assert.Equal(2, FizzBuzz(78))
assert.Equal(3, FizzBuzz(79))
assert.Equal(3, FizzBuzz(100))
assert.Equal(6, FizzBuzz(200))
assert.Equal(192, FizzBuzz(4000))
assert.Equal(639, FizzBuzz(10000))
assert.Equal(8026, FizzBuzz(100000))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/36 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/36 |
37 | go | THUDM/humaneval-x | Go_37 | Go_37.go | Go_37_test.go | func SortEven(l []int) []int {
evens := make([]int, 0)
for i := 0; i < len(l); i += 2 {
evens = append(evens, l[i])
}
sort.Ints(evens)
j := 0
for i := 0; i < len(l); i += 2 {
l[i] = evens[j]
j++
}
return l
} | func TestSortEven(t *testing.T) {
assert := assert.New(t)
same := func(src []int, target []int) bool {
for i := 0; i < len(src); i++ {
if src[i] != target[i] {
return false
}
}
return true
}
assert.Equal(true, same([]int{1, 2, 3}, SortEven([]int{1, 2, 3})))
assert.Equal(true, same([]int{-10, 3, -5, 2, -3, 3, 5, 0, 9, 1, 123}, SortEven([]int{5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10})))
assert.Equal(true, same([]int{-12, 8, 3, 4, 5, 2, 12, 11, 23, -10}, SortEven([]int{5, 8, -12, 4, 23, 2, 3, 11, 12, -10})))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/37 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/37 |
38 | go | THUDM/humaneval-x | Go_38 | Go_38.go | Go_38_test.go | func DecodeCyclic(s string) string {
return EncodeCyclic(EncodeCyclic(s))
} | func TestDecodeCyclic(t *testing.T) {
assert := assert.New(t)
randInt := func(min, max int) int {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
if min >= max || min == 0 || max == 0 {
return max
}
return rng.Intn(max-min) + min
}
for i := 0; i <100 ; i++ {
runes := make([]rune, 0)
for j := 0; j < randInt(10,20); j++ {
runes = append(runes, int32(randInt('a','z')))
}
encoded_str := EncodeCyclic(string(runes))
assert.Equal(string(runes), DecodeCyclic(encoded_str))
}
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/38 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/38 |
39 | go | THUDM/humaneval-x | Go_39 | Go_39.go | Go_39_test.go | func PrimeFib(n int) int {
isPrime := func(p int) bool {
if p < 2 {
return false
}
for i := 2; i < int(math.Min(math.Sqrt(float64(p))+1, float64(p-1))); i++ {
if p%i == 0 {
return false
}
}
return true
}
f := []int{0, 1}
for {
f = append(f, f[len(f)-1]+f[len(f)-2])
if isPrime(f[len(f)-1]) {
n -= 1
}
if n == 0 {
return f[len(f)-1]
}
}
} | func TestPrimeFib(t *testing.T) {
assert := assert.New(t)
assert.Equal(2, PrimeFib(1))
assert.Equal(3, PrimeFib(2))
assert.Equal(5, PrimeFib(3))
assert.Equal(13, PrimeFib(4))
assert.Equal(89, PrimeFib(5))
assert.Equal(233, PrimeFib(6))
assert.Equal(1597, PrimeFib(7))
assert.Equal(28657, PrimeFib(8))
assert.Equal(514229, PrimeFib(9))
assert.Equal(433494437, PrimeFib(10))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/39 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/39 |
40 | go | THUDM/humaneval-x | Go_40 | Go_40.go | Go_40_test.go | func TriplesSumToZero(l []int) bool {
for i := 0; i < len(l) - 2; i++ {
for j := i + 1; j < len(l) - 1; j++ {
for k := j + 1; k < len(l); k++ {
if l[i] + l[j] + l[k] == 0 {
return true
}
}
}
}
return false
} | func TestTriplesSumToZero(t *testing.T) {
assert := assert.New(t)
assert.Equal(false, TriplesSumToZero([]int{1, 3, 5, 0}))
assert.Equal(false, TriplesSumToZero([]int{1, 3, 5, -1}))
assert.Equal(true, TriplesSumToZero([]int{1, 3, -2, 1}))
assert.Equal(false, TriplesSumToZero([]int{1, 2, 3, 7}))
assert.Equal(false, TriplesSumToZero([]int{1, 2, 5, 7}))
assert.Equal(true, TriplesSumToZero([]int{2, 4, -5, 3, 9, 7}))
assert.Equal(false, TriplesSumToZero([]int{1}))
assert.Equal(false, TriplesSumToZero([]int{1, 3, 5, -100}))
assert.Equal(false, TriplesSumToZero([]int{100, 3, 5, -100}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/40 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/40 |
41 | go | THUDM/humaneval-x | Go_41 | Go_41.go | Go_41_test.go | func CarRaceCollision(n int) int {
return n * n
} | func TestCarRaceCollision(t *testing.T) {
assert := assert.New(t)
assert.Equal(4, CarRaceCollision(2))
assert.Equal(9, CarRaceCollision(3))
assert.Equal(16, CarRaceCollision(4))
assert.Equal(64, CarRaceCollision(8))
assert.Equal(100, CarRaceCollision(10))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/41 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/41 |
42 | go | THUDM/humaneval-x | Go_42 | Go_42.go | Go_42_test.go | func IncrList(l []int) []int {
n := len(l)
for i := 0; i < n; i++ {
l[i]++
}
return l
} | func TestIncrList(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{}, IncrList([]int{}))
assert.Equal([]int{4, 3, 2}, IncrList([]int{3, 2, 1}))
assert.Equal([]int{6, 3, 6, 3, 4, 4, 10, 1, 124}, IncrList([]int{5, 2, 5, 2, 3, 3, 9, 0, 123}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/42 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/42 |
43 | go | THUDM/humaneval-x | Go_43 | Go_43.go | Go_43_test.go | func PairsSumToZero(l []int) bool {
seen := map[int]bool{}
for i := 0; i < len(l); i++ {
for j := i + 1; j < len(l); j++ {
if l[i] + l[j] == 0 {
if _, ok := seen[l[i]]; !ok {
seen[l[i]] = true
return true
}
if _, ok := seen[l[j]]; !ok {
seen[l[j]] = true
return true
}
}
}
}
return false
} | func TestPairsSumToZero(t *testing.T) {
assert := assert.New(t)
assert.Equal(false, PairsSumToZero([]int{1, 3, 5, 0}))
assert.Equal(false, PairsSumToZero([]int{1, 3, -2, 1}))
assert.Equal(false, PairsSumToZero([]int{1, 2, 3, 7}))
assert.Equal(true, PairsSumToZero([]int{2, 4, -5, 3, 5, 7}))
assert.Equal(false, PairsSumToZero([]int{1}))
assert.Equal(true, PairsSumToZero([]int{-3, 9, -1, 3, 2, 30}))
assert.Equal(true, PairsSumToZero([]int{-3, 9, -1, 3, 2, 31}))
assert.Equal(false, PairsSumToZero([]int{-3, 9, -1, 4, 2, 30}))
assert.Equal(false, PairsSumToZero([]int{-3, 9, -1, 4, 2, 31}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/43 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/43 |
44 | go | THUDM/humaneval-x | Go_44 | Go_44.go | Go_44_test.go | func ChangeBase(x int, base int) string {
if x >= base {
return ChangeBase(x/base, base) + ChangeBase(x%base, base)
}
return strconv.Itoa(x)
} | func TestChangeBase(t *testing.T) {
assert := assert.New(t)
assert.Equal("22", ChangeBase(8, 3))
assert.Equal("100", ChangeBase(9, 3))
assert.Equal("11101010", ChangeBase(234, 2))
assert.Equal("10000", ChangeBase(16, 2))
assert.Equal("1000", ChangeBase(8, 2))
assert.Equal("111", ChangeBase(7, 2))
for i := 2; i < 8; i++ {
assert.Equal(strconv.Itoa(i), ChangeBase(i, i+1))
}
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/44 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/44 |
45 | go | THUDM/humaneval-x | Go_45 | Go_45.go | Go_45_test.go | func TriangleArea(a float64, h float64) float64 {
return a * h / 2
} | func TestTriangleArea(t *testing.T) {
assert := assert.New(t)
assert.Equal(7.5, TriangleArea(5, 3))
assert.Equal(2.0, TriangleArea(2, 2))
assert.Equal(40.0, TriangleArea(10, 8))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/45 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/45 |
46 | go | THUDM/humaneval-x | Go_46 | Go_46.go | Go_46_test.go | func Fib4(n int) int {
switch n {
case 0:
return 0
case 1:
return 0
case 2:
return 2
case 3:
return 0
default:
return Fib4(n-1) + Fib4(n-2) + Fib4(n-3) + Fib4(n-4)
}
} | func TestFib4(t *testing.T) {
assert := assert.New(t)
assert.Equal(4, Fib4(5))
assert.Equal(28, Fib4(8))
assert.Equal(104, Fib4(10))
assert.Equal(386, Fib4(12))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/46 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/46 |
47 | go | THUDM/humaneval-x | Go_47 | Go_47.go | Go_47_test.go | func Median(l []int) float64 {
sort.Ints(l)
if len(l)%2==1{
return float64(l[len(l)/2])
}else{
return float64(l[len(l)/2-1]+l[len(l)/2])/2.0
}
} | func TestMedian(t *testing.T) {
assert := assert.New(t)
assert.Equal(3.0, Median([]int{3, 1, 2, 4, 5}))
assert.Equal(8.0, Median([]int{-10, 4, 6, 1000, 10, 20}))
assert.Equal(5.0, Median([]int{5}))
assert.Equal(5.5, Median([]int{6, 5}))
assert.Equal(7.0, Median([]int{8, 1, 3, 9, 9, 2, 7}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/47 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/47 |
48 | go | THUDM/humaneval-x | Go_48 | Go_48.go | Go_48_test.go | func IsPalindrome(text string) bool {
runes := []rune(text)
result := make([]rune, 0)
for i := len(runes) - 1; i >= 0; i-- {
result = append(result, runes[i])
}
return text == string(result)
} | func TestIsPalindrome(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, IsPalindrome(""))
assert.Equal(true, IsPalindrome("aba"))
assert.Equal(true, IsPalindrome("aaaaa"))
assert.Equal(false, IsPalindrome("zbcd"))
assert.Equal(true, IsPalindrome("xywyx"))
assert.Equal(false, IsPalindrome("xywyz"))
assert.Equal(false, IsPalindrome("xywzx"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/48 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/48 |
49 | go | THUDM/humaneval-x | Go_49 | Go_49.go | Go_49_test.go | func Modp(n int,p int) int {
ret := 1
for i:= 0; i < n; i++ {
ret = (2 * ret) % p
}
return ret
} | func TestModp(t *testing.T) {
assert := assert.New(t)
assert.Equal(3, Modp(3, 5))
assert.Equal(2, Modp(1101, 101))
assert.Equal(1, Modp(0, 101))
assert.Equal(8, Modp(3, 11))
assert.Equal(1, Modp(100, 101))
assert.Equal(4, Modp(30, 5))
assert.Equal(3, Modp(31, 5))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/49 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/49 |
50 | go | THUDM/humaneval-x | Go_50 | Go_50.go | Go_50_test.go | func DecodeShift(s string) string {
runes := []rune(s)
newRunes := make([]rune, 0)
for _, ch := range runes {
newRunes = append(newRunes, (ch-5-'a')%26+'a')
}
return string(runes)
} | func TestDecodeShift(t *testing.T) {
assert := assert.New(t)
randInt := func(min, max int) int {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
if min >= max || min == 0 || max == 0 {
return max
}
return rng.Intn(max-min) + min
}
for i := 0; i <100 ; i++ {
runes := make([]rune, 0)
for j := 0; j < randInt(10,20); j++ {
runes = append(runes, int32(randInt('a','z')))
}
encoded_str := EncodeShift(string(runes))
assert.Equal(DecodeShift(encoded_str), string(runes))
}
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/50 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/50 |
51 | go | THUDM/humaneval-x | Go_51 | Go_51.go | Go_51_test.go | func RemoveVowels(text string) string {
var re = regexp.MustCompile("[aeiouAEIOU]")
text = re.ReplaceAllString(text, "")
return text
} | func TestRemoveVowels(t *testing.T) {
assert := assert.New(t)
assert.Equal("", RemoveVowels(""))
assert.Equal("bcdf\nghjklm", RemoveVowels("abcdef\nghijklm"))
assert.Equal("fdcb", RemoveVowels("fedcba"))
assert.Equal("", RemoveVowels("eeeee"))
assert.Equal("cB", RemoveVowels("acBAA"))
assert.Equal("cB", RemoveVowels("EcBOO"))
assert.Equal("ybcd", RemoveVowels("ybcd"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/51 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/51 |
52 | go | THUDM/humaneval-x | Go_52 | Go_52.go | Go_52_test.go | func BelowThreshold(l []int,t int) bool {
for _, n := range l {
if n >= t {
return false
}
}
return true
} | func TestBelowThreshold(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, BelowThreshold([]int{1, 2, 4, 10}, 100))
assert.Equal(false, BelowThreshold([]int{1, 20, 4, 10}, 5))
assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 21))
assert.Equal(true, BelowThreshold([]int{1, 20, 4, 10}, 22))
assert.Equal(true, BelowThreshold([]int{1, 8, 4, 10}, 11))
assert.Equal(false, BelowThreshold([]int{1, 8, 4, 10}, 10))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/52 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/52 |
53 | go | THUDM/humaneval-x | Go_53 | Go_53.go | Go_53_test.go | func Add(x int, y int) int {
return x + y
} | func TestAdd(t *testing.T) {
assert := assert.New(t)
assert.Equal(1, Add(0, 1))
assert.Equal(1, Add(1, 0))
assert.Equal(5, Add(2, 3))
assert.Equal(12, Add(5, 7))
assert.Equal(12, Add(7, 5))
for i := 0; i < 100; i++ {
x := rand.Int31n(1000)
y := rand.Int31n(1000)
assert.Equal(int(x+y), Add(int(x), int(y)))
}
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/53 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/53 |
54 | go | THUDM/humaneval-x | Go_54 | Go_54.go | Go_54_test.go | func SameChars(s0 string, s1 string) bool {
set0 := make(map[int32]interface{})
set1 := make(map[int32]interface{})
for _, i := range s0 {
set0[i] = nil
}
for _, i := range s1 {
set1[i] = nil
}
for i, _ := range set0 {
if _,ok:=set1[i];!ok{
return false
}
}
for i, _ := range set1 {
if _,ok:=set0[i];!ok{
return false
}
}
return true
} | func TestSameChars(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, SameChars("eabcdzzzz", "dddzzzzzzzddeddabc"))
assert.Equal(true, SameChars("abcd", "dddddddabc"))
assert.Equal(true, SameChars("dddddddabc", "abcd"))
assert.Equal(false, SameChars("eabcd", "dddddddabc"))
assert.Equal(false, SameChars("abcd", "dddddddabcf"))
assert.Equal(false, SameChars("eabcdzzzz", "dddzzzzzzzddddabc"))
assert.Equal(false, SameChars("aabb", "aaccc"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/54 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/54 |
55 | go | THUDM/humaneval-x | Go_55 | Go_55.go | Go_55_test.go | func Fib(n int) int {
if n <= 1 {
return n
}
return Fib(n-1) + Fib(n-2)
} | func TestFib(t *testing.T) {
assert := assert.New(t)
assert.Equal(55, Fib(10))
assert.Equal(1, Fib(1))
assert.Equal(21, Fib(8))
assert.Equal(89, Fib(11))
assert.Equal(144, Fib(12))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/55 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/55 |
56 | go | THUDM/humaneval-x | Go_56 | Go_56.go | Go_56_test.go | func CorrectBracketing(brackets string) bool {
l := len(brackets)
count := 0
for index := 0; index < l; index++ {
if brackets[index] == '<' {
count++
} else if brackets[index] == '>' {
count--
}
if count < 0 {
return false
}
}
if count == 0 {
return true
} else {
return false
}
} | func TestCorrectBracketing(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, CorrectBracketing("<>"))
assert.Equal(true, CorrectBracketing("<<><>>"))
assert.Equal(true, CorrectBracketing("<><><<><>><>"))
assert.Equal(true, CorrectBracketing("<><><<<><><>><>><<><><<>>>"))
assert.Equal(false, CorrectBracketing("<<<><>>>>"))
assert.Equal(false, CorrectBracketing("><<>"))
assert.Equal(false, CorrectBracketing("<"))
assert.Equal(false, CorrectBracketing("<<<<"))
assert.Equal(false, CorrectBracketing(">"))
assert.Equal(false, CorrectBracketing("<<>"))
assert.Equal(false, CorrectBracketing("<><><<><>><>><<>"))
assert.Equal(false, CorrectBracketing("<><><<><>><>>><>"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/56 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/56 |
57 | go | THUDM/humaneval-x | Go_57 | Go_57.go | Go_57_test.go | func Monotonic(l []int) bool {
flag := true
if len(l) > 1 {
for i := 0; i < len(l)-1; i++ {
if l[i] != l[i+1] {
flag = l[i] > l[i+1]
break
}
}
} else {
return false
}
for i := 0; i < len(l)-1; i++ {
if flag != (l[i] >= l[i+1]) {
return false
}
}
return true
} | func TestMonotonic(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, Monotonic([]int{1, 2, 4, 10}))
assert.Equal(true, Monotonic([]int{1, 2, 4, 20}))
assert.Equal(false, Monotonic([]int{1, 20, 4, 10}))
assert.Equal(true, Monotonic([]int{4, 1, 0, -10}))
assert.Equal(true, Monotonic([]int{4, 1, 1, 0}))
assert.Equal(false, Monotonic([]int{1, 2, 3, 2, 5, 60}))
assert.Equal(true, Monotonic([]int{1, 2, 3, 4, 5, 60}))
assert.Equal(true, Monotonic([]int{9, 9, 9, 9}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/57 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/57 |
58 | go | THUDM/humaneval-x | Go_58 | Go_58.go | Go_58_test.go | func Common(l1 []int,l2 []int) []int {
m := make(map[int]bool)
for _, e1 := range l1 {
if m[e1] {
continue
}
for _, e2 := range l2 {
if e1 == e2 {
m[e1] = true
break
}
}
}
res := make([]int, 0, len(m))
for k, _ := range m {
res = append(res, k)
}
sort.Ints(res)
return res
} | func TestCommon(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{1, 5, 653}, Common([]int{1, 4, 3, 34, 653, 2, 5}, []int{5, 7, 1, 5, 9, 653, 121}))
assert.Equal([]int{2, 3}, Common([]int{5, 3, 2, 8}, []int{3, 2}))
assert.Equal([]int{2, 3, 4}, Common([]int{4, 3, 2, 8}, []int{3, 2, 4}))
assert.Equal([]int{}, Common([]int{4, 3, 2, 8}, []int{}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/58 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/58 |
59 | go | THUDM/humaneval-x | Go_59 | Go_59.go | Go_59_test.go | func LargestPrimeFactor(n int) int {
isPrime := func(n int) bool {
for i := 2; i < int(math.Pow(float64(n), 0.5)+1); i++ {
if n%i == 0 {
return false
}
}
return true
}
largest := 1
for j := 2; j < n + 1; j++ {
if n % j == 0 && isPrime(j) {
if j > largest {
largest = j
}
}
}
return largest
} | func TestLargestPrimeFactor(t *testing.T) {
assert := assert.New(t)
assert.Equal(5, LargestPrimeFactor(15))
assert.Equal(3, LargestPrimeFactor(27))
assert.Equal(7, LargestPrimeFactor(63))
assert.Equal(11, LargestPrimeFactor(330))
assert.Equal(29, LargestPrimeFactor(13195))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/59 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/59 |
60 | go | THUDM/humaneval-x | Go_60 | Go_60.go | Go_60_test.go | func SumToN(n int) int {
if n <= 0 {
return 0
} else {
return n + SumToN(n - 1)
}
} | func TestSumToN(t *testing.T) {
assert := assert.New(t)
assert.Equal(1, SumToN(1))
assert.Equal(21, SumToN(6))
assert.Equal(66, SumToN(11))
assert.Equal(465, SumToN(30))
assert.Equal(5050, SumToN(100))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/60 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/60 |
61 | go | THUDM/humaneval-x | Go_61 | Go_61.go | Go_61_test.go | func CorrectBracketing(brackets string) bool {
brackets = strings.Replace(brackets, "(", " ( ", -1)
brackets = strings.Replace(brackets, ")", ") ", -1)
open := 0
for _, b := range brackets {
if b == '(' {
open++
} else if b == ')' {
open--
}
if open < 0 {
return false
}
}
return open == 0
} | func TestCorrectBracketing(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, CorrectBracketing("()"))
assert.Equal(true, CorrectBracketing("(()())"))
assert.Equal(true, CorrectBracketing("()()(()())()"))
assert.Equal(true, CorrectBracketing("()()((()()())())(()()(()))"))
assert.Equal(false, CorrectBracketing("((()())))"))
assert.Equal(false, CorrectBracketing(")(()"))
assert.Equal(false, CorrectBracketing("("))
assert.Equal(false, CorrectBracketing("(((("))
assert.Equal(false, CorrectBracketing(")"))
assert.Equal(false, CorrectBracketing("(()"))
assert.Equal(false, CorrectBracketing("()()(()())())(()"))
assert.Equal(false, CorrectBracketing("()()(()())()))()"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/61 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/61 |
62 | go | THUDM/humaneval-x | Go_62 | Go_62.go | Go_62_test.go | func Derivative(xs []int) []int {
l := len(xs)
y := make([]int, l - 1)
for i := 0; i < l - 1; i++ {
y[i] = xs[i + 1] * (i + 1)
}
return y
} | func TestDerivative(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{1, 4, 12, 20}, Derivative([]int{3, 1, 2, 4, 5}))
assert.Equal([]int{2, 6}, Derivative([]int{1, 2, 3}))
assert.Equal([]int{2, 2}, Derivative([]int{3, 2, 1}))
assert.Equal([]int{2, 2, 0, 16}, Derivative([]int{3, 2, 1,0, 4}))
assert.Equal([]int{}, Derivative([]int{1}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/62 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/62 |
63 | go | THUDM/humaneval-x | Go_63 | Go_63.go | Go_63_test.go | func Fibfib(n int) int {
if n <= 0 {
return 0
}
switch n {
case 0:
return 0
case 1:
return 0
case 2:
return 1
default:
return Fibfib(n-1) + Fibfib(n-2) + Fibfib(n-3)
}
} | func TestFibfib(t *testing.T) {
assert := assert.New(t)
assert.Equal(1, Fibfib(2))
assert.Equal(0, Fibfib(1))
assert.Equal(4, Fibfib(5))
assert.Equal(24, Fibfib(8))
assert.Equal(81, Fibfib(10))
assert.Equal(274, Fibfib(12))
assert.Equal(927, Fibfib(14))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/63 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/63 |
64 | go | THUDM/humaneval-x | Go_64 | Go_64.go | Go_64_test.go | func VowelsCount(s string) int {
s = strings.ToLower(s)
vowels := map[int32]interface{}{'a': nil, 'e': nil, 'i': nil, 'o': nil, 'u': nil}
count := 0
for _, i := range s {
if _, ok := vowels[i]; ok {
count++
}
}
if (s[len(s)-1]) == 'y' {
count++
}
return count
} | func TestVowelsCount(t *testing.T) {
assert := assert.New(t)
assert.Equal(2, VowelsCount("abcde"))
assert.Equal(3, VowelsCount("Alone"))
assert.Equal(2, VowelsCount("key"))
assert.Equal(1, VowelsCount("bye"))
assert.Equal(2, VowelsCount("keY"))
assert.Equal(1, VowelsCount("bYe"))
assert.Equal(3, VowelsCount("ACEDY"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/64 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/64 |
65 | go | THUDM/humaneval-x | Go_65 | Go_65.go | Go_65_test.go | func CircularShift(x int, shift int) string {
s := strconv.Itoa(x)
if shift > len(s) {
runes := make([]rune, 0)
for i := len(s)-1; i >= 0; i-- {
runes = append(runes, rune(s[i]))
}
return string(runes)
}else{
return s[len(s)-shift:]+s[:len(s)-shift]
}
} | func TestCircularShift(t *testing.T) {
assert := assert.New(t)
assert.Equal("001", CircularShift(100, 2))
assert.Equal("12", CircularShift(12, 2))
assert.Equal("79", CircularShift(97, 8))
assert.Equal("21", CircularShift(12, 1))
assert.Equal("11", CircularShift(11, 101))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/65 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/65 |
66 | go | THUDM/humaneval-x | Go_66 | Go_66.go | Go_66_test.go | func Digitsum(x string) int {
if len(x) == 0 {
return 0
}
result := 0
for _, i := range x {
if 'A' <= i && i <= 'Z' {
result += int(i)
}
}
return result
} | func TestDigitSum(t *testing.T) {
assert := assert.New(t)
assert.Equal(0, Digitsum(""))
assert.Equal(131, Digitsum("abAB"))
assert.Equal(67, Digitsum("abcCd"))
assert.Equal(69, Digitsum("helloE"))
assert.Equal(131, Digitsum("woArBld"))
assert.Equal(153, Digitsum("aAaaaXa"))
assert.Equal(151, Digitsum(" How are yOu?"))
assert.Equal(327, Digitsum("You arE Very Smart"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/66 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/66 |
67 | go | THUDM/humaneval-x | Go_67 | Go_67.go | Go_67_test.go | func FruitDistribution(s string,n int) int {
split := strings.Split(s, " ")
for _, i := range split {
atoi, err := strconv.Atoi(i)
if err != nil {
continue
}
n = n - atoi
}
return n
} | func TestFruitDistribution(t *testing.T) {
assert := assert.New(t)
assert.Equal(8, FruitDistribution("5 apples and 6 oranges", 19))
assert.Equal(10, FruitDistribution("5 apples and 6 oranges", 21))
assert.Equal(2, FruitDistribution("0 apples and 1 oranges", 3))
assert.Equal(2, FruitDistribution("1 apples and 0 oranges", 3))
assert.Equal(95, FruitDistribution("2 apples and 3 oranges", 100))
assert.Equal(0, FruitDistribution("2 apples and 3 oranges", 5))
assert.Equal(19, FruitDistribution("1 apples and 100 oranges", 120))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/67 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/67 |
68 | go | THUDM/humaneval-x | Go_68 | Go_68.go | Go_68_test.go | func Pluck(arr []int) []int {
result := make([]int, 0)
if len(arr) == 0 {
return result
}
evens := make([]int, 0)
min := math.MaxInt64
minIndex := 0
for i, x := range arr {
if x%2 == 0 {
evens = append(evens, x)
if x < min {
min = x
minIndex = i
}
}
}
if len(evens) == 0 {
return result
}
result = []int{min, minIndex}
return result
} | func TestPluck(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{2, 1}, Pluck([]int{4,2,3}))
assert.Equal([]int{2, 1}, Pluck([]int{1,2,3}))
assert.Equal([]int{}, Pluck([]int{}))
assert.Equal([]int{0, 1}, Pluck([]int{5, 0, 3, 0, 4, 2}))
assert.Equal([]int{0, 3}, Pluck([]int{1, 2, 3, 0, 5, 3}))
assert.Equal([]int{4, 1}, Pluck([]int{5, 4, 8, 4 ,8}))
assert.Equal([]int{6, 1}, Pluck([]int{7, 6, 7, 1}))
assert.Equal([]int{}, Pluck([]int{7, 9, 7, 1}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/68 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/68 |
69 | go | THUDM/humaneval-x | Go_69 | Go_69.go | Go_69_test.go | func Search(lst []int) int {
countMap := make(map[int]int)
for _, i := range lst {
if count, ok := countMap[i]; ok {
countMap[i] = count + 1
} else {
countMap[i] = 1
}
}
max := -1
for i, count := range countMap {
if count >= i && count > max {
max = i
}
}
return max
} | func TestSearch(t *testing.T) {
assert := assert.New(t)
assert.Equal(1, Search([]int{5, 5, 5, 5, 1}))
assert.Equal(4, Search([]int{4, 1, 4, 1, 4, 4}))
assert.Equal(-1, Search([]int{3, 3}))
assert.Equal(8, Search([]int{8, 8, 8, 8, 8, 8, 8, 8}))
assert.Equal(2, Search([]int{2, 3, 3, 2, 2}))
assert.Equal(1, Search([]int{2, 7, 8, 8, 4, 8, 7, 3, 9, 6,5, 10, 4, 3, 6, 7, 1, 7, 4, 10, 8, 1}))
assert.Equal(2, Search([]int{3, 2, 8, 2}))
assert.Equal(1, Search([]int{6, 7, 1, 8, 8, 10, 5, 8, 5, 3, 10}))
assert.Equal(-1, Search([]int{8, 8, 3, 6, 5, 6, 4}))
assert.Equal(1, Search([]int{6, 9, 6, 7, 1, 4, 7, 1, 8, 8,9, 8, 10, 10, 8, 4, 10, 4, 10, 1, 2, 9, 5, 7, 9}))
assert.Equal(1, Search([]int{1, 9, 10, 1, 3}))
assert.Equal(5, Search([]int{6, 9, 7, 5, 8, 7, 5, 3, 7, 5,10, 10, 3, 6, 10, 2, 8, 6, 5, 4, 9, 5, 3, 10}))
assert.Equal(1, Search([]int{1}))
assert.Equal(4, Search([]int{8, 8, 10, 6, 4, 3, 5, 8, 2, 4, 2, 8, 4, 6, 10, 4, 2, 1, 10, 2, 1, 1, 5}))
assert.Equal(2, Search([]int{2, 10, 4, 8, 2, 10, 5, 1, 2, 9, 5, 5, 6, 3, 8, 6, 4, 10}))
assert.Equal(1, Search([]int{1, 6, 10, 1, 6, 9, 10, 8, 6, 8, 7, 3}))
assert.Equal(4, Search([]int{9, 2, 4, 1, 5, 1, 5, 2, 5, 7,7, 7, 3, 10, 1, 5, 4, 2, 8, 4, 1, 9, 10, 7, 10, 2, 8, 10, 9, 4}))
assert.Equal(4, Search([]int{2, 6, 4, 2, 8, 7, 5, 6, 4, 10, 4, 6, 3, 7, 8, 8, 3, 1, 4, 2, 2, 10, 7}))
assert.Equal(2, Search([]int{9, 8, 6, 10, 2, 6, 10, 2, 7, 8, 10, 3, 8, 2, 6, 2, 3, 1}))
assert.Equal(-1, Search([]int{5, 5, 3, 9, 5, 6, 3, 2, 8, 5, 6, 10, 10, 6, 8, 4, 10, 7, 7, 10, 8}))
assert.Equal(-1, Search([]int{10}))
assert.Equal(2, Search([]int{9, 7, 7, 2, 4, 7, 2, 10, 9, 7, 5, 7, 2}))
assert.Equal(1, Search([]int{5, 4, 10, 2, 1, 1, 10, 3, 6, 1, 8}))
assert.Equal(1, Search([]int{7, 9, 9, 9, 3, 4, 1, 5, 9, 1,2, 1, 1, 10, 7, 5, 6, 7, 6, 7, 7, 6}))
assert.Equal(-1, Search([]int{3, 10, 10, 9, 2}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/69 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/69 |
70 | go | THUDM/humaneval-x | Go_70 | Go_70.go | Go_70_test.go | func StrangeSortList(lst []int) []int {
sort.Ints(lst)
result := make([]int, 0)
for i := 0; i < len(lst)/2; i++ {
result = append(result, lst[i])
result = append(result, lst[len(lst)-i-1])
}
if len(lst)%2 != 0 {
result = append(result, lst[len(lst)/2])
}
return result
} | func TestStrangeSortList(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{1, 4, 2, 3}, StrangeSortList([]int{1,2, 3, 4}))
assert.Equal([]int{5, 9, 6, 8, 7}, StrangeSortList([]int{5, 6, 7, 8, 9}))
assert.Equal([]int{1, 5, 2, 4, 3}, StrangeSortList([]int{1, 2, 3, 4, 5}))
assert.Equal([]int{1, 9, 5, 8, 6, 7}, StrangeSortList([]int{5, 6, 7, 8, 9, 1}))
assert.Equal([]int{5, 5, 5, 5}, StrangeSortList([]int{5,5, 5, 5}))
assert.Equal([]int{}, StrangeSortList([]int{}))
assert.Equal([]int{1, 8, 2, 7, 3, 6, 4, 5}, StrangeSortList([]int{1,2,3,4,5,6,7,8}))
assert.Equal([]int{-5, 5, -5, 5, 0, 2, 2, 2}, StrangeSortList([]int{0,2,2,2,5,5,-5,-5}))
assert.Equal([]int{111111}, StrangeSortList([]int{111111}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/70 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/70 |
71 | go | THUDM/humaneval-x | Go_71 | Go_71.go | Go_71_test.go | func TriangleArea(a float64, b float64, c float64) interface{} {
if a+b <= c || a+c <= b || b+c <= a {
return -1
}
s := (a + b + c) / 2
area := math.Pow(s * (s - a) * (s - b) * (s - c), 0.5)
area = math.Round(area*100)/100
return area
} | func TestTriangleArea(t *testing.T) {
assert := assert.New(t)
assert.Equal(6.00, TriangleArea(3, 4, 5))
assert.Equal(-1, TriangleArea(1, 2, 10))
assert.Equal(8.18, TriangleArea(4, 8, 5))
assert.Equal(1.73, TriangleArea(2, 2, 2))
assert.Equal(-1, TriangleArea(1, 2, 3))
assert.Equal(16.25, TriangleArea(10, 5, 7))
assert.Equal(-1, TriangleArea(2, 6, 3))
assert.Equal(0.43, TriangleArea(1, 1, 1))
assert.Equal(-1, TriangleArea(2, 2, 10))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/71 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/71 |
72 | go | THUDM/humaneval-x | Go_72 | Go_72.go | Go_72_test.go | func WillItFly(q []int,w int) bool {
sum := 0
for i := 0; i < len(q); i++ {
sum += q[i]
}
if sum <= w && isPalindrome(q) {
return true
}
return false
}
func isPalindrome(arr []int) bool {
for i := 0; i < (len(arr) / 2); i++ {
if arr[i] != arr[len(arr) - i - 1] {
return false
}
}
return true
} | func TestWillItFly(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, WillItFly([]int{3, 2, 3}, 9))
assert.Equal(false, WillItFly([]int{1, 2}, 5))
assert.Equal(true, WillItFly([]int{3}, 5))
assert.Equal(false, WillItFly([]int{3, 2, 3}, 1))
assert.Equal(false, WillItFly([]int{1, 2, 3}, 6))
assert.Equal(true, WillItFly([]int{5}, 5))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/72 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/72 |
73 | go | THUDM/humaneval-x | Go_73 | Go_73.go | Go_73_test.go | func SmallestChange(arr []int) int {
count := 0
for i := 0; i < len(arr) - 1; i++ {
a := arr[len(arr) - i - 1]
if arr[i] != a {
arr[i] = a
count++
}
}
return count
} | func TestSmallestChange(t *testing.T) {
assert := assert.New(t)
assert.Equal(4, SmallestChange([]int{1,2,3,5,4,7,9,6}))
assert.Equal(1, SmallestChange([]int{1, 2, 3, 4, 3, 2, 2}))
assert.Equal(1, SmallestChange([]int{1, 4, 2}))
assert.Equal(1, SmallestChange([]int{1, 4, 4, 2}))
assert.Equal(0, SmallestChange([]int{1, 2, 3, 2, 1}))
assert.Equal(0, SmallestChange([]int{3, 1, 1, 3}))
assert.Equal(0, SmallestChange([]int{1}))
assert.Equal(1, SmallestChange([]int{0, 1}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/73 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/73 |
74 | go | THUDM/humaneval-x | Go_74 | Go_74.go | Go_74_test.go | func TotalMatch(lst1 []string,lst2 []string) []string {
var numchar1 = 0
var numchar2 = 0
for _, item := range lst1 {
numchar1 += len(item)
}
for _, item := range lst2 {
numchar2 += len(item)
}
if numchar1 <= numchar2 {
return lst1
} else {
return lst2
}
} | func TestTotalMatch(t *testing.T) {
assert := assert.New(t)
assert.Equal([]string{}, TotalMatch([]string{}, []string{}))
assert.Equal([]string{"hi", "hi"}, TotalMatch([]string{"hi", "admin"}, []string{"hi", "hi"}))
assert.Equal([]string{"hi", "admin"}, TotalMatch([]string{"hi", "admin"}, []string{"hi", "hi", "admin", "project"}))
assert.Equal([]string{"4"}, TotalMatch([]string{"4"},[]string{"1", "2", "3", "4", "5"}))
assert.Equal([]string{"hI", "Hi"}, TotalMatch([]string{"hi", "admin"}, []string{"hI", "Hi"}))
assert.Equal([]string{"hI", "hi", "hi"}, TotalMatch([]string{"hi", "admin"}, []string{"hI", "hi", "hi"}))
assert.Equal([]string{"hi", "admin"}, TotalMatch([]string{"hi", "admin"}, []string{"hI", "hi", "hii"}))
assert.Equal([]string{}, TotalMatch([]string{}, []string{"this"}))
assert.Equal([]string{}, TotalMatch([]string{"this"}, []string{}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/74 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/74 |
75 | go | THUDM/humaneval-x | Go_75 | Go_75.go | Go_75_test.go | func IsMultiplyPrime(a int) bool {
isPrime := func(n int) bool {
for i := 2; i < int(math.Pow(float64(n), 0.5)+1); i++ {
if n%i == 0 {
return false
}
}
return true
}
for i := 2; i < 101; i++ {
if !isPrime(i) {
continue
}
for j := 2; j < 101; j++ {
if !isPrime(j) {
continue
}
for k := 2; k < 101; k++ {
if !isPrime(k) {
continue
}
if i*j*k == a {
return true
}
}
}
}
return false
} | func TestIsMultiplyPrime(t *testing.T) {
assert := assert.New(t)
assert.Equal(false, IsMultiplyPrime(5))
assert.Equal(true, IsMultiplyPrime(30))
assert.Equal(true, IsMultiplyPrime(8))
assert.Equal(false, IsMultiplyPrime(10))
assert.Equal(true, IsMultiplyPrime(125))
assert.Equal(true, IsMultiplyPrime(3 * 5 * 7))
assert.Equal(false, IsMultiplyPrime(3 * 6 * 7))
assert.Equal(false, IsMultiplyPrime(9 * 9 * 9))
assert.Equal(false, IsMultiplyPrime(11 * 9 * 9))
assert.Equal(true, IsMultiplyPrime(11 * 13 * 7))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/75 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/75 |
76 | go | THUDM/humaneval-x | Go_76 | Go_76.go | Go_76_test.go | func IsSimplePower(x int,n int) bool {
if x == 1 {
return true
}
if n==1 {
return false
}
if x % n != 0 {
return false
}
return IsSimplePower(x / n, n)
} | func TestIsSimplePower(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, IsSimplePower(1, 4))
assert.Equal(true, IsSimplePower(2, 2))
assert.Equal(true, IsSimplePower(8, 2))
assert.Equal(false, IsSimplePower(3, 2))
assert.Equal(false, IsSimplePower(3, 1))
assert.Equal(false, IsSimplePower(5, 3))
assert.Equal(true, IsSimplePower(16, 2))
assert.Equal(false, IsSimplePower(143214, 16))
assert.Equal(true, IsSimplePower(4, 2))
assert.Equal(true, IsSimplePower(9, 3))
assert.Equal(true, IsSimplePower(16, 4))
assert.Equal(false, IsSimplePower(24, 2))
assert.Equal(false, IsSimplePower(128, 4))
assert.Equal(false, IsSimplePower(12, 6))
assert.Equal(true, IsSimplePower(1, 1))
assert.Equal(true, IsSimplePower(1, 12))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/76 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/76 |
77 | go | THUDM/humaneval-x | Go_77 | Go_77.go | Go_77_test.go | func Iscube(a int) bool {
abs := math.Abs(float64(a))
return int(math.Pow(math.Round(math.Pow(abs, 1.0/3.0)), 3.0)) == int(abs)
} | func TestIscube(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, Iscube(1))
assert.Equal(false, Iscube(2))
assert.Equal(true, Iscube(-1))
assert.Equal(true, Iscube(64))
assert.Equal(false, Iscube(180))
assert.Equal(true, Iscube(1000))
assert.Equal(true, Iscube(0))
assert.Equal(false, Iscube(1729))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/77 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/77 |
78 | go | THUDM/humaneval-x | Go_78 | Go_78.go | Go_78_test.go | func HexKey(num string) int {
primes := map[int32]interface{}{'2': nil, '3': nil, '5': nil, '7': nil, 'B': nil, 'D': nil}
total := 0
for _, c := range num {
if _, ok := primes[c]; ok {
total++
}
}
return total
} | func TestHexKey(t *testing.T) {
assert := assert.New(t)
assert.Equal(1, HexKey("AB"))
assert.Equal(2, HexKey("1077E"))
assert.Equal(4, HexKey("ABED1A33"))
assert.Equal(2, HexKey("2020"))
assert.Equal(6, HexKey("123456789ABCDEF0"))
assert.Equal(12, HexKey("112233445566778899AABBCCDDEEFF00"))
assert.Equal(0, HexKey(""))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/78 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/78 |
79 | go | THUDM/humaneval-x | Go_79 | Go_79.go | Go_79_test.go | func DecimalToBinary(decimal int) string {
return fmt.Sprintf("db%bdb", decimal)
} | func TestDecimalToBinary(t *testing.T) {
assert := assert.New(t)
assert.Equal("db0db", DecimalToBinary(0))
assert.Equal("db100000db", DecimalToBinary(32))
assert.Equal("db1100111db", DecimalToBinary(103))
assert.Equal("db1111db", DecimalToBinary(15))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/79 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/79 |
80 | go | THUDM/humaneval-x | Go_80 | Go_80.go | Go_80_test.go | func IsHappy(s string) bool {
if len(s) < 3 {
return false
}
for i := 0; i < len(s)-2; i++ {
if s[i] == s[i+1] || s[i+1] == s[i+2] || s[i] == s[i+2] {
return false
}
}
return true
} | func TestIsHappy(t *testing.T) {
assert := assert.New(t)
assert.Equal(false, IsHappy("a"), "a")
assert.Equal(false, IsHappy("aa"), "aa")
assert.Equal(true, IsHappy("abcd"), "abcd")
assert.Equal(false, IsHappy("aabb"), "aabb")
assert.Equal(true, IsHappy("adb"), "adb")
assert.Equal(false, IsHappy("xyy"), "xyy")
assert.Equal(true, IsHappy("iopaxpoi"), "iopaxpoi")
assert.Equal(false, IsHappy("iopaxioi"), "iopaxioi")
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/80 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/80 |
81 | go | THUDM/humaneval-x | Go_81 | Go_81.go | Go_81_test.go | func NumericalLetterGrade(grades []float64) []string {
letter_grade := make([]string, 0, len(grades))
for _, gpa := range grades {
switch {
case gpa == 4.0:
letter_grade = append(letter_grade, "A+")
case gpa > 3.7:
letter_grade = append(letter_grade, "A")
case gpa > 3.3:
letter_grade = append(letter_grade, "A-")
case gpa > 3.0:
letter_grade = append(letter_grade, "B+")
case gpa > 2.7:
letter_grade = append(letter_grade, "B")
case gpa > 2.3:
letter_grade = append(letter_grade, "B-")
case gpa > 2.0:
letter_grade = append(letter_grade, "C+")
case gpa > 1.7:
letter_grade = append(letter_grade, "C")
case gpa > 1.3:
letter_grade = append(letter_grade, "C-")
case gpa > 1.0:
letter_grade = append(letter_grade, "D+")
case gpa > 0.7:
letter_grade = append(letter_grade, "D")
case gpa > 0.0:
letter_grade = append(letter_grade, "D-")
default:
letter_grade = append(letter_grade, "E")
}
}
return letter_grade
} | func TestNumericalLetterGrade(t *testing.T) {
assert := assert.New(t)
assert.Equal([]string{"A+", "B", "C-", "C", "A-"}, NumericalLetterGrade([]float64{4.0, 3, 1.7, 2, 3.5}))
assert.Equal([]string{"D+"}, NumericalLetterGrade([]float64{1.2}))
assert.Equal([]string{"D-"}, NumericalLetterGrade([]float64{0.5}))
assert.Equal([]string{"E"}, NumericalLetterGrade([]float64{0.0}))
assert.Equal([]string{"D", "D-", "C-", "B", "B+"}, NumericalLetterGrade([]float64{1, 0.3, 1.5, 2.8, 3.3}))
assert.Equal([]string{"E", "D-"}, NumericalLetterGrade([]float64{0, 0.7}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/81 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/81 |
82 | go | THUDM/humaneval-x | Go_82 | Go_82.go | Go_82_test.go | func PrimeLength(s string) bool {
l := len(s)
if l == 0 || l == 1 {
return false
}
for i := 2; i < l; i++ {
if l%i == 0 {
return false
}
}
return true
} | func TestPrimeLength(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, PrimeLength("Hello"))
assert.Equal(true, PrimeLength("abcdcba"))
assert.Equal(true, PrimeLength("kittens"))
assert.Equal(false, PrimeLength("orange"))
assert.Equal(true, PrimeLength("wow"))
assert.Equal(true, PrimeLength("world"))
assert.Equal(true, PrimeLength("MadaM"))
assert.Equal(true, PrimeLength("Wow"))
assert.Equal(false, PrimeLength(""))
assert.Equal(true, PrimeLength("HI"))
assert.Equal(true, PrimeLength("go"))
assert.Equal(false, PrimeLength("gogo"))
assert.Equal(false, PrimeLength("aaaaaaaaaaaaaaa"))
assert.Equal(true, PrimeLength("Madam"))
assert.Equal(false, PrimeLength("M"))
assert.Equal(false, PrimeLength("0"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/82 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/82 |
83 | go | THUDM/humaneval-x | Go_83 | Go_83.go | Go_83_test.go | func StartsOneEnds(n int) int {
if n == 1 {
return 1
}
return 18 * int(math.Pow(10, float64(n-2)))
} | func TestStartsOneEnds(t *testing.T) {
assert := assert.New(t)
assert.Equal(1, StartsOneEnds(1))
assert.Equal(18, StartsOneEnds(2))
assert.Equal(180, StartsOneEnds(3))
assert.Equal(1800, StartsOneEnds(4))
assert.Equal(18000, StartsOneEnds(5))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/83 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/83 |
84 | go | THUDM/humaneval-x | Go_84 | Go_84.go | Go_84_test.go | func Solve(N int) string {
sum := 0
for _, c := range strconv.Itoa(N) {
sum += int(c - '0')
}
return fmt.Sprintf("%b", sum)
} | func TestSolve(t *testing.T) {
assert := assert.New(t)
assert.Equal("1", Solve(1000), "Error")
assert.Equal("110", Solve(150), "Error")
assert.Equal("1100", Solve(147), "Error")
assert.Equal("1001", Solve(333), "Error")
assert.Equal("10010", Solve(963), "Error")
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/84 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/84 |
85 | go | THUDM/humaneval-x | Go_85 | Go_85.go | Go_85_test.go | func Add(lst []int) int {
sum := 0
for i := 1; i < len(lst); i += 2 {
if lst[i]%2 == 0 {
sum += lst[i]
}
}
return sum
} | func TestAdd(t *testing.T) {
assert := assert.New(t)
assert.Equal(88, Add([]int{4, 88}))
assert.Equal(122, Add([]int{4, 5, 6, 7, 2, 122}))
assert.Equal(0, Add([]int{4, 0, 6, 7}))
assert.Equal(12, Add([]int{4, 4, 6, 8}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/85 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/85 |
86 | go | THUDM/humaneval-x | Go_86 | Go_86.go | Go_86_test.go | func AntiShuffle(s string) string {
strs := make([]string, 0)
for _, i := range strings.Fields(s) {
word := []rune(i)
sort.Slice(word, func(i, j int) bool {
return word[i] < word[j]
})
strs = append(strs, string(word))
}
return strings.Join(strs, " ")
} | func TestAntiShuffle(t *testing.T) {
assert := assert.New(t)
assert.Equal("Hi", AntiShuffle("Hi"))
assert.Equal("ehllo", AntiShuffle("hello"))
assert.Equal("bemnru", AntiShuffle("number"))
assert.Equal("abcd", AntiShuffle("abcd"))
assert.Equal("Hello !!!Wdlor", AntiShuffle("Hello World!!!"))
assert.Equal("", AntiShuffle(""))
assert.Equal(".Hi My aemn is Meirst .Rboot How aer ?ouy", AntiShuffle("Hi. My name is Mister Robot. How are you?"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/86 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/86 |
87 | go | THUDM/humaneval-x | Go_87 | Go_87.go | Go_87_test.go | func GetRow(lst [][]int, x int) [][2]int {
coords := make([][2]int, 0)
for i, row := range lst {
for j, item := range row {
if item == x {
coords = append(coords, [2]int{i, j})
}
}
}
sort.Slice(coords, func(i, j int) bool {
if coords[i][0] == coords[j][0] {
return coords[i][1] > coords[j][1]
}
return coords[i][0] < coords[j][0]
})
return coords
} | func TestGetRow(t *testing.T) {
assert := assert.New(t)
assert.Equal([][2]int{{0, 0}, {1, 4}, {1, 0}, {2, 5}, {2, 0}}, GetRow([][]int{
{1, 2, 3, 4, 5, 6},
{1, 2, 3, 4, 1, 6},
{1, 2, 3, 4, 5, 1},
}, 1))
assert.Equal([][2]int{{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}}, GetRow([][]int{
{1, 2, 3, 4, 5, 6},
{1, 2, 3, 4, 5, 6},
{1, 2, 3, 4, 5, 6},
{1, 2, 3, 4, 5, 6},
{1, 2, 3, 4, 5, 6},
{1, 2, 3, 4, 5, 6},
}, 2))
assert.Equal([][2]int{{0, 0}, {1, 0}, {2, 1}, {2, 0}, {3, 2}, {3, 0}, {4, 3}, {4, 0}, {5, 4}, {5, 0}, {6, 5}, {6, 0}}, GetRow([][]int{
{1, 2, 3, 4, 5, 6},
{1, 2, 3, 4, 5, 6},
{1, 1, 3, 4, 5, 6},
{1, 2, 1, 4, 5, 6},
{1, 2, 3, 1, 5, 6},
{1, 2, 3, 4, 1, 6},
{1, 2, 3, 4, 5, 1},
}, 1))
assert.Equal([][2]int{}, GetRow([][]int{{}}, 1))
assert.Equal([][2]int{}, GetRow([][]int{{1}}, 2))
assert.Equal([][2]int{{2, 2}}, GetRow([][]int{{}, {1}, {1, 2, 3}}, 3))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/87 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/87 |
88 | go | THUDM/humaneval-x | Go_88 | Go_88.go | Go_88_test.go | func SortArray(array []int) []int {
arr := make([]int, len(array))
copy(arr, array)
if len(arr) == 0 {
return arr
}
if (arr[0]+arr[len(arr)-1])%2 == 0 {
sort.Slice(arr, func(i, j int) bool {
return arr[i] > arr[j]
})
} else {
sort.Slice(arr, func(i, j int) bool {
return arr[i] < arr[j]
})
}
return arr
} | func TestSortArray(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{}, SortArray([]int{}), "Error")
assert.Equal([]int{5}, SortArray([]int{5}), "Error")
assert.Equal([]int{0, 1, 2, 3, 4, 5}, SortArray([]int{2, 4, 3, 0, 1, 5}), "Error")
assert.Equal([]int{6, 5, 4, 3, 2, 1, 0}, SortArray([]int{2, 4, 3, 0, 1, 5, 6}), "Error")
assert.Equal([]int{1, 2}, SortArray([]int{2, 1}), "Error")
assert.Equal([]int{0, 11, 15, 32, 42, 87}, SortArray([]int{15, 42, 87, 32, 11, 0}), "Error")
assert.Equal([]int{23, 21, 14, 11}, SortArray([]int{21, 14, 23, 11}), "Error")
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/88 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/88 |
89 | go | THUDM/humaneval-x | Go_89 | Go_89.go | Go_89_test.go | func Encrypt(s string) string {
d := "abcdefghijklmnopqrstuvwxyz"
out := make([]rune, 0, len(s))
for _, c := range s {
pos := strings.IndexRune(d, c)
if pos != -1 {
out = append(out, []rune(d)[(pos+2*2)%26])
} else {
out = append(out, c)
}
}
return string(out)
} | func TestEncrypt(t *testing.T) {
assert := assert.New(t)
assert.Equal("lm", Encrypt("hi"))
assert.Equal("ewhjklnop", Encrypt("asdfghjkl"))
assert.Equal("kj", Encrypt("gf"))
assert.Equal("ix", Encrypt("et"))
assert.Equal("jeiajeaijeiak", Encrypt("faewfawefaewg"))
assert.Equal("lippsqcjvmirh", Encrypt("hellomyfriend"))
assert.Equal("hbdhpqrmpjylqmpyjlpmlyjrqpmqryjlpmqryjljygyjl", Encrypt("dxzdlmnilfuhmilufhlihufnmlimnufhlimnufhfucufh"))
assert.Equal("e", Encrypt("a"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/89 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/89 |
90 | go | THUDM/humaneval-x | Go_90 | Go_90.go | Go_90_test.go | func NextSmallest(lst []int) interface{} {
set := make(map[int]struct{})
for _, i := range lst {
set[i] = struct{}{}
}
vals := make([]int, 0, len(set))
for k := range set {
vals = append(vals, k)
}
sort.Slice(vals, func(i, j int) bool {
return vals[i] < vals[j]
})
if len(vals) < 2 {
return nil
}
return vals[1]
} | func TestNextSmallest(t *testing.T) {
assert := assert.New(t)
assert.Equal(2, NextSmallest([]int{1, 2, 3, 4, 5}))
assert.Equal(2, NextSmallest([]int{5, 1, 4, 3, 2}))
assert.Equal(nil, NextSmallest([]int{}))
assert.Equal(nil, NextSmallest([]int{1, 1}))
assert.Equal(1, NextSmallest([]int{1,1,1,1,0}))
assert.Equal(nil, NextSmallest([]int{1, int(math.Pow(0, 0))}))
assert.Equal(-35, NextSmallest([]int{-35, 34, 12, -45}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/90 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/90 |
91 | go | THUDM/humaneval-x | Go_91 | Go_91.go | Go_91_test.go | func IsBored(S string) int {
r, _ := regexp.Compile(`[.?!]\s*`)
sentences := r.Split(S, -1)
sum := 0
for _, s := range sentences {
if len(s) >= 2 && s[:2] == "I " {
sum++
}
}
return sum
} | func TestIsBored(t *testing.T) {
assert := assert.New(t)
assert.Equal(0, IsBored("Hello world"), "Test 1")
assert.Equal(0, IsBored("Is the sky blue?"), "Test 2")
assert.Equal(1, IsBored("I love It !"), "Test 3")
assert.Equal(0, IsBored("bIt"), "Test 4")
assert.Equal(2, IsBored("I feel good today. I will be productive. will kill It"), "Test 5")
assert.Equal(0, IsBored("You and I are going for a walk"), "Test 6")
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/91 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/91 |
92 | go | THUDM/humaneval-x | Go_92 | Go_92.go | Go_92_test.go | func AnyInt(x, y, z interface{}) bool {
xx, ok := x.(int)
if !ok {
return false
}
yy, ok := y.(int)
if !ok {
return false
}
zz, ok := z.(int)
if !ok {
return false
}
if (xx+yy == zz) || (xx+zz == yy) || (yy+zz == xx) {
return true
}
return false
} | func TestAnyInt(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, AnyInt(2, 3, 1))
assert.Equal(false, AnyInt(2.5, 2, 3))
assert.Equal(false, AnyInt(1.5, 5, 3.5))
assert.Equal(false, AnyInt(2, 6, 2))
assert.Equal(true, AnyInt(4, 2, 2))
assert.Equal(false, AnyInt(2.2, 2.2, 2.2))
assert.Equal(true, AnyInt(-4, 6, 2))
assert.Equal(true, AnyInt(2, 1, 1))
assert.Equal(true, AnyInt(3, 4, 7))
assert.Equal(false, AnyInt(3.0, 4, 7))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/92 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/92 |
93 | go | THUDM/humaneval-x | Go_93 | Go_93.go | Go_93_test.go | func Encode(message string) string {
vowels := "aeiouAEIOU"
vowels_replace := make(map[rune]rune)
for _, c := range vowels {
vowels_replace[c] = c + 2
}
result := make([]rune, 0, len(message))
for _, c := range message {
if 'a' <= c && c <= 'z' {
c += 'A' - 'a'
} else if 'A' <= c && c <= 'Z' {
c += 'a' - 'A'
}
if strings.ContainsRune(vowels, c) {
result = append(result, vowels_replace[c])
} else {
result = append(result, c)
}
}
return string(result)
} | func TestEncode(t *testing.T) {
assert := assert.New(t)
assert.Equal("tgst", Encode("TEST"))
assert.Equal("mWDCSKR", Encode("Mudasir"))
assert.Equal("ygs", Encode("YES"))
assert.Equal("tHKS KS C MGSSCGG", Encode("This is a message"))
assert.Equal("k dQnT kNqW wHcT Tq wRkTg", Encode("I DoNt KnOw WhAt tO WrItE"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/93 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/93 |
94 | go | THUDM/humaneval-x | Go_94 | Go_94.go | Go_94_test.go | func Skjkasdkd(lst []int) int {
isPrime := func(n int) bool {
for i := 2; i < int(math.Pow(float64(n), 0.5)+1); i++ {
if n%i == 0 {
return false
}
}
return true
}
maxx := 0
i := 0
for i < len(lst) {
if lst[i] > maxx && isPrime(lst[i]) {
maxx = lst[i]
}
i++
}
sum := 0
for _, d := range strconv.Itoa(maxx) {
sum += int(d - '0')
}
return sum
} | func TestSkjkasdkd(t *testing.T) {
assert := assert.New(t)
assert.Equal(10, Skjkasdkd([]int{0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3}))
assert.Equal(25, Skjkasdkd([]int{1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1}))
assert.Equal(13, Skjkasdkd([]int{1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3}))
assert.Equal(11, Skjkasdkd([]int{0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6}))
assert.Equal(3, Skjkasdkd([]int{0, 81, 12, 3, 1, 21}))
assert.Equal(7, Skjkasdkd([]int{0, 8, 1, 2, 1, 7}))
assert.Equal(19, Skjkasdkd([]int{8191}))
assert.Equal(19, Skjkasdkd([]int{8191, 123456, 127, 7}))
assert.Equal(10, Skjkasdkd([]int{127, 97, 8192}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/94 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/94 |
95 | go | THUDM/humaneval-x | Go_95 | Go_95.go | Go_95_test.go | func CheckDictCase(dict map[interface{}]interface{}) bool {
if len(dict) == 0 {
return false
}
state := "start"
key := ""
ok := false
for k := range dict {
if key, ok = k.(string); !ok {
state = "mixed"
break
}
if state == "start" {
if key == strings.ToUpper(key) {
state = "upper"
} else if key == strings.ToLower(key) {
state = "lower"
} else {
break
}
} else if (state == "upper" && key != strings.ToUpper(key)) || (state == "lower" && key != strings.ToLower(key)) {
state = "mixed"
break
} else {
break
}
}
return state == "upper" || state == "lower"
} | func TestCheckDictCase(t *testing.T) {
assert := assert.New(t)
assert.Equal(true, CheckDictCase(map[interface{}]interface{}{"p": "pineapple", "b": "banana"}))
assert.Equal(false, CheckDictCase(map[interface{}]interface{}{"p": "pineapple", "A": "banana", "B": "banana"}))
assert.Equal(false, CheckDictCase(map[interface{}]interface{}{"p": "pineapple", 5: "banana", "a": "apple"}))
assert.Equal(false, CheckDictCase(map[interface{}]interface{}{"Name": "John", "Age": "36", "City": "Houston"}))
assert.Equal(true, CheckDictCase(map[interface{}]interface{}{"STATE": "NC", "ZIP": "12345"}))
assert.Equal(true, CheckDictCase(map[interface{}]interface{}{"fruit": "Orange", "taste": "Sweet"}))
assert.Equal(false, CheckDictCase(map[interface{}]interface{}{}))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/95 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/95 |
96 | go | THUDM/humaneval-x | Go_96 | Go_96.go | Go_96_test.go | func CountUpTo(n int) []int {
primes := make([]int, 0)
for i := 2; i < n; i++ {
is_prime := true
for j := 2; j < i; j++ {
if i%j == 0 {
is_prime = false
break
}
}
if is_prime {
primes = append(primes, i)
}
}
return primes
} | func TestCountUpTo(t *testing.T) {
assert := assert.New(t)
assert.Equal([]int{2, 3}, CountUpTo(5))
assert.Equal([]int{2, 3, 5}, CountUpTo(6))
assert.Equal([]int{2, 3, 5}, CountUpTo(7))
assert.Equal([]int{2, 3, 5, 7}, CountUpTo(10))
assert.Equal([]int{}, CountUpTo(0))
assert.Equal([]int{2, 3, 5, 7, 11, 13, 17, 19}, CountUpTo(22))
assert.Equal([]int{}, CountUpTo(1))
assert.Equal([]int{2, 3, 5, 7, 11, 13, 17}, CountUpTo(18))
assert.Equal([]int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43}, CountUpTo(47))
assert.Equal([]int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}, CountUpTo(101))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/96 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/96 |
97 | go | THUDM/humaneval-x | Go_97 | Go_97.go | Go_97_test.go | func Multiply(a, b int) int {
return int(math.Abs(float64(a%10)) * math.Abs(float64(b%10)))
} | func TestMultiply(t *testing.T) {
assert := assert.New(t)
assert.Equal(16, Multiply(148, 412))
assert.Equal(72, Multiply(19, 28))
assert.Equal(0, Multiply(2020, 1851))
assert.Equal(20, Multiply(14, -15))
assert.Equal(42, Multiply(76, 67))
assert.Equal(49, Multiply(17, 27))
assert.Equal(0, Multiply(0, 1))
assert.Equal(0, Multiply(0, 0))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/97 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/97 |
98 | go | THUDM/humaneval-x | Go_98 | Go_98.go | Go_98_test.go | func CountUpper(s string) int {
count := 0
runes := []rune(s)
for i := 0; i < len(runes); i += 2 {
if strings.ContainsRune("AEIOU", runes[i]) {
count += 1
}
}
return count
} | func TestCountUpper(t *testing.T) {
assert := assert.New(t)
assert.Equal(1, CountUpper("aBCdEf"))
assert.Equal(0, CountUpper("abcdefg"))
assert.Equal(0, CountUpper("dBBE"))
assert.Equal(0, CountUpper("B"))
assert.Equal(1, CountUpper("U"))
assert.Equal(0, CountUpper(""))
assert.Equal(2, CountUpper("EEEE"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/98 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/98 |
99 | go | THUDM/humaneval-x | Go_99 | Go_99.go | Go_99_test.go | func ClosestInteger(value string) int {
if strings.Count(value, ".") == 1 {
for value[len(value)-1] == '0' {
value = value[:len(value)-1]
}
}
var res float64
num, _ := strconv.ParseFloat(value, 64)
if len(value) >= 2 && value[len(value)-2:] == ".5" {
if num > 0 {
res = math.Ceil(num)
} else {
res = math.Floor(num)
}
} else if len(value) > 0 {
res = math.Round(num)
} else {
res = 0
}
return int(res)
} | func TestClosestInteger(t *testing.T) {
assert := assert.New(t)
assert.Equal(10, ClosestInteger("10"))
assert.Equal(15, ClosestInteger("14.5"))
assert.Equal(-16, ClosestInteger("-15.5"))
assert.Equal(15, ClosestInteger("15.3"))
assert.Equal(0, ClosestInteger("0"))
} | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/99 | https://huggingface.co/datasets/THUDM/humaneval-x/viewer/go/99 |
End of preview. Expand
in Data Studio
README.md exists but content is empty.
- Downloads last month
- 9