mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 04:45:28 +03:00
Test Util.groupBy
This commit is contained in:
parent
97f083fc2c
commit
0e966c9302
29
test/Unused/UtilSpec.hs
Normal file
29
test/Unused/UtilSpec.hs
Normal file
@ -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])]
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user