Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e0b72fc40 | ||
|
|
2c5b4a0791 | ||
|
|
bce31d059b | ||
|
|
99baebe144 | ||
|
|
eb3714c40a | ||
|
|
1bd3ae9564 | ||
|
|
2adfe9b016 | ||
|
|
85a8e3baf1 | ||
|
|
393a2c6dc4 | ||
|
|
ed240c6a38 | ||
|
|
4f147cd5a4 | ||
|
|
9b6dfc4be9 |
@@ -1,5 +1,14 @@
|
||||
# Changelog for mtlstats
|
||||
|
||||
## 0.16.0
|
||||
- enter months by number
|
||||
|
||||
## 0.15.2
|
||||
- allow ties
|
||||
|
||||
## 0.15.1
|
||||
- only search for active players/goalies on game data input
|
||||
|
||||
## 0.15.0
|
||||
- Ask for database to load on start-up
|
||||
- Add page break to report file
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: mtlstats
|
||||
version: 0.15.0
|
||||
version: 0.16.0
|
||||
github: "mtlstats/mtlstats"
|
||||
license: GPL-3
|
||||
author: "Jonathan Lamothe"
|
||||
|
||||
@@ -43,9 +43,7 @@ import Mtlstats.Util
|
||||
overtimeCheck :: ProgState -> ProgState
|
||||
overtimeCheck s
|
||||
| fromMaybe False $ gameTied $ s^.progMode.gameStateL =
|
||||
s & progMode.gameStateL
|
||||
%~ (homeScore .~ Nothing)
|
||||
. (awayScore .~ Nothing)
|
||||
s & progMode.gameStateL.overtimeFlag ?~ True
|
||||
| fromMaybe False $ gameWon $ s^.progMode.gameStateL =
|
||||
s & progMode.gameStateL.overtimeFlag ?~ False
|
||||
| otherwise = s
|
||||
|
||||
@@ -62,7 +62,7 @@ gameYearC :: Controller
|
||||
gameYearC = promptControllerWith header gameYearPrompt
|
||||
|
||||
gameMonthC :: Controller
|
||||
gameMonthC = menuControllerWith header gameMonthMenu
|
||||
gameMonthC = promptControllerWith monthHeader gameMonthPrompt
|
||||
|
||||
gameDayC :: Controller
|
||||
gameDayC = promptControllerWith header gameDayPrompt
|
||||
@@ -226,6 +226,31 @@ header :: ProgState -> C.Update ()
|
||||
header s = C.drawString $
|
||||
"*** GAME " ++ padNum 2 (s^.database.dbGames) ++ " ***\n"
|
||||
|
||||
monthHeader :: ProgState -> C.Update ()
|
||||
monthHeader s = do
|
||||
(_, cols) <- C.windowSize
|
||||
header s
|
||||
|
||||
let
|
||||
table = labelTable $ zip (map show ([1..] :: [Int]))
|
||||
[ "JANUARY"
|
||||
, "FEBRUARY"
|
||||
, "MARCH"
|
||||
, "APRIL"
|
||||
, "MAY"
|
||||
, "JUNE"
|
||||
, "JULY"
|
||||
, "AUGUST"
|
||||
, "SEPTEMBER"
|
||||
, "OCTOBER"
|
||||
, "NOVEMBER"
|
||||
, "DECEMBER"
|
||||
]
|
||||
|
||||
C.drawString $ unlines $
|
||||
map (centre $ fromIntegral $ pred cols) $
|
||||
["MONTH:", ""] ++ table ++ [""]
|
||||
|
||||
gameGoal :: ProgState -> (Int, Int)
|
||||
gameGoal s =
|
||||
( s^.database.dbGames
|
||||
|
||||
@@ -129,9 +129,14 @@ month _ = ""
|
||||
labelTable :: [(String, String)] -> [String]
|
||||
labelTable xs = let
|
||||
labelWidth = maximum $ map (length . fst) xs
|
||||
valWidth = maximum $ map (length . snd) xs
|
||||
|
||||
in map
|
||||
(\(label, val) -> right labelWidth label ++ ": " ++ val)
|
||||
xs
|
||||
( \(label, val)
|
||||
-> right labelWidth label
|
||||
++ ": "
|
||||
++ left valWidth val
|
||||
) xs
|
||||
|
||||
-- | Creates a variable column table of numbers with two axes
|
||||
numTable
|
||||
|
||||
@@ -29,7 +29,6 @@ module Mtlstats.Menu (
|
||||
-- * Menus
|
||||
mainMenu,
|
||||
newSeasonMenu,
|
||||
gameMonthMenu,
|
||||
gameTypeMenu,
|
||||
gameGoalieMenu,
|
||||
editMenu
|
||||
@@ -130,26 +129,6 @@ newSeasonMenu = Menu "SEASON TYPE" ()
|
||||
. startNewGame
|
||||
]
|
||||
|
||||
-- | Requests the month in which the game took place
|
||||
gameMonthMenu :: Menu ()
|
||||
gameMonthMenu = Menu "MONTH:" () $ map
|
||||
(\(ch, name, val) ->
|
||||
MenuItem ch name $
|
||||
modify $ progMode.gameStateL.gameMonth ?~ val)
|
||||
[ ( 'A', "JANUARY", 1 )
|
||||
, ( 'B', "FEBRUARY", 2 )
|
||||
, ( 'C', "MARCH", 3 )
|
||||
, ( 'D', "APRIL", 4 )
|
||||
, ( 'E', "MAY", 5 )
|
||||
, ( 'F', "JUNE", 6 )
|
||||
, ( 'G', "JULY", 7 )
|
||||
, ( 'H', "AUGUST", 8 )
|
||||
, ( 'I', "SEPTEMBER", 9 )
|
||||
, ( 'J', "OCTOBER", 10 )
|
||||
, ( 'K', "NOVEMBER", 11 )
|
||||
, ( 'L', "DECEMBER", 12 )
|
||||
]
|
||||
|
||||
-- | The game type menu (home/away)
|
||||
gameTypeMenu :: Menu ()
|
||||
gameTypeMenu = Menu "GAME TYPE:" ()
|
||||
|
||||
@@ -31,6 +31,7 @@ module Mtlstats.Prompt (
|
||||
ucStrPrompt,
|
||||
namePrompt,
|
||||
numPrompt,
|
||||
numPromptRange,
|
||||
numPromptWithFallback,
|
||||
dbNamePrompt,
|
||||
selectPrompt,
|
||||
@@ -43,7 +44,9 @@ module Mtlstats.Prompt (
|
||||
goalieNumPrompt,
|
||||
goalieNamePrompt,
|
||||
selectPlayerPrompt,
|
||||
selectActivePlayerPrompt,
|
||||
selectGoaliePrompt,
|
||||
selectActiveGoaliePrompt,
|
||||
selectPositionPrompt,
|
||||
playerToEditPrompt
|
||||
) where
|
||||
@@ -152,6 +155,20 @@ numPrompt
|
||||
-> Prompt
|
||||
numPrompt pStr = numPromptWithFallback pStr $ return ()
|
||||
|
||||
-- | Builds a numberic prompt with a range
|
||||
numPromptRange
|
||||
:: Int
|
||||
-- ^ The minimum value
|
||||
-> Int
|
||||
-- ^ The maximum value
|
||||
-> String
|
||||
-- ^ The prompt string
|
||||
-> (Int -> Action ())
|
||||
-- ^ The callback function for the result
|
||||
-> Prompt
|
||||
numPromptRange nMin nMax pStr callback = numPrompt pStr $ \n ->
|
||||
when (n >= nMin && n <= nMax) $ callback n
|
||||
|
||||
-- | Builds a numeric prompt with a fallback action
|
||||
numPromptWithFallback
|
||||
:: String
|
||||
@@ -263,18 +280,21 @@ goalieNamePrompt :: Prompt
|
||||
goalieNamePrompt = namePrompt "Goalie name: " $
|
||||
modify . (progMode.createGoalieStateL.cgsName .~)
|
||||
|
||||
-- | Selects a player (creating one if necessary)
|
||||
selectPlayerPrompt
|
||||
:: String
|
||||
-- | Selects a player using a specified search function (creating the
|
||||
-- player if necessary)
|
||||
selectPlayerPromptWith
|
||||
:: (String -> [Player] -> [(Int, Player)])
|
||||
-- ^ The search function
|
||||
-> String
|
||||
-- ^ The prompt string
|
||||
-> (Maybe Int -> Action ())
|
||||
-- ^ The callback to run (takes the index number of the payer as
|
||||
-- input)
|
||||
-> Prompt
|
||||
selectPlayerPrompt pStr callback = selectPrompt SelectParams
|
||||
selectPlayerPromptWith sFunc pStr callback = selectPrompt SelectParams
|
||||
{ spPrompt = pStr
|
||||
, spSearchHeader = "Player select:"
|
||||
, spSearch = \sStr db -> playerSearch sStr (db^.dbPlayers)
|
||||
, spSearch = \sStr db -> sFunc sStr (db^.dbPlayers)
|
||||
, spSearchExact = \sStr db -> fst <$> playerSearchExact sStr (db^.dbPlayers)
|
||||
, spElemDesc = playerSummary
|
||||
, spProcessChar = capitalizeName
|
||||
@@ -292,18 +312,41 @@ selectPlayerPrompt pStr callback = selectPrompt SelectParams
|
||||
modify $ progMode .~ CreatePlayer cps
|
||||
}
|
||||
|
||||
-- | Selects a goalie (creating one if necessary)
|
||||
selectGoaliePrompt
|
||||
-- | Selects a player (creating one if necessary)
|
||||
selectPlayerPrompt
|
||||
:: String
|
||||
-- ^ The prompt string
|
||||
-> (Maybe Int -> Action ())
|
||||
-- ^ The callback to run (takes the index number of the payer as
|
||||
-- input)
|
||||
-> Prompt
|
||||
selectPlayerPrompt = selectPlayerPromptWith playerSearch
|
||||
|
||||
-- | Selects an active player (creating one if necessary)
|
||||
selectActivePlayerPrompt
|
||||
:: String
|
||||
-- ^ The prompt string
|
||||
-> (Maybe Int -> Action ())
|
||||
-- ^ The callback to run (takes the index number of the payer as
|
||||
-- input)
|
||||
-> Prompt
|
||||
selectActivePlayerPrompt = selectPlayerPromptWith activePlayerSearch
|
||||
|
||||
-- | Selects a goalie with a specified search criteria (creating the
|
||||
-- goalie if necessary)
|
||||
selectGoaliePromptWith
|
||||
:: (String -> [Goalie] -> [(Int, Goalie)])
|
||||
-- ^ The search criteria
|
||||
-> String
|
||||
-- ^ The prompt string
|
||||
-> (Maybe Int -> Action ())
|
||||
-- ^ The callback to run (takes the index number of the goalie as
|
||||
-- input)
|
||||
-> Prompt
|
||||
selectGoaliePrompt pStr callback = selectPrompt SelectParams
|
||||
selectGoaliePromptWith criteria pStr callback = selectPrompt SelectParams
|
||||
{ spPrompt = pStr
|
||||
, spSearchHeader = "Goalie select:"
|
||||
, spSearch = \sStr db -> goalieSearch sStr (db^.dbGoalies)
|
||||
, spSearch = \sStr db -> criteria sStr (db^.dbGoalies)
|
||||
, spSearchExact = \sStr db -> fst <$> goalieSearchExact sStr (db^.dbGoalies)
|
||||
, spElemDesc = goalieSummary
|
||||
, spProcessChar = capitalizeName
|
||||
@@ -321,6 +364,26 @@ selectGoaliePrompt pStr callback = selectPrompt SelectParams
|
||||
modify $ progMode .~ CreateGoalie cgs
|
||||
}
|
||||
|
||||
-- | Selects a goalie (creating one if necessary)
|
||||
selectGoaliePrompt
|
||||
:: String
|
||||
-- ^ The prompt string
|
||||
-> (Maybe Int -> Action ())
|
||||
-- ^ The callback to run (takes the index number of the goalie as
|
||||
-- input)
|
||||
-> Prompt
|
||||
selectGoaliePrompt = selectGoaliePromptWith goalieSearch
|
||||
|
||||
-- | Selects an active goalie (creating one if necessary)
|
||||
selectActiveGoaliePrompt
|
||||
:: String
|
||||
-- ^ The prompt string
|
||||
-> (Maybe Int -> Action ())
|
||||
-- ^ The callback to run (takes the index number of the goalie as
|
||||
-- input)
|
||||
-> Prompt
|
||||
selectActiveGoaliePrompt = selectGoaliePromptWith activeGoalieSearch
|
||||
|
||||
-- | Selects (or creates) a player position
|
||||
selectPositionPrompt
|
||||
:: String
|
||||
|
||||
@@ -23,6 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
module Mtlstats.Prompt.NewGame
|
||||
( gameYearPrompt
|
||||
, gameMonthPrompt
|
||||
, gameDayPrompt
|
||||
, otherTeamPrompt
|
||||
, homeScorePrompt
|
||||
@@ -48,6 +49,11 @@ gameYearPrompt :: Prompt
|
||||
gameYearPrompt = numPrompt "Game year: " $
|
||||
modify . (progMode.gameStateL.gameYear ?~)
|
||||
|
||||
-- | Prompts for the game month
|
||||
gameMonthPrompt :: Prompt
|
||||
gameMonthPrompt = numPromptRange 1 12 "Game month: " $
|
||||
modify . (progMode.gameStateL.gameMonth ?~)
|
||||
|
||||
-- | Prompts for the day of the month the game took place
|
||||
gameDayPrompt :: Prompt
|
||||
gameDayPrompt = numPrompt "Day of month: " $
|
||||
@@ -76,7 +82,7 @@ recordGoalPrompt
|
||||
-> Int
|
||||
-- ^ The goal number
|
||||
-> Prompt
|
||||
recordGoalPrompt game goal = selectPlayerPrompt
|
||||
recordGoalPrompt game goal = selectActivePlayerPrompt
|
||||
( "*** GAME " ++ padNum 2 game ++ " ***\n"
|
||||
++ "Who scored goal number " ++ show goal ++ "? "
|
||||
) $ modify . (progMode.gameStateL.goalBy .~)
|
||||
@@ -90,7 +96,7 @@ recordAssistPrompt
|
||||
-> Int
|
||||
-- ^ The assist number
|
||||
-> Prompt
|
||||
recordAssistPrompt game goal assist = selectPlayerPrompt
|
||||
recordAssistPrompt game goal assist = selectActivePlayerPrompt
|
||||
( "*** GAME " ++ padNum 2 game ++ " ***\n"
|
||||
++ "Goal: " ++ show goal ++ "\n"
|
||||
++ "Assist #" ++ show assist ++ ": "
|
||||
@@ -104,7 +110,7 @@ recordAssistPrompt game goal assist = selectPlayerPrompt
|
||||
|
||||
-- | Prompts for the player to assign penalty minutes to
|
||||
pMinPlayerPrompt :: Prompt
|
||||
pMinPlayerPrompt = selectPlayerPrompt
|
||||
pMinPlayerPrompt = selectActivePlayerPrompt
|
||||
"Assign penalty minutes to: " $
|
||||
\case
|
||||
Nothing -> modify $ progMode.gameStateL.gamePMinsRecorded .~ True
|
||||
|
||||
@@ -36,7 +36,8 @@ import Mtlstats.Types
|
||||
|
||||
-- | Prompts for a goalie who played in the game
|
||||
selectGameGoaliePrompt :: Prompt
|
||||
selectGameGoaliePrompt = selectGoaliePrompt "Which goalie played this game: " $
|
||||
selectGameGoaliePrompt = selectActiveGoaliePrompt
|
||||
"Which goalie played this game: " $
|
||||
\case
|
||||
Nothing -> modify finishGoalieEntry
|
||||
Just n -> modify $ progMode.gameStateL.gameSelectedGoalie ?~ n
|
||||
|
||||
@@ -176,6 +176,7 @@ module Mtlstats.Types (
|
||||
addGameStats,
|
||||
-- ** Player Helpers
|
||||
playerSearch,
|
||||
activePlayerSearch,
|
||||
playerSearchExact,
|
||||
modifyPlayer,
|
||||
playerSummary,
|
||||
@@ -185,6 +186,7 @@ module Mtlstats.Types (
|
||||
addPlayerStats,
|
||||
-- ** Goalie Helpers
|
||||
goalieSearch,
|
||||
activeGoalieSearch,
|
||||
goalieSearchExact,
|
||||
goalieSummary,
|
||||
goalieIsActive,
|
||||
@@ -1003,6 +1005,23 @@ addGameStats s1 s2 = GameStats
|
||||
, _gmsGoalsAgainst = s1^.gmsGoalsAgainst + s2^.gmsGoalsAgainst
|
||||
}
|
||||
|
||||
-- | Searches through a list of players with a specified criteria
|
||||
playerSearchWith
|
||||
:: (Player -> Bool)
|
||||
-- ^ The search criteria
|
||||
-> String
|
||||
-- ^ The search string
|
||||
-> [Player]
|
||||
-- ^ The list of players to search
|
||||
-> [(Int, Player)]
|
||||
-- ^ The matching players with their index numbers
|
||||
playerSearchWith criteria sStr =
|
||||
filter match . zip [0..]
|
||||
where
|
||||
match (_, p)
|
||||
= map toUpper sStr `isInfixOf` map toUpper (p^.pName)
|
||||
&& criteria p
|
||||
|
||||
-- | Searches through a list of players
|
||||
playerSearch
|
||||
:: String
|
||||
@@ -1011,9 +1030,17 @@ playerSearch
|
||||
-- ^ The list of players to search
|
||||
-> [(Int, Player)]
|
||||
-- ^ The matching players with their index numbers
|
||||
playerSearch sStr =
|
||||
filter match . zip [0..]
|
||||
where match (_, p) = map toUpper sStr `isInfixOf` map toUpper (p^.pName)
|
||||
playerSearch = playerSearchWith $ const True
|
||||
|
||||
-- | Searches through a list of players for an active player
|
||||
activePlayerSearch
|
||||
:: String
|
||||
-- ^ The search string
|
||||
-> [Player]
|
||||
-- ^ The list of players to search
|
||||
-> [(Int, Player)]
|
||||
-- ^ The matching players with their index numbers
|
||||
activePlayerSearch = playerSearchWith (^.pActive)
|
||||
|
||||
-- | Searches for a player by exact match on name
|
||||
playerSearchExact
|
||||
@@ -1068,6 +1095,23 @@ addPlayerStats s1 s2 = newPlayerStats
|
||||
& psAssists .~ s1^.psAssists + s2^.psAssists
|
||||
& psPMin .~ s1^.psPMin + s2^.psPMin
|
||||
|
||||
-- | Searches a list of goalies with a search criteria
|
||||
goalieSearchWith
|
||||
:: (Goalie -> Bool)
|
||||
-- ^ The search criteria
|
||||
-> String
|
||||
-- ^ The search string
|
||||
-> [Goalie]
|
||||
-- ^ The list to search
|
||||
-> [(Int, Goalie)]
|
||||
-- ^ The search results with their corresponding index numbers
|
||||
goalieSearchWith criteria sStr =
|
||||
filter match . zip [0..]
|
||||
where
|
||||
match (_, g)
|
||||
= map toUpper sStr `isInfixOf` map toUpper (g^.gName)
|
||||
&& criteria g
|
||||
|
||||
-- | Searches a list of goalies
|
||||
goalieSearch
|
||||
:: String
|
||||
@@ -1076,9 +1120,17 @@ goalieSearch
|
||||
-- ^ The list to search
|
||||
-> [(Int, Goalie)]
|
||||
-- ^ The search results with their corresponding index numbers
|
||||
goalieSearch sStr =
|
||||
filter match . zip [0..]
|
||||
where match (_, g) = map toUpper sStr `isInfixOf` map toUpper (g^.gName)
|
||||
goalieSearch = goalieSearchWith $ const True
|
||||
|
||||
-- | Searches a list of goalies for an active goalie
|
||||
activeGoalieSearch
|
||||
:: String
|
||||
-- ^ The search string
|
||||
-> [Goalie]
|
||||
-- ^ The list to search
|
||||
-> [(Int, Goalie)]
|
||||
-- ^ The search results with their corresponding index numbers
|
||||
activeGoalieSearch = goalieSearchWith (^.gActive)
|
||||
|
||||
-- | Searches a list of goalies for an exact match
|
||||
goalieSearchExact
|
||||
|
||||
@@ -48,61 +48,31 @@ spec = describe "NewGame" $ do
|
||||
GoalieInput.spec
|
||||
|
||||
overtimeCheckSpec :: Spec
|
||||
overtimeCheckSpec = describe "overtimeCheck" $ do
|
||||
overtimeCheckSpec = describe "overtimeCheck" $ mapM_
|
||||
(\(label, expectation, gt, home, away, otf) ->
|
||||
context label $
|
||||
it expectation $ let
|
||||
ps = newProgState & progMode.gameStateL
|
||||
%~ (gameType ?~ gt)
|
||||
. (homeScore ?~ home)
|
||||
. (awayScore ?~ away)
|
||||
|
||||
context "tie game" $ do
|
||||
let
|
||||
s = newProgState
|
||||
& progMode.gameStateL
|
||||
%~ (gameType ?~ HomeGame)
|
||||
. (homeScore ?~ 1)
|
||||
. (awayScore ?~ 1)
|
||||
& overtimeCheck
|
||||
ps' = overtimeCheck ps
|
||||
in ps'^.progMode.gameStateL.overtimeFlag `shouldBe` otf)
|
||||
|
||||
it "should clear the home score" $
|
||||
s^.progMode.gameStateL.homeScore `shouldBe` Nothing
|
||||
-- label, expectation, type, home, away, ot flag
|
||||
[ ( "home win", clearFlag, HomeGame, 2, 1, Just False )
|
||||
, ( "home loss", leaveFlag, HomeGame, 1, 2, Nothing )
|
||||
, ( "home tie", setFlag, HomeGame, 1, 1, Just True )
|
||||
, ( "away win", clearFlag, AwayGame, 1, 2, Just False )
|
||||
, ( "away loss", leaveFlag, AwayGame, 2, 1, Nothing )
|
||||
, ( "away tie", setFlag, AwayGame, 1, 1, Just True )
|
||||
]
|
||||
|
||||
it "should clear the away score" $
|
||||
s^.progMode.gameStateL.awayScore `shouldBe` Nothing
|
||||
|
||||
it "should leave the overtimeFlag blank" $
|
||||
s^.progMode.gameStateL.overtimeFlag `shouldBe` Nothing
|
||||
|
||||
context "game won" $ do
|
||||
let
|
||||
s = newProgState
|
||||
& progMode.gameStateL
|
||||
%~ (gameType ?~ HomeGame)
|
||||
. (homeScore ?~ 2)
|
||||
. (awayScore ?~ 1)
|
||||
& overtimeCheck
|
||||
|
||||
it "should not change the home score" $
|
||||
s^.progMode.gameStateL.homeScore `shouldBe` Just 2
|
||||
|
||||
it "should not change the away score" $
|
||||
s^.progMode.gameStateL.awayScore `shouldBe` Just 1
|
||||
|
||||
it "should set the overtimeCheck flag to False" $
|
||||
s^.progMode.gameStateL.overtimeFlag `shouldBe` Just False
|
||||
|
||||
context "game lost" $ do
|
||||
let
|
||||
s = newProgState
|
||||
& progMode.gameStateL
|
||||
%~ (gameType ?~ HomeGame)
|
||||
. (homeScore ?~ 1)
|
||||
. (awayScore ?~ 2)
|
||||
& overtimeCheck
|
||||
|
||||
it "should not change the home score" $
|
||||
s^.progMode.gameStateL.homeScore `shouldBe` Just 1
|
||||
|
||||
it "should not change the away score" $
|
||||
s^.progMode.gameStateL.awayScore `shouldBe` Just 2
|
||||
|
||||
it "should leave the overtimeCheck flag blank" $
|
||||
s^.progMode.gameStateL.overtimeFlag `shouldBe` Nothing
|
||||
where
|
||||
clearFlag = "should set the overtimeFlag to True"
|
||||
setFlag = "should set the overtimeFlag to False"
|
||||
leaveFlag = "should leave the overtimeFlag as Nothing"
|
||||
|
||||
updateGameStatsSpec :: Spec
|
||||
updateGameStatsSpec = describe "updateGameStats" $ do
|
||||
|
||||
@@ -141,9 +141,9 @@ labelTableSpec = describe "labelTable" $
|
||||
]
|
||||
|
||||
expected =
|
||||
[ " foo: bar"
|
||||
[ " foo: bar "
|
||||
, " baz: quux"
|
||||
, "longer: x"
|
||||
, "longer: x "
|
||||
]
|
||||
|
||||
in labelTable input `shouldBe` expected
|
||||
|
||||
@@ -54,7 +54,7 @@ goalieDetailsSpec = describe "goalieDetails" $ let
|
||||
. ( gsTies .~ 15 )
|
||||
|
||||
expected = unlines
|
||||
[ "Number: 1"
|
||||
[ "Number: 1 "
|
||||
, " Name: Joe*"
|
||||
, ""
|
||||
, " YTD Lifetime"
|
||||
|
||||
@@ -50,8 +50,8 @@ playerDetailsSpec = describe "playerDetails" $
|
||||
}
|
||||
|
||||
expected = unlines
|
||||
[ " Number: 1"
|
||||
, " Name: Joe*"
|
||||
[ " Number: 1 "
|
||||
, " Name: Joe* "
|
||||
, "Position: centre"
|
||||
, ""
|
||||
, " YTD Lifetime"
|
||||
|
||||
@@ -73,6 +73,7 @@ spec = describe "Mtlstats.Types" $ do
|
||||
gmsPointsSpec
|
||||
addGameStatsSpec
|
||||
playerSearchSpec
|
||||
activePlayerSearchSpec
|
||||
playerSearchExactSpec
|
||||
modifyPlayerSpec
|
||||
playerSummarySpec
|
||||
@@ -80,6 +81,7 @@ spec = describe "Mtlstats.Types" $ do
|
||||
psPointsSpec
|
||||
addPlayerStatsSpec
|
||||
goalieSearchSpec
|
||||
activeGoalieSearchSpec
|
||||
goalieSearchExactSpec
|
||||
goalieSummarySpec
|
||||
goalieIsActiveSpec
|
||||
@@ -647,6 +649,19 @@ playerSearchSpec = describe "playerSearch" $ mapM_
|
||||
, ( "x", [] )
|
||||
]
|
||||
|
||||
activePlayerSearchSpec :: Spec
|
||||
activePlayerSearchSpec = describe "activePlayerSearch" $ mapM_
|
||||
(\(sStr, expected) -> context sStr $
|
||||
it ("should return " ++ show expected) $ let
|
||||
ps = [joe, bob, steve & pActive .~ False]
|
||||
in activePlayerSearch sStr ps `shouldBe` expected)
|
||||
-- search, result
|
||||
[ ( "joe", [(0, joe)] )
|
||||
, ( "o", [(0, joe), (1, bob)] )
|
||||
, ( "e", [(0, joe)] )
|
||||
, ( "x", [] )
|
||||
]
|
||||
|
||||
playerSearchExactSpec :: Spec
|
||||
playerSearchExactSpec = describe "playerSearchExact" $ mapM_
|
||||
(\(sStr, expected) -> context sStr $
|
||||
@@ -778,6 +793,28 @@ goalieSearchSpec = describe "goalieSearch" $ do
|
||||
it "should return Bob" $
|
||||
goalieSearch "bob" goalies `shouldBe` [result 1]
|
||||
|
||||
activeGoalieSearchSpec :: Spec
|
||||
activeGoalieSearchSpec = describe "activeGoalieSearch" $ do
|
||||
let
|
||||
goalies =
|
||||
[ newGoalie 2 "Joe"
|
||||
, newGoalie 3 "Bob"
|
||||
, newGoalie 5 "Steve" & gActive .~ False
|
||||
]
|
||||
result n = (n, goalies!!n)
|
||||
|
||||
context "partial match" $
|
||||
it "should return Joe" $
|
||||
activeGoalieSearch "e" goalies `shouldBe` [result 0]
|
||||
|
||||
context "no match" $
|
||||
it "should return an empty list" $
|
||||
activeGoalieSearch "x" goalies `shouldBe` []
|
||||
|
||||
context "exact match" $
|
||||
it "should return Bob" $
|
||||
activeGoalieSearch "bob" goalies `shouldBe` [result 1]
|
||||
|
||||
goalieSearchExactSpec :: Spec
|
||||
goalieSearchExactSpec = describe "goalieSearchExact" $ do
|
||||
let
|
||||
|
||||
Reference in New Issue
Block a user