From 29e5bd1fd3a7d03063a49d86c5a77fc72d3baf9e Mon Sep 17 00:00:00 2001 From: xing Date: Thu, 27 Oct 2022 10:02:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper/func_test.go | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/helper/func_test.go b/helper/func_test.go index f11425f..2d014b2 100644 --- a/helper/func_test.go +++ b/helper/func_test.go @@ -609,24 +609,47 @@ func TestRandNum(t *testing.T) { } func TestSampleSort(t *testing.T) { + type xy struct { + x int + y int + } + type args struct { - arr []int - fn func(i, j int) bool + arr []xy + fn func(i, j xy) bool } tests := []struct { name string args args - wantR []int + wantR []xy }{ { name: "t1", args: args{ - arr: []int{3, 5, 6, 1}, - fn: func(i, j int) bool { - return i < j + arr: []xy{ + {1, 2}, + {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 {