blob: e9bc8fa39f0b97471e6616cf4b8d22a1159cfe97 [file]
// Copyright 2026 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.
package graph
import (
"slices"
"testing"
)
func TestShortestPath(t *testing.T) {
g := stringGraph{
"A": {"B", "C"},
"B": {"D"},
"C": {"D"},
"D": {"E"},
"E": {},
}
got := ShortestPath(g, "A", "E")
want := []string{"A", "B", "D", "E"}
if !slices.Equal(got, want) {
t.Errorf("ShortestPath(A, E) = %v, want %v", got, want)
}
got = ShortestPath(g, "A", "F")
if got != nil {
t.Errorf("ShortestPath(A, F) = %v, want nil", got)
}
}