Пример #1
0
        public void ExportGraph_GraphAndFileName_ReturnsCorrectLabelGraph()
        {
            IInterpreterGraph parent      = Substitute.For <IInterpreterGraph>();
            GraphHelper       graphHelper = SetUpHelper(parent);

            graphHelper.SetASTRoot(GetAST());
            parent.Function <Element>(Arg.Any <FunctionNode>(), Arg.Any <List <Object> >()).Returns(x => HandleFunctionNode(x));
            parent.DispatchString(Arg.Any <ExpressionNode>(), Arg.Any <List <Object> >()).Returns("File");
            parent.DispatchGraph(Arg.Any <ExpressionNode>(), Arg.Any <List <Object> >()).Returns(GetGraph());
            List <int> src = new List <int> {
                0, 1, 2
            };
            List <int> dst = new List <int> {
                2, 1, 0
            };

            string[,] vertexLabels = new string[0, 3];
            string[,] edgeLabels   = new string[0, 3];

            LabelGraph expected = new LabelGraph("File", src, dst, vertexLabels, edgeLabels, 3);

            LabelGraph result = graphHelper.ExportGraph(new ExportNode(new IdentifierExpression("", 0, 0), 0, 0));

            result.Should().BeEquivalentTo(expected);
        }
Пример #2
0
        public void ExportGraph_GraphAndFileName_ReturnsCorrectLabelGraphWithLabels()
        {
            IInterpreterGraph parent      = Substitute.For <IInterpreterGraph>();
            GraphHelper       graphHelper = SetUpHelper(parent);
            AST ast = GetAST();

            graphHelper.SetASTRoot(ast);
            parent.Function <Element>(Arg.Any <FunctionNode>(), Arg.Any <List <Object> >()).Returns(new Element(5));
            parent.DispatchString(Arg.Any <ExpressionNode>(), Arg.Any <List <Object> >()).Returns("File");
            parent.DispatchGraph(Arg.Any <ExpressionNode>(), Arg.Any <List <Object> >()).Returns(GetGraph());
            parent.DispatchFunction(Arg.Any <IdentifierExpression>(), Arg.Any <List <Object> >()).Returns(new Function(0));
            parent.DispatchFunction(Arg.Any <FunctionCallExpression>(), Arg.Any <List <Object> >()).Returns(new Function(1));
            parent.Function <string>(ast.Functions[0], Arg.Any <List <Object> >()).Returns("a");
            parent.Function <string>(ast.Functions[1], Arg.Any <List <Object> >()).Returns("b");
            List <int> src = new List <int> {
                0, 0, 0
            };
            List <int> dst = new List <int> {
                0, 0, 0
            };

            string[,] vertexLabels = new string[, ] {
                { "a", "a", "a" }, { "b", "b", "b" }
            };
            string[,] edgeLabels = new string[, ] {
                { "a", "a", "a" }
            };
            LabelGraph             expected     = new LabelGraph("File", src, dst, vertexLabels, edgeLabels, 3);
            IdentifierExpression   identifier   = new IdentifierExpression("", 0, 0);
            FunctionCallExpression functionCall = new FunctionCallExpression("", null, 0, 0);
            ExportNode             node         = new ExportNode(identifier,
                                                                 identifier,
                                                                 new List <ExpressionNode>()
            {
                identifier, functionCall
            },
                                                                 new List <ExpressionNode>()
            {
                identifier
            },
                                                                 0, 0);

            LabelGraph result = graphHelper.ExportGraph(node);

            result.Should().BeEquivalentTo(expected);
        }