Passed
Push — master ( 6fc6be...61ccf3 )
by ertugrul
02:06 queued 01:08
created

internal.TestSome   A

Complexity

Conditions 5

Size

Total Lines 8
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 8
dl 0
loc 8
rs 9.3333
c 0
b 0
f 0
nop 1
1
package internal
2
3
import (
4
	"fmt"
5
	"reflect"
6
	"testing"
7
)
8
9
func TestSome(t *testing.T) {
10
	testData := getSomeTestData()
11
	for _, test := range testData {
12
		a, erra := test.output, test.err
13
		b, errb := Some(test.inputValue1, test.inputValue2)
14
		if erra == nil {
15
			if !reflect.DeepEqual(a, b) || errb != nil {
16
				t.Errorf(errb.Error())
17
			}
18
		}
19
	}
20
}
21
22
func ExampleSome() {
23
	data := []int64{-100, -5, 30, 100}
24
	// Input: [-100 -5 30 100]
25
	result, _ := Some(data, -100)
26
	fmt.Println(result)
27
	// Output: false
28
}
29
30
func getSomeTestData() map[string]struct {
31
	inputValue1 interface{}
32
	inputValue2 interface{}
33
	output      bool
34
	err         error
35
} {
36
37
	testData := map[string]struct {
38
		inputValue1 interface{}
39
		inputValue2 interface{}
40
		output      bool
41
		err         error
42
	}{
43
		"every_int": {
44
			inputValue1: []int64{-100, -5, 30, 100},
45
			inputValue2: -100,
46
			output:      true,
47
			err:         nil,
48
		},
49
		"every_int2": {
50
			inputValue1: []int64{-100, -100, -100},
51
			inputValue2: 100,
52
			output:      false,
53
			err:         nil,
54
		},
55
	}
56
	return testData
57
}
58