Total Lines | 56 |
Duplicated Lines | 0 % |
Changes | 0 |
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 |