From d8e1b3381024d82e1056f67849cf72be9b60ac75 Mon Sep 17 00:00:00 2001 From: Victor Martinez <49537445+JasterV@users.noreply.github.com> Date: Thu, 13 Mar 2025 16:32:41 +0100 Subject: [PATCH] setup tests! --- aoc2024.cabal | 5 ++++- package.yaml | 3 +++ test/Spec.hs | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/aoc2024.cabal b/aoc2024.cabal index 323cb63..3ebd261 100644 --- a/aoc2024.cabal +++ b/aoc2024.cabal @@ -51,7 +51,10 @@ test-suite aoc2024-test test ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N build-depends: - aoc2024 + HUnit >=1.6.2.0 && <1.7 + , QuickCheck >=2.14.3 && <2.15 + , aoc2024 , base >=4.7 && <5 + , hspec >=2.0.0 , regex-tdfa >=1.3.2 && <1.4 default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 86ee13e..45c9262 100644 --- a/package.yaml +++ b/package.yaml @@ -47,3 +47,6 @@ tests: - -with-rtsopts=-N dependencies: - aoc2024 + - QuickCheck ^>= 2.14.3 + - HUnit ^>= 1.6.2.0 + - hspec >=2.0.0 diff --git a/test/Spec.hs b/test/Spec.hs index cd4753f..5d33250 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1,2 +1,16 @@ +import Control.Exception (evaluate) +import Test.Hspec +import Test.QuickCheck + main :: IO () -main = putStrLn "Test suite not yet implemented" +main = hspec $ do + describe "Prelude.head" $ do + it "returns the first element of a list" $ do + head [23 ..] `shouldBe` (23 :: Int) + + it "returns the first element of an *arbitrary* list" $ + property $ + \x xs -> head (x : xs) == (x :: Int) + + it "throws an exception if used with an empty list" $ do + evaluate (head []) `shouldThrow` anyException