From 7a82a4b2d49471868e4b898001df1f60b8a5c8a7 Mon Sep 17 00:00:00 2001 From: Kevin Quick Date: Wed, 27 Mar 2024 22:17:43 -0700 Subject: [PATCH] Add test robustness for order independence of Vertex/VertexLabel --- tests/GraphTests.hs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/GraphTests.hs b/tests/GraphTests.hs index e628830..c02219e 100644 --- a/tests/GraphTests.hs +++ b/tests/GraphTests.hs @@ -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. @@ -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" ~: @@ -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?