Beispiel #1
0
        public void NestedIfs()
        {
            var a = GraphModel.CreateFunction("A", Vector2.zero);

            StackBaseModel b, c;

            CreateIfThenElseStacks(a, "b", "c", out b, out c);
            var d = GraphModel.CreateStack("d", Vector2.left);
            var e = GraphModel.CreateStack("e", Vector2.left);

            b.CreateStackedNode <Type0FakeNodeModel>("b");
            c.CreateStackedNode <Type0FakeNodeModel>("c");
            d.CreateStackedNode <Type0FakeNodeModel>("d");
            e.CreateStackedNode <Type0FakeNodeModel>("e");

            var cIfNode = c.CreateStackedNode <IfConditionNodeModel>("if_c");

            GraphModel.CreateEdge(b.InputPorts[0], cIfNode.ThenPort);
            GraphModel.CreateEdge(d.InputPorts[0], cIfNode.ElsePort);

            GraphModel.CreateEdge(e.InputPorts[0], b.OutputPorts[0]);
            GraphModel.CreateEdge(e.InputPorts[0], d.OutputPorts[0]);

            // as C has an if node, a common descendant of (C,X) must be a descendant of (B,D,X), here E
            Assert.That(RoslynTranslator.FindCommonDescendant(a, a, c), Is.EqualTo(e));
            Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(e));
        }
Beispiel #2
0
        public void UnjoinedIfHasNoCommonDescendant()
        {
            var a = GraphModel.CreateFunction("A", Vector2.zero);

            StackBaseModel b, c;

            CreateIfThenElseStacks(a, "b", "c", out b, out c);
            Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.Null);
        }
Beispiel #3
0
        public void SimpleIf()
        {
            var a = GraphModel.CreateFunction("A", Vector2.zero);

            StackBaseModel b, c, d;

            CreateIfThenElseStacks(a, "b", "c", out b, out c);
            JoinStacks(b, c, "d", out d);

            Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(d));
        }
Beispiel #4
0
        public void IfNoThen()
        {
            var a = GraphModel.CreateFunction("A", Vector2.zero);

            StackBaseModel b, c;

            CreateIfThenElseStacks(a, "b", "c", out b, out c);

            GraphModel.CreateEdge(b.InputPorts[0], c.OutputPorts[0]);

            Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(b));
        }
Beispiel #5
0
        public void ThreeWayIf()
        {
            var a = GraphModel.CreateFunction("A", Vector2.zero);

            StackBaseModel b, c, d, e, f;

            CreateIfThenElseStacks(a, "b", "c", out b, out c);
            CreateIfThenElseStacks(c, "d", "e", out d, out e);
            JoinStacks(d, e, "f", out f);
            GraphModel.CreateEdge(f.InputPorts[0], b.OutputPorts[0]);

            Assert.That(RoslynTranslator.FindCommonDescendant(a, d, e), Is.EqualTo(f));
            Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(f));
        }
Beispiel #6
0
        public void TwoLevelIfs()
        {
            var            a = GraphModel.CreateFunction("A", Vector2.zero);
            StackBaseModel b, c, d, e, f, g, h, i, j;

            CreateIfThenElseStacks(a, "b", "c", out b, out c);
            CreateIfThenElseStacks(b, "d", "e", out d, out e);
            CreateIfThenElseStacks(c, "f", "g", out f, out g);
            JoinStacks(d, e, "h", out h);
            JoinStacks(f, g, "i", out i);
            JoinStacks(h, i, "h", out j);

            Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(j));
            Assert.That(RoslynTranslator.FindCommonDescendant(a, d, e), Is.EqualTo(h));
            Assert.That(RoslynTranslator.FindCommonDescendant(a, f, g), Is.EqualTo(i));
            Assert.That(RoslynTranslator.FindCommonDescendant(a, d, f), Is.EqualTo(j));
        }
Beispiel #7
0
        public void IfNoThenElseIfNoThen()
        {
            var a = GraphModel.CreateFunction("A", Vector2.zero);

            StackBaseModel b, c;

            CreateIfThenElseStacks(a, "b", "c", out b, out c);
            b.CreateStackedNode <Type0FakeNodeModel>("b");
            c.CreateStackedNode <Type0FakeNodeModel>("c");

            var cIfNode = c.CreateStackedNode <IfConditionNodeModel>("if_c");

            GraphModel.CreateEdge(b.InputPorts[0], cIfNode.ThenPort);

            // as C has an if node with a disconnect else branch, B cannot be a descendant of both branches
            // so common(b,c) should return null
            Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.Null);
        }
Beispiel #8
0
        public void FourWayJoin()
        {
            var            a = GraphModel.CreateFunction("A", Vector2.zero);
            StackBaseModel b, c, d, e, f, g, h;

            CreateIfThenElseStacks(a, "b", "c", out b, out c);
            CreateIfThenElseStacks(b, "d", "e", out d, out e);
            CreateIfThenElseStacks(c, "f", "g", out f, out g);
            JoinStacks(d, e, "h", out h);

            GraphModel.CreateEdge(h.InputPorts[0], f.OutputPorts[0]);
            GraphModel.CreateEdge(h.InputPorts[0], g.OutputPorts[0]);

            Assert.That(RoslynTranslator.FindCommonDescendant(a, b, c), Is.EqualTo(h));
            Assert.That(RoslynTranslator.FindCommonDescendant(a, d, e), Is.EqualTo(h));
            Assert.That(RoslynTranslator.FindCommonDescendant(a, f, g), Is.EqualTo(h));
            Assert.That(RoslynTranslator.FindCommonDescendant(a, d, f), Is.EqualTo(h));
        }