-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriendly_test.go
56 lines (51 loc) · 1.19 KB
/
friendly_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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package friendly
import (
"fmt"
"testing"
)
func TestArrayContains(t *testing.T) {
inputArrInt := []int{1, 2, 3, 4, 5, 6, 7}
inputElInt := []int{1, 3, 89}
want := []bool{true, true, false}
for i, n := range inputElInt {
t.Run(fmt.Sprintf("ArrayContains=%d, int", i), func(t *testing.T) {
got := ArrayContains(inputArrInt, n)
if got != want[i] {
t.Fatalf("got %v, want %v", got, want[i])
}
})
}
inputArrStr := []string{"hello", "world", "I", "am", "Go"}
inputElStr := []string{"hello", "go", "pythoN"}
want = []bool{true, false, false}
for i, n := range inputElStr {
t.Run(fmt.Sprintf("ArrayContains=%d, string", i), func(t *testing.T) {
got := ArrayContains(inputArrStr, n)
if got != want[i] {
t.Fatalf("got %v, want %v", got, want[i])
}
})
}
}
func TestIsInt(t *testing.T) {
tests := []struct {
input string
want bool
}{
{"1", true},
{"26", true},
{"1987", true},
{"873.298", false},
{"2873.iud", false},
{"uebdu", false},
{"87hvi87", false},
}
for i, tc := range tests {
t.Run(fmt.Sprintf("IsInt=%d", i), func(t *testing.T) {
got := IsInt(tc.input)
if got != tc.want {
t.Fatalf("got %v, want %v", got, tc.want)
}
})
}
}