Skip to content

Commit 4e4b0aa

Browse files
test things a little bit more
1 parent 6ec2910 commit 4e4b0aa

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

test/Constrained/GraphSpec.hs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ instance Arbitrary Node where
2222
arbitrary = Node <$> choose (0, 20)
2323
shrink (Node n) = Node <$> shrink n
2424

25+
prop_arbitrary_reasonable_distribution :: Graph Node -> Property
26+
prop_arbitrary_reasonable_distribution g =
27+
cover 60 (isRight $ topsort g) "has topsort" True
28+
2529
prop_no_dependencies_topsort :: Set Node -> Property
2630
prop_no_dependencies_topsort = property . isRight . topsort . noDependencies
2731

@@ -37,13 +41,11 @@ prop_delete_topsort g n =
3741

3842
prop_op_topsort :: Graph Node -> Property
3943
prop_op_topsort g =
40-
cover 60 (isRight (topsort g)) "has topsort" $
41-
isRight (topsort g) == isRight (topsort $ opGraph g)
44+
isRight (topsort g) === isRight (topsort $ opGraph g)
4245

4346
prop_trC_topsort :: Graph Node -> Property
4447
prop_trC_topsort g =
45-
cover 60 (isRight (topsort g)) "has topsort" $
46-
isRight (topsort g) == isRight (topsort $ transitiveClosure g)
48+
isRight (topsort g) === isRight (topsort $ transitiveClosure g)
4749

4850
prop_trC_opgraph_commute :: Graph Node -> Property
4951
prop_trC_opgraph_commute g =
@@ -60,17 +62,21 @@ prop_topsort_all_nodes :: Graph Node -> Property
6062
prop_topsort_all_nodes g =
6163
case topsort g of
6264
Left{} -> discard
63-
Right o -> cover 60 True "has topsort" $ Set.fromList o === nodes g
65+
Right o -> Set.fromList o === nodes g
6466

6567
prop_topsort_sound :: Graph Node -> Property
6668
prop_topsort_sound g =
6769
case topsort g of
6870
Left{} -> discard
69-
Right o -> cover 60 True "has topsort" $ property $ go o
71+
Right o -> property $ go o
7072
where
7173
go [] = True
7274
go (n : ns) = all (\n' -> not $ dependsOn n n' g) ns && go ns
7375

76+
prop_topsort_complete :: Graph Node -> Property
77+
prop_topsort_complete g =
78+
isLeft (topsort g) === any (\ n -> not . null $ findCycle g n) (nodes g)
79+
7480
prop_find_cycle_sound :: Property
7581
prop_find_cycle_sound =
7682
forAllShrink (mkGraph @Node <$> arbitrary) shrink $ \ g ->
@@ -92,14 +98,19 @@ prop_find_cycle_loops =
9298
tests :: Bool -> Spec
9399
tests _nightly =
94100
describe "Graph tests" $ do
95-
prop "prop_no_dependencies_topsort" $ checkCoverage $ withMaxSuccess 10000 prop_no_dependencies_topsort
96-
prop "prop_subtract_topsort" $ checkCoverage $ withMaxSuccess 10000 prop_subtract_topsort
97-
prop "prop_delete_topsort" $ checkCoverage $ withMaxSuccess 10000 prop_delete_topsort
98-
prop "prop_op_topsort" $ checkCoverage $ withMaxSuccess 10000 prop_op_topsort
99-
prop "prop_trC_topsort" $ checkCoverage $ withMaxSuccess 10000 prop_trC_topsort
100-
prop "prop_trC_opgraph_commute" $ checkCoverage $ withMaxSuccess 10000 prop_trC_opgraph_commute
101-
prop "prop_depends_grows" $ checkCoverage $ withMaxSuccess 10000 prop_depends_grows
102-
prop "prop_topsort_all_nodes" $ checkCoverage $ withMaxSuccess 10000 prop_topsort_all_nodes
103-
prop "prop_topsort_sound" $ checkCoverage $ withMaxSuccess 10000 prop_topsort_sound
104-
prop "prop_find_cycle_sound" $ checkCoverage $ withMaxSuccess 10000 prop_find_cycle_sound
105-
prop "prop_find_cycle_loops" $ checkCoverage $ withMaxSuccess 10000 prop_find_cycle_loops
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

0 commit comments

Comments
 (0)