public void Create_RotationOfSeperateTree() { var left = new AbstractSyntaxTreeNode("A"); var branchLeft = new AbstractSyntaxTreeNode("B"); var terminalLeft = new AbstractSyntaxTreeNode("C"); branchLeft.Append(terminalLeft); var branchRight = new AbstractSyntaxTreeNode("D"); var terminalRight = new AbstractSyntaxTreeNode("E"); branchRight.Append(terminalRight); left.Append(branchLeft); left.Append(branchRight); var right = new AbstractSyntaxTreeNode("A"); right.Append(branchRight.CopyDeep()); right.Append(branchLeft.CopyDeep()); var metric = Creator.Create(left, right); Assert.AreEqual( new AbstractSyntaxTreeMetric() { Insertations = 0, Deletions = 0, Rotations = 1 }, metric ); }
protected void BaseInit() { Root = new AbstractSyntaxTreeNode("1"); var leftRootChild = new AbstractSyntaxTreeNode("2"); var rightRootChild = new AbstractSyntaxTreeNode("3"); leftRootChild.Append(new AbstractSyntaxTreeNode("4")); leftRootChild.Append(new AbstractSyntaxTreeNode("5")); rightRootChild.Append(new AbstractSyntaxTreeNode("6")); Root.Append(leftRootChild); Root.Append(rightRootChild); PreOrderExpected = new[] { "1", "2", "4", "5", "3", "6" }; PostOrderExpected = new[] { "4", "5", "2", "6", "3", "1" }; BreadthFirstExpected = new[] { "1", "2", "3", "4", "5", "6" }; }
public AbstractSyntaxTreeNode GatherMethodDeclaration(AbstractSyntaxTreeNode classNode, ClassExtractorObj obj, string hashCode) { var root = new AbstractSyntaxTreeNode("Root"); root.Append(classNode); foreach (var node in obj.CxxMethodDecls.Where(wrapper => IsDefinedClassMethod(wrapper, hashCode))) { root.Append(node); } return(root); }
public void Create_OneDeletionsOfNode() { var left = new AbstractSyntaxTreeNode("A"); left.Append(new AbstractSyntaxTreeNode("B")); var right = left.CopyDeep(); left.Append(new AbstractSyntaxTreeNode("C")); var metric = Creator.Create(left, right); Assert.AreEqual(new AbstractSyntaxTreeMetric() { Deletions = 1, }, metric); }
public void Create_IdenticalTreeShouldBeNoDifference() { var left = new AbstractSyntaxTreeNode("A"); var terminal = new AbstractSyntaxTreeNode("B"); var branch = new AbstractSyntaxTreeNode("C"); branch.Append(terminal); left.Append(branch); left.Append(terminal.CopyDeep()); var right = left.CopyDeep(); var metric = Creator.Create(left, right); Assert.AreEqual(new AbstractSyntaxTreeMetric(), metric); }
public AbstractSyntaxTreeNode GatherCallExpressions(MethodExtractorObj obj, AbstractSyntaxTreeNode methodNode, AbstractSyntaxTreeNode root, string methodHashCode) { var hasCodes = new List <string>(); foreach (var callExpressionNode in obj.CallExpressions) { var visitor = new AbstractSyntaxTreeWordSearchVisitor(Splitter, "MemberExpr"); callExpressionNode.BreadthFirst(visitor); if (!visitor.Found) { continue; } var hashCode = Splitter.Split(visitor.Node.Value).Last(); if (hashCode.Equals(methodHashCode) || hasCodes.Contains(hashCode)) { continue; } hasCodes.Add(hashCode); var callNode = GetCallNodeOrDefault(root, hashCode); if (callNode == null) { continue; } methodNode.Append(callNode); } return(methodNode); }
public void Create_CheckDistanceOfDifferentAbstractSyntaxTreeNodesWithOperator() { var left = new AbstractSyntaxTreeNode("one"); left.Append(new AbstractSyntaxTreeNode("two")); left.Append(new AbstractSyntaxTreeNode("three")); left.Append(new AbstractSyntaxTreeNode("one (two) + + + + + + + three")); var right = new AbstractSyntaxTreeNode("four"); right.Append(new AbstractSyntaxTreeNode("one")); right.Append(new AbstractSyntaxTreeNode("ones")); right.Append(new AbstractSyntaxTreeNode("four ones")); var metric = Creator.Create(left, right); Assert.AreEqual(Math.Pow(64, 0.5), metric.Difference); }
public void Search_ShouldNotFindTwo() { var root = new AbstractSyntaxTreeNode("root"); root.Append(new AbstractSyntaxTreeNode("1 one")); var visitor = new AbstractSyntaxTreeWordSearchVisitor(Splitter, "two"); root.PreOrder(visitor); Assert.IsNull(visitor.Node); }
public void Search_ShouldFindTheNodeWithOne() { var root = new AbstractSyntaxTreeNode("root"); root.Append(new AbstractSyntaxTreeNode("1 one")); var visitor = new AbstractSyntaxTreeWordSearchVisitor(Splitter, "one"); root.PreOrder(visitor); Assert.IsTrue(visitor.Node.Value.Contains("1")); }
public void ExtractLevel(ref AbstractSyntaxTreeNode root, out string lastLine) { while (CurrentLine.Length > Depth && CurrentLine[Depth] == '-') { var line = CurrentLine.Substring(Depth + 1); var node = new AbstractSyntaxTreeNode(line); if (Reader.EndOfStream) { lastLine = CurrentLine; root.Append(node); return; } var level = new ClangAbstractSyntaxTreeLevelExtractor(Reader, Reader.ReadLine(), Depth + 2); level.ExtractLevel(ref node, out lastLine); CurrentLine = lastLine; root.Append(node); } lastLine = CurrentLine; }
public AbstractSyntaxTreeNode GetMethodOrDefault(MethodExtractorObj obj, MethodDeclaration methodDeclaration, out string hashCode) { var root = new AbstractSyntaxTreeNode("Root"); foreach (var methodNode in obj.Methods) { if (!NodeIsMethod(methodNode, methodDeclaration)) { continue; } hashCode = GetMethodHashCodeOrDefault(methodNode, methodDeclaration.AstType); if (hashCode == null) { continue; } if (methodNode.Value.EndsWith("default")) { root.Append(methodNode); return(root); } var visitor = new AbstractSyntaxTreeWordSearchVisitor(Splitter, "CompoundStmt"); methodNode.BreadthFirst(visitor); if (!visitor.Found) { continue; } root.Append(methodNode); return(root); } hashCode = null; return(null); }
public void Create_RotateWithinNode() { var left = new AbstractSyntaxTreeNode("A"); left.Append(new AbstractSyntaxTreeNode("B")); left.Append(new AbstractSyntaxTreeNode("C")); var right = new AbstractSyntaxTreeNode("A"); right.Append(new AbstractSyntaxTreeNode("C")); right.Append(new AbstractSyntaxTreeNode("B")); var metric = Creator.Create(left, right); Assert.AreEqual( new AbstractSyntaxTreeMetric() { Insertations = 0, Deletions = 0, Rotations = 1 }, metric ); }
public void Create_BranchHeavyRightSide() { var left = new AbstractSyntaxTreeNode("A"); var right = new AbstractSyntaxTreeNode("A"); right.Append(new AbstractSyntaxTreeNode("B")); var metric = Creator.Create(left, right); Assert.AreEqual( new AbstractSyntaxTreeMetric() { Insertations = 2, Deletions = 1, Rotations = 1 }, metric ); }
public void Append_IsTerminalShouldBeFalse() { Root.Append(Child); Assert.IsFalse(Root.Terminal); }