From 0e966c93029ba6728592e0ce53f8f8463f16fa5d Mon Sep 17 00:00:00 2001 From: Joshua Clayton Date: Sun, 15 May 2016 05:53:29 -0400 Subject: [PATCH] Test Util.groupBy --- test/Unused/UtilSpec.hs | 29 +++++++++++++++++++++++++++++ unused.cabal | 1 + 2 files changed, 30 insertions(+) create mode 100644 test/Unused/UtilSpec.hs diff --git a/test/Unused/UtilSpec.hs b/test/Unused/UtilSpec.hs new file mode 100644 index 0000000..f4f3fe0 --- /dev/null +++ b/test/Unused/UtilSpec.hs @@ -0,0 +1,29 @@ +module Unused.UtilSpec + ( main + , spec + ) where + +import Test.Hspec +import Unused.Util + +data Person = Person + { pName :: String + , pAge :: Int + } deriving (Eq, Show) + +main :: IO () +main = hspec spec + +spec :: Spec +spec = parallel $ + describe "groupBy" $ do + it "groups by the result of a function" $ do + let numbers = [1..10] :: [Int] + + groupBy ((0 ==) . flip mod 2) numbers `shouldBe` [(False, [1, 3, 5, 7, 9]), (True, [2, 4, 6, 8, 10])] + + it "handles records" $ do + let people = [Person "Jane" 10, Person "Jane" 20, Person "John" 20] + + groupBy pName people `shouldBe` [("Jane", [Person "Jane" 10, Person "Jane" 20]), ("John", [Person "John" 20])] + groupBy pAge people `shouldBe` [(10, [Person "Jane" 10]), (20, [Person "Jane" 20, Person "John" 20])] diff --git a/unused.cabal b/unused.cabal index 64c6b85..6f6574f 100644 --- a/unused.cabal +++ b/unused.cabal @@ -73,6 +73,7 @@ test-suite unused-test , Unused.LikelihoodCalculatorSpec , Unused.Grouping.InternalSpec , Unused.TermSearch.InternalSpec + , Unused.UtilSpec ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Werror default-language: Haskell2010