package assigngraph import ( "slices" "testing" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" ) // Design 47 G ยง272 (AS10): a cycle among the waits within one step is found; an acting part acting on itself's other module, two parts // acting on each other in different steps, and a chain are none. func TestACycleAmongTheWaitsWithinOneStepIsFound(t *testing.T) { act := func(node, module, step string) meshwants.Edge { return meshwants.Edge{Kind: EdgeActing, Node: node, Module: module, Step: step} } entry := func(module string, edges ...meshwants.Edge) meshwants.AssignmentEntry { return meshwants.AssignmentEntry{Node: "ace", Module: module, Edges: edges} } for _, c := range []struct { name string entries []meshwants.AssignmentEntry want []string }{ {"two parts on each other in one step", []meshwants.AssignmentEntry{entry("a", act("ace", "b", "compose")), entry("b", act("ace", "a", "compose"))}, []string{"compose: ace/a -> ace/b -> ace/a"}}, {"three in a ring, said once", []meshwants.AssignmentEntry{entry("c", act("ace", "a", "build")), entry("a", act("ace", "b", "build")), entry("b", act("ace", "c", "build"))}, []string{"build: ace/a -> ace/b -> ace/c -> ace/a"}}, {"the indexer taking in the checker, the checker checking the indexer", []meshwants.AssignmentEntry{entry("checker", act("ace", "indexer", "take-in")), entry("indexer", act("ace", "checker", "check"))}, nil}, {"a chain", []meshwants.AssignmentEntry{entry("a", act("ace", "b", "compose")), entry("b", act("ace", "c", "compose")), entry("c")}, nil}, {"provisioning edges are no wait of a step", []meshwants.AssignmentEntry{entry("a", meshwants.Edge{Kind: EdgeProvisioning, Node: "ace", Module: "b"}), entry("b", meshwants.Edge{Kind: EdgeProvisioning, Node: "ace", Module: "a"})}, nil}, } { if got := Cycles(c.entries); !slices.Equal(got, c.want) { t.Errorf("%s: cycles %v, want %v", c.name, got, c.want) } } }