Created
February 4, 2022 11:55
-
-
Save jcdan3/e335a8e5d34062c69859b7fb92f8cb27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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