Skip to content

Instantly share code, notes, and snippets.

@bennypowers
Created May 24, 2021 09:46
Show Gist options
  • Save bennypowers/56e9c586c0231db370dc3e4e546db550 to your computer and use it in GitHub Desktop.
Save bennypowers/56e9c586c0231db370dc3e4e546db550 to your computer and use it in GitHub Desktop.
Unit testing with QuickCheck
cabal-version: 2.4
name: haskell-course
version: 0.1.0.0
maintainer: [email protected]
author: Benny Powers
extra-source-files: CHANGELOG.md
test-suite min-max-test
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs: tests
default-language: Haskell2010
build-depends:
base,
sort,
hspec,
QuickCheck
module Main where
import Data.Sort
import Test.Hspec
import Test.QuickCheck
prop_abs :: Int -> Bool
prop_abs n = abs n == n || 0 - abs n == n
prop_min :: [Int] -> Bool
prop_min l
| null l = True
| otherwise = minimum l == head (sort l)
prop_max :: [Int] -> Bool
prop_max l
| null l = True
| otherwise = maximum l == last (sort l)
main :: IO ()
main = hspec $ do
describe "Bounds" $
do it "gets the minimum" $ property prop_min
it "gets the maximum" $ property prop_max
describe "Absolute" $
it "removes the sign" $ property prop_abs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment