Bag.hs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. {-# LANGUAGE TemplateHaskell #-}
  2. module Internal.Utils.Bag ( tests ) where
  3. import Agda.Utils.Bag
  4. import Data.Functor.Identity
  5. import qualified Data.List as List
  6. import qualified Data.Set as Set
  7. import Prelude hiding ( map )
  8. import Internal.Helpers
  9. ------------------------------------------------------------------------
  10. -- * Properties
  11. ------------------------------------------------------------------------
  12. instance (Ord a, Arbitrary a) => Arbitrary (Bag a) where
  13. arbitrary = fromList <$> arbitrary
  14. prop_count_empty :: Ord a => a -> Bool
  15. prop_count_empty a = count a empty == 0
  16. prop_count_singleton :: Ord a => a -> Bool
  17. prop_count_singleton a = count a (singleton a) == 1
  18. prop_count_insert :: Ord a => a -> Bag a -> Bool
  19. prop_count_insert a b = count a (insert a b) == 1 + count a b
  20. prop_size_union :: Ord a => Bag a -> Bag a -> Bool
  21. prop_size_union b c = size (b `union` c) == size b + size c
  22. prop_size_fromList :: Ord a => [a] -> Bool
  23. prop_size_fromList l = size (fromList l) == length l
  24. prop_fromList_toList :: Ord a => Bag a -> Bool
  25. prop_fromList_toList b = fromList (toList b) == b
  26. prop_toList_fromList :: Ord a => [a] -> Bool
  27. prop_toList_fromList l = toList (fromList l) == List.sort l
  28. prop_keys_fromList :: Ord a => [a] -> Bool
  29. prop_keys_fromList l = keys (fromList l) == Set.toList (Set.fromList l)
  30. prop_nonempty_groups :: Bag a -> Bool
  31. prop_nonempty_groups b = all (not . List.null) $ groups b
  32. prop_map_id :: Ord a => Bag a -> Bool
  33. prop_map_id b = map id b == b
  34. prop_map_compose :: (Ord b, Ord c) =>
  35. (b -> c) -> (a -> b) -> Bag a -> Bool
  36. prop_map_compose f g b = map f (map g b) == map (f . g) b
  37. prop_traverse_id :: Ord a => Bag a -> Bool
  38. prop_traverse_id b = traverse' Identity b == Identity b
  39. ------------------------------------------------------------------------
  40. -- * All tests
  41. ------------------------------------------------------------------------
  42. -- Template Haskell hack to make the following $allProperties work
  43. -- under ghc-7.8.
  44. return [] -- KEEP!
  45. -- | All tests as collected by 'allProperties'.
  46. --
  47. -- Using 'allProperties' is convenient and superior to the manual
  48. -- enumeration of tests, since the name of the property is added
  49. -- automatically.
  50. tests :: TestTree
  51. tests = testProperties "Internal.Utils.Bag" $allProperties