|
| 1 | +package parentheses_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + "github.com/thenativeweb/codingcircle/parentheses" |
| 8 | +) |
| 9 | + |
| 10 | +func TestIsBalanced(t *testing.T) { |
| 11 | + t.Run("empty string", func(t *testing.T) { |
| 12 | + assert.True(t, parentheses.IsBalanced("")) |
| 13 | + }) |
| 14 | + |
| 15 | + t.Run("balanced string", func(t *testing.T) { |
| 16 | + assert.True(t, parentheses.IsBalanced("()")) |
| 17 | + assert.True(t, parentheses.IsBalanced("(())")) |
| 18 | + assert.True(t, parentheses.IsBalanced("()()")) |
| 19 | + assert.True(t, parentheses.IsBalanced("(()())")) |
| 20 | + assert.True(t, parentheses.IsBalanced("((()))")) |
| 21 | + }) |
| 22 | + |
| 23 | + t.Run("unbalanced string", func(t *testing.T) { |
| 24 | + assert.False(t, parentheses.IsBalanced("(")) |
| 25 | + assert.False(t, parentheses.IsBalanced(")")) |
| 26 | + assert.False(t, parentheses.IsBalanced(")(")) |
| 27 | + assert.False(t, parentheses.IsBalanced("())")) |
| 28 | + assert.False(t, parentheses.IsBalanced("(()")) |
| 29 | + assert.False(t, parentheses.IsBalanced("((())")) |
| 30 | + }) |
| 31 | + |
| 32 | + t.Run("balanced string with wildcard", func(t *testing.T) { |
| 33 | + assert.True(t, parentheses.IsBalanced("*")) |
| 34 | + assert.True(t, parentheses.IsBalanced("(*)")) |
| 35 | + assert.True(t, parentheses.IsBalanced("(*))")) |
| 36 | + assert.True(t, parentheses.IsBalanced("(**))*")) |
| 37 | + assert.True(t, parentheses.IsBalanced("*((**))*")) |
| 38 | + assert.True(t, parentheses.IsBalanced("(***")) |
| 39 | + }) |
| 40 | + |
| 41 | + t.Run("unbalanced string with wildcard", func(t *testing.T) { |
| 42 | + assert.False(t, parentheses.IsBalanced("*(")) |
| 43 | + assert.False(t, parentheses.IsBalanced("*)(")) |
| 44 | + assert.False(t, parentheses.IsBalanced("***(")) |
| 45 | + assert.False(t, parentheses.IsBalanced("(***(()")) |
| 46 | + assert.False(t, parentheses.IsBalanced("(**(")) |
| 47 | + }) |
| 48 | +} |
0 commit comments