|
| 1 | +package dfs_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/anirudhology/leetcode-go/problems/dfs" |
| 7 | +) |
| 8 | + |
| 9 | +func TestNumIslands_EmptyGrid(t *testing.T) { |
| 10 | + grid := [][]byte{} |
| 11 | + if res := dfs.NumberOfIslands(grid); res != 0 { |
| 12 | + t.Errorf("expected 0, got %d", res) |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +func TestNumIslands_NullGrid(t *testing.T) { |
| 17 | + var grid [][]byte |
| 18 | + if res := dfs.NumberOfIslands(grid); res != 0 { |
| 19 | + t.Errorf("expected 0, got %d", res) |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +func TestNumIslands_SingleIsland(t *testing.T) { |
| 24 | + grid := [][]byte{ |
| 25 | + {'1', '1', '0', '0'}, |
| 26 | + {'1', '1', '0', '0'}, |
| 27 | + {'0', '0', '0', '0'}, |
| 28 | + {'0', '0', '0', '0'}, |
| 29 | + } |
| 30 | + if res := dfs.NumberOfIslands(grid); res != 1 { |
| 31 | + t.Errorf("expected 1, got %d", res) |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func TestNumIslands_MultipleIslands(t *testing.T) { |
| 36 | + grid := [][]byte{ |
| 37 | + {'1', '1', '0', '0', '1'}, |
| 38 | + {'1', '0', '0', '1', '1'}, |
| 39 | + {'0', '0', '1', '0', '0'}, |
| 40 | + {'1', '0', '0', '1', '1'}, |
| 41 | + } |
| 42 | + if res := dfs.NumberOfIslands(grid); res != 5 { |
| 43 | + t.Errorf("expected 5, got %d", res) |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +func TestNumIslands_NoIslands(t *testing.T) { |
| 48 | + grid := [][]byte{ |
| 49 | + {'0', '0', '0', '0'}, |
| 50 | + {'0', '0', '0', '0'}, |
| 51 | + } |
| 52 | + if res := dfs.NumberOfIslands(grid); res != 0 { |
| 53 | + t.Errorf("expected 0, got %d", res) |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +func TestNumIslands_MixedGrid(t *testing.T) { |
| 58 | + grid := [][]byte{ |
| 59 | + {'1', '0', '1', '0'}, |
| 60 | + {'0', '1', '0', '1'}, |
| 61 | + {'1', '0', '1', '0'}, |
| 62 | + } |
| 63 | + if res := dfs.NumberOfIslands(grid); res != 6 { |
| 64 | + t.Errorf("expected 6, got %d", res) |
| 65 | + } |
| 66 | +} |
0 commit comments