Skip to content

Instantly share code, notes, and snippets.

@jcdan3
Created February 4, 2022 11:55
Show Gist options
  • Save jcdan3/e335a8e5d34062c69859b7fb92f8cb27 to your computer and use it in GitHub Desktop.
Save jcdan3/e335a8e5d34062c69859b7fb92f8cb27 to your computer and use it in GitHub Desktop.
func Test_intInSlice(t *testing.T) {
type args struct {
a int
list []int
}
tests := []struct {
name string
args args
want bool
}{
{
name: "empty slice",
args: args{
a: 0,
list: []int{},
},
want: false,
},
{
name: "int is in slice",
args: args{
a: 0,
list: []int{1,2,0},
},
want: true,
},
{
name: "int is not in slice",
args: args{
a: 7,
list: []int{1,2,0},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := intInSlice(tt.args.a, tt.args.list); got != tt.want {
t.Errorf("intInSlice() = %v, want %v", got, tt.want)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment