package day25 import ( "testing" mapset "github.com/deckarep/golang-set/v2" ) func TestReadFileExample(t *testing.T) { filename := "example" g := ReadGraphFile(filename) t.Logf("read graph %+v", g) } func TestRemoveEdge(t *testing.T) { filename := "example" g := ReadGraphFile(filename) t.Logf("read graph %+v", g) g.RemoveEdge("bvb", "hfx") t.Logf("after removing bvb-hfv %+v", g) } func TestCreateExampleMermaid(t *testing.T) { filename := "example" g := ReadGraphFile(filename) g.SaveAsMermaid("example-graph.mmd") } func TestComponentOnInitial(t *testing.T) { // should be all nodes filename := "example" g := ReadGraphFile(filename) comp := g.ComponentFrom("bvb") t.Logf("got component %+v", comp) if comp.Cardinality() != len(g.Nodes) { t.Errorf("should have same size!") } } func TestComponentOnMini(t *testing.T) { // should be all nodes filename := "example2" g := ReadGraphFile(filename) comp := g.ComponentFrom("jqt") t.Logf("got component %+v", comp) if comp.Cardinality() == len(g.Nodes) { t.Errorf("should have different size!") } } func TestRemoveAllCycles(t *testing.T) { filename := "example" g := ReadGraphFile(filename) g.SaveAsMermaid("example-before-removing.mmd") t.Logf("initial graph is %+v", g) edges := g.RemoveAllCycles() expectedNecessary := mapset.NewSet[Edge]( CreateEdge("hfx", "pzl"), CreateEdge("bvb", "cmg"), CreateEdge("nvd", "jqt"), ) intersection := expectedNecessary.Intersect(edges) t.Logf("i expect that exactly two will be in intersection %+v", intersection) if intersection.Cardinality() != 2 { panic("huh?") // ok, this is not what i expected. // this is unstable. but i could run it several times? and hopefully luck out? } t.Logf("removed edges %+v", edges) t.Logf("after removal graph is %+v", g) g.SaveAsMermaid("example-after-removing.mmd") } func TestSplittingExample(t *testing.T) { filename := "example" g := ReadGraphFile(filename) result := g.TryToSplit() t.Logf("hopefully same as example answer: %d", result) } func TestSplittingInput(t *testing.T) { // kind of brute force result := 0 filename := "input" for result == 0 { g := ReadGraphFile(filename) result = g.TryToSplit() t.Logf("hopefully as answer: %d", result) } }