Пример #1
0
        public void should_get_correct_count()
        {
            var graph = new DAG <int>();

            Assert.Equal(graph.Out().Count(), 0);

            graph.Add(0);
            Assert.Equal(graph.Out().Count(), 1);
        }
Пример #2
0
        public void should_get_vertexes_for_simple_direct()
        {
            var       graph = new DAG <int>();
            const int from  = 0;
            const int to    = 1;

            graph.Add(from);
            graph.AddPath(from, to);

            var items = graph.Out();

            Assert.Equal(2, items.Length);
            Assert.Equal(to, items[0]);
            Assert.Equal(from, items[1]);
        }
Пример #3
0
        public void should_not_merge_virtual_if_will_create_cycle()
        {
            var       graph = new DAG <int>();
            const int v1    = 1;
            const int v2    = 2;
            const int v3    = 3;

            graph.AddMergePath(v3, v1);
            graph.AddPath(v3, v2);
            graph.AddPath(v2, v1);
            graph.Simplify();
            var ints = graph.Out();

            Assert.Equal(1, ints[0]);
            Assert.Equal(2, ints[1]);
            Assert.Equal(3, ints[2]);
        }
Пример #4
0
        public void should_simplify_all_virtual()
        {
            var          graph          = new DAG <string>();
            const string extensions     = "extensions";
            const string modelApi       = "model-api";
            const string persistenceApi = "persistence-api";
            const string containerApi   = "container-api";

            graph.AddMergePath(modelApi, extensions);
            graph.AddMergePath(persistenceApi, extensions);
            graph.AddMergePath(persistenceApi, modelApi);
            graph.AddMergePath(containerApi, extensions);
            graph.Simplify();
            var vertexes = graph.Out();

            Assert.Equal(2, vertexes.Length);
            Assert.Equal(persistenceApi, vertexes[0]);
            Assert.Equal(containerApi, vertexes[1]);
        }
Пример #5
0
        public void should_get_vertexes_for_complex_direct()
        {
            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.AddPath(v3, v2);
            graph.AddPath(v2, v4);
            graph.AddPath(v3, v4);

            var items = graph.Out();

            Assert.Equal(4, items.Length);
            Assert.Equal(v4, items[0]);
            Assert.Equal(v2, items[1]);
            Assert.Equal(v3, items[2]);
            Assert.Equal(v1, items[3]);
        }
Пример #6
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]);
        }