Skip to content

Commit

Permalink
Add test robustness for order independence of Vertex/VertexLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
kquick committed Mar 28, 2024
1 parent 09549ef commit 7a82a4b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions tests/GraphTests.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}

-- | This module tests Haggle by comparing its results to those of FGL.
-- This assumes that FGL is reasonably correct.
Expand Down Expand Up @@ -252,15 +254,15 @@ testExplicit =
testPatricia :: [Test.Framework.Test]
testPatricia =
let gr0 = foldl (\g -> snd . HGL.insertLabeledVertex g)
(HGL.emptyGraph :: HGL.PatriciaTree Int Char)
[1,2,4,3,5,0]
vs = fst <$> HGL.labeledVertices gr0
(HGL.emptyGraph :: HGL.PatriciaTree Int Char)
[1,2,4,3,5,0]
vs = fst <$> (L.sortBy (compare `on` snd) $ HGL.labeledVertices gr0)
gr1 = foldl (\g (f,t,l) ->
snd $ fromJust $ HGL.insertLabeledEdge g f t l)
gr0
[ (vs !! 1, vs !! 2, 'a')
, (vs !! 0, vs !! 2, 'b')
, (vs !! 1, vs !! 5, 'c')
[ (vs !! 2, vs !! 4, 'a')
, (vs !! 1, vs !! 4, 'b')
, (vs !! 2, vs !! 0, 'c')
]
in hUnitTestToTests $ test
[ "create graph" ~:
Expand All @@ -283,7 +285,7 @@ testPatricia =
L.sort (snd <$> HGL.labeledEdges gr2) @?= "cde"

, "replaceLabeledVertex" ~:
do let gr2 = HGL.replaceLabeledVertex gr1 (vs !! 2) 11
do let gr2 = HGL.replaceLabeledVertex gr1 (vs !! 4) 11
-- Vertex label changed?
sum (snd <$> HGL.labeledVertices gr2) @?= (15 + (11 - 4))
-- Edges are still in place?
Expand Down

0 comments on commit 7a82a4b

Please sign in to comment.