Exemple #1
0
        public void SaveFileTest()
        {
            // 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.Combine(Path.GetFullPath("."), FILE_NAME);

            File.Delete(fullPath);

            communityAlg.ToD3GraphFile(FILE_NAME, Formatting.Indented);

            Console.WriteLine(fullPath);
            Assert.IsTrue(File.Exists(fullPath), $"D3 json file should exist in {fullPath}.");
            Assert.IsTrue(new FileInfo(fullPath).Length > 0, "Json file size should be > 0 bytes.");
#if !DEBUG
            File.Delete(fullPath);
#endif
        }