refactor: stabilize showCompactCorrectorLoad
This commit is contained in:
parent
e73f09bbb0
commit
e95abc97ee
@ -363,15 +363,15 @@ derivePersistField "CorrectorState"
|
|||||||
showCompactCorrectorLoad :: Load -> CorrectorState -> Text
|
showCompactCorrectorLoad :: Load -> CorrectorState -> Text
|
||||||
showCompactCorrectorLoad load CorrectorMissing = "[" <> showCompactCorrectorLoad load CorrectorNormal <> "]"
|
showCompactCorrectorLoad load CorrectorMissing = "[" <> showCompactCorrectorLoad load CorrectorNormal <> "]"
|
||||||
showCompactCorrectorLoad load CorrectorExcused = "{" <> showCompactCorrectorLoad load CorrectorNormal <> "}"
|
showCompactCorrectorLoad load CorrectorExcused = "{" <> showCompactCorrectorLoad load CorrectorNormal <> "}"
|
||||||
showCompactCorrectorLoad Load{..} CorrectorNormal | byProportion == 0 = tutorialText
|
showCompactCorrectorLoad Load{..} CorrectorNormal | byProportion == 0 = fromMaybe mempty tutorialText
|
||||||
| otherwise = proportionText <> " + " <> tutorialText
|
| otherwise = maybe id (\tt pt -> pt <> " + " <> tt) tutorialText proportionText
|
||||||
where
|
where
|
||||||
proportionText = let propDbl :: Double
|
proportionText = let propDbl :: Double
|
||||||
propDbl = fromRational byProportion
|
propDbl = fromRational byProportion
|
||||||
in tshow $ roundToDigits 2 propDbl
|
in tshow $ roundToDigits 2 propDbl
|
||||||
tutorialText = case byTutorial of Nothing -> mempty
|
tutorialText = byTutorial <&> \case
|
||||||
Just True -> "(T)"
|
True -> "(T)"
|
||||||
Just False -> "T"
|
False -> "T"
|
||||||
|
|
||||||
instance Csv.ToField (SheetType epid, Maybe Points) where
|
instance Csv.ToField (SheetType epid, Maybe Points) where
|
||||||
toField (_, Nothing) = mempty
|
toField (_, Nothing) = mempty
|
||||||
|
|||||||
@ -523,6 +523,16 @@ spec = do
|
|||||||
toPathPiece ExamCloseSeparate `shouldBe` "separate"
|
toPathPiece ExamCloseSeparate `shouldBe` "separate"
|
||||||
toPathPiece (ExamCloseOnFinished False) `shouldBe` "on-finished"
|
toPathPiece (ExamCloseOnFinished False) `shouldBe` "on-finished"
|
||||||
toPathPiece (ExamCloseOnFinished True) `shouldBe` "on-finished-hidden"
|
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 :: (TermIdentifier, Text) -> Expectation
|
||||||
termExample (term, encoded) = example $ do
|
termExample (term, encoded) = example $ do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user