def test_simple_grid(self): ncol = nrow = 4 grid = [[False] * ncol for _ in range(nrow)] true_indices = [(0, 1), (0, 3), (1, 0), (1, 1), (2, 2), (3, 2)] for row, col in true_indices: grid[row][col] = True self.assertEqual(3, count_islands(nrow, ncol, grid))
def test_1_big_island(): map = [ [1, 1, 1, 0, 0], [0, 0, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 1, 1, 1], ] assert count_islands(map) == 1
def test_3_islands(): map = [ [1, 0, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 1], ] assert count_islands(map) == 3
def test_1_two_row_island(): map = [ [0, 0, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0], ] assert count_islands(map) == 1
def test_1_simple_island(): map = [ [0, 0, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], ] assert count_islands(map) == 1
def test_no_islands(): map = [ [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], ] assert count_islands(map) == 0
def test_count_islands(data, expected): assert count_islands(data) == expected
def test_grid_no_islands(self): ncol = nrow = 4 grid = [[False] * ncol for _ in range(nrow)] self.assertEqual(0, count_islands(nrow, ncol, grid))
def test_grid_is_island_itself(self): ncol = nrow = 30 grid = [[True] * ncol for _ in range(nrow)] self.assertEqual(1, count_islands(nrow, ncol, grid))
def test_empty_grid(self): self.assertEqual(0, count_islands(0, 0, []))