Exemplo n.º 1
0
        public void should_simplify()
        {
            var       graph = new DAG <int>();
            const int v1    = 1;
            const int v2    = 2;
            const int v3    = 3;
            const int v4    = 4;

            graph.AddPath(v1, v2);
            graph.AddPath(v1, v3);
            graph.AddPath(v1, v4);
            graph.AddMergePath(v3, v2);
            graph.AddPath(v2, v4);
            graph.AddPath(v3, v4);

            graph.Simplify();

            Assert.Null(graph.Get(v2));
            var incommings = graph.Get(v3).Incommings;

            Assert.Equal(1, incommings.Count);
            Assert.Equal(v1, incommings.First().Data);
            var outcommings = graph.Get(v3).Outcommings;

            Assert.Equal(1, outcommings.Count);
            Assert.Equal(v4, outcommings.First().Data);
        }
Exemplo n.º 2
0
        public void should_deal_with_merge_path()
        {
            var       graph = new DAG <int>();
            const int v1    = 1;
            const int v2    = 2;
            const int v3    = 3;

            graph.AddMergePath(v1, v2);
            graph.AddPath(v1, v3);
            graph.AddMergePath(v2, v3);

            graph.Simplify();

            Assert.Null(graph.Get(v2));
            Assert.Equal(0, graph.Get(v1).Incommings.Count);
            Assert.Equal(1, graph.Get(v1).Outcommings.Count);
            Assert.Equal(1, graph.Get(v3).Incommings.Count);
            Assert.Equal(0, graph.Get(v3).Outcommings.Count);
        }
Exemplo n.º 3
0
        public void should_simplify_complex()
        {
            var       graph = new DAG <int>();
            const int v1    = 1;
            const int v2    = 2;
            const int v3    = 3;
            const int v4    = 4;

            graph.AddPath(v1, v2);
            graph.AddPath(v1, v3);
            graph.AddPath(v1, v4);
            graph.AddMergePath(v3, v2);
            graph.AddPath(v3, v4);
            graph.AddPath(v4, v2);

            graph.Simplify();

            Assert.NotNull(graph.Get(v2));
            Assert.Equal(3, graph.Get(v2).Incommings.Count);
            Assert.Equal(0, graph.Get(v2).Outcommings.Count);
            Assert.Equal(1, graph.Get(v3).Incommings.Count);
            Assert.Equal(2, graph.Get(v3).Outcommings.Count);
        }
Exemplo n.º 4
0
        public void should_simplify_more_complex()
        {
            var graph = new DAG <string>();

            const string securityCore    = "security-core";
            const string securityCoreWeb = "security-core-web";
            const string extensions      = "extensions";
            const string container       = "container";
            const string containerApi    = "container-api";
            const string web             = "web";
            const string modelApi        = "model-api";
            const string loggingApi      = "logging-api";
            const string loggingSpi      = "logging-spi";
            const string logging         = "logging";
            const string persistenceApi  = "persistence-api";
            const string templateApi     = "template-api";
            const string persistenceSpi  = "persistence-spi";
            const string template        = "template";
            const string templateSpi     = "template-spi";

            graph.AddPath(securityCore, extensions);
            graph.AddPath(securityCoreWeb, container);
            graph.AddPath(securityCoreWeb, containerApi);
            graph.AddPath(securityCoreWeb, extensions);
            graph.AddPath(securityCoreWeb, web);

            graph.AddMergePath(container, containerApi);
            graph.AddMergePath(container, extensions);
            graph.AddMergePath(container, loggingApi);

            graph.AddMergePath(containerApi, extensions);

            graph.AddMergePath(loggingApi, extensions);
            graph.AddMergePath(loggingApi, modelApi);

            graph.AddMergePath(modelApi, extensions);

            graph.AddMergePath(web, containerApi);
            graph.AddMergePath(web, container);
            graph.AddMergePath(web, extensions);
            graph.AddMergePath(web, loggingApi);
            graph.AddMergePath(web, loggingSpi);
            graph.AddMergePath(web, logging);
            graph.AddMergePath(web, modelApi);
            graph.AddMergePath(web, persistenceApi);
            graph.AddMergePath(web, templateSpi);
            graph.AddMergePath(web, template);

            graph.AddMergePath(loggingSpi, containerApi);
            graph.AddMergePath(loggingSpi, container);
            graph.AddMergePath(loggingSpi, extensions);
            graph.AddMergePath(loggingSpi, loggingApi);
            graph.AddMergePath(loggingSpi, modelApi);
            graph.AddMergePath(loggingSpi, persistenceApi);
            graph.AddMergePath(loggingSpi, persistenceSpi);

            graph.AddMergePath(persistenceApi, extensions);
            graph.AddMergePath(persistenceApi, modelApi);

            graph.AddMergePath(persistenceSpi, containerApi);
            graph.AddMergePath(persistenceSpi, extensions);
            graph.AddMergePath(persistenceSpi, modelApi);
            graph.AddMergePath(persistenceSpi, persistenceApi);

            graph.AddMergePath(logging, containerApi);
            graph.AddMergePath(logging, container);
            graph.AddMergePath(logging, extensions);
            graph.AddMergePath(logging, loggingApi);
            graph.AddMergePath(logging, loggingSpi);
            graph.AddMergePath(logging, modelApi);
            graph.AddMergePath(logging, persistenceApi);
            graph.AddMergePath(logging, persistenceSpi);
            graph.AddMergePath(logging, templateApi);
            graph.AddMergePath(logging, template);

            graph.AddMergePath(templateApi, extensions);

            graph.AddMergePath(template, containerApi);
            graph.AddMergePath(template, container);
            graph.AddMergePath(template, extensions);
            graph.AddMergePath(template, templateApi);
            graph.AddMergePath(template, templateSpi);

            graph.AddMergePath(templateSpi, container);
            graph.AddMergePath(templateSpi, extensions);
            graph.AddMergePath(templateSpi, templateApi);

            graph.Simplify();

            Assert.NotNull(graph.Get(securityCore));
            Assert.NotNull(graph.Get(securityCoreWeb));
            Assert.NotNull(graph.Get(web));
            var vertexes = graph.Out();

            Assert.Equal(3, vertexes.Length);
            Assert.Equal(web, vertexes[0]);
            Assert.Equal(securityCore, vertexes[1]);
            Assert.Equal(securityCoreWeb, vertexes[2]);
        }