-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstockportfolio.hs
31 lines (22 loc) · 1018 Bytes
/
stockportfolio.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import Test.Hspec
import Data.Time.Calendar (Day, fromGregorian)
import Data.Function ((&))
type Company = String
type NumberOfShares = Int
type Shares = [Share]
data Share = Share Company NumberOfShares Day
newShares = []
buyShares :: Int -> String -> Day -> Shares -> Shares
buyShares amount company day existingShares = (Share company amount day):existingShares
displayShares :: Shares -> String
displayShares shares = "company | shares | current price | current value | last operation"
-- Tests
main :: IO ()
main = hspec $ do
describe "Given a list of specific shares" $ do
it "should display a specific portfolio" $ do
let shares = newShares
& buyShares 1000 "Old School Waterfall Software LTD" (fromGregorian 1990 02 14)
let result = displayShares shares
result `shouldBe` "company | shares | current price | current value | last operation\n\
\Old School Waterfall Software LTD | 500 | $5.75 | $2785.75 | sold 500 on 11/12/2018"