Skip to content

Commit 7e980d3

Browse files
test filter
1 parent 8b44a33 commit 7e980d3

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

app/app_test.go

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
11
package main
22

33
import (
4-
/*"net/http"
5-
"reflect"*/
4+
// "net/http"
5+
"reflect"
6+
"strconv"
67
"testing"
78
)
89

10+
func TestFilter(t *testing.T) {
11+
type args struct {
12+
input []string
13+
f func(string) bool
14+
}
15+
tests := []struct {
16+
name string
17+
args args
18+
want []string
19+
}{
20+
{
21+
"Filter out non-positive non-int strings", args{
22+
[]string{"a", "a1", "1", "-1", "2", "1a"},
23+
func(s string) bool {
24+
val, _ := strconv.Atoi(s)
25+
return val > 0
26+
},
27+
}, []string{"1", "2"},
28+
},
29+
}
30+
for _, tt := range tests {
31+
t.Run(tt.name, func(t *testing.T) {
32+
if got := Filter(tt.args.input, tt.args.f); !reflect.DeepEqual(got, tt.want) {
33+
t.Errorf("Filter() = %v, want %v", got, tt.want)
34+
}
35+
})
36+
}
37+
}
38+
939
func TestByPrepTime_Len(t *testing.T) {
1040
tests := []struct {
1141
name string

0 commit comments

Comments
 (0)