November 2017
Intermediate to advanced
670 pages
17h 35m
English
First, let's create the testIterEq function to test whether two collections are equivalent:
func testIterEq(t *testing.T, it1, it2 Iter) { t.Log("Start") for el1 := range it1 { if el2, ok := <- it2; !ok { t.Error("it2 shorter than it1!", el1) return } else if !reflect.DeepEqual(el1, el2) { t.Error("Elements are not equal", el1, el2) } else { t.Log(el1, el2) } } if el2, ok := <- it2; ok { t.Error("it1 shorter than it2!", el2) } t.Log("Stop")}
In our test function TestMap, we define a mapper function literal that is passed to our Map function to perform the transformation. The mapper function returns the length of each string passed to it:
func TestMap(t *testing.T) { mapper := func (i interface{}) interface{} ...