Пример #1
0
        private void CreateConfig()
        {
            NodeFamily nodes = new NodeFamily(
                new List <IdentifierPartTemplate>()
            {
                new IdentifierPartTemplate("v", "0", "n")
            }
                );
            EdgeFamily edges = new EdgeFamily(
                new List <IdentifierPartTemplate>
            {
                new IdentifierPartTemplate("a", "0", "n"),
                new IdentifierPartTemplate("b", "0", "n"),
                new IdentifierPartTemplate("x", "0", "n")
            }, new EdgeFamily.EdgeEnd(nodes, new List <string> {
                "__a__"
            }),
                new EdgeFamily.EdgeEnd(nodes, new List <string> {
                "__b__"
            })
                )
            {
                ValidationTemplate = "g[__a__][__x__] == __b__", IsDirected = true
            };

            _config = new GraphConfig
            {
                Edges = new HashSet <EdgeFamily> {
                    edges
                },
                Nodes = new HashSet <NodeFamily> {
                    nodes
                }
            };
        }
        public void FromNodeFamily(NodeFamily nodeFamily)
        {
            IdentifierPartRangeControl.FromRanges(nodeFamily.Ranges);
            validationTemplateBox.Text = nodeFamily.ValidationTemplate;
            FamilyName.Text            = nodeFamily.Name;
            var windows = new List <Window>();

            foreach (var conditionalProperty in nodeFamily.ConditionalProperties)
            {
                var window = new NodeConditionalPropertyWindow();
                window.FromConditionalProperty(conditionalProperty);
                windows.Add(window);
            }
            PropertiesControl.SetNewWindows(windows);
        }
Пример #3
0
        public void Parse_Concurrency_ThrowsNodeConcurrencyException()
        {
            // Arrange
            INodeFamily nodeFamily = new NodeFamily("family");
            INode       idle       = new IdleNode(nodeFamily, null);
            INode       exactText  = new ExactTextNode(
                "foo",
                new[] { WordTextClass.Instance, },
                false,
                (node, token, arg3) => { },
                nodeFamily,
                null);
            INode someText = new TextNode(
                new ITextClass[] { WordTextClass.Instance, },
                null,
                nodeFamily,
                null);

            idle.EstablishLink(someText);
            idle.EstablishLink(exactText);
            someText.EstablishLink(EndNode.Instance);
            exactText.EstablishLink(EndNode.Instance);

            IParser parser = new Parser();

            var tokens = new List <IToken>
            {
                new TextToken(
                    WordTextClass.Instance,
                    NoneTextDecoration.Instance,
                    "foo",
                    Position.Zero,
                    3),
            };

            // Act
            parser.Root = idle;
            var ex = Assert.Throws <NodeConcurrencyException>(() => parser.Parse(tokens));

            // Assert
            Assert.That(ex.Message, Is.EqualTo("More than one node accepted the token."));
            Assert.That(ex.ConcurrentNodes, Has.Length.EqualTo(2));
            Assert.That(ex.ConcurrentNodes, Does.Contain(exactText));
            Assert.That(ex.ConcurrentNodes, Does.Contain(someText));
            Assert.That(ex.Token, Is.SameAs(tokens.Single()));
        }
Пример #4
0
        public void CreateGraphConfigForDfs()
        {
            NodeFamily nodes = new NodeFamily(
                new List <IdentifierPartTemplate>
            {
                new IdentifierPartTemplate("v", "0", "n")
            });
            var dfsNode = System.Tuple.Create(
                new Condition("\"__CURRENT_FUNCTION__\" == \"dfs\" && __ARG1__ == __v__"),
                (INodeProperty) new FillColorNodeProperty(Color.Red));

            nodes.Properties.Add(dfsNode);
            EdgeFamily edges = new EdgeFamily(
                new List <IdentifierPartTemplate>
            {
                new IdentifierPartTemplate("a", "0", "n"),
                new IdentifierPartTemplate("b", "0", "n"),
                new IdentifierPartTemplate("x", "0", "g[__a__].size()")
            }, new EdgeFamily.EdgeEnd(nodes, new List <string> {
                "__a__"
            }),
                new EdgeFamily.EdgeEnd(nodes, new List <string> {
                "__b__"
            }))
            {
                ValidationTemplate = "__a__ < __b__ && g[__a__][__x__] == __b__"
            };


            var dfsEdges = Tuple.Create(new Condition("p[__a__] == __b__ || p[__b__] == __a__"),
                                        (IEdgeProperty) new LineColorEdgeProperty(Color.Red));


            edges.Properties.Add(dfsEdges);
            GraphConfig config = new GraphConfig
            {
                Edges = new HashSet <EdgeFamily> {
                    edges
                }, Nodes = new HashSet <NodeFamily> {
                    nodes
                }
            };
        }