Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Graphs/NumberOfIslands.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,3 @@ const islands = (matrixGrid) => {
}

export { islands }

// islands(
// ['1', '1', '0', '0', '0'],
// ['1', '1', '0', '0', '0'],
// ['0', '0', '1', '0', '0'],
// ['0', '0', '0', '1', '1']
// )
31 changes: 31 additions & 0 deletions Graphs/test/NumberOfIslands.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { islands } from '../NumberOfIslands'

describe('Number of Islands', () => {
test('Graph with three islands', () => {
const graph = [
['1', '1', '0', '0', '0'],
['1', '1', '0', '0', '0'],
['0', '0', '1', '0', '0'],
['0', '0', '0', '1', '1']
]
expect(islands(graph)).toBe(3)
})

test('Graph with only one island', () => {
const graph = [
['1', '1'],
['1', '1'],
['0', '0'],
['0', '0']
]
expect(islands(graph)).toBe(1)
})

test('No islands', () => {
const graph = [
['0', '0'],
['0', '0']
]
expect(islands(graph)).toBe(0)
})
})