{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE ScopedTypeVariables #-}
module FoldTree (tests) where
import Test.HUnit
import Data.Generics
data Tree a w = Leaf a
| Fork (Tree a w) (Tree a w)
| WithWeight (Tree a w) w
deriving (Typeable, Data)
mytree :: Tree Int Int
mytree = Fork (WithWeight (Leaf 42) 1)
(WithWeight (Fork (Leaf 88) (Leaf 37)) 2)
mytree' :: Tree Int Int
mytree' = Fork (Leaf 42)
(WithWeight (Fork (Leaf 88) (Leaf 37)) 2)
tests = show ( listify (\(_::Int) -> True) mytree
, everything (++) ([] `mkQ` fromLeaf) mytree
, everythingBut (++)
(([],False) `mkQ` (\x -> (fromLeaf x, stop x))) mytree'
) ~=? output
where
fromLeaf :: Tree Int Int -> [Int]
fromLeaf (Leaf x) = [x]
fromLeaf _ = []
stop :: (Data a, Data b) => Tree a b -> Bool
stop (WithWeight _ _) = True
stop _ = False
output = "([42,1,88,37,2],[42,88,37],[42])"