| 312 | } |
| 313 | |
| 314 | func (s) TestEndpointMap_All(t *testing.T) { |
| 315 | em := NewEndpointMap[int]() |
| 316 | em.Set(endpoint1, 1) |
| 317 | // The second endpoint endpoint21 should override. |
| 318 | em.Set(endpoint12, 1) |
| 319 | em.Set(endpoint21, 2) |
| 320 | em.Set(endpoint3, 3) |
| 321 | em.Set(endpoint4, 4) |
| 322 | em.Set(endpoint5, 5) |
| 323 | em.Set(endpoint6, 6) |
| 324 | em.Set(endpoint7, 7) |
| 325 | |
| 326 | type pair struct { |
| 327 | K Endpoint |
| 328 | V int |
| 329 | } |
| 330 | |
| 331 | want := []pair{{endpoint1, 1}, {endpoint21, 2}, {endpoint3, 3}, {endpoint4, 4}, {endpoint5, 5}, {endpoint6, 6}, {endpoint7, 7}} |
| 332 | var got []pair |
| 333 | for k, v := range em.All() { |
| 334 | got = append(got, pair{k, v}) |
| 335 | } |
| 336 | if d := cmp.Diff(want, got, cmp.Transformer("sort", func(in []pair) []pair { |
| 337 | out := append([]pair(nil), in...) |
| 338 | sort.Slice(out, func(i, j int) bool { return out[i].V < out[j].V }) |
| 339 | return out |
| 340 | })); d != "" { |
| 341 | t.Fatalf("em.All returned unexpected elements (-want, +got):\n%v", d) |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | // BenchmarkEndpointMap benchmarks map operations that are expected to run |
| 346 | // faster than O(n). This test doesn't run O(n) operations including listing |