implemented homeTeam and awayTeam
This commit is contained in:
parent
f0e0d644d2
commit
6136151614
|
@ -0,0 +1,26 @@
|
|||
{- |
|
||||
|
||||
mtlstats
|
||||
Copyright (C) 2019 Rhéal Lamothe
|
||||
<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 Mtlstats.Config (myTeam) where
|
||||
|
||||
-- | The name of the team whose stats we're tracking
|
||||
myTeam :: String
|
||||
myTeam = "MONTREAL"
|
|
@ -97,6 +97,8 @@ module Mtlstats.Types (
|
|||
-- ** GameState Helpers
|
||||
teamScore,
|
||||
otherScore,
|
||||
homeTeam,
|
||||
awayTeam,
|
||||
gameWon,
|
||||
gameLost,
|
||||
gameTied,
|
||||
|
@ -124,6 +126,8 @@ import Lens.Micro (Lens', lens, (&), (^.), (.~))
|
|||
import Lens.Micro.TH (makeLenses)
|
||||
import UI.NCurses (Curses, Update)
|
||||
|
||||
import Mtlstats.Config
|
||||
|
||||
-- | Action which maintains program state
|
||||
type Action a = StateT ProgState Curses a
|
||||
|
||||
|
@ -509,6 +513,22 @@ otherScore s = case s ^. gameType of
|
|||
Just AwayGame -> s ^. homeScore
|
||||
Nothing -> Nothing
|
||||
|
||||
-- | Returns the name of the home team (or an empty string if
|
||||
-- unavailable)
|
||||
homeTeam :: GameState -> String
|
||||
homeTeam gs = case gs^.gameType of
|
||||
Just HomeGame -> myTeam
|
||||
Just AwayGame -> gs^.otherTeam
|
||||
Nothing -> ""
|
||||
|
||||
-- | Returns the name of the visiting team (or an empty string if
|
||||
-- unavailable)
|
||||
awayTeam :: GameState -> String
|
||||
awayTeam gs = case gs^.gameType of
|
||||
Just HomeGame -> gs^.otherTeam
|
||||
Just AwayGame -> myTeam
|
||||
Nothing -> ""
|
||||
|
||||
-- | Checks if the game was won
|
||||
gameWon :: GameState -> Maybe Bool
|
||||
gameWon gs = (>) <$> teamScore gs <*> otherScore gs
|
||||
|
|
|
@ -30,6 +30,7 @@ import qualified Data.HashMap.Strict as HM
|
|||
import Lens.Micro (Lens', (&), (^.), (.~), (?~))
|
||||
import Test.Hspec (Spec, context, describe, it, shouldBe)
|
||||
|
||||
import Mtlstats.Config
|
||||
import Mtlstats.Types
|
||||
|
||||
import qualified Types.MenuSpec as Menu
|
||||
|
@ -43,6 +44,8 @@ spec = describe "Mtlstats.Types" $ do
|
|||
gameStateLSpec
|
||||
teamScoreSpec
|
||||
otherScoreSpec
|
||||
homeTeamSpec
|
||||
awayTeamSpec
|
||||
gameWonSpec
|
||||
gameLostSpec
|
||||
gameTiedSpec
|
||||
|
@ -248,6 +251,44 @@ dbJSON = Object $ HM.fromList
|
|||
, ( "away_game_stats", gameStatsJSON 2 )
|
||||
]
|
||||
|
||||
homeTeamSpec :: Spec
|
||||
homeTeamSpec = describe "homeTeam" $ do
|
||||
let
|
||||
gs gt = newGameState
|
||||
& gameType .~ gt
|
||||
& otherTeam .~ "foo"
|
||||
|
||||
context "unknown game type" $
|
||||
it "should return an empty string" $
|
||||
homeTeam (gs Nothing) `shouldBe` ""
|
||||
|
||||
context "home game" $
|
||||
it ("should return " ++ show myTeam) $
|
||||
homeTeam (gs $ Just HomeGame) `shouldBe` myTeam
|
||||
|
||||
context "away game" $
|
||||
it "should return \"foo\"" $
|
||||
homeTeam (gs $ Just AwayGame) `shouldBe` "foo"
|
||||
|
||||
awayTeamSpec :: Spec
|
||||
awayTeamSpec = describe "awayTeam" $ do
|
||||
let
|
||||
gs gt = newGameState
|
||||
& gameType .~ gt
|
||||
& otherTeam .~ "foo"
|
||||
|
||||
context "unknown game type" $
|
||||
it "should return an empty string" $
|
||||
awayTeam (gs Nothing) `shouldBe` ""
|
||||
|
||||
context "home game" $
|
||||
it "should return \"foo\"" $
|
||||
awayTeam (gs $ Just HomeGame) `shouldBe` "foo"
|
||||
|
||||
context "away game" $
|
||||
it ("should return " ++ show myTeam) $
|
||||
awayTeam (gs $ Just AwayGame) `shouldBe` myTeam
|
||||
|
||||
gameWonSpec :: Spec
|
||||
gameWonSpec = describe "gameWon" $ mapM_
|
||||
(\(t, h, a, expected) -> let
|
||||
|
|
Loading…
Reference in New Issue
Block a user