From 15bc82acf0e243017464f307b098bf8fa642991d Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 22 Nov 2022 18:26:18 +0100 Subject: solve run length encoding --- go/run-length-encoding/run_length_encoding_test.go | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 go/run-length-encoding/run_length_encoding_test.go (limited to 'go/run-length-encoding/run_length_encoding_test.go') diff --git a/go/run-length-encoding/run_length_encoding_test.go b/go/run-length-encoding/run_length_encoding_test.go new file mode 100644 index 0000000..2440d65 --- /dev/null +++ b/go/run-length-encoding/run_length_encoding_test.go @@ -0,0 +1,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) + } + } +} -- cgit v1.2.3