|
| 1 | +package runlengthencoding_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + "github.com/thenativeweb/codingcircle/runlengthencoding" |
| 8 | +) |
| 9 | + |
| 10 | +func TestDecode(t *testing.T) { |
| 11 | + t.Run("decodes an empty input", func(t *testing.T) { |
| 12 | + result := runlengthencoding.Decode("") |
| 13 | + assert.Equal(t, "", result) |
| 14 | + }) |
| 15 | + |
| 16 | + t.Run("decodes a single character", func(t *testing.T) { |
| 17 | + result := runlengthencoding.Decode("1A") |
| 18 | + assert.Equal(t, "A", result) |
| 19 | + }) |
| 20 | + |
| 21 | + t.Run("decodes multiple characters", func(t *testing.T) { |
| 22 | + result := runlengthencoding.Decode("1A1B1C1D") |
| 23 | + assert.Equal(t, "ABCD", result) |
| 24 | + }) |
| 25 | + |
| 26 | + t.Run("decodes repeated characters", func(t *testing.T) { |
| 27 | + result := runlengthencoding.Decode("1A2B3C4D") |
| 28 | + assert.Equal(t, "ABBCCCDDDD", result) |
| 29 | + }) |
| 30 | + |
| 31 | + t.Run("decodes characters repeated more than 9 times", func(t *testing.T) { |
| 32 | + result := runlengthencoding.Decode("1A10B3C4D") |
| 33 | + assert.Equal(t, "ABBBBBBBBBBCCCDDDD", result) |
| 34 | + }) |
| 35 | + |
| 36 | +} |
0 commit comments