private void TryInvalid( IDictionary<string, ICollection<string>> graph, string msg) { try { GraphUtil.GetTopDownOrder(graph); Assert.Fail(); } catch (GraphCircularDependencyException ex) { // expected Assert.AreEqual(msg, ex.Message); } }
public void TestSimpleTopDownOrder() { IDictionary<string, ICollection<string>> graph = new LinkedHashMap<string, ICollection<string>>(); Assert.AreEqual(0, GraphUtil.GetTopDownOrder(graph).Count); Add(graph, "1_1", "1"); EPAssertionUtil.AssertEqualsExactOrder(GraphUtil.GetTopDownOrder(graph).ToArray(), new [] { "1","1_1" }); Add(graph, "1_1_1", "1_1"); EPAssertionUtil.AssertEqualsExactOrder( GraphUtil.GetTopDownOrder(graph).ToArray(), new [] { "1","1_1","1_1_1" }); Add(graph, "0_1", "0"); EPAssertionUtil.AssertEqualsExactOrder( GraphUtil.GetTopDownOrder(graph).ToArray(), new [] { "0","0_1","1","1_1","1_1_1" }); Add(graph, "1_2", "1"); EPAssertionUtil.AssertEqualsExactOrder( GraphUtil.GetTopDownOrder(graph).ToArray(), new [] { "0","0_1","1","1_1","1_1_1","1_2" }); Add(graph, "1_1_2", "1_1"); EPAssertionUtil.AssertEqualsExactOrder( GraphUtil.GetTopDownOrder(graph).ToArray(), new [] { "0","0_1","1","1_1","1_1_1","1_1_2","1_2" }); Add(graph, "1_2_1", "1_2"); EPAssertionUtil.AssertEqualsExactOrder( GraphUtil.GetTopDownOrder(graph).ToArray(), new [] { "0","0_1","1","1_1","1_1_1","1_1_2","1_2","1_2_1" }); Add(graph, "0", "R"); EPAssertionUtil.AssertEqualsExactOrder( GraphUtil.GetTopDownOrder(graph).ToArray(), new [] { "1","1_1","1_1_1","1_1_2","1_2","1_2_1","R","0","0_1" }); Add(graph, "1", "R"); EPAssertionUtil.AssertEqualsExactOrder( GraphUtil.GetTopDownOrder(graph).ToArray(), new [] { "R","0","0_1","1","1_1","1_1_1","1_1_2","1_2","1_2_1" }); }
public void TestAcyclicTopDownOrder() { IDictionary<string, ICollection<string>> graph = new LinkedHashMap<string, ICollection<string>>(); Add(graph, "1_1", "R2"); Add(graph, "A", "R1"); Add(graph, "A", "R2"); EPAssertionUtil.AssertEqualsExactOrder(new [] { "R1","R2","1_1","A" }, GraphUtil.GetTopDownOrder(graph).ToArray()); Add(graph, "R1", "R2"); EPAssertionUtil.AssertEqualsExactOrder(new [] { "R2","1_1","R1","A" }, GraphUtil.GetTopDownOrder(graph).ToArray()); Add(graph, "1_1", "A"); EPAssertionUtil.AssertEqualsExactOrder(new [] { "R2","R1","A","1_1" }, GraphUtil.GetTopDownOrder(graph).ToArray()); Add(graph, "0", "1_1"); EPAssertionUtil.AssertEqualsExactOrder(new [] { "R2","R1","A","1_1","0" }, GraphUtil.GetTopDownOrder(graph).ToArray()); Add(graph, "R1", "0"); TryInvalid(graph, "Circular dependency detected between [\"0\", \"R1\", \"A\", \"1_1\"]"); }