summaryrefslogtreecommitdiff
path: root/go/run-length-encoding/run_length_encoding_test.go
blob: 2440d65aa48ed0d3ff0cb09fb69428337a4cf773 (plain)
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 _, tc := range encodeTests {
		t.Run(tc.description, func(t *testing.T) {
			if actual := RunLengthEncode(tc.input); actual != tc.expected {
				t.Errorf("RunLengthEncode(%q) = %q, want:%q", tc.input, actual, tc.expected)
			}
		})
	}
}
func TestRunLengthDecode(t *testing.T) {
	for _, tc := range decodeTests {
		t.Run(tc.description, func(t *testing.T) {
			if actual := RunLengthDecode(tc.input); actual != tc.expected {
				t.Errorf("RunLengthDecode(%q) = %q, want:%q", tc.input, actual, tc.expected)
			}
		})
	}
}
func TestRunLengthEncodeDecode(t *testing.T) {
	for _, tc := range encodeDecodeTests {
		t.Run(tc.description, func(t *testing.T) {
			if actual := RunLengthDecode(RunLengthEncode(tc.input)); actual != tc.expected {
				t.Errorf("RunLengthDecode(RunLengthEncode(%q)) = %q, want:%q", tc.input, actual, tc.expected)
			}
		})
	}
}

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 encodeTests {
			RunLengthEncode(test.input)
		}
	}
}

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)
		}
	}
}