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); }
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); }
private string[,] GetLabels(List <ExpressionNode> functions, Set set) { List <Object> parameters = new List <Object>(); List <FunctionNode> nodes = functions.ConvertAll(x => _interpreter.DispatchFunction(x, parameters)). ConvertAll(x => _functions[x.Reference]); string[,] labels = new string[functions.Count, set.List.Count]; for (int i = 0; i < functions.Count; i++) { for (int ii = 0; ii < set.Elements.Count; ii++) { labels[i, ii] = _interpreter.Function <string>(nodes[i], new List <Object> { set.List[ii] }); } } return(labels); }
public void ExportGraph_GraphAndFileName_ThrowsError() { IInterpreterGraph parent = Substitute.For <IInterpreterGraph>(); GraphHelper graphHelper = SetUpHelper(parent); graphHelper.SetASTRoot(GetAST()); parent.Function <Element>(Arg.Any <FunctionNode>(), Arg.Any <List <Object> >()).Returns(new Element(3)); parent.DispatchString(Arg.Any <ExpressionNode>(), Arg.Any <List <Object> >()).Returns("File"); parent.DispatchGraph(Arg.Any <ExpressionNode>(), Arg.Any <List <Object> >()).Returns(GetGraph()); Assert.ThrowsException <InvalidElementException>(() => graphHelper.ExportGraph(new ExportNode(new IdentifierExpression("", 0, 0), 0, 0))); }