mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-12-19 06:58:15 +08:00
Wrapping the example matrix with outer array (#1057)
This commit is contained in:
31
Graphs/test/NumberOfIslands.test.js
Normal file
31
Graphs/test/NumberOfIslands.test.js
Normal 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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user