From b07b00565b0d06d521e7c7aee0897a6434157c0f Mon Sep 17 00:00:00 2001 From: jiahua wang Date: Sat, 8 Apr 2023 20:42:26 +0800 Subject: [PATCH] maps: replace slicesEqual with slices.Equal Change-Id: I15aeef9c6d3ddc80644a14d6266d21a8515ede4e Reviewed-on: https://go-review.googlesource.com/c/go/+/483156 Auto-Submit: Ian Lance Taylor Reviewed-by: Bryan Mills Run-TryBot: Tobias Klauser TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- src/maps/maps_test.go | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/maps/maps_test.go b/src/maps/maps_test.go index 144f5375c96..1825df5b771 100644 --- a/src/maps/maps_test.go +++ b/src/maps/maps_test.go @@ -6,24 +6,12 @@ package maps import ( "math" + "slices" "sort" "strconv" "testing" ) -// TODO: replace with slices.Equal when slices is in GOROOT. -func slicesEqual[E comparable](s1, s2 []E) bool { - if len(s1) != len(s2) { - return false - } - for i := range s1 { - if s1[i] != s2[i] { - return false - } - } - return true -} - var m1 = map[int]int{1: 2, 2: 4, 4: 8, 8: 16} var m2 = map[int]string{1: "2", 2: "4", 4: "8", 8: "16"} @@ -32,13 +20,13 @@ func TestKeys(t *testing.T) { got1 := Keys(m1) sort.Ints(got1) - if !slicesEqual(got1, want) { + if !slices.Equal(got1, want) { t.Errorf("Keys(%v) = %v, want %v", m1, got1, want) } got2 := Keys(m2) sort.Ints(got2) - if !slicesEqual(got2, want) { + if !slices.Equal(got2, want) { t.Errorf("Keys(%v) = %v, want %v", m2, got2, want) } } @@ -47,14 +35,14 @@ func TestValues(t *testing.T) { got1 := Values(m1) want1 := []int{2, 4, 8, 16} sort.Ints(got1) - if !slicesEqual(got1, want1) { + if !slices.Equal(got1, want1) { t.Errorf("Values(%v) = %v, want %v", m1, got1, want1) } got2 := Values(m2) want2 := []string{"16", "2", "4", "8"} sort.Strings(got2) - if !slicesEqual(got2, want2) { + if !slices.Equal(got2, want2) { t.Errorf("Values(%v) = %v, want %v", m2, got2, want2) } }