public void VerifyIdInDifferentExpression_AllEquals() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var D = new CircularEntity("D"); A = A + (B + B + D) + B; var expression1 = A.AsExpression(f => f.Children); var expression2 = A.AsExpression(f => f.Children); Assert.Equal(expression2.Graph.Vertexes[0].Id, expression2.Graph.Vertexes[0].Id); Assert.Equal(expression2.Graph.Vertexes[1].Id, expression2.Graph.Vertexes[1].Id); Assert.Equal(expression2.Graph.Vertexes[2].Id, expression2.Graph.Vertexes[2].Id); }
public void VerifyIndegreesParentsInDeepBuild_AllOk() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var D = new CircularEntity("D"); A = A + (B + B + D) + B; var expression = A.AsExpression(f => f.Children, true); Assert.Equal(7, expression.Count); Assert.Equal(3, expression.Graph.Vertexes.Count); Assert.Equal(0, expression.Graph.Vertexes[0].Parents.Count); Assert.Equal(0, expression.Graph.Vertexes[0].Indegrees); Assert.Equal(4, expression.Graph.Vertexes[1].Parents.Count); Assert.Equal(4, expression.Graph.Vertexes[1].Indegrees); Assert.Same(expression[0], expression.Graph.Vertexes[1].Parents[0]); Assert.Same(expression[1], expression.Graph.Vertexes[1].Parents[1]); Assert.Same(expression[0], expression.Graph.Vertexes[1].Parents[2]); Assert.Same(expression[4], expression.Graph.Vertexes[1].Parents[3]); Assert.Equal(2, expression.Graph.Vertexes[2].Parents.Count); Assert.Equal(2, expression.Graph.Vertexes[2].Indegrees); Assert.Same(expression[1], expression.Graph.Vertexes[2].Parents[0]); Assert.Same(expression[4], expression.Graph.Vertexes[2].Parents[1]); }
public void VerifyExpressionWithOneEntityOnly_ShouldBe_IsIsolated() { var A = new CircularEntity("A"); var expression = A.AsExpression(f => f.Children); Assert.True(expression.Graph.Vertexes[0].IsIsolated); }
public void VerifyOutdegreesChildrenInSurfaceBuild_AllOk() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var D = new CircularEntity("D"); A = A + (B + B + D) + B; var expression = A.AsExpression(f => f.Children); Assert.Equal(5, expression.Count); Assert.Equal(3, expression.Graph.Vertexes.Count); Assert.Equal(2, expression.Graph.Vertexes[0].Children.Count); Assert.Equal(2, expression.Graph.Vertexes[0].Outdegrees); Assert.Same(expression[1], expression.Graph.Vertexes[0].Children[0]); Assert.Same(expression[4], expression.Graph.Vertexes[0].Children[1]); Assert.Equal(2, expression.Graph.Vertexes[1].Children.Count); Assert.Equal(2, expression.Graph.Vertexes[1].Outdegrees); Assert.Same(expression[2], expression.Graph.Vertexes[1].Children[0]); Assert.Same(expression[3], expression.Graph.Vertexes[1].Children[1]); Assert.Equal(0, expression.Graph.Vertexes[2].Children.Count); Assert.Equal(0, expression.Graph.Vertexes[2].Outdegrees); }
public void VerifyContainGraph() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var C = new CircularEntity("C"); var D = new CircularEntity("D"); var E = new CircularEntity("E"); var F = new CircularEntity("F"); A = A + (B + (C + D)) + (F + C); // A + (B + (C + D)) + (F + (C + D)) // Deep (repeat C in final) var expressionA = A.AsExpression(f => f.Children, true); var expressionC = C.AsExpression(f => f.Children); Assert.Equal(7, expressionA.Count); Assert.Equal(2, expressionC.Count); // A.B.C.D contains C.D Assert.True(expressionA[3].Path.ContainsPath(expressionC[1].Path)); Assert.True(expressionA[6].Path.ContainsPath(expressionC[1].Path)); // check if all paths in graphC exists in graphA Assert.True(expressionA.Graph.ContainsGraph(expressionC.Graph)); }
public void VerifyOutdegreesChildrenInDeepBuild_AllOk() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var D = new CircularEntity("D"); A = A + (B + B + D) + B; // "A + (B + B + D) + (B + B + D)" var expression = A.AsExpression(f => f.Children, true); Assert.Equal(7, expression.Count); Assert.Equal(3, expression.Graph.Vertexes.Count); Assert.Equal(2, expression.Graph.Vertexes[0].Children.Count); Assert.Equal(2, expression.Graph.Vertexes[0].Outdegrees); Assert.Equal(expression[1], expression.Graph.Vertexes[0].Children[0]); Assert.Equal(expression[4], expression.Graph.Vertexes[0].Children[1]); Assert.Equal(4, expression.Graph.Vertexes[1].Children.Count); Assert.Equal(4, expression.Graph.Vertexes[1].Outdegrees); Assert.Equal(expression[2], expression.Graph.Vertexes[1].Children[0]); Assert.Equal(expression[3], expression.Graph.Vertexes[1].Children[1]); Assert.Equal(expression[5], expression.Graph.Vertexes[1].Children[2]); Assert.Equal(expression[6], expression.Graph.Vertexes[1].Children[3]); Assert.Equal(0, expression.Graph.Vertexes[2].Children.Count); Assert.Equal(0, expression.Graph.Vertexes[2].Outdegrees); }
public void VerifyIsSink_ShouldBe_NotIsSinkForAAndSinkForB() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); A = A + B; var expression = A.AsExpression(f => f.Children); Assert.False(expression.Graph.Vertexes[0].IsSink); Assert.True(expression.Graph.Vertexes[1].IsSink); }
public void VerifyExpressionWithTwoEntityOnly_ShouldBe_NotIsIsolated() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); A = A + B; var expression = A.AsExpression(f => f.Children); Assert.False(expression.Graph.Vertexes[0].IsIsolated); Assert.False(expression.Graph.Vertexes[1].IsIsolated); }
public void CreateCiclicalExpression_NullEntity_SerializeNullFormat() { var A = new CircularEntity("A"); var B = new CircularEntity(null); var r = A + B; var expression = A.AsExpression(f => f.Children); Assert.Equal(2, expression.Count); Assert.Equal("A + null", expression.DefaultSerializer.Serialize()); }
public void CreateExpressionCircularValidName_ForceQuoteEvenWhenValidIdentified_DEFAULT_ShouldNotEnclosed() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var r = A + B; var expression = A.AsExpression(f => f.Children); var output = expression.DefaultSerializer.Serialize(); Assert.Equal(2, expression.Count); Assert.Equal("A + B", output); }
public void CreateExpressionCircularInvalidName_ForceQuoteEvenWhenValidIdentified_FALSE_ShouldEnclosedBecauseIsInvalid() { var A = new CircularEntity("A-B"); // "-" is a special char, can throw in deserializer var B = new CircularEntity("if"); // special c# name, can throw in deserializer var r = A + B; var expression = A.AsExpression(f => f.Children); var serializer = expression.GetSerializer <CircularEntityExpressionSerializer <CircularEntity> >(); serializer.ForceQuoteEvenWhenValidIdentified = false; Assert.Equal(2, expression.Count); Assert.Equal("\"A-B\" + \"if\"", expression.DefaultSerializer.Serialize()); }
public void VerifyIsSource_ShouldBe_IsSourceForAOnly() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var C = new CircularEntity("C"); A = A + (B + C); var expression = A.AsExpression(f => f.Children); Assert.True(expression.Graph.Vertexes[0].IsSource); Assert.False(expression.Graph.Vertexes[1].IsSource); Assert.False(expression.Graph.Vertexes[2].IsSource); }
public void VerifyToString_ReturnEntityToString() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var C = new CircularEntity("C"); A = A + (B + C); var expression = A.AsExpression(f => f.Children); Assert.Equal("A", expression.Graph.Vertexes[0].ToString()); Assert.Equal("B", expression.Graph.Vertexes[1].ToString()); Assert.Equal("C", expression.Graph.Vertexes[2].ToString()); }
public void VerifyIsLoop_NoEntityIsLooping() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var C = new CircularEntity("C"); A = A + (B + C); var expression = A.AsExpression(f => f.Children); Assert.Equal(3, expression.Graph.Edges.Count); Assert.False(expression.Graph.Edges[0].IsLoop); Assert.False(expression.Graph.Edges[1].IsLoop); Assert.False(expression.Graph.Edges[2].IsLoop); }
public void VerifyIsLoop_AllEntityInLoopingExceptB() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); A = A + (A + A) + B; var expression = A.AsExpression(f => f.Children); Assert.Equal(4, expression.Graph.Edges.Count); Assert.False(expression.Graph.Edges[0].IsLoop); Assert.True(expression.Graph.Edges[1].IsLoop); Assert.True(expression.Graph.Edges[2].IsLoop); Assert.False(expression.Graph.Edges[3].IsLoop); }
public void VerifyPathType_AllIsSimple() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var C = new CircularEntity("C"); A = A + (B + C); var expression = A.AsExpression(f => f.Children); Assert.Equal(3, expression.Count); Assert.Equal(PathType.Simple, expression[0].Path.PathType); Assert.Equal(PathType.Simple, expression[1].Path.PathType); Assert.Equal(PathType.Simple, expression[2].Path.PathType); }
public void VerifyPathType_RepeatCircularEntityB_ReturnCircleForEntityB() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var C = new CircularEntity("C"); A = A + (B + B); var expression = A.AsExpression(f => f.Children); Assert.Equal(3, expression.Count); Assert.Equal(PathType.Simple, expression[0].Path.PathType); Assert.Equal(PathType.Simple, expression[1].Path.PathType); Assert.Equal(PathType.Circle, expression[2].Path.PathType); }
public void VerifyLastPaths_ShouldHasOnlyLastPaths() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var C = new CircularEntity("C"); var D = new CircularEntity("D"); A = A + (B + C) + D; var expression = A.AsExpression(f => f.Children); Assert.Equal(4, expression.Count); Assert.Equal(2, expression.Graph.Paths.Count); Assert.Equal("[A].[B].[C]", expression.Graph.Paths[0].ToString()); Assert.Equal("[A].[D]", expression.Graph.Paths[1].ToString()); }
public void CreateExpressionCircularValidName_ForceQuoteEvenWhenValidIdentified_TRUE_ShouldEnclosedBecauseIsForced() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var r = A + B; var expression = A.AsExpression(f => f.Children); var serializer = expression.GetSerializer <CircularEntityExpressionSerializer <CircularEntity> >(); serializer.ForceQuoteEvenWhenValidIdentified = true; var output = serializer.Serialize(); Assert.Equal(2, expression.Count); Assert.Equal("\"A\" + \"B\"", output); }
public void VerifyEntityInDeepBuild_AllOk() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var D = new CircularEntity("D"); A = A + (B + B + D) + B; var expression = A.AsExpression(f => f.Children, true); Assert.Equal(7, expression.Count); Assert.Equal(3, expression.Graph.Vertexes.Count); Assert.Same(A, expression.Graph.Vertexes[0].Entity); Assert.Same(B, expression.Graph.Vertexes[1].Entity); Assert.Same(D, expression.Graph.Vertexes[2].Entity); }
public void VerifyCountVisitInSurfaceBuild_AllOk() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var D = new CircularEntity("D"); A = A + (B + B + D) + B; var expression = A.AsExpression(f => f.Children); Assert.Equal(5, expression.Count); Assert.Equal(3, expression.Graph.Vertexes.Count); Assert.Equal(1, expression.Graph.Vertexes[0].CountVisited); Assert.Equal(3, expression.Graph.Vertexes[1].CountVisited); Assert.Equal(1, expression.Graph.Vertexes[2].CountVisited); }
public void VerifyExpressionPaths_ShouldBeProgressivePath() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var C = new CircularEntity("C"); var D = new CircularEntity("D"); A = A + (B + (C + D)); var expression = A.AsExpression(f => f.Children); Assert.Equal(4, expression.Count); Assert.Equal("[A]", expression[0].Path.ToString()); Assert.Equal("[A].[B]", expression[1].Path.ToString()); Assert.Equal("[A].[B].[C]", expression[2].Path.ToString()); Assert.Equal("[A].[B].[C].[D]", expression[3].Path.ToString()); }
public void VerifyCountVisitInDeepBuild_AllOk() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var D = new CircularEntity("D"); A = A + (B + B + D) + B; // "A + (B + B + D) + (B + B + D)" var expression = A.AsExpression(f => f.Children, true); Assert.Equal(7, expression.Count); Assert.Equal(3, expression.Graph.Vertexes.Count); Assert.Equal(1, expression.Graph.Vertexes[0].CountVisited); Assert.Equal(4, expression.Graph.Vertexes[1].CountVisited); Assert.Equal(2, expression.Graph.Vertexes[2].CountVisited); }
public void VerifyToStringCircular_ReturnEdgeToString() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var C = new CircularEntity("C"); var TW = new CircularEntity("TWO WORD"); A = A + (B + C) + TW; var expression = A.AsExpression(f => f.Children); Assert.Equal(4, expression.Graph.Edges.Count); Assert.Equal(", A", expression.Graph.Edges[0].ToString()); Assert.Equal("A, B", expression.Graph.Edges[1].ToString()); Assert.Equal("B, C", expression.Graph.Edges[2].ToString()); Assert.Equal("A, TWO WORD", expression.Graph.Edges[3].ToString()); }
public void CreateExpressionCircular_EmptyString_ShouldNothingInAEntity() { var A = new CircularEntity(""); var B = new CircularEntity("B"); var r = A + B; var expression = A.AsExpression(f => f.Children); var serializer = expression.GetSerializer <CircularEntityExpressionSerializer <CircularEntity> >(); serializer.ForceQuoteEvenWhenValidIdentified = true; var output = serializer.Serialize(); var outputEntity = expression[0].ToString(); Assert.Equal(2, expression.Count); Assert.Equal("", outputEntity); Assert.Equal("\"\" + \"B\"", output); }
public void VerifyEntityItemVertex_AllOk() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var D = new CircularEntity("D"); A = A + (B + B + D) + B; var expression = A.AsExpression(f => f.Children); Assert.Equal(5, expression.Count); Assert.Equal(3, expression.Select(f => f.Vertex).Distinct().Count()); Assert.Equal(expression.Graph.Vertexes[0], expression[0].Vertex); Assert.Equal(expression.Graph.Vertexes[1], expression[1].Vertex); Assert.Equal(expression.Graph.Vertexes[1], expression[2].Vertex); Assert.Equal(expression.Graph.Vertexes[2], expression[3].Vertex); Assert.Equal(expression.Graph.Vertexes[1], expression[4].Vertex); }
public void VerifyIsAntiparallel_AllEntityInLoopingExceptB() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); A = A + (B + A); var expression = A.AsExpression(f => f.Children); Assert.Equal(3, expression.Graph.Edges.Count); // [0] -> null, A // [1] -> A, B // not antiparallel Assert.False(expression.Graph.Edges[0].IsAntiparallel(expression.Graph.Edges[1])); // [0] -> A, B // [1] -> B, A // = is antiparallel Assert.True(expression.Graph.Edges[1].IsAntiparallel(expression.Graph.Edges[2])); }
public void VerifyIdInSameExpression_AllOk() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var D = new CircularEntity("D"); A = A + (B + B + D) + B; var expression = A.AsExpression(f => f.Children); var vertexA = VertexContainer <CircularEntity> .GetEntityId(expression.Graph.Vertexes[0].Entity).Id; var vertexB = VertexContainer <CircularEntity> .GetEntityId(expression.Graph.Vertexes[1].Entity).Id; var vertexD = VertexContainer <CircularEntity> .GetEntityId(expression.Graph.Vertexes[2].Entity).Id; Assert.Equal(vertexA, expression.Graph.Vertexes[0].Id); Assert.Equal(vertexB, expression.Graph.Vertexes[1].Id); Assert.Equal(vertexD, expression.Graph.Vertexes[2].Id); }
public void VerifyTargetAndSource_CheckMatchWithExpression() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var C = new CircularEntity("C"); A = A + (B + C); var expression = A.AsExpression(f => f.Children); Assert.Equal(3, expression.Graph.Edges.Count); Assert.Null(expression.Graph.Edges[0].Source); Assert.Same(expression[0], expression.Graph.Edges[0].Target); Assert.Same(expression[0], expression.Graph.Edges[1].Source); Assert.Same(expression[1], expression.Graph.Edges[1].Target); Assert.Same(expression[1], expression.Graph.Edges[2].Source); Assert.Same(expression[2], expression.Graph.Edges[2].Target); }
public void VerifyIdentity_ShouldEqualsVertexContainer() { var A = new CircularEntity("A"); var B = new CircularEntity("B"); var C = new CircularEntity("C"); A = A + (B + C); var expression = A.AsExpression(f => f.Children); var vertexA = VertexContainer <CircularEntity> .GetEntityId(A).Id; var vertexB = VertexContainer <CircularEntity> .GetEntityId(B).Id; var vertexC = VertexContainer <CircularEntity> .GetEntityId(C).Id; Assert.Equal(3, expression.Count); Assert.Equal($"[{vertexA}]", expression[0].Path.Identity); Assert.Equal($"[{vertexA}].[{vertexB}]", expression[1].Path.Identity); Assert.Equal($"[{vertexA}].[{vertexB}].[{vertexC}]", expression[2].Path.Identity); }