Commit 86ddc5ed authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Add spinglass corrected test (clustering)

parent 03c8885d
......@@ -144,16 +144,18 @@ bridgeTest = testCase "Bridges" $ edgeLab g <$> bridges g @?= ["bridge"]
communityTest :: TestTree
communityTest = testGroup "Community"
[ consistency, consistency2, consistency3]
[ testGroup "Consistency" [ consistency, consistency2, consistency3 ]
, testGroup "Correctness" [ communityCorrectnessTests ]
]
where
consistency = testCase "Consistency" $ do
consistency = testCase "spinglass" $ do
rs <- replicateM 50 $ withSeed 134 $ findCommunity zacharyKarate Nothing Nothing spinglass
all (== head rs) rs @=? True
consistency2 = testCase "Consistency -- leiden" $ do
consistency2 = testCase "leiden" $ do
rs <- replicateM 50 $ withSeed 234 $ findCommunity zacharyKarate Nothing Nothing leiden
True @=? all (== head rs) rs
consistency3 = testCase "Consistency -- infomap" $ do
consistency3 = testCase "infomap" $ do
rs <- replicateM 50 $ withSeed 234 $ findCommunity zacharyKarate Nothing Nothing infomap
True @=? all (== head rs) rs
......@@ -162,6 +164,26 @@ communityTest = testGroup "Community"
, (3, 4), (5, 6), (5, 7), (5, 8), (5, 9), (6, 7), (6, 8), (6, 9), (7, 8)
, (7, 9), (8, 9), (0, 5) ] :: Graph 'U () ()
communityCorrectnessTests :: TestTree
communityCorrectnessTests = testGroup "Clustering" [
testCase "spinglass" spinglassClustering
]
where
spinglassClustering :: Assertion
spinglassClustering = do
clusters <- withSeed 1 $ findCommunity testGraph Nothing Nothing spinglass
clusters @?= [[3,4], [0,1,2]]
testGraph :: Graph 'U () ()
testGraph = mkGraphUfromEdges [(0,1),(1,2),(2,0),(2,3),(3,4),(4,2)]
-- | Helper function to create an undirected graph from undirected edges.
mkGraphUfromEdges :: [(Int, Int)] -> Graph 'U () ()
mkGraphUfromEdges es = mkGraph (replicate n ()) $ zip es $ repeat ()
where
(a,b) = unzip es
n = length (nub $ a <> b)
pagerankTest :: TestTree
pagerankTest = testGroup "PageRank"
[ consistency
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment