1
0
mirror of https://github.com/golang/go synced 2024-11-26 14:56:47 -07:00

maps: replace slicesEqual with slices.Equal

Change-Id: I15aeef9c6d3ddc80644a14d6266d21a8515ede4e
Reviewed-on: https://go-review.googlesource.com/c/go/+/483156
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
jiahua wang 2023-04-08 20:42:26 +08:00 committed by Gopher Robot
parent 14ab998f95
commit b07b00565b

View File

@ -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)
}
}