コード例 #1
0
        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);
        }
コード例 #2
0
        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]);
        }
コード例 #3
0
        public void VerifyExpressionWithOneEntityOnly_ShouldBe_IsIsolated()
        {
            var A          = new CircularEntity("A");
            var expression = A.AsExpression(f => f.Children);

            Assert.True(expression.Graph.Vertexes[0].IsIsolated);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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());
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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());
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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());
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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());
        }
コード例 #19
0
        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);
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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());
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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());
        }
コード例 #25
0
        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);
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        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]));
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        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);
        }
コード例 #30
0
        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);
        }