2019-11-18 21:36:36 -05:00
|
|
|
{-
|
|
|
|
|
|
|
|
mtlstats
|
2020-01-11 00:29:45 -05:00
|
|
|
Copyright (C) 1984, 1985, 2019, 2020 Rhéal Lamothe
|
2019-11-18 21:36:36 -05:00
|
|
|
<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/>.
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Helpers.PlayerSpec (spec) where
|
|
|
|
|
|
|
|
import Lens.Micro ((&), (.~))
|
2020-01-03 22:01:09 -05:00
|
|
|
import Test.Hspec (Spec, context, describe, it, shouldBe)
|
2019-11-18 21:36:36 -05:00
|
|
|
|
|
|
|
import Mtlstats.Helpers.Player
|
|
|
|
import Mtlstats.Types
|
|
|
|
|
|
|
|
spec :: Spec
|
2020-01-03 22:01:09 -05:00
|
|
|
spec = describe "Player" $ do
|
2019-11-18 21:36:36 -05:00
|
|
|
playerDetailsSpec
|
2020-01-03 22:01:09 -05:00
|
|
|
playerNameSpec
|
2019-11-18 21:36:36 -05:00
|
|
|
|
|
|
|
playerDetailsSpec :: Spec
|
|
|
|
playerDetailsSpec = describe "playerDetails" $
|
|
|
|
it "should give a detailed description" $ let
|
|
|
|
|
|
|
|
p = newPlayer 1 "Joe" "centre"
|
2020-01-04 12:10:19 -05:00
|
|
|
& pRookie .~ True
|
2019-11-18 21:36:36 -05:00
|
|
|
& pYtd .~ PlayerStats
|
|
|
|
{ _psGoals = 2
|
|
|
|
, _psAssists = 3
|
|
|
|
, _psPMin = 4
|
|
|
|
}
|
|
|
|
& pLifetime .~ PlayerStats
|
|
|
|
{ _psGoals = 5
|
|
|
|
, _psAssists = 6
|
|
|
|
, _psPMin = 7
|
|
|
|
}
|
|
|
|
|
|
|
|
expected = unlines
|
|
|
|
[ " Number: 1"
|
2020-01-04 12:10:19 -05:00
|
|
|
, " Name: Joe*"
|
2019-11-18 21:36:36 -05:00
|
|
|
, "Position: centre"
|
|
|
|
, ""
|
|
|
|
, " YTD Lifetime"
|
|
|
|
, " Goals 2 5"
|
|
|
|
, " Assists 3 6"
|
|
|
|
, "Penalty mins 4 7"
|
|
|
|
]
|
|
|
|
|
|
|
|
in playerDetails p `shouldBe` expected
|
2020-01-03 22:01:09 -05:00
|
|
|
|
|
|
|
playerNameSpec :: Spec
|
|
|
|
playerNameSpec = describe "playerName" $ mapM_
|
|
|
|
(\(label, p, expected) -> context label $
|
|
|
|
it ("should be " ++ expected) $
|
|
|
|
playerName p `shouldBe` expected)
|
|
|
|
|
|
|
|
-- label, player, expected
|
|
|
|
[ ( "rookie", rookie, "foo*" )
|
|
|
|
, ( "non-rookie", nonRookie, "foo" )
|
2020-01-11 01:27:01 -05:00
|
|
|
, ( "retired", retired, "*foo" )
|
2020-01-03 22:01:09 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
where
|
2020-01-11 01:27:01 -05:00
|
|
|
rookie = player True True
|
|
|
|
nonRookie = player False True
|
|
|
|
retired = player False False
|
|
|
|
player r a = newPlayer 1 "foo" "centre"
|
|
|
|
& pRookie .~ r
|
|
|
|
& pActive .~ a
|