-
Notifications
You must be signed in to change notification settings - Fork 1
/
filters_test.go
74 lines (60 loc) · 1.43 KB
/
filters_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import "testing"
func TestFilterInit(t *testing.T) {
filterInit(&FiltOpts{ScoreF: true, FavesF: true}, false)
if len(filters) != 2 {
t.Error("Filter initialization doesn't work as expected")
}
}
func TestFilterNone(t *testing.T) {
in := make(chan Image, 1)
out := FilterChannel(in)
in <- Image{}
_, ok := <-out
if !ok {
t.Fatal("No-op filter closed unexpectedly")
}
}
func TestFilterAlwaysTrue(t *testing.T) {
in := make(chan Image, 1)
filter := filterGenerator(func(Image) bool { return true }, false)
out := filter(in)
in <- Image{}
_, ok := <-out
if !ok {
t.Fatal("Filter closed unexpectedly")
}
close(in)
_, ok = <-out
if ok {
t.Error("Filter remains unexpectedly open")
}
}
func TestFilterAlwaysFalse(t *testing.T) {
in := make(chan Image, 1)
filter := filterGenerator(func(Image) bool { return false }, false)
out := filter(in)
in <- Image{}
close(in)
_, ok := <-out
if ok {
t.Error("Filter remains unexpectedly open")
}
}
func TestFilterComplex(t *testing.T) {
filterInit(&FiltOpts{ScoreF: true, FavesF: true}, false)
in := make(chan Image, 3)
in <- Image{Score: -1}
in <- Image{Faves: -1}
in <- Image{Imgid: 1}
out := FilterChannel(in)
close(in)
pass := <-out
if (pass != Image{Imgid: 1}) {
t.Error("Incorrect work of the filter, passed ", pass, "instead of ", Image{Imgid: 1})
}
pass, ok := <-out
if ok && (pass != Image{}) {
t.Error("Wat is going on with FilterChannel?")
}
}