Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

二维数组查找鲁棒性测试建议 #7

Open
chunlongyuan opened this issue Sep 29, 2020 · 1 comment
Open

二维数组查找鲁棒性测试建议 #7

chunlongyuan opened this issue Sep 29, 2020 · 1 comment

Comments

@chunlongyuan
Copy link

首先肯定作者的整理,建议同时考虑下实现的鲁棒性,使得代码更健壮,谢谢。

package problem003

import "testing"

func TestIsExist(t *testing.T) {
	type args struct {
		matrix [][]int
		number int
	}
	tests := []struct {
		name string
		args args
		want bool
	}{
		{name: "exist",
			args: args{
				matrix: [][]int{
					{1, 2, 8, 9},
					{2, 4, 9, 12},
					{4, 7, 10, 13},
					{6, 8, 11, 15},
				},
				number: 7,
			},
			want: true},
		{name: "notExist",
			args: args{
				matrix: [][]int{
					{1, 2, 8, 9},
					{2, 4, 9, 12},
					{4, 7, 10, 13},
					{6, 8, 11, 15},
				},
				number: 5,
			},
			want: false},
		{name: "empty",
			args: args{
				matrix: [][]int{},
				number: 7,
			},
			want: false},
		{name: "emptyRow",
			args: args{
				matrix: [][]int{{}},
				number: 7,
			},
			want: false},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := Find(tt.args.matrix, tt.args.number); got != tt.want {
				t.Errorf("IsExist() = %v, want %v", got, tt.want)
			}
		})
	}
}

@chunlongyuan
Copy link
Author

=== RUN   TestIsExist

Process finished with exit code 1
=== RUN   TestIsExist/exist
=== RUN   TestIsExist/notExist
=== RUN   TestIsExist/empty
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant