-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstats_test.go
147 lines (133 loc) Β· 3.67 KB
/
stats_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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package cloningprimer
import (
"errors"
"testing"
)
type testCaseGC struct {
in string
want float64
err error
}
type testCaseTm struct {
in tmInput
want float64
err error
}
type tmInput struct {
primer string
complementary int
}
func TestCalculateGC(t *testing.T) {
cases := []testCaseGC{
// test primer with GC content of 50%
{
in: "GGCCTTAA",
want: 0.5,
err: nil,
},
// test primer with GC content of 0%
{
in: "TTAA",
want: 0.0,
err: nil,
},
// test primer with GC content of 100%
{
in: "GGCC",
want: 1.0,
err: nil,
},
// test invalid input: empty `primer' argument
{
in: "",
want: 0.0,
err: errors.New("input sequence `primer' cannot be empty"),
},
// test invalid input: non-nucleotide letter
{
in: "QTAG",
want: 0.0,
err: errors.New("error while calculating GC content: invalid char in nucleotide sequence: Q"),
},
}
// loop over test cases
for _, c := range cases {
got, err := CalculateGC(c.in)
// test similarity of expected and received value
if got != c.want {
t.Errorf("CalculateGC(%v) == %v, want %v\n", c.in, got, c.want)
}
// if no error is returned, test if none is expected
if err == nil && c.err != nil {
t.Errorf("CalculateGC(%v) == %v, want %v\n", c.in, 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("CalculateGC(%v) == %v, want %v\n", c.in, err, c.err)
} else if err.Error() != c.err.Error() {
t.Errorf("CalculateGC(%v) == %v, want %v\n", c.in, err, c.err)
}
}
}
}
func TestCalculateTm(t *testing.T) {
cases := []testCaseTm{
// test invalid input for argument `complementary'
{
in: tmInput{"GGCCTTAA", -3},
want: 0.0,
err: errors.New("invalid input: `complementary' should be >= 0, not -3"),
},
// test valid input
{
in: tmInput{"GGCCTTAA", 0},
want: 24.0,
err: nil,
},
// test input with more than 15 nucleotides (should throw an error)
{
in: tmInput{"AGAGCGAGCGATTGATAGCACCGTGAC", 0},
want: 0.0,
err: errors.New("this method should only be used for sequences with less than 15 nucleotides"),
},
// test invalid input: empty `primer' argument
{
in: tmInput{"", 0},
want: 0.0,
err: errors.New("input sequence `primer' cannot be empty"),
},
// test invalid input: non-nucleotide letter in `primer'
{
in: tmInput{"AGAGACGCGAQ", 0},
want: 0.0,
err: errors.New("error while calculating Tm: invalid char in nucleotide sequence: Q"),
},
}
// loop over test cases
for _, c := range cases {
got, err := CalculateTm(c.in.primer, c.in.complementary)
// test similarity of expected and received value
if got != c.want {
t.Errorf("CalculateTm(%v, %v) == %v, want %v\n", c.in.primer, c.in.complementary, got, c.want)
}
// if no error is returned, test if none is expected
if err == nil && c.err != nil {
t.Errorf("CalculateTm(%v, %v) == %v, want %v\n", c.in.primer, c.in.complementary, got, c.want)
}
// 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("CalculateTm(%v, %v) == %v, want %v\n", c.in.primer, c.in.complementary, err, c.err)
} else if err.Error() != c.err.Error() {
t.Errorf("CalculateTm(%v, %v) == %v, want %v\n", c.in.primer, c.in.complementary, err, c.err)
}
}
}
}