I am Learning Go and try to understand basics of Go. I have written function and now i want to test function with predefined test cases.
here is code
filename is arr_test.go
package arr_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/manjeettahkur/r_project/arr"
"testing"
)
func TestSo(t *testing.T) {
RunSpecs(t, "My Test Suite")
}
var _ = Describe("Array", func() {
Context("i have no idea why is going here", func() {
It("should be like this", func() {
Expect(arr.ArrayExm([]int{1, 2, 3, 4}, 10)).To(Equal([]int{1,2,3,4,4,3,2,1,1,2}))
})
})
})
here is file where function is written arr.go
package arr
func ArrayExm(array []int, limit int) []int {
var res []int
length := len(array)
for i:=0; i < limit; i++ {
if(i/length)%2 == 0{
res = append(res,array[i%length])
} else {
res = append(res, array[length -i % length - 1])
}
}
return res
}
when i run test case i receive this error
Test Panicked You are trying to make an assertion, but Gomega's fail handler is nil. If you're using Ginkgo then you probably forgot to put your assertion in an It(). Alternatively, you may have forgotten to register a fail handler with RegisterFailHandler() or RegisterTestingT().
can anyone help what i am doing wrong here.TIA