-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgraph_test.go
More file actions
35 lines (31 loc) · 771 Bytes
/
graph_test.go
File metadata and controls
35 lines (31 loc) · 771 Bytes
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
// Copyright 2023 Frederik Zipp. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package pathfind
import (
"reflect"
"slices"
"testing"
)
func TestGraphNeighbours(t *testing.T) {
g := make(graph[string])
g.link("a", "b").link("a", "c").link("a", "d")
g.link("b", "a").link("b", "d")
g.link("c", "d").link("c", "b")
tests := []struct {
node string
want []string
}{
{"a", []string{"b", "c", "d"}},
{"b", []string{"a", "d"}},
{"c", []string{"d", "b"}},
{"d", nil},
}
for _, tt := range tests {
got := slices.Collect(g.Neighbours(tt.node))
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Neighbors of node %q: got %v, want %v",
tt.node, got, tt.want)
}
}
}