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 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 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); }
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 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); }
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 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 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 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 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 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 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 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); }
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 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 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 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 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 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 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); }