implemented playerName
This commit is contained in:
parent
3ee97406f1
commit
8dcef502be
|
@ -19,7 +19,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Mtlstats.Helpers.Player (playerDetails) where
|
module Mtlstats.Helpers.Player (playerDetails, playerName) where
|
||||||
|
|
||||||
import Lens.Micro ((^.))
|
import Lens.Micro ((^.))
|
||||||
|
|
||||||
|
@ -43,3 +43,14 @@ playerDetails p = unlines $ top ++ [""] ++ table
|
||||||
, ( "Assists", psAssists )
|
, ( "Assists", psAssists )
|
||||||
, ( "Penalty mins", psPMin )
|
, ( "Penalty mins", psPMin )
|
||||||
]
|
]
|
||||||
|
|
||||||
|
-- | Presents a modified version of the player's name indicating
|
||||||
|
-- whether or not they're a rookie
|
||||||
|
playerName :: Player -> String
|
||||||
|
playerName p = let
|
||||||
|
|
||||||
|
suffix = if p^.pRookie
|
||||||
|
then "*"
|
||||||
|
else ""
|
||||||
|
|
||||||
|
in p^.pName ++ suffix
|
||||||
|
|
|
@ -22,14 +22,15 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
module Helpers.PlayerSpec (spec) where
|
module Helpers.PlayerSpec (spec) where
|
||||||
|
|
||||||
import Lens.Micro ((&), (.~))
|
import Lens.Micro ((&), (.~))
|
||||||
import Test.Hspec (Spec, describe, it, shouldBe)
|
import Test.Hspec (Spec, context, describe, it, shouldBe)
|
||||||
|
|
||||||
import Mtlstats.Helpers.Player
|
import Mtlstats.Helpers.Player
|
||||||
import Mtlstats.Types
|
import Mtlstats.Types
|
||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = describe "Player"
|
spec = describe "Player" $ do
|
||||||
playerDetailsSpec
|
playerDetailsSpec
|
||||||
|
playerNameSpec
|
||||||
|
|
||||||
playerDetailsSpec :: Spec
|
playerDetailsSpec :: Spec
|
||||||
playerDetailsSpec = describe "playerDetails" $
|
playerDetailsSpec = describe "playerDetails" $
|
||||||
|
@ -59,3 +60,19 @@ playerDetailsSpec = describe "playerDetails" $
|
||||||
]
|
]
|
||||||
|
|
||||||
in playerDetails p `shouldBe` expected
|
in playerDetails p `shouldBe` expected
|
||||||
|
|
||||||
|
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" )
|
||||||
|
]
|
||||||
|
|
||||||
|
where
|
||||||
|
rookie = player True
|
||||||
|
nonRookie = player False
|
||||||
|
player r = newPlayer 1 "foo" "centre" & pRookie .~ r
|
||||||
|
|
Loading…
Reference in New Issue
Block a user