Created
May 24, 2021 09:46
-
-
Save bennypowers/56e9c586c0231db370dc3e4e546db550 to your computer and use it in GitHub Desktop.
Unit testing with QuickCheck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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