about summary refs log tree commit diff
path: root/scratch/brilliant/Spec.hs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-08-05T20·37+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-08-05T20·37+0100
commit40753e9f3b2df9f620c588d1d385b5ddfb9bd1bc (patch)
tree4d9783a632519a8a8b0415e0aaac2a40782a9adb /scratch/brilliant/Spec.hs
parentc4299558a75df8ea173c77dbc8800930dfa6519d (diff)
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.
Diffstat (limited to 'scratch/brilliant/Spec.hs')
-rw-r--r--scratch/brilliant/Spec.hs19
1 files changed, 19 insertions, 0 deletions
diff --git a/scratch/brilliant/Spec.hs b/scratch/brilliant/Spec.hs
new file mode 100644
index 000000000000..f348dd0669a1
--- /dev/null
+++ b/scratch/brilliant/Spec.hs
@@ -0,0 +1,19 @@
+--------------------------------------------------------------------------------
+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