diff --git a/src/Model/Types/Sheet.hs b/src/Model/Types/Sheet.hs index 23b1a7f80..3a6e015f9 100644 --- a/src/Model/Types/Sheet.hs +++ b/src/Model/Types/Sheet.hs @@ -363,15 +363,15 @@ derivePersistField "CorrectorState" showCompactCorrectorLoad :: Load -> CorrectorState -> Text showCompactCorrectorLoad load CorrectorMissing = "[" <> showCompactCorrectorLoad load CorrectorNormal <> "]" showCompactCorrectorLoad load CorrectorExcused = "{" <> showCompactCorrectorLoad load CorrectorNormal <> "}" -showCompactCorrectorLoad Load{..} CorrectorNormal | byProportion == 0 = tutorialText - | otherwise = proportionText <> " + " <> tutorialText +showCompactCorrectorLoad Load{..} CorrectorNormal | byProportion == 0 = fromMaybe mempty tutorialText + | otherwise = maybe id (\tt pt -> pt <> " + " <> tt) tutorialText proportionText where proportionText = let propDbl :: Double propDbl = fromRational byProportion in tshow $ roundToDigits 2 propDbl - tutorialText = case byTutorial of Nothing -> mempty - Just True -> "(T)" - Just False -> "T" + tutorialText = byTutorial <&> \case + True -> "(T)" + False -> "T" instance Csv.ToField (SheetType epid, Maybe Points) where toField (_, Nothing) = mempty diff --git a/test/Model/TypesSpec.hs b/test/Model/TypesSpec.hs index 95a9caa14..a5c011ea5 100644 --- a/test/Model/TypesSpec.hs +++ b/test/Model/TypesSpec.hs @@ -523,6 +523,16 @@ spec = do toPathPiece ExamCloseSeparate `shouldBe` "separate" toPathPiece (ExamCloseOnFinished False) `shouldBe` "on-finished" toPathPiece (ExamCloseOnFinished True) `shouldBe` "on-finished-hidden" + describe "CompactCorrectorLoad" $ do + it "matches expectations" . example $ do + showCompactCorrectorLoad Load{ byTutorial = Just False, byProportion = 0 } CorrectorNormal `shouldBe` "T" + showCompactCorrectorLoad Load{ byTutorial = Just True, byProportion = 0 } CorrectorNormal `shouldBe` "(T)" + showCompactCorrectorLoad Load{ byTutorial = Nothing, byProportion = 1 } CorrectorNormal `shouldBe` "1.0" + showCompactCorrectorLoad Load{ byTutorial = Just False, byProportion = 1 } CorrectorNormal `shouldBe` "1.0 + T" + showCompactCorrectorLoad Load{ byTutorial = Just True, byProportion = 1 } CorrectorNormal `shouldBe` "1.0 + (T)" + showCompactCorrectorLoad Load{ byTutorial = Nothing, byProportion = 0 } CorrectorNormal `shouldBe` "" + showCompactCorrectorLoad Load{ byTutorial = Nothing, byProportion = 1 } CorrectorMissing `shouldBe` "[1.0]" + showCompactCorrectorLoad Load{ byTutorial = Nothing, byProportion = 1 } CorrectorExcused `shouldBe` "{1.0}" termExample :: (TermIdentifier, Text) -> Expectation termExample (term, encoded) = example $ do