summaryrefslogtreecommitdiff
path: root/go/run-length-encoding/cases_test.go
blob: 38266e97446d3cf96cff326ddf6c976f2c7c3e65 (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
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
package encode

// This is an auto-generated file. Do not change it manually. Run the generator to update the file.
// See https://github.com/exercism/go#synchronizing-tests-and-instructions
// Source: exercism/problem-specifications
// Commit: a757698 run-length-encoding: 'lower case' -> 'lowercase' (#1708)

type testCase struct {
	description string
	input       string
	expected    string
}

// run-length encode a string
var encodeTests = []testCase{
	{
		description: "empty string",
		input:       "",
		expected:    "",
	},
	{
		description: "single characters only are encoded without count",
		input:       "XYZ",
		expected:    "XYZ",
	},
	{
		description: "string with no single characters",
		input:       "AABBBCCCC",
		expected:    "2A3B4C",
	},
	{
		description: "single characters mixed with repeated characters",
		input:       "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB",
		expected:    "12WB12W3B24WB",
	},
	{
		description: "multiple whitespace mixed in string",
		input:       "  hsqq qww  ",
		expected:    "2 hs2q q2w2 ",
	},
	{
		description: "lowercase characters",
		input:       "aabbbcccc",
		expected:    "2a3b4c",
	},
}

// run-length decode a string
var decodeTests = []testCase{
	{
		description: "empty string",
		input:       "",
		expected:    "",
	},
	{
		description: "single characters only",
		input:       "XYZ",
		expected:    "XYZ",
	},
	{
		description: "string with no single characters",
		input:       "2A3B4C",
		expected:    "AABBBCCCC",
	},
	{
		description: "single characters with repeated characters",
		input:       "12WB12W3B24WB",
		expected:    "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB",
	},
	{
		description: "multiple whitespace mixed in string",
		input:       "2 hs2q q2w2 ",
		expected:    "  hsqq qww  ",
	},
	{
		description: "lowercase string",
		input:       "2a3b4c",
		expected:    "aabbbcccc",
	},
}

// encode and then decode
var encodeDecodeTests = []testCase{
	{
		description: "encode followed by decode gives original string",
		input:       "zzz ZZ  zZ",
		expected:    "zzz ZZ  zZ",
	},
}