]> Cypherpunks.ru repositories - gostls13.git/commitdiff
maps: replace slicesEqual with slices.Equal
authorjiahua wang <wjh180909@gmail.com>
Sat, 8 Apr 2023 12:42:26 +0000 (20:42 +0800)
committerGopher Robot <gobot@golang.org>
Tue, 18 Apr 2023 13:37:52 +0000 (13:37 +0000)
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>
src/maps/maps_test.go

index 144f5375c960b5e96821f1fabc600b8321bccbd7..1825df5b7716ab4b3f094a1595e6cbb77668d77c 100644 (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)
        }
 }