102 lines
1.9 KiB
Go
102 lines
1.9 KiB
Go
package day23
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
mapset "github.com/deckarep/golang-set/v2"
|
|
)
|
|
|
|
func TestGraphCreate(t *testing.T) {
|
|
filename := "example2"
|
|
field := ReadField(filename)
|
|
|
|
fmt.Println(field.SparseString())
|
|
|
|
graph := CreateGraph(field)
|
|
t.Log(graph)
|
|
}
|
|
|
|
func TestPrintGraph(t *testing.T) {
|
|
filename := "example2"
|
|
field := ReadField(filename)
|
|
|
|
fmt.Println(field.SparseString())
|
|
|
|
graph := CreateGraph(field)
|
|
t.Log(PrintFieldWithGraph(graph, field))
|
|
t.Logf(">>>\n %+v\n", graph)
|
|
|
|
}
|
|
|
|
func TestPrintGraphInput(t *testing.T) {
|
|
filename := "input"
|
|
field := ReadField(filename)
|
|
|
|
fmt.Println(field.SparseString())
|
|
|
|
graph := CreateGraph(field)
|
|
t.Log(PrintFieldWithGraph(graph, field))
|
|
t.Logf(">>>\n %+v\n", graph)
|
|
|
|
}
|
|
|
|
func TestPrintMermaidGraphInput(t *testing.T) {
|
|
filename := "input"
|
|
field := ReadField(filename)
|
|
|
|
fmt.Println(field.SparseString())
|
|
|
|
graph := CreateGraph(field)
|
|
mmdContent := GraphToMermaid(graph)
|
|
t.Log(mmdContent)
|
|
|
|
fileBorder, err := os.Create(filename + ".mmd")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer func() {
|
|
if err := fileBorder.Close(); err != nil {
|
|
panic(err)
|
|
}
|
|
}()
|
|
|
|
fileBorder.WriteString(mmdContent)
|
|
}
|
|
|
|
func TestGraphMaxBetweenExample(t *testing.T) {
|
|
filename := "example"
|
|
field := ReadField(filename)
|
|
graph := CreateGraph(field)
|
|
|
|
t.Log(PrintFieldWithGraph(graph, field))
|
|
|
|
|
|
from := graph.nodes[Coord{Row: 0, Col: field.StartCol}]
|
|
to := graph.nodes[field.EndCoord()]
|
|
|
|
dist := graph.DFSLenOnGraph(from, mapset.NewSet[int](), to, 0)
|
|
|
|
t.Log(graph)
|
|
t.Logf("please dist %d", dist)
|
|
|
|
}
|
|
|
|
func TestGraphMaxBetweenInput(t *testing.T) {
|
|
filename := "input"
|
|
field := ReadField(filename)
|
|
|
|
graph := CreateGraph(field)
|
|
|
|
t.Log(PrintFieldWithGraph(graph, field))
|
|
from := graph.nodes[Coord{Row: 0, Col: field.StartCol}]
|
|
to := graph.nodes[field.EndCoord()]
|
|
|
|
dist := graph.DFSLenOnGraph(from, mapset.NewSet[int](), to, 0)
|
|
|
|
t.Log(graph)
|
|
t.Logf("please dist %d", dist)
|
|
|
|
}
|