-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathexist_test.go
39 lines (31 loc) · 1.25 KB
/
exist_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package goterators
import (
"fmt"
"testing"
)
func TestExistInt(t *testing.T) {
testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
expectedItem1 := 18
if existed := Exist(testSource, expectedItem1); !existed {
t.Errorf("Exist item1 = %v, Expected = found , got = not_found", expectedItem1)
}
expectedItem2 := 50
if existed := Exist(testSource, expectedItem2); existed {
t.Errorf("Exist item1 = %v, Expected = not_found , got = found", expectedItem1)
}
}
func TestExistString(t *testing.T) {
testSource := []string{"basis", "pray", "platform", "top", "border", "pole", "kidnap", "eaux", "stream", "lemon", "helpless", "indulge", "highlight", "city", "miner", "photography", "squeeze", "king", "offender", "rugby"}
expectedItem1 := "king"
if existed := Exist(testSource, expectedItem1); !existed {
t.Errorf("Exist item2 = %v, Expected = found , got = not_found", expectedItem1)
}
expectedItem2 := "webuild"
if existed := Exist(testSource, expectedItem2); existed {
t.Errorf("Exist item2 = %v, Expected = not_found , got = found", expectedItem1)
}
}
func ExampleExist() {
testSource := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
fmt.Println("Exist: ", Exist(testSource, 15))
}