implemented playerNameColWidth
This commit is contained in:
parent
d338930800
commit
277ba9a9dd
|
@ -19,7 +19,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
module Mtlstats.Report (report, gameDate) where
|
module Mtlstats.Report (report, gameDate, playerNameColWidth) where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
|
@ -141,6 +141,11 @@ gameDate gs = fromMaybe "" $ do
|
||||||
day <- padNum 2 <$> gs^.gameDay
|
day <- padNum 2 <$> gs^.gameDay
|
||||||
Just $ month ++ " " ++ day ++ " " ++ year
|
Just $ month ++ " " ++ day ++ " " ++ year
|
||||||
|
|
||||||
|
playerNameColWidth :: [Player] -> Int
|
||||||
|
playerNameColWidth = foldr
|
||||||
|
(\player current -> max current $ length $ player^.pName)
|
||||||
|
10
|
||||||
|
|
||||||
showStats :: GameStats -> String
|
showStats :: GameStats -> String
|
||||||
showStats gs
|
showStats gs
|
||||||
= right 2 (show $ gmsGames gs)
|
= right 2 (show $ gmsGames gs)
|
||||||
|
|
|
@ -28,8 +28,9 @@ import Mtlstats.Report
|
||||||
import Mtlstats.Types
|
import Mtlstats.Types
|
||||||
|
|
||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = describe "Mtlstats.Report"
|
spec = describe "Mtlstats.Report" $ do
|
||||||
gameDateSpec
|
gameDateSpec
|
||||||
|
playerNameColWidthSpec
|
||||||
|
|
||||||
gameDateSpec :: Spec
|
gameDateSpec :: Spec
|
||||||
gameDateSpec = describe "gameDate" $ do
|
gameDateSpec = describe "gameDate" $ do
|
||||||
|
@ -45,3 +46,20 @@ gameDateSpec = describe "gameDate" $ do
|
||||||
context "invalid date" $
|
context "invalid date" $
|
||||||
it "should return an empty string" $
|
it "should return an empty string" $
|
||||||
gameDate newGameState `shouldBe` ""
|
gameDate newGameState `shouldBe` ""
|
||||||
|
|
||||||
|
playerNameColWidthSpec :: Spec
|
||||||
|
playerNameColWidthSpec = describe "playerNameColWidth" $ do
|
||||||
|
let
|
||||||
|
short1 = newPlayer 1 "short" "foo"
|
||||||
|
short2 = newPlayer 2 "shorty" "bar"
|
||||||
|
long = newPlayer 3 "123456789012345" "baz"
|
||||||
|
|
||||||
|
mapM_
|
||||||
|
(\(label, players, expected) -> context label $
|
||||||
|
it ("should be " ++ show expected) $
|
||||||
|
playerNameColWidth players `shouldBe` expected)
|
||||||
|
-- label, players, expected
|
||||||
|
[ ( "empty list", [], 10 )
|
||||||
|
, ( "short names", [short1, short2], 10 )
|
||||||
|
, ( "long name", [short1, long], 15 )
|
||||||
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user