-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathnumber_of_islands_test.go
More file actions
32 lines (27 loc) · 932 Bytes
/
number_of_islands_test.go
File metadata and controls
32 lines (27 loc) · 932 Bytes
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
package graph
import "testing"
/*
TestNumberOfIslands tests solution(s) with the following signature and problem description:
func NumberOfIslands(grid [][]int) int
Given a grid in which 0 represents water and 1 represents a piece of land, return the
number of islands. An Island is one or more piece of land that could be connected to other
pieces of land on left, right, top or bottom.
*/
func TestNumberOfIslands(t *testing.T) {
tests := []struct {
grid [][]int
islandCount int
}{
{[][]int{}, 0},
{[][]int{{1, 0, 0}, {0, 0, 0}}, 1},
{[][]int{{1, 0, 1}, {0, 0, 0}}, 2},
{[][]int{{1, 0, 1}, {0, 0, 0}, {0, 1, 0}}, 3},
{[][]int{{1, 0, 1}, {0, 0, 0}, {0, 1, 1}}, 3},
{[][]int{{1, 0, 1}, {0, 0, 1}, {0, 1, 1}}, 2},
}
for i, test := range tests {
if got := NumberOfIslands(test.grid); got != test.islandCount {
t.Fatalf("Failed test case #%d. Want %#v got %#v", i, test.islandCount, got)
}
}
}