2019-08-20 11:31:03 -04:00
|
|
|
{-
|
|
|
|
|
|
|
|
mtlstats
|
|
|
|
Copyright (C) 2019 Rhéal Lamothe
|
|
|
|
<rheal.lamothe@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or (at
|
|
|
|
your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
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
|
|
|
|
|
2019-08-21 00:21:22 -04:00
|
|
|
import qualified Types.MenuSpec as Menu
|
|
|
|
|
2019-08-09 11:06:13 -04:00
|
|
|
spec :: Spec
|
2019-08-10 10:01:36 -04:00
|
|
|
spec = describe "Mtlstats.Types" $ do
|
|
|
|
pPointsSpec
|
|
|
|
playerSpec
|
2019-08-11 10:24:39 -04:00
|
|
|
goalieSpec
|
2019-08-16 11:49:04 -04:00
|
|
|
databaseSpec
|
2019-08-21 00:21:22 -04:00
|
|
|
Menu.spec
|
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
|
|
|
|
|
2019-08-11 10:24:39 -04:00
|
|
|
goalieSpec :: Spec
|
|
|
|
goalieSpec = describe "Goalie" $ do
|
|
|
|
|
|
|
|
describe "decode" $
|
|
|
|
it "should decode" $
|
|
|
|
decode goalieJSON `shouldBe` Just goalie
|
|
|
|
|
|
|
|
describe "encode" $
|
|
|
|
it "should encode" $
|
|
|
|
decode (encode goalie) `shouldBe` Just goalie
|
|
|
|
|
2019-08-16 11:49:04 -04:00
|
|
|
databaseSpec :: Spec
|
|
|
|
databaseSpec = describe "Database" $ do
|
|
|
|
|
|
|
|
describe "decode" $
|
|
|
|
it "should decode" $
|
|
|
|
decode dbJSON `shouldBe` Just db
|
|
|
|
|
|
|
|
describe "encode" $
|
|
|
|
it "should encode" $
|
|
|
|
decode (encode db) `shouldBe` Just db
|
|
|
|
|
2019-08-10 10:01:36 -04:00
|
|
|
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
|
|
|
|
|
2019-08-11 10:24:39 -04:00
|
|
|
goalie :: Goalie
|
|
|
|
goalie = newGoalie 1 "Joe"
|
|
|
|
& gYtd . gsGames .~ 2
|
|
|
|
& gYtd . gsMinsPlayed .~ 3
|
|
|
|
& gYtd . gsGoalsAllowed .~ 4
|
|
|
|
& gYtd . gsGoalsAgainst .~ 5
|
|
|
|
& gYtd . gsWins .~ 6
|
|
|
|
& gYtd . gsLosses .~ 7
|
|
|
|
& gYtd . gsTies .~ 8
|
|
|
|
& gLifetime . gsGames .~ 9
|
|
|
|
& gLifetime . gsMinsPlayed .~ 10
|
|
|
|
& gLifetime . gsGoalsAllowed .~ 11
|
|
|
|
& gLifetime . gsGoalsAgainst .~ 12
|
|
|
|
& gLifetime . gsWins .~ 13
|
|
|
|
& gLifetime . gsLosses .~ 14
|
|
|
|
& gLifetime . gsTies .~ 15
|
|
|
|
|
2019-08-16 11:49:04 -04:00
|
|
|
db :: Database
|
|
|
|
db = newDatabase
|
|
|
|
& dbPlayers .~ [player]
|
|
|
|
& dbGoalies .~ [goalie]
|
2019-08-19 09:31:24 -04:00
|
|
|
& dbGames .~ 1
|
2019-08-16 11:49:04 -04:00
|
|
|
|
2019-08-10 10:01:36 -04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}|]
|
2019-08-11 10:24:39 -04:00
|
|
|
|
|
|
|
goalieJSON :: ByteString
|
|
|
|
goalieJSON = [r|
|
|
|
|
{ "number": 1
|
|
|
|
, "name": "Joe"
|
|
|
|
, "ytd":
|
|
|
|
{ "games": 2
|
|
|
|
, "mins_played": 3
|
|
|
|
, "goals_allowed": 4
|
|
|
|
, "goals_against": 5
|
|
|
|
, "wins": 6
|
|
|
|
, "losses": 7
|
|
|
|
, "ties": 8
|
|
|
|
}
|
|
|
|
, "lifetime":
|
|
|
|
{ "games": 9
|
|
|
|
, "mins_played": 10
|
|
|
|
, "goals_allowed": 11
|
|
|
|
, "goals_against": 12
|
|
|
|
, "wins": 13
|
|
|
|
, "losses": 14
|
|
|
|
, "ties": 15
|
|
|
|
}
|
|
|
|
}|]
|
2019-08-16 11:49:04 -04:00
|
|
|
|
|
|
|
dbJSON :: ByteString
|
|
|
|
dbJSON = [r|
|
|
|
|
{ "players":
|
|
|
|
[ |] <> playerJSON <> [r| ]
|
|
|
|
, "goalies":
|
|
|
|
[ |] <> goalieJSON <> [r| ]
|
2019-08-19 09:31:24 -04:00
|
|
|
, "games": 1
|
2019-08-16 11:49:04 -04:00
|
|
|
}|]
|