Passed
Pull Request — master (#66)
by Hayrullah
56s
created

internal/each_test.go   A

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 32
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A internal.TestEach 0 8 4
A internal.ExampleEach 0 4 2
A internal.printTestLine 0 2 1
A internal.getEachTestData 0 18 1
1
package internal
2
3
import (
4
	"fmt"
5
	"os"
6
	"testing"
7
)
8
9
func TestEach(t *testing.T) {
10
	testData := getEachTestData()
11
	for key, test := range testData {
12
		erra := test.err
13
		errb := Each(test.inputValue, test.mapFunction)
14
		if erra == nil {
15
			if errb != nil {
16
				t.Errorf("Convert.ToUint64 does not works expected\ncase %s: error: %s", key, errb.Error())
17
			}
18
		}
19
	}
20
}
21
22
func ExampleEach() {
23
	data := []int64{10, 20, 30}
24
	_ = Each(data, func(val interface{}, i int) {
25
		fmt.Printf("%d apples", val)
26
	})
27
	// Output: 10 apples20 apples30 apples
28
}
29
func printTestLine(val interface{}, i int) {
30
	fmt.Fprintln(os.Stdout, val)
31
}
32
33
func getEachTestData() map[string]struct {
34
	inputValue  interface{}
35
	mapFunction func(a interface{}, i int)
36
	err         error
37
} {
38
39
	testData := map[string]struct {
40
		inputValue  interface{}
41
		mapFunction func(a interface{}, i int)
42
		err         error
43
	}{
44
		"string": {
45
			inputValue:  []string{"gotilty", "gotil"},
46
			mapFunction: printTestLine,
47
			err:         nil,
48
		},
49
	}
50
	return testData
51
}
52