@@ -26,7 +26,7 @@ import Test.Hspec (Spec, describe, it, shouldBe, shouldMatchList,
26
26
import Test.QuickCheck
27
27
28
28
import Control.Arrow (second )
29
- import Data.List (delete , sort , unfoldr )
29
+ import Data.List (delete , sort , unfoldr , group , (\\) )
30
30
import qualified Data.Set as S
31
31
32
32
#if __GLASGOW_HASKELL__ < 710
@@ -327,18 +327,41 @@ test_sp _ cg = all test_p (map unLPath (msTree g))
327
327
-- -----------------------------------------------------------------------------
328
328
-- TransClos
329
329
330
- test_trc :: (ArbGraph gr , Eq (BaseGraph gr a () )) => Proxy (gr a b )
331
- -> UConnected (SimpleGraph gr ) a ()
332
- -> Bool
333
- test_trc _ cg = gReach == trc g
330
+ -- | The transitive, reflexive closure of a graph means that every
331
+ -- node is a successor of itself, and also that if (a, b) is an edge,
332
+ -- and (b, c) is an edge, then (a, c) must also be an edge.
333
+ test_trc :: DynGraph gr => Proxy (gr a b ) -> (NoMultipleEdges gr ) a b -> Bool
334
+ test_trc _ nme = all valid $ nodes gTrans
334
335
where
335
- g = connGraph cg
336
-
337
- lns = labNodes g
338
-
339
- gReach = (`asTypeOf` g)
340
- . insEdges [(v,w,() ) | (v,_) <- lns, (w,_) <- lns]
341
- $ mkGraph lns []
336
+ g = emap (const () ) (nmeGraph nme)
337
+ gTrans = trc g
338
+ valid n =
339
+ -- For each node n, check that:
340
+ -- the successors for n in gTrans are a superset of the successors for n in g.
341
+ null (suc g n \\ suc gTrans n) &&
342
+ -- the successors for n in gTrans are exactly equal to the reachable nodes for n in g, plus n.
343
+ sort (suc gTrans n) == map head (group (sort (n: [ v | u <- suc g n, v <- reachable u g ])))
344
+
345
+ -- | The transitive closure of a graph means that if (a, b) is an
346
+ -- edge, and (b, c) is an edge, then (a, c) must also be an edge.
347
+ test_tc :: DynGraph gr => Proxy (gr a b ) -> (NoMultipleEdges gr ) a b -> Bool
348
+ test_tc _ nme = all valid $ nodes gTrans
349
+ where
350
+ g = nmeGraph nme
351
+ gTrans = tc g
352
+ valid n =
353
+ -- For each node n, check that:
354
+ -- the successors for n in gTrans are a superset of the successors for n in g.
355
+ null (suc g n \\ suc gTrans n) &&
356
+ -- the successors for n in gTrans are exactly equal to the reachable nodes for n in g.
357
+ sort (suc gTrans n) == map head (group (sort [ v | u <- suc g n, v <- reachable u g ]))
358
+
359
+ -- | The reflexive closure of a graph means that all nodes are a
360
+ -- successor of themselves.
361
+ test_rc :: DynGraph gr => Proxy (gr a b ) -> gr a b -> Bool
362
+ test_rc _ g = and [ n `elem` suc gRefl n | n <- nodes gRefl ]
363
+ where
364
+ gRefl = rc g
342
365
343
366
-- -----------------------------------------------------------------------------
344
367
-- Utility functions
0 commit comments