Beispiel #1
0
 private void Assert_AreDAGs(DirectedGraphContext[] directed_graphs_in_json, bool invert = false)
 {
     foreach (var expected in directed_graphs_in_json)
     {
         var dag = new DirectedAcyclicGraph <Node>(expected.Json);
         expected.Roots.Assert_NoDifferences(dag.Template.Roots);
         expected.Sinks.Assert_NoDifferences(dag.Template.Sinks);
         Assert.IsTrue(dag.Template.IsDirectedAcyclicGraph ^ invert);
         if (!string.IsNullOrEmpty(expected.NodeRelations))
         {
             var nodes = new NodeDictionary(expected.NodeRelations);
             foreach (var n in nodes.ToArray())
             {
                 dag[n.Key]._children.Select(x => x.variable).ToArray().Assert_NoDifferences(n.Value["children"]);
                 dag[n.Key]._parents.Select(x => x.variable).ToArray().Assert_NoDifferences(n.Value["parents"]);
                 dag.Remove(n.Key);
             }
             Assert.IsTrue(dag.Count == 0);
         }
     }
 }
Beispiel #2
0
        public void TestOscilattors()
        {
            var oscillators = new OscilattorContext[]
            {
                new OscilattorContext {
                    Object        = new Oscillator <Node>(),
                    Loops         = new string[] { "A", "B" },
                    NodeRelations = "{'A':{'children':['B'],'parents':['B']},'B':{'children':['A'],'parents':['A']}}"
                },
                new OscilattorContext {
                    Object        = new Oscillator <Node>("{'A':['B'],'B':['A'],'C':['A']}"),
                    Loops         = new string[] { "A", "B" },
                    NodeRelations = "{'A':{'children':['B'],'parents':['B','C']},'B':{'children':['A'],'parents':['A']},'C':{'children':['A'],'parents':[]}}"
                },
                new OscilattorContext {
                    Object        = new Oscillator <Node>("{'A':['B','C'],'B':['A']}"),
                    Loops         = new string[] { "A", "B" },
                    NodeRelations = "{'A':{'children':['B','C'],'parents':['B']},'B':{'children':['A'],'parents':['A']},'C':{'children':[],'parents':['A']}}"
                }
            };

            foreach (var expected in oscillators)
            {
                //{string:[string]} directed graph testing i.e. compact serialization form.
                expected.Loops.Assert_NoDifferences(expected.Object.Loops.Select(x => x.Key).ToArray());
                expected.Loops.Assert_NoDifferences(expected.Object.Loops.SelectMany(x => x.Value).Distinct().ToArray());

                //{string:{string:[string]}} directed graph testing i.e. independent element form.
                var nodes = new NodeDictionary(expected.NodeRelations);
                foreach (var n in nodes.ToArray())
                {
                    expected.Object.Graph[n.Key]._children.Select(x => x.variable).ToArray().Assert_NoDifferences(n.Value["children"]);
                    expected.Object.Graph[n.Key]._parents.Select(x => x.variable).ToArray().Assert_NoDifferences(n.Value["parents"]);
                    expected.Object.Graph.Remove(n.Key);
                }
                Assert.IsTrue(expected.Object.Graph.Count == 0);
            }
        }