implemented playerSearch
This commit is contained in:
parent
2ff8cff1c8
commit
ed9e437a1a
@ -120,7 +120,8 @@ module Mtlstats.Types (
|
|||||||
gmsPoints,
|
gmsPoints,
|
||||||
addGameStats,
|
addGameStats,
|
||||||
-- ** Player Helpers
|
-- ** Player Helpers
|
||||||
pPoints
|
pPoints,
|
||||||
|
playerSearch
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Trans.State (StateT)
|
import Control.Monad.Trans.State (StateT)
|
||||||
@ -136,6 +137,7 @@ import Data.Aeson
|
|||||||
, (.:)
|
, (.:)
|
||||||
, (.=)
|
, (.=)
|
||||||
)
|
)
|
||||||
|
import Data.List (isInfixOf)
|
||||||
import Lens.Micro (Lens', lens, (&), (^.), (.~))
|
import Lens.Micro (Lens', lens, (&), (^.), (.~))
|
||||||
import Lens.Micro.TH (makeLenses)
|
import Lens.Micro.TH (makeLenses)
|
||||||
import qualified UI.NCurses as C
|
import qualified UI.NCurses as C
|
||||||
@ -636,3 +638,16 @@ addGameStats s1 s2 = GameStats
|
|||||||
-- | Calculates a player's points
|
-- | Calculates a player's points
|
||||||
pPoints :: PlayerStats -> Int
|
pPoints :: PlayerStats -> Int
|
||||||
pPoints s = s^.psGoals + s^.psAssists
|
pPoints s = s^.psGoals + s^.psAssists
|
||||||
|
|
||||||
|
-- | Searches through a list of players
|
||||||
|
playerSearch
|
||||||
|
:: String
|
||||||
|
-- ^ The search string
|
||||||
|
-> [Player]
|
||||||
|
-- ^ The list of players to search
|
||||||
|
-> [(Int, Player)]
|
||||||
|
-- ^ The matching players with their index numbers
|
||||||
|
playerSearch sStr =
|
||||||
|
filter (match sStr) .
|
||||||
|
zip [0..]
|
||||||
|
where match sStr (_, p) = sStr `isInfixOf` (p^.pName)
|
||||||
|
@ -55,6 +55,7 @@ spec = describe "Mtlstats.Types" $ do
|
|||||||
gmsPointsSpec
|
gmsPointsSpec
|
||||||
addGameStatsSpec
|
addGameStatsSpec
|
||||||
pPointsSpec
|
pPointsSpec
|
||||||
|
playerSearchSpec
|
||||||
Menu.spec
|
Menu.spec
|
||||||
|
|
||||||
playerSpec :: Spec
|
playerSpec :: Spec
|
||||||
@ -512,3 +513,20 @@ pPointsSpec = describe "pPoints" $ mapM_
|
|||||||
, ( 0, 1, 1 )
|
, ( 0, 1, 1 )
|
||||||
, ( 2, 3, 5 )
|
, ( 2, 3, 5 )
|
||||||
]
|
]
|
||||||
|
|
||||||
|
playerSearchSpec :: Spec
|
||||||
|
playerSearchSpec = describe "playerSearch" $ mapM_
|
||||||
|
(\(sStr, expected) -> context sStr $
|
||||||
|
it ("should return " ++ show expected) $ let
|
||||||
|
ps = [joe, bob, steve]
|
||||||
|
in playerSearch sStr ps `shouldBe` expected)
|
||||||
|
-- search, result
|
||||||
|
[ ( "Joe", [(0, joe)] )
|
||||||
|
, ( "o", [(0, joe), (1, bob)] )
|
||||||
|
, ( "e", [(0, joe), (2, steve)] )
|
||||||
|
, ( "x", [] )
|
||||||
|
]
|
||||||
|
where
|
||||||
|
joe = newPlayer 2 "Joe" "center"
|
||||||
|
bob = newPlayer 3 "Bob" "defense"
|
||||||
|
steve = newPlayer 5 "Steve" "forward"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user