mirror of
https://github.com/golang/go
synced 2024-11-26 17:36:56 -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:
parent
14ab998f95
commit
b07b00565b
@ -6,24 +6,12 @@ package maps
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"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 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"}
|
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)
|
got1 := Keys(m1)
|
||||||
sort.Ints(got1)
|
sort.Ints(got1)
|
||||||
if !slicesEqual(got1, want) {
|
if !slices.Equal(got1, want) {
|
||||||
t.Errorf("Keys(%v) = %v, want %v", m1, got1, want)
|
t.Errorf("Keys(%v) = %v, want %v", m1, got1, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
got2 := Keys(m2)
|
got2 := Keys(m2)
|
||||||
sort.Ints(got2)
|
sort.Ints(got2)
|
||||||
if !slicesEqual(got2, want) {
|
if !slices.Equal(got2, want) {
|
||||||
t.Errorf("Keys(%v) = %v, want %v", m2, got2, want)
|
t.Errorf("Keys(%v) = %v, want %v", m2, got2, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,14 +35,14 @@ func TestValues(t *testing.T) {
|
|||||||
got1 := Values(m1)
|
got1 := Values(m1)
|
||||||
want1 := []int{2, 4, 8, 16}
|
want1 := []int{2, 4, 8, 16}
|
||||||
sort.Ints(got1)
|
sort.Ints(got1)
|
||||||
if !slicesEqual(got1, want1) {
|
if !slices.Equal(got1, want1) {
|
||||||
t.Errorf("Values(%v) = %v, want %v", m1, got1, want1)
|
t.Errorf("Values(%v) = %v, want %v", m1, got1, want1)
|
||||||
}
|
}
|
||||||
|
|
||||||
got2 := Values(m2)
|
got2 := Values(m2)
|
||||||
want2 := []string{"16", "2", "4", "8"}
|
want2 := []string{"16", "2", "4", "8"}
|
||||||
sort.Strings(got2)
|
sort.Strings(got2)
|
||||||
if !slicesEqual(got2, want2) {
|
if !slices.Equal(got2, want2) {
|
||||||
t.Errorf("Values(%v) = %v, want %v", m2, got2, want2)
|
t.Errorf("Values(%v) = %v, want %v", m2, got2, want2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user