mtlstats/test/Helpers/GoalieSpec.hs

92 lines
2.5 KiB
Haskell
Raw Normal View History

2019-11-20 22:00:58 -05:00
{-
mtlstats
2020-01-11 00:29:45 -05:00
Copyright (C) 1984, 1985, 2019, 2020 Rhéal Lamothe
2019-11-20 22:00:58 -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.GoalieSpec (spec) where
import Lens.Micro ((&), (.~), (%~))
2020-01-04 11:02:58 -05:00
import Test.Hspec (Spec, context, describe, it, shouldBe)
2019-11-20 22:00:58 -05:00
import Mtlstats.Helpers.Goalie
import Mtlstats.Types
spec :: Spec
2020-01-04 11:02:58 -05:00
spec = describe "Goalie" $ do
2019-11-20 22:00:58 -05:00
goalieDetailsSpec
2020-01-04 11:02:58 -05:00
goalieNameSpec
2019-11-20 22:00:58 -05:00
goalieDetailsSpec :: Spec
goalieDetailsSpec = describe "goalieDetails" $ let
input = newGoalie 1 "Joe"
2020-01-08 23:54:16 -05:00
& gRookie .~ True
2019-11-20 22:00:58 -05:00
& gYtd
%~ ( gsGames .~ 2 )
. ( gsMinsPlayed .~ 3 )
. ( gsGoalsAllowed .~ 4 )
2020-01-02 00:42:04 -05:00
. ( gsShutouts .~ 5 )
. ( gsWins .~ 6 )
. ( gsLosses .~ 7 )
. ( gsTies .~ 8 )
2019-11-20 22:00:58 -05:00
& gLifetime
2020-01-02 00:42:04 -05:00
%~ ( gsGames .~ 9 )
. ( gsMinsPlayed .~ 10 )
. ( gsGoalsAllowed .~ 11 )
. ( gsShutouts .~ 12 )
. ( gsWins .~ 13 )
. ( gsLosses .~ 14 )
. ( gsTies .~ 15 )
2019-11-20 22:00:58 -05:00
expected = unlines
2020-04-15 22:07:56 -04:00
[ "Number: 1 "
2020-01-08 23:54:16 -05:00
, " Name: Joe*"
2019-11-20 22:00:58 -05:00
, ""
, " YTD Lifetime"
2020-01-02 00:42:04 -05:00
, " Games played 2 9"
, " Mins played 3 10"
, "Goals allowed 4 11"
, " Shutouts 5 12"
, " Wins 6 13"
, " Losses 7 14"
, " Ties 8 15"
2019-11-20 22:00:58 -05:00
]
in it "should format the output correctly" $
goalieDetails input `shouldBe` expected
2020-01-04 11:02:58 -05:00
goalieNameSpec :: Spec
goalieNameSpec = describe "goalieName" $ mapM_
(\(label, g, expected) -> context label $
it ("should be " ++ expected) $
goalieName g `shouldBe` expected)
2020-01-11 01:46:40 -05:00
-- label, goalie, expected
[ ( "rookie", rookie, "foo*" )
, ( "non-rookie", active, "foo" )
, ( "retired", retired, "*foo" )
2020-01-04 11:02:58 -05:00
]
where
2020-01-11 01:46:40 -05:00
rookie = goalie True True
active = goalie False True
retired = goalie False False
goalie r a = newGoalie 1 "foo"
& gRookie .~ r
& gActive .~ a