awardGoal updates game stats
This commit is contained in:
parent
b17e63246f
commit
ad840cca65
|
@ -39,6 +39,7 @@ module Mtlstats.Actions
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.Trans.State (modify)
|
import Control.Monad.Trans.State (modify)
|
||||||
|
import qualified Data.Map as M
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import Data.Time.Calendar (fromGregorianValid)
|
import Data.Time.Calendar (fromGregorianValid)
|
||||||
import Lens.Micro (over, (^.), (&), (.~), (?~), (%~), (+~))
|
import Lens.Micro (over, (^.), (&), (.~), (?~), (%~), (+~))
|
||||||
|
@ -174,8 +175,11 @@ awardGoal
|
||||||
-> ProgState
|
-> ProgState
|
||||||
-> ProgState
|
-> ProgState
|
||||||
awardGoal n ps = ps
|
awardGoal n ps = ps
|
||||||
& database.dbPlayers
|
& progMode.gameStateL.gamePlayerStats %~
|
||||||
%~ map
|
(\m -> let
|
||||||
|
stats = M.findWithDefault newPlayerStats n m
|
||||||
|
in M.insert n (stats & psGoals %~ succ) m)
|
||||||
|
& database.dbPlayers %~ map
|
||||||
(\(i, p) -> if i == n
|
(\(i, p) -> if i == n
|
||||||
then p
|
then p
|
||||||
& pYtd.psGoals %~ succ
|
& pYtd.psGoals %~ succ
|
||||||
|
|
|
@ -22,6 +22,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
module ActionsSpec (spec) where
|
module ActionsSpec (spec) where
|
||||||
|
|
||||||
import Control.Monad (replicateM)
|
import Control.Monad (replicateM)
|
||||||
|
import qualified Data.Map as M
|
||||||
import Lens.Micro ((^.), (&), (.~), (?~), (%~))
|
import Lens.Micro ((^.), (&), (.~), (?~), (%~))
|
||||||
import System.Random (randomRIO)
|
import System.Random (randomRIO)
|
||||||
import Test.Hspec (Spec, context, describe, it, runIO, shouldBe, shouldNotBe)
|
import Test.Hspec (Spec, context, describe, it, runIO, shouldBe, shouldNotBe)
|
||||||
|
@ -426,31 +427,34 @@ awardGoalSpec = describe "awardGoal" $ do
|
||||||
db
|
db
|
||||||
= newDatabase
|
= newDatabase
|
||||||
& dbPlayers .~ [joe, bob]
|
& dbPlayers .~ [joe, bob]
|
||||||
|
joeStats
|
||||||
|
= newPlayerStats
|
||||||
|
& psGoals .~ 1
|
||||||
ps
|
ps
|
||||||
= newProgState
|
= newProgState
|
||||||
|
& progMode.gameStateL.gamePlayerStats .~ M.singleton 0 joeStats
|
||||||
& database .~ db
|
& database .~ db
|
||||||
|
|
||||||
context "Joe" $ do
|
mapM_
|
||||||
|
(\(pName, pid, ytd, lt, game) ->
|
||||||
|
context pName $ do
|
||||||
let
|
let
|
||||||
ps' = awardGoal 0 ps
|
ps' = awardGoal pid ps
|
||||||
player = head $ ps'^.database.dbPlayers
|
player = (ps'^.database.dbPlayers) !! pid
|
||||||
|
gStats = (ps'^.progMode.gameStateL.gamePlayerStats) M.! pid
|
||||||
|
|
||||||
it "should increment Joe's year-to-date goals" $
|
it ("should increment " ++ pName ++ "'s year-to-date goals") $
|
||||||
player^.pYtd.psGoals `shouldBe` 2
|
player^.pYtd.psGoals `shouldBe` ytd
|
||||||
|
|
||||||
it "should increment Joe's lifetime goals" $
|
it ("should increment " ++ pName ++ "'s lifetime goals") $
|
||||||
player^.pLifetime.psGoals `shouldBe` 3
|
player^.pLifetime.psGoals `shouldBe` lt
|
||||||
|
|
||||||
context "Bob" $ do
|
it ("should increment " ++ pName ++ "'s game goals") $
|
||||||
let
|
gStats^.psGoals `shouldBe` game)
|
||||||
ps' = awardGoal 1 ps
|
-- player name, player id, ytd goals, lifetime goals, game goals
|
||||||
player = last $ ps'^.database.dbPlayers
|
[ ( "Joe", 0, 2, 3, 2 )
|
||||||
|
, ( "Bob", 1, 4, 5, 1 )
|
||||||
it "should increment Bob's year-to-data goals" $
|
]
|
||||||
player^.pYtd.psGoals `shouldBe` 4
|
|
||||||
|
|
||||||
it "should increment Bob's lifetime goals" $
|
|
||||||
player^.pLifetime.psGoals `shouldBe` 5
|
|
||||||
|
|
||||||
context "invalid index" $ let
|
context "invalid index" $ let
|
||||||
ps' = awardGoal 2 ps
|
ps' = awardGoal 2 ps
|
||||||
|
|
Loading…
Reference in New Issue
Block a user