public void ZeroWeightsTest() { // creates network nodes const int num = 10; var network = new Network(); for (var i = 0u; i < num; i++) { network.AddVertex(i); } // creates edges (full with 0 weight) for (var i = 0u; i < num; i++) { for (var j = i + 1; j < num; j++) { network.AddEdge(new Connection(i, j, 0)); } } Console.WriteLine(network); // creates and updates community algorithm var commAlgorithm = new CommunityAlgorithm(network); commAlgorithm.Update(); commAlgorithm.DisplayNodesCommunities(); commAlgorithm.DisplayCommunities(); for (var i = 0u; i < num; i++) { Assert.AreEqual(i, commAlgorithm.NodesCommunities[i], $"Node {i} should be in community {i}."); } Assert.AreEqual(num, commAlgorithm.GetNumberCommunities(), $"Num. communities should be {num}."); Assert.AreEqual(0, commAlgorithm.GetModularity(), double.Epsilon, "Community modularity should be 0."); }
public void NoConnectionsTest() { // creates network nodes const int num = 10; var network = new Network(); for (var i = 0u; i < num; i++) { network.AddVertex(i); } Console.WriteLine(network); // creates and updates community algorithm var commAlgorithm = new CommunityAlgorithm(network); commAlgorithm.Update(); commAlgorithm.DisplayNodesCommunities(); commAlgorithm.DisplayCommunities(); Assert.AreEqual(0, network.EdgeCount, "Network should not contain edges."); for (var i = 0u; i < num; i++) { Assert.AreEqual(i, commAlgorithm.NodesCommunities[i], $"Node {i} should be in community {i}."); } Assert.AreEqual(num, commAlgorithm.GetNumberCommunities(), $"Num. communities should be {num}."); Assert.AreEqual(0, commAlgorithm.GetModularity(), double.Epsilon, "Community modularity should be 0."); }
private static void Update(CommunityAlgorithm communityAlg, CommunityTracker tracker) { communityAlg.Update(); communityAlg.DisplayNodesCommunities(); Console.WriteLine("Modularity: {0}", communityAlg.GetModularity()); tracker.Update(); }