refactor: stabilize showCompactCorrectorLoad
This commit is contained in:
parent
e73f09bbb0
commit
e95abc97ee
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user