Sha256: 72a0ebb69df440a2ccfb75d8b0f960c044f15d5822298858ef702a6ed6d44079
Contents?: true
Size: 1.81 KB
Versions: 165
Compression:
Stored size: 1.81 KB
Contents
import Control.Concurrent (forkIO, newEmptyMVar, putMVar, takeMVar) import Control.Monad (replicateM) import Data.Foldable (for_) import Test.Hspec (Spec, describe, it, shouldReturn) import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith) import BankAccount ( closeAccount , incrementBalance , getBalance , openAccount ) main :: IO () main = hspecWith defaultConfig {configFastFail = True} specs specs :: Spec specs = describe "bank-account" $ do -- As of 2016-08-01, there was no reference file -- for the test cases in `exercism/x-common`. it "initial balance is 0" $ do account <- openAccount getBalance account `shouldReturn` Just 0 closeAccount account it "incrementing and checking balance" $ do account <- openAccount getBalance account `shouldReturn` Just 0 incrementBalance account 10 `shouldReturn` Just 10 incrementBalance account 20 `shouldReturn` Just 30 getBalance account `shouldReturn` Just 30 closeAccount account it "incrementing balance from other processes then checking it from test process" $ do account <- openAccount vs <- replicateM 20 $ do v <- newEmptyMVar _ <- forkIO $ incrementBalance account 1 >> putMVar v () return v for_ vs takeMVar getBalance account `shouldReturn` Just 20 closeAccount account it "closed banks hold no balance" $ do account <- openAccount getBalance account `shouldReturn` Just 0 incrementBalance account 15 `shouldReturn` Just 15 closeAccount account getBalance account `shouldReturn` Nothing incrementBalance account 10 `shouldReturn` Nothing
Version data entries
165 entries across 165 versions & 1 rubygems