Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 93bc86e

Browse files
Create number-of-islands-ii_test.go
1 parent 3afb15a commit 93bc86e

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package number_of_islands_ii
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func Test_numIslands2(t *testing.T) {
9+
type args struct {
10+
height int
11+
width int
12+
positions [][]int
13+
}
14+
tests := []struct {
15+
name string
16+
args args
17+
want []int
18+
}{
19+
{
20+
name: "test case 1",
21+
args: args{
22+
height: 3,
23+
width: 3,
24+
positions: [][]int{
25+
{0, 0},
26+
{1, 0},
27+
{1, 2},
28+
{1, 1},
29+
},
30+
},
31+
want: []int{1, 1, 2, 1},
32+
},
33+
{
34+
name: "test case 2",
35+
args: args{
36+
height: 2,
37+
width: 2,
38+
positions: [][]int{
39+
{0, 0},
40+
{1, 1},
41+
{0, 1},
42+
},
43+
},
44+
want: []int{1, 2, 1},
45+
},
46+
{
47+
name: "test case 3",
48+
args: args{
49+
height: 3,
50+
width: 3,
51+
positions: [][]int{
52+
{0, 0},
53+
{0, 1},
54+
{1, 2},
55+
{1, 2},
56+
},
57+
},
58+
want: []int{1, 1, 2, 2},
59+
},
60+
{
61+
name: "test case 4",
62+
args: args{
63+
height: 3,
64+
width: 3,
65+
positions: [][]int{
66+
{0, 1},
67+
{0, 0},
68+
{1, 2},
69+
{1, 2},
70+
},
71+
},
72+
want: []int{1, 1, 2, 2},
73+
},
74+
{
75+
name: "test case 5",
76+
args: args{
77+
height: 3,
78+
width: 3,
79+
positions: [][]int{
80+
{0, 0},
81+
{1, 0},
82+
{0, 1},
83+
{1, 1},
84+
},
85+
},
86+
want: []int{1, 1, 1, 1},
87+
},
88+
}
89+
for _, tt := range tests {
90+
t.Run(tt.name, func(t *testing.T) {
91+
if got := numIslands2(tt.args.height, tt.args.width, tt.args.positions); !reflect.DeepEqual(got, tt.want) {
92+
t.Errorf("numIslands2() = %v, want %v", got, tt.want)
93+
}
94+
})
95+
}
96+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /