コード例 #1
0
ファイル: GraphvizTests.cs プロジェクト: pedrodbs/Comuna
        private static void SaveFileTest(PaletteGenerator paletteGenerator, string name)
        {
            // creates graph and adds nodes
            var network = new Network();

            for (var i = 0u; i < NUM_NODES; i++)
            {
                network.AddVertex(i);
            }

            // adds connections
            network.AddEdge(new Connection(0, 1));
            network.AddEdge(new Connection(0, 2));
            network.AddEdge(new Connection(0, 9));
            network.AddEdge(new Connection(2, 4));
            network.AddEdge(new Connection(2, 9));
            network.AddEdge(new Connection(4, 7));
            network.AddEdge(new Connection(7, 9));
            network.AddEdge(new Connection(8, 9));

            // creates algorithm and updates communities
            var communityAlg = new CommunityAlgorithm(network, -1, 0.000001);

            communityAlg.Update();
            communityAlg.DisplayCommunities();

            var fullPath = Path.GetFullPath(".");

            foreach (var imageType in ImageTypes)
            {
                var fileName = $"{FILE_NAME}-{name}-{imageType}";
                var dotPath  = Path.Combine(fullPath, $"{fileName}.dot");
                var imgPath  = $"{dotPath}.{imageType.ToString().ToLower()}";
                File.Delete(dotPath);
                File.Delete(imgPath);

                var filePath = communityAlg.ToGraphvizFile(
                    fullPath, fileName, true, imageType, paletteGenerator, WAIT_TIMEOUT);

                Console.WriteLine(dotPath);
                Assert.IsTrue(File.Exists(dotPath), $"Dot file should exist in {dotPath}.");
                Assert.AreEqual(filePath, dotPath, $"Dot file should be exist in {imgPath}");

                Console.WriteLine(imgPath);
                Assert.IsTrue(File.Exists(imgPath), $"Image file should exist in {imgPath}.");
                Assert.IsTrue(new FileInfo(imgPath).Length > 0, "Image size should be > 0 bytes.");

#if !DEBUG
                File.Delete(dotPath);
                File.Delete(imgPath);
#endif
            }
        }