74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
|
package arrays
|
||
|
|
||
|
import (
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestIndexOf(t *testing.T) {
|
||
|
type args[T comparable] struct {
|
||
|
a T
|
||
|
vs []T
|
||
|
}
|
||
|
type testCase[T comparable] struct {
|
||
|
name string
|
||
|
args args[T]
|
||
|
want int
|
||
|
}
|
||
|
tests := []testCase[string]{
|
||
|
{"exists", args[string]{a: "a", vs: []string{"a", "b"}}, 0},
|
||
|
{"not exists", args[string]{a: "a", vs: []string{"c", "b"}}, -1},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
if got := IndexOf(tt.args.a, tt.args.vs); got != tt.want {
|
||
|
t.Errorf("IndexOf() = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestExists(t *testing.T) {
|
||
|
type args[T comparable] struct {
|
||
|
a T
|
||
|
vs []T
|
||
|
}
|
||
|
type testCase[T comparable] struct {
|
||
|
name string
|
||
|
args args[T]
|
||
|
want bool
|
||
|
}
|
||
|
tests := []testCase[int]{
|
||
|
{"exists", args[int]{a: 1, vs: []int{1, 2}}, true},
|
||
|
{"not exists", args[int]{a: 2, vs: []int{3, 4}}, false},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
if got := Exists(tt.args.a, tt.args.vs); got != tt.want {
|
||
|
t.Errorf("Exists() = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestReverse(t *testing.T) {
|
||
|
type args[T comparable] struct {
|
||
|
s []T
|
||
|
}
|
||
|
type testCase[T comparable] struct {
|
||
|
name string
|
||
|
args args[T]
|
||
|
want []T
|
||
|
}
|
||
|
tests := []testCase[int]{
|
||
|
{"one", args[int]{s: []int{1, 2, 3}}, []int{3, 2, 1}},
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
if got := Reverse(tt.args.s); !reflect.DeepEqual(got, tt.want) {
|
||
|
t.Errorf("Reverse() = %v, want %v", got, tt.want)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|