Skip to content

Commit ecf496e

Browse files
Some more tests
1 parent cc0d31c commit ecf496e

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

src/Constrained/Graph.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ topsort gr@(Graph e _) = go [] e
169169
else Left . concat . take 1 . sortOn length . filter (not . null) . map (findCycle gr) $ Map.keys e
170170

171171
-- | Simple DFS cycle finding
172-
-- TODO: tests for this, currently it can produce a stem with a cycle after it
173172
findCycle :: Ord node => Graph node -> node -> [node]
174173
findCycle g@(Graph e _) node = concat . take 1 $ filter loopy $ go mempty node
175174
where

test/Constrained/GraphSpec.hs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DerivingStrategies #-}
2+
{-# LANGUAGE TemplateHaskell #-}
23
{-# LANGUAGE TypeApplications #-}
34
{-# LANGUAGE ScopedTypeVariables #-}
45
{-# LANGUAGE NumericUnderscores #-}
@@ -34,6 +35,21 @@ prop_subtract_topsort g g' =
3435
isRight (topsort g) ==>
3536
isRight (topsort $ subtractGraph g g')
3637

38+
prop_subtract_union :: Graph Node -> Graph Node -> Property
39+
prop_subtract_union g g0' =
40+
let g' = subtractGraph g g0'
41+
in subtractGraph g g' <> g' === g
42+
43+
prop_subtract_keeps_nodes :: Graph Node -> Graph Node -> Property
44+
prop_subtract_keeps_nodes g g' = nodes (subtractGraph g g') === nodes g
45+
46+
prop_subtract_removes_edges :: Graph Node -> Graph Node -> Node -> Node -> Property
47+
prop_subtract_removes_edges g g' x y =
48+
property $ not (dependsOn x y (subtractGraph g $ dependency x (Set.singleton y) <> g'))
49+
50+
prop_union_commutes :: Graph Node -> Graph Node -> Property
51+
prop_union_commutes g g' = g <> g' === g' <> g
52+
3753
prop_delete_topsort :: Graph Node -> Node -> Property
3854
prop_delete_topsort g n =
3955
isRight (topsort g) ==>
@@ -95,22 +111,8 @@ prop_find_cycle_loops =
95111
| n <- Set.toList $ nodes g
96112
]
97113

114+
return []
115+
98116
tests :: Bool -> Spec
99117
tests _nightly =
100-
describe "Graph tests" $ do
101-
prop "prop_arbitrary_reasonable_distribution" $ checkCoverage $ prop_arbitrary_reasonable_distribution
102-
prop "prop_no_dependencies_topsort" $ checkCoverage $ prop_no_dependencies_topsort
103-
prop "prop_subtract_topsort" $ checkCoverage $ prop_subtract_topsort
104-
prop "prop_delete_topsort" $ checkCoverage $ prop_delete_topsort
105-
prop "prop_op_topsort" $ checkCoverage $ prop_op_topsort
106-
prop "prop_trC_topsort" $ checkCoverage $ prop_trC_topsort
107-
prop "prop_trC_opgraph_commute" $ checkCoverage $ prop_trC_opgraph_commute
108-
prop "prop_depends_grows" $ checkCoverage $ prop_depends_grows
109-
prop "prop_topsort_all_nodes" $ checkCoverage $ prop_topsort_all_nodes
110-
prop "prop_topsort_sound" $ checkCoverage $ prop_topsort_sound
111-
prop "prop_topsort_complete" $ checkCoverage $ prop_topsort_complete
112-
prop "prop_find_cycle_sound" $ checkCoverage $ prop_find_cycle_sound
113-
prop "prop_find_cycle_loops" $ checkCoverage $ prop_find_cycle_loops
114-
115-
runTests :: IO ()
116-
runTests = hspec $ tests False
118+
describe "Graph tests" $ sequence_ [ prop n (checkCoverage $ withMaxSuccess 1000 p) | (n, p) <- $allProperties ]

0 commit comments

Comments
 (0)