Exemple #1
0
        public void Constructor()
        {
            const int vertex            = 10;
            var       graph             = new AdjacencyGraph <int, Edge <int> >();
            var       verticesPositions = new Dictionary <int, Point>();
            var       verticesSizes     = new Dictionary <int, Size>();
            var       context           = new ContextualLayoutContext <int, Edge <int>, AdjacencyGraph <int, Edge <int> > >(
                graph,
                vertex,
                verticesPositions,
                verticesSizes);

            Assert.AreEqual(vertex, context.SelectedVertex);
            Assert.AreSame(verticesPositions, context.Positions);
            Assert.AreSame(verticesSizes, context.Sizes);
            Assert.AreSame(graph, context.Graph);
            Assert.AreEqual(LayoutMode.Simple, context.Mode);
        }
        public void StandardFactory()
        {
            var vertex    = new TestVertex("10");
            var positions = new Dictionary <TestVertex, Point>();
            var sizes     = new Dictionary <TestVertex, Size>();
            var graph     = new BidirectionalGraph <TestVertex, Edge <TestVertex> >();

            graph.AddVertex(vertex);
            var context = new ContextualLayoutContext <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(
                graph,
                vertex,
                positions,
                sizes);

            var factory = new ContextualLayoutAlgorithmFactory <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >();

            CollectionAssert.AreEqual(
                new[] { "DoubleTree", "BalloonTree" },
                factory.AlgorithmTypes);


            Assert.IsNull(
                factory.CreateAlgorithm(
                    string.Empty,
                    context,
                    new DoubleTreeLayoutParameters()));

            Assert.IsNull(
                factory.CreateAlgorithm(
                    "NotExist",
                    context,
                    new DoubleTreeLayoutParameters()));

            Assert.IsNull(
                factory.CreateAlgorithm(
                    "doubletree",
                    context,
                    new DoubleTreeLayoutParameters()));

            Assert.IsInstanceOf <DoubleTreeLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "DoubleTree",
                    context,
                    new DoubleTreeLayoutParameters()));

            Assert.IsInstanceOf <BalloonTreeLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > > >(
                factory.CreateAlgorithm(
                    "BalloonTree",
                    context,
                    new BalloonTreeLayoutParameters()));


            var testParameters                  = new TestLayoutParameters();
            var doubleTreeParameters            = new DoubleTreeLayoutParameters();
            ILayoutParameters createdParameters = factory.CreateParameters(string.Empty, doubleTreeParameters);

            Assert.IsNull(createdParameters);

            createdParameters = factory.CreateParameters("NotExist", doubleTreeParameters);
            Assert.IsNull(createdParameters);

            createdParameters = factory.CreateParameters("DoubleTree", null);
            Assert.IsInstanceOf <DoubleTreeLayoutParameters>(createdParameters);
            Assert.AreNotSame(doubleTreeParameters, createdParameters);

            createdParameters = factory.CreateParameters("DoubleTree", testParameters);
            Assert.IsInstanceOf <DoubleTreeLayoutParameters>(createdParameters);
            Assert.AreNotSame(testParameters, createdParameters);

            createdParameters = factory.CreateParameters("DoubleTree", doubleTreeParameters);
            Assert.IsInstanceOf <DoubleTreeLayoutParameters>(createdParameters);
            Assert.AreNotSame(doubleTreeParameters, createdParameters);

            var balloonTreeParameters = new BalloonTreeLayoutParameters();

            createdParameters = factory.CreateParameters("BalloonTree", null);
            Assert.IsInstanceOf <BalloonTreeLayoutParameters>(createdParameters);
            Assert.AreNotSame(balloonTreeParameters, createdParameters);

            createdParameters = factory.CreateParameters("BalloonTree", testParameters);
            Assert.IsInstanceOf <BalloonTreeLayoutParameters>(createdParameters);
            Assert.AreNotSame(testParameters, createdParameters);

            createdParameters = factory.CreateParameters("BalloonTree", balloonTreeParameters);
            Assert.IsInstanceOf <BalloonTreeLayoutParameters>(createdParameters);
            Assert.AreNotSame(balloonTreeParameters, createdParameters);


            Assert.IsFalse(factory.IsValidAlgorithm(null));
            Assert.IsFalse(factory.IsValidAlgorithm(string.Empty));
            Assert.IsTrue(factory.IsValidAlgorithm("DoubleTree"));
            Assert.IsFalse(factory.IsValidAlgorithm("doubletree"));
            Assert.IsTrue(factory.IsValidAlgorithm("BalloonTree"));


            var algorithm1 = new TestLayoutAlgorithm();

            Assert.IsEmpty(factory.GetAlgorithmType(algorithm1));

            var algorithm2 = new DoubleTreeLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph, positions, sizes, vertex, doubleTreeParameters);

            Assert.AreEqual("DoubleTree", factory.GetAlgorithmType(algorithm2));

            var algorithm3 = new BalloonTreeLayoutAlgorithm <TestVertex, Edge <TestVertex>, BidirectionalGraph <TestVertex, Edge <TestVertex> > >(graph, positions, vertex, balloonTreeParameters);

            Assert.AreEqual("BalloonTree", factory.GetAlgorithmType(algorithm3));


            Assert.IsFalse(factory.NeedEdgeRouting(string.Empty));
            Assert.IsTrue(factory.NeedEdgeRouting("DoubleTree"));
            Assert.IsTrue(factory.NeedEdgeRouting("BalloonTree"));


            Assert.IsFalse(factory.NeedOverlapRemoval(string.Empty));
            Assert.IsFalse(factory.NeedOverlapRemoval("DoubleTree"));
            Assert.IsFalse(factory.NeedOverlapRemoval("BalloonTree"));
        }