This commit is contained in:
xing 2022-10-27 10:02:01 +08:00
parent 87758d77a8
commit 29e5bd1fd3

View File

@ -609,24 +609,47 @@ func TestRandNum(t *testing.T) {
} }
func TestSampleSort(t *testing.T) { func TestSampleSort(t *testing.T) {
type xy struct {
x int
y int
}
type args struct { type args struct {
arr []int arr []xy
fn func(i, j int) bool fn func(i, j xy) bool
} }
tests := []struct { tests := []struct {
name string name string
args args args args
wantR []int wantR []xy
}{ }{
{ {
name: "t1", name: "t1",
args: args{ args: args{
arr: []int{3, 5, 6, 1}, arr: []xy{
fn: func(i, j int) bool { {1, 2},
return i < j {3, 4},
{1, 3},
{2, 1},
{1, 6},
},
fn: func(i, j xy) bool {
if i.x < j.x {
return true
}
if i.x == j.x && i.y > i.y {
return true
}
return false
}, },
}, },
wantR: []int{1, 3, 5, 6}, wantR: []xy{
{1, 2},
{1, 3},
{1, 6},
{2, 1},
{3, 4},
},
}, },
} }
for _, tt := range tests { for _, tt := range tests {