Example #1
0
        public void ComputeStronglyConnectedComponents_LongLine_HaveCorrectLength()
        {
            var g   = new DependencyGraph <int>(i => i == 5 ? new[] { 12, 4 } : i <= 0 ? ArrayTools.Empty <int>() : new[] { i - 1 });
            var a   = new TarjanStronglyConnectedComponentsAlgorithm <DependencyGraph <int>, int, DependencyGraph <int> .Edge>(g);
            var scc = a.ComputeStronglyConnectedComponents(100);

            Assert.That(scc.Length, Is.EqualTo(94));
            Assert.That(scc[5].Length, Is.EqualTo(8));
            var scc2 = a.ComputeStronglyConnectedComponents(105);

            Assert.That(scc2.Length, Is.EqualTo(5));
        }
Example #2
0
        public void ComputeStronglyConnectedComponents_TypeDependencies_Print()
        {
            var assembly = typeof(DynamicArray <>).Assembly;
            var g        = new DependencyGraph <Type>(t => CalculateTypeDependencies(t, assembly).ToArray());
            var a        = new TarjanStronglyConnectedComponentsAlgorithm <DependencyGraph <Type>, Type, DependencyGraph <Type> .Edge>(g);

            var types = assembly.GetTypes();

            foreach (var type in types)
            {
                var scc = a.ComputeStronglyConnectedComponents(type);
                for (var i = 0; i < scc.Length; i++)
                {
                    var component = scc[i];
                    if (component.Length == 1)
                    {
                        var t = component[0];
                        Console.WriteLine(t);
                    }
                    else
                    {
                        Console.WriteLine("╒════");
                        foreach (var t in component)
                        {
                            Console.WriteLine($"╞ {t}");
                        }
                        Console.WriteLine("╘════");
                    }
                }
            }
        }