Commit 1acd124c authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[FLouvain] test -- fix weights (<= 1.0)

parent df34c362
......@@ -18,7 +18,7 @@ import Data.Graph.FGL
simpleGraph :: FGraph () ()
simpleGraph = mkFGraph' [ (1, 2, 1.0)
, (2, 3, 2.0)
, (2, 3, 0.5)
]
simpleLGraph :: FGraph Text ()
......@@ -26,18 +26,21 @@ simpleLGraph = mkFGraph [ (1, "one")
, (2, "two")
, (3, "three")]
[ (1, 2, 1.0)
, (2, 3, 1.0) ]
, (2, 3, 0.5) ]
spec :: Spec
spec = do
describe "FLouvain tests" $ do
it "graphWeight computes correctly" $ do
graphWeight simpleGraph `shouldBe` GraphWeightSum 3.0
assertApproxEqual "graphWeights don't match"
0.00001
1.5
(unGraphWeightSum $ graphWeight simpleGraph)
it "nodeWeightSum computes correctly" $ do
nodeWeightSum (DGI.context simpleGraph 1) `shouldBe` NodeWeightSum 1.0
nodeWeightSum (DGI.context simpleGraph 2) `shouldBe` NodeWeightSum 3.0
nodeWeightSum (DGI.context simpleGraph 3) `shouldBe` NodeWeightSum 2.0
nodeWeightSum (DGI.context simpleGraph 2) `shouldBe` NodeWeightSum 1.5
nodeWeightSum (DGI.context simpleGraph 3) `shouldBe` NodeWeightSum 0.5
it "replaceLNode works correctly" $ do
let replaced = replaceLNode simpleLGraph (1, "ONE")
......@@ -55,8 +58,8 @@ spec = do
Protolude.map comInWeightSum communities `shouldBe` [iws0, iws0, iws0]
Protolude.map comTotWeightSum communities `shouldBe`
[ TotWeightSum 1.0
, TotWeightSum 3.0
, TotWeightSum 2.0 ]
, TotWeightSum 1.5
, TotWeightSum 0.5 ]
it "nodeComWeightSum computes correctly" $ do
let cgr = initialCGr simpleGraph
......@@ -69,9 +72,9 @@ spec = do
nodeComWeightSum fstCom (DGI.context simpleGraph 3) `shouldBe` NodeComWeightSum 0.0
nodeComWeightSum sndCom (DGI.context simpleGraph 1) `shouldBe` NodeComWeightSum 1.0
nodeComWeightSum sndCom (DGI.context simpleGraph 2) `shouldBe` NodeComWeightSum 0.0
nodeComWeightSum sndCom (DGI.context simpleGraph 3) `shouldBe` NodeComWeightSum 2.0
nodeComWeightSum sndCom (DGI.context simpleGraph 3) `shouldBe` NodeComWeightSum 0.5
nodeComWeightSum trdCom (DGI.context simpleGraph 1) `shouldBe` NodeComWeightSum 0.0
nodeComWeightSum trdCom (DGI.context simpleGraph 2) `shouldBe` NodeComWeightSum 2.0
nodeComWeightSum trdCom (DGI.context simpleGraph 2) `shouldBe` NodeComWeightSum 0.5
nodeComWeightSum trdCom (DGI.context simpleGraph 3) `shouldBe` NodeComWeightSum 0.0
it "modularity computes correctly" $ do
......@@ -114,7 +117,7 @@ spec = do
intoOutOf ctx com = moveNodeWithContext ctx OutOf $ moveNodeWithContext ctx Into com
outOfInto ctx com = moveNodeWithContext ctx Into $ moveNodeWithContext ctx OutOf com
newCom1 `shouldBe` Community ([], InWeightSum 0.0, TotWeightSum 0.0)
newCom2 `shouldBe` Community ([1, 2], InWeightSum 1.0, TotWeightSum 2.0)
newCom2 `shouldBe` Community ([1, 2], InWeightSum 1.0, TotWeightSum 0.5)
-- TODO moveNodeWithContext ctx Into (moveNodeWithContext ctx OutOf) is an
-- identity, this can be used in QuickCheck testing
......
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