Skip to content

Commit 959aeee

Browse files
committed
add test cases for NumberOfIslands
1 parent b9998a6 commit 959aeee

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

Graphs/NumberOfIslands.js

-9
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,3 @@ const islands = (matrixGrid) => {
7979
}
8080

8181
export { islands }
82-
83-
// islands(
84-
// [
85-
// ['1', '1', '0', '0', '0'],
86-
// ['1', '1', '0', '0', '0'],
87-
// ['0', '0', '1', '0', '0'],
88-
// ['0', '0', '0', '1', '1']
89-
// ]
90-
// )

Graphs/test/NumberOfIslands.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { islands } from '../NumberOfIslands'
2+
3+
describe('Number of Islands', () => {
4+
test('Test Case 1', () => {
5+
const graph = [
6+
['1', '1', '0', '0', '0'],
7+
['1', '1', '0', '0', '0'],
8+
['0', '0', '1', '0', '0'],
9+
['0', '0', '0', '1', '1']
10+
]
11+
const result = islands(graph)
12+
expect(result).toBe(3)
13+
})
14+
15+
test('Test Case 2', () => {
16+
const graph = [
17+
['1', '1'],
18+
['1', '1'],
19+
['0', '0'],
20+
['0', '0']
21+
]
22+
const result = islands(graph)
23+
expect(result).toBe(1)
24+
})
25+
26+
test('Test Case 3', () => {
27+
const graph = [
28+
['0', '0'],
29+
['0', '0']
30+
]
31+
const result = islands(graph)
32+
expect(result).toBe(0)
33+
})
34+
})

0 commit comments

Comments
 (0)