tvl-depot/scratch/brilliant/Spec.hs
William Carroll 40753e9f3b Add some the scaffolding for testing
As I attempt to habituate TDD, I should have some examples of tests to minimize
all friction preventing me from testing.
2020-08-05 21:37:08 +01:00

19 lines
727 B
Haskell

--------------------------------------------------------------------------------
module Spec where
--------------------------------------------------------------------------------
import Test.Hspec
import Test.QuickCheck
import Control.Exception (evaluate)
--------------------------------------------------------------------------------
main :: IO ()
main = hspec $ do
describe "Prelude.head" $ do
it "returns the first element of a list" $ do
head [23 ..] `shouldBe` (23 :: Integer)
it "returns the first element of an arbitrary list" $
property $ \x xs -> head (x:xs) == (x :: Integer)
it "throws an exception if used with an empty list" $ do
evaluate (head []) `shouldThrow` anyException