From daceac95fc6c997c3322734446f1631ca16a258e Mon Sep 17 00:00:00 2001 From: Wolfgang Witt Date: Wed, 24 Feb 2021 16:33:01 +0100 Subject: [PATCH] chore(test): relax requirements for justified nullResult Instances with bigger user buckets than the smallest room might correctly fail Thus, don't report an error for them. --- src/Handler/Utils/Exam.hs | 2 +- test/Handler/Utils/ExamSpec.hs | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Handler/Utils/Exam.hs b/src/Handler/Utils/Exam.hs index 874b8144b..b54ac379c 100644 --- a/src/Handler/Utils/Exam.hs +++ b/src/Handler/Utils/Exam.hs @@ -636,7 +636,7 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences withAlphabetChars :: [CI Char] -> [CI Char] withAlphabetChars [] = [] withAlphabetChars (c:cs) - | elem c alphabet = c : withAlphabetChars cs + | c `elem` alphabet = c : withAlphabetChars cs | otherwise= case previousAlphabetChar c of Nothing -> [] (Just c') -> c' : replicate (length cs) (last alphabet) diff --git a/test/Handler/Utils/ExamSpec.hs b/test/Handler/Utils/ExamSpec.hs index 0bf308ba0..c2c3b673f 100644 --- a/test/Handler/Utils/ExamSpec.hs +++ b/test/Handler/Utils/ExamSpec.hs @@ -316,16 +316,24 @@ spec = do mappingImpossible rule userProperties@(sort . map (ruleProperty rule . fst) . Map.elems . Map.filter (isRelevantUser rule) -> relevantUsers) - (map snd . Map.toList . adjustOccurrences userProperties -> occurrences') = go relevantUsers occurrences' + (map snd . Map.toList . adjustOccurrences userProperties -> occurrences') = go 0 True relevantUsers occurrences' where - go :: [Maybe Text] -> [Natural] -> Bool - go [] _occurrences = False - go _remainingUsers [] = True - go remainingUsers (0:t) = go remainingUsers t - go remainingUsers@(h:_t) (firstOccurrence:laterOccurrences) - | nextUsers <= firstOccurrence = go remainingUsers' $ firstOccurrence - nextUsers : laterOccurrences - | otherwise = go remainingUsers laterOccurrences + smallestRoom :: Natural + smallestRoom = maybe 0 minimum $ fromNullable occurrences' + -- If there exists a bucket with the same tag bigger than the smallest room a nullResult might be returned + -- It may still work, but is not guaranteed (e.g. both the first bucket) + go :: Natural -> [Maybe Text] -> [Natural] -> Bool + go biggestUserBucket [] _occurrences = biggestUserBucket > small + go _biggestUserBucket _remainingUsers [] = True + go biggestUserBucket remainingUsers (0:t) = go biggestUserBucket remainingUsers t + go biggestUserBucket remainingUsers@(h:_t) (firstOccurrence:laterOccurrences) + | nextUsers <= firstOccurrence + = go (max biggestUserBucket nextUsers) remainingUsers' $ firstOccurrence - nextUsers : laterOccurrences + | otherwise + = go biggestUserBucket remainingUsers laterOccurrences where + nextUsers :: Natural + remainingUsers' :: [Maybe Text] (fromIntegral . length -> nextUsers, remainingUsers') = span (== h) remainingUsers ruleProperty :: ExamOccurrenceRule -> UserProperties -> Maybe Text ruleProperty rule = case rule of