-
Notifications
You must be signed in to change notification settings - Fork 2
/
Test.hs
82 lines (67 loc) · 2.3 KB
/
Test.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import System.Exit (exitFailure)
import Tuura.Concurrency
import Data.List
import Data.Set (Set)
import qualified Data.Set as Set
import qualified Data.Map as Map
import Tuura.Log
readLog :: String -> IO (Log String)
readLog strLog = do
return . canonicalise $ parse strLog
toIntLog :: Log String -> (Log Int, Set Int, Int -> String)
toIntLog log1 = (intLog, Set.map a2i alphabet, i2a)
where
alphabet = events log1
a2i s = Set.findIndex s alphabet
i2a i = Set.elemAt i alphabet
intLog = map (map a2i) log1
findConcurrentPairs :: String -> [(String,String)] -> IO()
findConcurrentPairs inputLog expPairs = do
(logOriginal, alphabet, decode) <- fmap toIntLog $ readLog inputLog
let lg = dropSubtraces $ split logOriginal
oracle = oracleMokhovCarmona lg
evnts = Set.elems alphabet
cache = Map.fromSet (uncurry oracle) $
Set.fromList [ (x, y) | x <- evnts, y <- evnts, x <= y ]
co a b = cache Map.! (min a b, max a b)
putStr "Found concurrent pairs: "
let foundPairs = [ (decode x, decode y) | (x:xs) <- tails evnts, y <- xs, x `co` y ]
print foundPairs
if expPairs /= foundPairs
then do putStrLn "Test failure, expected and found concurrent pairs do not match"
exitFailure
else putStrLn "Test passed, expected and found concurrent pairs match"
putStrLn ""
putStrLn "______________"
putStrLn ""
main :: IO ()
main = do
putStrLn ""
let log1 = "a b c\na c b"
let expPairs1 = [("b","c")]
putStrLn "Log 1: "
print log1
putStr "Expected concurrent pairs: "
print expPairs1
findConcurrentPairs log1 expPairs1
let log2 = "a b c d\na c b d"
let expPairs2 = [("b","c")]
putStrLn "Log 2: "
print log2
putStr "Expected concurrent pairs: "
print expPairs2
findConcurrentPairs log2 expPairs2
let log3 = "a b c d\na c b d\na c d b\na c b d"
let expPairs3 = [("b","c"),("b","d")]
putStrLn "Log 3: "
print log3
putStr "Expected concurrent pairs: "
print expPairs3
findConcurrentPairs log3 expPairs3
let log4 = "a p q b\na q p b\na p q c\na q p c"
let expPairs4 = [("p","q")]
putStr "Log 4: "
print log4
putStr "Expected concurrent pairs: "
print expPairs4
findConcurrentPairs log4 expPairs4