Esempio n. 1
0
        public void GetEdgeInfo()
        {
            var vertex1 = new TestVertex("1");
            var vertex2 = new TestVertex("2");
            var edge    = new Edge <TestVertex>(vertex1, vertex2);

            var graph      = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var algorithm1 = new TestSimpleParameterizedLayoutAlgorithm(graph);

            Assert.IsNull(algorithm1.GetEdgeInfo(edge));

            var algorithm2 = new TestDefaultSimpleParameterizedLayoutAlgorithm(graph);

            Assert.IsNull(algorithm2.GetEdgeInfo(edge));

            var algorithm3 = new TestComplexParameterizedLayoutAlgorithm(graph);

            Assert.IsNull(algorithm3.GetEdgeInfo(edge));

            graph.AddVerticesAndEdge(edge);
            Assert.IsNull(algorithm3.GetEdgeInfo(edge));

            const double edgeInfo = 1.2;

            algorithm3.EdgesInfos.Add(edge, edgeInfo);
            Assert.AreEqual(edgeInfo, algorithm3.GetEdgeInfo(edge));

            algorithm3.EdgesInfos.Remove(edge);
            Assert.IsNull(algorithm3.GetEdgeInfo(edge));
        }
Esempio n. 2
0
        public void GetVertexInfo()
        {
            var vertex = new TestVertex("1");

            var graph      = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var algorithm1 = new TestSimpleParameterizedLayoutAlgorithm(graph);

            Assert.IsNull(algorithm1.GetVertexInfo(vertex));

            var algorithm2 = new TestDefaultSimpleParameterizedLayoutAlgorithm(graph);

            Assert.IsNull(algorithm2.GetVertexInfo(vertex));

            var algorithm3 = new TestComplexParameterizedLayoutAlgorithm(graph);

            Assert.IsNull(algorithm3.GetVertexInfo(vertex));

            graph.AddVertex(vertex);
            Assert.IsNull(algorithm3.GetVertexInfo(vertex));

            const int vertexInfo = 1;

            algorithm3.VerticesInfos.Add(vertex, vertexInfo);
            Assert.AreEqual(vertexInfo, algorithm3.GetVertexInfo(vertex));

            algorithm3.VerticesInfos.Remove(vertex);
            Assert.IsNull(algorithm3.GetVertexInfo(vertex));
        }
Esempio n. 3
0
        public void ProgressChanged_Complex()
        {
            var graph      = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var algorithm  = new TestComplexParameterizedLayoutAlgorithm(graph);
            var progresses = new Stack <double>(new[] { 100.0, 50.0, 0.0 });

            algorithm.ProgressChanged += (sender, percent) => Assert.AreEqual(progresses.Pop(), percent);

            algorithm.Compute();

            CollectionAssert.IsEmpty(progresses);
        }
Esempio n. 4
0
        public void IterationEnded_Complex()
        {
            var vertex1 = new TestVertex("1");
            var vertex2 = new TestVertex("2");

            var verticesPositions = new Dictionary <TestVertex, Point>
            {
                [vertex1] = new Point(12, 5),
                [vertex2] = new Point(5, 42)
            };

            var graph = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();

            graph.AddVertexRange(new[] { vertex1, vertex2 });

            var algorithm = new TestComplexParameterizedLayoutAlgorithm(graph, verticesPositions, null);

            var iteration1 = new EventArgsContentChecker(1, 50, "Test", verticesPositions);
            var normalizedVerticesPositions = new Dictionary <TestVertex, Point>(verticesPositions);

            LayoutUtils.NormalizePositions(normalizedVerticesPositions);
            var iteration2     = new EventArgsContentChecker(2, 60, "Test2", normalizedVerticesPositions);
            var iterations     = new Stack <EventArgsContentChecker>(new[] { iteration2, iteration1 });
            var infoIterations = new Stack <EventArgsContentChecker>(new[] { iteration2, iteration1 });

            algorithm.IterationEnded += (sender, args) =>
            {
                EventArgsContentChecker contentChecker = iterations.Pop();
                Assert.AreEqual(contentChecker.Iteration, args.Iteration);
                Assert.AreEqual(contentChecker.Percent, args.StatusInPercent);
                Assert.AreEqual(contentChecker.Message, args.Message);
                Assert.AreEqual(contentChecker.Positions, args.VerticesPositions);
            };
            algorithm.InfoIterationEnded += (sender, args) =>
            {
                EventArgsContentChecker contentChecker = infoIterations.Pop();
                Assert.AreEqual(contentChecker.Iteration, args.Iteration);
                Assert.AreEqual(contentChecker.Percent, args.StatusInPercent);
                Assert.AreEqual(contentChecker.Message, args.Message);
                Assert.AreEqual(contentChecker.Positions, args.VerticesPositions);
            };

            algorithm.Compute();

            Assert.AreEqual(ComputationState.Finished, algorithm.State);
            CollectionAssert.IsEmpty(iterations);
            CollectionAssert.IsEmpty(infoIterations);
        }
Esempio n. 5
0
        public void Constructor3()
        {
            var verticesPositions = new Dictionary <TestVertex, Point>();
            var graph             = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var algorithm         = new TestComplexParameterizedLayoutAlgorithm(graph);

            AssertAlgorithmProperties(algorithm, graph);

            algorithm = new TestComplexParameterizedLayoutAlgorithm(graph);
            algorithm.IterationEnded += (sender, args) => { };
            AssertAlgorithmProperties(algorithm, graph, expectedReportIterationEnd: true);

            algorithm = new TestComplexParameterizedLayoutAlgorithm(graph);
            algorithm.ProgressChanged += (sender, args) => { };
            AssertAlgorithmProperties(algorithm, graph, expectedReportProgress: true);

            algorithm = new TestComplexParameterizedLayoutAlgorithm(graph);
            algorithm.IterationEnded  += (sender, args) => { };
            algorithm.ProgressChanged += (sender, args) => { };
            AssertAlgorithmProperties(algorithm, graph, expectedReportIterationEnd: true, expectedReportProgress: true);

            algorithm = new TestComplexParameterizedLayoutAlgorithm(graph, verticesPositions, null);
            AssertAlgorithmProperties(algorithm, graph, verticesPositions);

            algorithm = new TestComplexParameterizedLayoutAlgorithm(graph, verticesPositions, null);
            algorithm.IterationEnded += (sender, args) => { };
            AssertAlgorithmProperties(algorithm, graph, verticesPositions, true);

            algorithm = new TestComplexParameterizedLayoutAlgorithm(graph, verticesPositions, null);
            algorithm.ProgressChanged += (sender, args) => { };
            AssertAlgorithmProperties(algorithm, graph, verticesPositions, expectedReportProgress: true);

            algorithm = new TestComplexParameterizedLayoutAlgorithm(graph, verticesPositions, null);
            algorithm.IterationEnded  += (sender, args) => { };
            algorithm.ProgressChanged += (sender, args) => { };
            AssertAlgorithmProperties(algorithm, graph, verticesPositions, true, true);

            algorithm = new TestComplexParameterizedLayoutAlgorithm(graph, null, null);
            AssertAlgorithmProperties(algorithm, graph);

            var parameters = new TestLayoutParameters();

            algorithm = new TestComplexParameterizedLayoutAlgorithm(graph, null, parameters);
            AssertAlgorithmProperties(algorithm, graph, parameters: parameters);
        }
Esempio n. 6
0
        public void GetEdgeInfo_Throws()
        {
            // ReSharper disable ReturnValueOfPureMethodIsNotUsed
            // ReSharper disable AssignNullToNotNullAttribute
            var graph      = new AdjacencyGraph <TestVertex, Edge <TestVertex> >();
            var algorithm1 = new TestSimpleParameterizedLayoutAlgorithm(graph);

            Assert.Throws <ArgumentNullException>(() => algorithm1.GetEdgeInfo(null));

            var algorithm2 = new TestDefaultSimpleParameterizedLayoutAlgorithm(graph);

            Assert.Throws <ArgumentNullException>(() => algorithm2.GetEdgeInfo(null));

            var algorithm3 = new TestComplexParameterizedLayoutAlgorithm(graph);

            Assert.Throws <ArgumentNullException>(() => algorithm3.GetEdgeInfo(null));
            // ReSharper restore AssignNullToNotNullAttribute
            // ReSharper restore ReturnValueOfPureMethodIsNotUsed
        }