예제 #1
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);
        }
예제 #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 Deserialize_CreateStartupEntities_SubstractEntities()
        {
            var A = new CircularEntity("A");
            var B = new CircularEntity("B");

            var deserializer = new CircularEntityExpressionDeserializer <CircularEntity>();
            var factory      = new CircularEntityFactory <CircularEntity>();

            factory.Entities.Add("AA", A);
            factory.Entities.Add("BB", B);

            var strExp = "AA + BB";
            var root   = deserializer.Deserialize(strExp, factory);

            Assert.Single(root.Children);
            Assert.Equal("A", root.Name);
            Assert.Equal("B", root.Children.ElementAt(0).Name);

            strExp = "AA - BB + C + D";
            var root2 = deserializer.Deserialize(strExp, factory);

            Assert.Same(root2, root);
            Assert.Equal(2, root2.Children.Count());
            Assert.Equal("A", root2.Name);
            Assert.Equal("C", root2.Children.ElementAt(0).Name);
            Assert.Equal("D", root2.Children.ElementAt(1).Name);
        }
예제 #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 RemoveCoexistents_CheckPathsAfterRemove_AllOk()
        {
            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");
            var G = new CircularEntity("G");
            var H = new CircularEntity("H");
            var J = new CircularEntity("J");

            A = A + (B + C + D) + D + (E + B) + F + (G + G + C) + (H + C);

            var vertexesSources = new CircularEntity[] { A, B, C, D, E, F, G, H };
            var graphs          = new List <Graph <CircularEntity> >();

            foreach (var v in vertexesSources)
            {
                var expression = v.AsExpression(f => f.Children, true);
                graphs.Add(expression.Graph);
            }

            var graphsClean = graphs.RemoveCoexistents();

            var output      = this.GetOutputPaths(graphs.ToPaths());
            var outputClean = this.GetOutputPaths(graphs.ToPaths().RemoveCoexistents());

            var expected      = "[A].[B].[C]\r\n[A].[B].[D]\r\n[A].[D]\r\n[A].[E].[B].[C]\r\n[A].[E].[B].[D]\r\n[A].[F]\r\n[A].[G].[G]\r\n[A].[G].[C]\r\n[A].[H].[C]\r\n[B].[C]\r\n[B].[D]\r\n[C]\r\n[D]\r\n[E].[B].[C]\r\n[E].[B].[D]\r\n[F]\r\n[G].[G]\r\n[G].[C]\r\n[H].[C]";
            var expectedClean = "[A].[B].[C]\r\n[A].[B].[D]\r\n[A].[D]\r\n[A].[E].[B].[C]\r\n[A].[E].[B].[D]\r\n[A].[F]\r\n[A].[G].[G]\r\n[A].[G].[C]\r\n[A].[H].[C]";

            Assert.Equal(output, expected);
            Assert.Equal(outputClean, expectedClean);
        }
예제 #7
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);
        }
예제 #8
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);
        }
예제 #9
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);
        }
예제 #10
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());
        }
예제 #11
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);
        }
예제 #12
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());
        }
예제 #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 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);
        }
예제 #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 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);
        }
예제 #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 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);
        }
예제 #19
0
        public void VerifyAllAntiparallelInExpression()
        {
            var A = new CircularEntity("A");
            var B = new CircularEntity("B");
            var C = new CircularEntity("C");
            var D = new CircularEntity("D");
            var I = new CircularEntity("I");
            var J = new CircularEntity("J");

            A = A + (B + C + D) + A + (I + (J + C) + A);

            var vertexesSources = new CircularEntity[] { A, B, C, D, I, J };
            var graphs          = new List <Graph <CircularEntity> >();

            foreach (var v in vertexesSources)
            {
                var expression = v.AsExpression(f => f.Children);
                graphs.Add(expression.Graph);
            }

            var res = "";

            foreach (var edge in graphs.ElementAt(0).Edges)
            {
                foreach (var edge2 in graphs.ElementAt(0).Edges)
                {
                    if (edge.IsAntiparallel(edge2))
                    {
                        res += "'" + edge.ToString() + "' antiparallel of '" + edge2.ToString() + "'; ";
                    }
                }
            }

            Assert.Equal("'A, A' antiparallel of 'A, A'; 'A, I' antiparallel of 'I, A'; 'I, A' antiparallel of 'A, I'; ", res);

            res = "";
            foreach (var edge in graphs.ElementAt(4).Edges)
            {
                foreach (var edge2 in graphs.ElementAt(4).Edges)
                {
                    if (edge.IsAntiparallel(edge2))
                    {
                        res += "'" + edge.ToString() + "' antiparallel of '" + edge2.ToString() + "'; ";
                    }
                }
            }

            Assert.Equal("'I, A' antiparallel of 'A, I'; 'A, A' antiparallel of 'A, A'; 'A, I' antiparallel of 'I, A'; ", res);
        }
예제 #20
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);
        }
예제 #21
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);
        }
예제 #22
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);
        }
예제 #23
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);
        }
예제 #24
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());
        }
예제 #25
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);
        }
예제 #26
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());
        }
예제 #27
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());
        }
예제 #28
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);
        }
예제 #29
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);
        }
예제 #30
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);
        }