-
Notifications
You must be signed in to change notification settings - Fork 1
/
iter_test.go
70 lines (63 loc) · 1.46 KB
/
iter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Modifications copyright (c) Arista Networks, Inc. 2024
// Underlying
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build goexperiment.rangefunc
package gomap
import (
"hash/maphash"
"maps"
"testing"
)
func TestRangeFuncs(t *testing.T) {
m := New(
func(a, b string) bool { return a == b },
maphash.String,
KeyElem[string, string]{"Avenue", "AVE"},
KeyElem[string, string]{"Street", "ST"},
KeyElem[string, string]{"Court", "CT"},
)
t.Run("All", func(t *testing.T) {
exp := map[string]string{
"Avenue": "AVE",
"Street": "ST",
"Court": "CT",
}
got := make(map[string]string)
for k, v := range m.All() {
got[k] = v
}
if !maps.Equal(exp, got) {
t.Errorf("expected: %v got: %v", exp, got)
}
})
t.Run("Keys", func(t *testing.T) {
exp := map[string]struct{}{
"Avenue": struct{}{},
"Street": struct{}{},
"Court": struct{}{},
}
got := make(map[string]struct{})
for k := range m.Keys() {
got[k] = struct{}{}
}
if !maps.Equal(exp, got) {
t.Errorf("expected: %v got: %v", exp, got)
}
})
t.Run("Values", func(t *testing.T) {
exp := map[string]struct{}{
"AVE": struct{}{},
"ST": struct{}{},
"CT": struct{}{},
}
got := make(map[string]struct{})
for k := range m.Values() {
got[k] = struct{}{}
}
if !maps.Equal(exp, got) {
t.Errorf("expected: %v got: %v", exp, got)
}
})
}