-
-
Notifications
You must be signed in to change notification settings - Fork 654
/
run_length_encoding_test.go
53 lines (49 loc) · 1.47 KB
/
run_length_encoding_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
package encode
import "testing"
func TestRunLengthEncode(t *testing.T) {
for _, test := range encodeTests {
if actual := RunLengthEncode(test.input); actual != test.expected {
t.Errorf("FAIL %s - RunLengthEncode(%s) = %q, expected %q.",
test.description, test.input, actual, test.expected)
}
t.Logf("PASS RunLengthEncode - %s", test.description)
}
}
func TestRunLengthDecode(t *testing.T) {
for _, test := range decodeTests {
if actual := RunLengthDecode(test.input); actual != test.expected {
t.Errorf("FAIL %s - RunLengthDecode(%s) = %q, expected %q.",
test.description, test.input, actual, test.expected)
}
t.Logf("PASS RunLengthDecode - %s", test.description)
}
}
func TestRunLengthEncodeDecode(t *testing.T) {
for _, test := range encodeDecodeTests {
if actual := RunLengthDecode(RunLengthEncode(test.input)); actual != test.expected {
t.Errorf("FAIL %s - RunLengthDecode(RunLengthEncode(%s)) = %q, expected %q.",
test.description, test.input, actual, test.expected)
}
t.Logf("PASS %s", test.description)
}
}
func BenchmarkRunLengthDecode(b *testing.B) {
if testing.Short() {
b.Skip("skipping benchmark in short mode.")
}
for i := 0; i < b.N; i++ {
for _, test := range decodeTests {
RunLengthDecode(test.input)
}
}
}
func BenchmarkRunLengthEncode(b *testing.B) {
if testing.Short() {
b.Skip("skipping benchmark in short mode.")
}
for i := 0; i < b.N; i++ {
for _, test := range decodeTests {
RunLengthEncode(test.input)
}
}
}