Skip to content

Instantly share code, notes, and snippets.

@joshcough
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshcough/327df601b748783bd3e3 to your computer and use it in GitHub Desktop.
Save joshcough/327df601b748783bd3e3 to your computer and use it in GitHub Desktop.
type ModuleName = Int
type ModuleGraph = HM.HashMap Int (HS.HashSet Int)
singletonGraph :: Int -> [Int] -> ModuleGraph
singletonGraph i ds = HM.singleton i (HS.fromList ds)
arbModuleName :: Gen ModuleName
arbModuleName = oneof (map return [0..100])
arbModuleGraph :: Gen ModuleGraph
arbModuleGraph = sized f where
f 0 = return HM.empty
f n = arbModuleName >>= rec
rec :: Int -> Gen ModuleGraph
rec d = smaller $ do
ddeps <- listOf arbModuleName
gs <- traverse rec ddeps
return $ foldl (HM.unionWith HS.union) (singletonGraph d ddeps) gs
newtype CyclicGraph = CyclicGraph (Int, ModuleGraph) deriving Show
instance Arbitrary CyclicGraph where
arbitrary = do
rootInt <- arbModuleName
graph <- rec rootInt
return $ CyclicGraph (rootInt, graph)
prop_fetchGraphHMIdentity :: CyclicGraph -> Bool
prop_fetchGraphHMIdentity (CyclicGraph (root, g)) =
trace (show g) (a == b) where
g' = fmap HS.toList g
a = HS.fromList (HM.keys g)
b = HS.fromList . HM.keys . runIdentity $
fetchGraphM (g' HM.!) (const . return) (join HM.singleton 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment