public static IEnumerable <object[]> DagToTreeData() { IFuncSet <char> mkfs(IEnumerable <char> cs) => new FuncSet <char>(cs); var g = new CharSetGraph(); yield return(new object[] { g, Maybe.Nothing <Tree <IFuncSet <char> > >() }); g = new CharSetGraph(); g.Add(mkfs("a")); yield return(new object[] { g, Maybe.Just(Tree.MakeLeaf(mkfs("a"))) }); g = new CharSetGraph(); g.Add(mkfs("a")); g.Add(mkfs("b")); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("a"), mkfs("b"))); yield return(new object[] { g, Maybe.Just(Tree.MakeInner(mkfs("a"), new[] { Tree.MakeLeaf(mkfs("b")) })) }); g = new CharSetGraph(); g.Add(mkfs("a")); g.Add(mkfs("b")); g.Add(mkfs("c")); g.Add(mkfs("d")); g.Add(mkfs("e")); g.Add(mkfs("f")); g.Add(mkfs("g")); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("a"), mkfs("b"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("a"), mkfs("e"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("b"), mkfs("c"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("b"), mkfs("d"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("e"), mkfs("f"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("e"), mkfs("g"))); yield return(new object[] { g, Maybe.Just( Tree.MakeInner(mkfs("a"), new [] { Tree.MakeInner(mkfs("b"), new [] { Tree.MakeLeaf(mkfs("c")), Tree.MakeLeaf(mkfs("d")) }), Tree.MakeInner(mkfs("e"), new [] { Tree.MakeLeaf(mkfs("f")), Tree.MakeLeaf(mkfs("g")) }) })) }); g = new CharSetGraph(); g.Add(mkfs("a")); g.Add(mkfs("b")); g.Add(mkfs("c")); g.Add(mkfs("d")); g.Add(mkfs("e")); g.Add(mkfs("f")); g.Add(mkfs("g")); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("a"), mkfs("b"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("a"), mkfs("e"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("b"), mkfs("c"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("b"), mkfs("d"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("e"), mkfs("f"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("e"), mkfs("g"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("f"), mkfs("g"))); yield return(new object[] { g, Maybe.Nothing <Tree <IFuncSet <char> > >() }); g = new CharSetGraph(); g.Add(mkfs("a")); g.Add(mkfs("b")); g.Add(mkfs("c")); g.Add(mkfs("d")); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("a"), mkfs("b"))); g.Add(new DirectedEdge <IFuncSet <char> >(mkfs("c"), mkfs("d"))); yield return(new object[] { g, Maybe.Nothing <Tree <IFuncSet <char> > >() }); }
public static IEnumerable <object[]> MergeAncestorsData() { DirectedEdge <IFuncSet <char> > mkEdge(IEnumerable <char> from, IEnumerable <char> to) => new DirectedEdge <IFuncSet <char> >(new FuncSet <char>(from), new FuncSet <char>(to)); //trees //these should remain unchanged var g = new CharGraph(); var g2 = new CharSetGraph(); yield return(new object[] { g, g2 }); g = new CharGraph(); g.Add('a'); g2 = new CharSetGraph(); g2.Add(new FuncSet <char> { 'a' }); yield return(new object[] { g, g2 }); g = new CharGraph(); g.Add('a'); g.Add('b'); g2 = new CharSetGraph(); g2.Add(new FuncSet <char> { 'a' }); g2.Add(new FuncSet <char> { 'b' }); yield return(new object[] { g, g2 }); g = new CharGraph(); g.Add('a'); g.Add('b'); g.Add(new DirectedEdge <char>('a', 'b')); g2 = new CharSetGraph(); g2.Add(new FuncSet <char> { 'a' }); g2.Add(new FuncSet <char> { 'b' }); g2.Add(mkEdge("a", "b")); yield return(new object[] { g, g2 }); g = new CharGraph(); g.Add('a'); g.Add('b'); g.Add('c'); g.Add('d'); g.Add('e'); g.Add('f'); g.Add('g'); g.Add(new DirectedEdge <char>('a', 'b')); g.Add(new DirectedEdge <char>('a', 'c')); g.Add(new DirectedEdge <char>('b', 'd')); g.Add(new DirectedEdge <char>('b', 'e')); g.Add(new DirectedEdge <char>('c', 'f')); g.Add(new DirectedEdge <char>('c', 'g')); g2 = new CharSetGraph(); g2.Add(new FuncSet <char> { 'a' }); g2.Add(new FuncSet <char> { 'b' }); g2.Add(new FuncSet <char> { 'c' }); g2.Add(new FuncSet <char> { 'd' }); g2.Add(new FuncSet <char> { 'e' }); g2.Add(new FuncSet <char> { 'f' }); g2.Add(new FuncSet <char> { 'g' }); g2.Add(mkEdge("a", "b")); g2.Add(mkEdge("a", "c")); g2.Add(mkEdge("b", "d")); g2.Add(mkEdge("b", "e")); g2.Add(mkEdge("c", "f")); g2.Add(mkEdge("c", "g")); yield return(new object[] { g, g2 }); //weakly but not strongly cyclic DAGs //the algorithm succeeds on these but changes the graph. g = new CharGraph(); g.Add('a'); g.Add('b'); g.Add('c'); g.Add(new DirectedEdge <char>('a', 'b')); g.Add(new DirectedEdge <char>('a', 'c')); g.Add(new DirectedEdge <char>('b', 'c')); g2 = new CharSetGraph(); g2.Add(new FuncSet <char> { 'a', 'b' }); g2.Add(new FuncSet <char> { 'c' }); g2.Add(mkEdge("ab", "c")); yield return(new object[] { g, g2 }); g = new CharGraph(); g.Add('a'); g.Add('b'); g.Add('c'); g.Add('d'); g.Add('e'); g.Add(new DirectedEdge <char>('a', 'b')); g.Add(new DirectedEdge <char>('a', 'c')); g.Add(new DirectedEdge <char>('b', 'd')); g.Add(new DirectedEdge <char>('b', 'e')); g.Add(new DirectedEdge <char>('c', 'e')); g2 = new CharSetGraph(); g2.Add(new FuncSet <char> { 'a' }); g2.Add(new FuncSet <char> { 'b', 'c' }); g2.Add(new FuncSet <char> { 'd' }); g2.Add(new FuncSet <char> { 'e' }); g2.Add(mkEdge("a", "bc")); g2.Add(mkEdge("bc", "d")); g2.Add(mkEdge("bc", "e")); yield return(new object[] { g, g2 }); g = new CharGraph(); g.Add('a'); g.Add('b'); g.Add('c'); g.Add('d'); g.Add('e'); g.Add('f'); g.Add(new DirectedEdge <char>('a', 'b')); g.Add(new DirectedEdge <char>('a', 'c')); g.Add(new DirectedEdge <char>('b', 'd')); g.Add(new DirectedEdge <char>('b', 'e')); g.Add(new DirectedEdge <char>('b', 'f')); g.Add(new DirectedEdge <char>('c', 'd')); g.Add(new DirectedEdge <char>('c', 'e')); g.Add(new DirectedEdge <char>('c', 'f')); g2 = new CharSetGraph(); g2.Add(new FuncSet <char> { 'a' }); g2.Add(new FuncSet <char> { 'b', 'c' }); g2.Add(new FuncSet <char> { 'd' }); g2.Add(new FuncSet <char> { 'e' }); g2.Add(new FuncSet <char> { 'f' }); g2.Add(mkEdge("a", "bc")); g2.Add(mkEdge("bc", "d")); g2.Add(mkEdge("bc", "e")); g2.Add(mkEdge("bc", "f")); yield return(new object[] { g, g2 }); g = new CharGraph(); g.Add('a'); g.Add('b'); g.Add('c'); g.Add('d'); g.Add('e'); g.Add('f'); g.Add('g'); g.Add('h'); g.Add('i'); g.Add(new DirectedEdge <char>('a', 'b')); g.Add(new DirectedEdge <char>('a', 'c')); g.Add(new DirectedEdge <char>('b', 'd')); g.Add(new DirectedEdge <char>('c', 'd')); g.Add(new DirectedEdge <char>('d', 'e')); g.Add(new DirectedEdge <char>('e', 'f')); g.Add(new DirectedEdge <char>('e', 'g')); g.Add(new DirectedEdge <char>('f', 'h')); g.Add(new DirectedEdge <char>('g', 'h')); g.Add(new DirectedEdge <char>('h', 'i')); g2 = new CharSetGraph(); g2.Add(new FuncSet <char> { 'a' }); g2.Add(new FuncSet <char> { 'b', 'c' }); g2.Add(new FuncSet <char> { 'd' }); g2.Add(new FuncSet <char> { 'e' }); g2.Add(new FuncSet <char> { 'f', 'g' }); g2.Add(new FuncSet <char> { 'h' }); g2.Add(new FuncSet <char> { 'i' }); g2.Add(mkEdge("a", "bc")); g2.Add(mkEdge("bc", "d")); g2.Add(mkEdge("d", "e")); g2.Add(mkEdge("e", "fg")); g2.Add(mkEdge("fg", "h")); g2.Add(mkEdge("h", "i")); yield return(new object[] { g, g2 }); }