-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch_test.go
79 lines (71 loc) Β· 2.18 KB
/
search_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
75
76
77
78
79
package cloningprimer
import (
"errors"
"testing"
)
type searchInput struct {
m map[string]RestrictEnzyme
pattern string
}
type testCaseSearch struct {
in searchInput
want string
err error
}
func TestFilterEnzymeMap(t *testing.T) {
cases := []testCaseSearch{
// test matching of pattern 'ba' against 'BamHI'
{
in: searchInput{map[string]RestrictEnzyme{"BamHI": {}}, "ba"},
want: "BamHI",
err: nil,
},
// test matching of pattern 'cor' against 'EcoRI'
{
in: searchInput{map[string]RestrictEnzyme{"EcoRI": {}}, "cor"},
want: "EcoRI",
err: nil,
},
// test matching of pattern 'ba' against 'EcoRI'
{
in: searchInput{map[string]RestrictEnzyme{"EcoRI": {}}, "ba"},
want: "", /* do not expect a match for this test */
err: nil,
},
// test matching of invalid string (i.e. with partial regex syntax)
{
in: searchInput{map[string]RestrictEnzyme{"EcoRI": {}}, "ba(*"},
want: "",
err: errors.New("error matching pattern ba(*.*: error parsing regexp: missing argument to repetition operator: `*`"), /* expect an error for this test */
},
}
// loop over test cases
for _, c := range cases {
m, err := FilterEnzymeMap(c.in.m, c.in.pattern)
// test similarity of expected and received value
// get first key of `FilterEnzymeMap' result `m' and assign it to `got'
var got string
for key := range m {
got = key
break
}
if got != c.want {
t.Errorf("FilterEnzymeMap(%v, %v) == %v, want %v\n", c.in.m, c.in.pattern, got, c.want)
}
// if no error is returned, test if none is expected
if err == nil && c.err != nil {
t.Errorf("FilterEnzymeMap(%v, %v) == %v, want %v\n", c.in.m, c.in.pattern, err, c.err)
}
// if error is returned, test if an error is expected
if err != nil {
// if c.err is nil, print wanted and received error
// else if an error is wanted and received but error messages are not the same
// print wanted and received error
if c.err == nil {
t.Errorf("FilterEnzymeMap(%v, %v) == %v, want %v\n", c.in.m, c.in.pattern, err, c.err)
} else if err.Error() != c.err.Error() {
t.Errorf("FilterEnzymeMap(%v, %v) == %v, want %v\n", c.in.m, c.in.pattern, err, c.err)
}
}
}
}