public void NetworkPassesTest() { // creates network nodes const int numNodes = 16; var network = new Network(); for (var i = 0u; i < numNodes; i++) { network.AddVertex(i); } // creates edges (according to paper) network.AddEdge(new Connection(0, 2)); network.AddEdge(new Connection(0, 4)); network.AddEdge(new Connection(0, 3)); network.AddEdge(new Connection(0, 5)); network.AddEdge(new Connection(1, 2)); network.AddEdge(new Connection(1, 4)); network.AddEdge(new Connection(1, 7)); network.AddEdge(new Connection(2, 4)); network.AddEdge(new Connection(2, 5)); network.AddEdge(new Connection(2, 6)); network.AddEdge(new Connection(3, 7)); network.AddEdge(new Connection(4, 10)); network.AddEdge(new Connection(5, 7)); network.AddEdge(new Connection(5, 11)); network.AddEdge(new Connection(6, 7)); network.AddEdge(new Connection(6, 11)); network.AddEdge(new Connection(8, 9)); network.AddEdge(new Connection(8, 10)); network.AddEdge(new Connection(8, 11)); network.AddEdge(new Connection(8, 14)); network.AddEdge(new Connection(8, 15)); network.AddEdge(new Connection(9, 12)); network.AddEdge(new Connection(9, 14)); network.AddEdge(new Connection(10, 11)); network.AddEdge(new Connection(10, 12)); network.AddEdge(new Connection(10, 13)); network.AddEdge(new Connection(10, 14)); network.AddEdge(new Connection(11, 13)); // creates and updates community algorithm var communityAlg = new CommunityAlgorithm(network, -1, 0); communityAlg.Update(); communityAlg.DisplayCommunities(); //checks communities Assert.AreEqual(4, communityAlg.GetNumberCommunities(), "Network should have 4 communities."); var communities = new[] { new HashSet <uint> { 0, 1, 2, 4, 5 }, new HashSet <uint> { 3, 6, 7 }, new HashSet <uint> { 11, 13 }, new HashSet <uint> { 8, 9, 10, 12, 14, 15 } }; for (var i = 0; i < 4; i++) { var community = communityAlg.Communities[i]; Console.WriteLine(ArrayUtil.ToString(community.ToArray())); Assert.IsTrue(communities.Any(comm => comm.SetEquals(community)), $"Community {i} is unexpected."); } // gets and checks community graph (1st pass) communityAlg.DisplayCommunityGraph(); communityAlg.DisplayPartition(); network = communityAlg.GetCommunityNetwork(); Assert.AreEqual(4, network.VertexCount, "Community network should have 4 nodes."); // checks connections var exptConns = new HashSet <Connection> { new Connection(0, 0, 16), new Connection(0, 1, 1), new Connection(0, 2, 3), new Connection(1, 1, 14), new Connection(1, 2, 1), new Connection(1, 3, 4), new Connection(2, 2, 2), new Connection(2, 3, 1), new Connection(3, 3, 4) }; var netConns = new HashSet <Connection>(network.Edges); foreach (var exptConn in exptConns) { Console.WriteLine(exptConn); Assert.IsTrue(netConns.Contains(exptConn), $"Community network should contain connection: {exptConn}."); } //// creates and updates community algorithm //communityAlg = new CommunityAlgorithm(network, -1, 0); //communityAlg.Update(); //communityAlg.DisplayCommunities(); }