-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDFSTest.hs
48 lines (32 loc) · 1.04 KB
/
DFSTest.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
module DFSTest where
import DFS
import GenericGraph hiding (bounds)
import Control.Monad (liftM2)
import Test.QuickCheck
{-
exampleGraph:
+-1--2--3--4
+-+ \ |
----5
-}
edges :: [Edge Int]
edges = [(1,2), (2,3), (2,5), (3,4), (4,5)]
bounds :: Bounds Int
bounds = liftM2 (,) (foldl1 min) (foldl1 max) $
(map fst edges) ++ (map snd edges)
exampleGraph :: GenericGraph Int
exampleGraph = buildG bounds (edges ++ rev edges)
where rev = map (\(a,b) -> (b,a))
prop_SearchEqvTraverse :: Property
prop_SearchEqvTraverse =
forAll inBounds $ \beg ->
forAll inBounds $ \end ->
let sResult = dfsSearch exampleGraph beg end
tResult = dfsTraverse exampleGraph beg
in sResult == (takeWhile (/=end) tResult) ++ [end]
where inBounds = choose bounds
main :: IO ()
main = do quickCheck (dfsTraverse exampleGraph (1::Int) == [1..5])
quickCheck (dfsTraverse exampleGraph (2::Int) == [2,1,3,4,5])
quickCheck (dfsTraverse exampleGraph (3::Int) == [3,2,1,5,4])
quickCheck prop_SearchEqvTraverse