2019-08-10 10:01:36 -04:00
|
|
|
{-# LANGUAGE OverloadedStrings, QuasiQuotes #-}
|
|
|
|
|
2019-08-09 11:06:13 -04:00
|
|
|
module TypesSpec (spec) where
|
|
|
|
|
2019-08-10 10:01:36 -04:00
|
|
|
import Data.Aeson (decode, encode)
|
|
|
|
import Data.ByteString.Lazy (ByteString)
|
2019-08-09 11:06:13 -04:00
|
|
|
import Lens.Micro ((&), (.~))
|
|
|
|
import Test.Hspec (Spec, context, describe, it, shouldBe)
|
2019-08-10 10:01:36 -04:00
|
|
|
import Text.RawString.QQ (r)
|
2019-08-09 11:06:13 -04:00
|
|
|
import Mtlstats.Types
|
|
|
|
|
|
|
|
spec :: Spec
|
2019-08-10 10:01:36 -04:00
|
|
|
spec = describe "Mtlstats.Types" $ do
|
|
|
|
pPointsSpec
|
|
|
|
playerSpec
|
2019-08-09 11:06:13 -04:00
|
|
|
|
2019-08-10 10:01:36 -04:00
|
|
|
pPointsSpec :: Spec
|
2019-08-09 11:06:13 -04:00
|
|
|
pPointsSpec = describe "pPoints" $ mapM_
|
|
|
|
(\(goals, assists, points) -> let
|
|
|
|
desc = "goals: " ++ show goals ++
|
|
|
|
", assists: " ++ show assists
|
|
|
|
stats = newPlayerStats &
|
|
|
|
psGoals .~ goals &
|
|
|
|
psAssists .~ assists
|
|
|
|
in context desc $
|
|
|
|
it ("should be " ++ show points) $
|
|
|
|
pPoints stats `shouldBe` points)
|
|
|
|
-- goals, assists, points
|
|
|
|
[ ( 0, 0, 0 )
|
|
|
|
, ( 1, 0, 1 )
|
|
|
|
, ( 0, 1, 1 )
|
|
|
|
, ( 2, 3, 5 )
|
|
|
|
]
|
2019-08-10 10:01:36 -04:00
|
|
|
|
|
|
|
playerSpec :: Spec
|
|
|
|
playerSpec = describe "Player" $ do
|
|
|
|
|
|
|
|
describe "decode" $
|
|
|
|
it "should decode" $
|
|
|
|
decode playerJSON `shouldBe` Just player
|
|
|
|
|
|
|
|
describe "encode" $
|
|
|
|
it "should encode" $
|
|
|
|
decode (encode player) `shouldBe` Just player
|
|
|
|
|
|
|
|
player :: Player
|
|
|
|
player = newPlayer 1 "Joe" "centre"
|
|
|
|
& pYtd . psGoals .~ 2
|
|
|
|
& pYtd . psAssists .~ 3
|
|
|
|
& pYtd . psPMin .~ 4
|
|
|
|
& pLifetime . psGoals .~ 5
|
|
|
|
& pLifetime . psAssists .~ 6
|
|
|
|
& pLifetime . psPMin .~ 7
|
|
|
|
|
|
|
|
playerJSON :: ByteString
|
|
|
|
playerJSON = [r|
|
|
|
|
{ "number": 1
|
|
|
|
, "name": "Joe"
|
|
|
|
, "position": "centre"
|
|
|
|
, "ytd":
|
|
|
|
{ "goals": 2
|
|
|
|
, "assists": 3
|
|
|
|
, "penalty_mins": 4
|
|
|
|
}
|
|
|
|
, "lifetime":
|
|
|
|
{ "goals": 5
|
|
|
|
, "assists": 6
|
|
|
|
, "penalty_mins": 7
|
|
|
|
}
|
|
|
|
}|]
|