Wrapping the example matrix with outer array (#1057)

This commit is contained in:
Kasun Thennakoon
2022-08-02 18:53:41 +05:30
committed by GitHub
parent 1a089cc491
commit a9e65cd865
2 changed files with 31 additions and 7 deletions

View File

@ -79,10 +79,3 @@ const islands = (matrixGrid) => {
} }
export { islands } export { islands }
// islands(
// ['1', '1', '0', '0', '0'],
// ['1', '1', '0', '0', '0'],
// ['0', '0', '1', '0', '0'],
// ['0', '0', '0', '1', '1']
// )

View File

@ -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)
})
})