Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. type ModuleName = Int
  2. type ModuleGraph = HM.HashMap Int (HS.HashSet Int)
  3.  
  4. singletonGraph :: Int -> [Int] -> ModuleGraph
  5. singletonGraph i ds = HM.singleton i (HS.fromList ds)
  6.  
  7. arbModuleName :: Gen ModuleName
  8. arbModuleName = oneof (map return [0..100])
  9.  
  10. arbModuleGraph :: Gen ModuleGraph
  11. arbModuleGraph = sized f where
  12. f 0 = return HM.empty
  13. f n = arbModuleName >>= rec
  14.  
  15. rec :: Int -> Gen ModuleGraph
  16. rec d = smaller $ do
  17. ddeps <- listOf arbModuleName
  18. gs <- traverse rec ddeps
  19. return $ foldl (HM.unionWith HS.union) (singletonGraph d ddeps) gs
  20.  
  21. newtype CyclicGraph = CyclicGraph (Int, ModuleGraph) deriving Show
  22. instance Arbitrary CyclicGraph where
  23. arbitrary = do
  24. rootInt <- arbModuleName
  25. graph <- rec rootInt
  26. return $ CyclicGraph (rootInt, graph)
  27.  
  28. prop_fetchGraphHMIdentity :: CyclicGraph -> Bool
  29. prop_fetchGraphHMIdentity (CyclicGraph (root, g)) =
  30. trace (show g) (a == b) where
  31. g' = fmap HS.toList g
  32. a = HS.fromList (HM.keys g)
  33. b = HS.fromList . HM.keys . runIdentity $
  34. fetchGraphM (g' HM.!) (const . return) (join HM.singleton 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement