From d60f93561f5ee84d460645a945db35ac6b55e97d Mon Sep 17 00:00:00 2001 From: Wolfgang Witt Date: Thu, 11 Feb 2021 15:51:51 +0100 Subject: [PATCH] fix: make sure it compiles again + add 2-letter name --- src/Handler/Utils/Exam.hs | 12 +++++------- test/Handler/Utils/ExamSpec.hs | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Handler/Utils/Exam.hs b/src/Handler/Utils/Exam.hs index ef6050f7e..dfc895c92 100644 --- a/src/Handler/Utils/Exam.hs +++ b/src/Handler/Utils/Exam.hs @@ -535,7 +535,7 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences postprocess result = seq resultAscList (resultAscList, resultUsers) where maxTagLength :: Int - maxTagLength = maximum $ map (length . snd) result + maxTagLength = maybe 0 maximum $ fromNullable $ map (length . snd) result rangeAlphabet :: [CI Char] rangeAlphabet = case rule of @@ -565,7 +565,7 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences | length start < maxTagLength = go (impureNonNull $ replicate (succ $ length start) $ head alphabet) [] result | otherwise - = Map.empty + = [] where mappingDescription :: ExamOccurrenceMappingDescription mappingDescription = ExamOccurrenceMappingRange (toNullable start) end @@ -592,10 +592,10 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences increase :: [CI Char] -> [CI Char] increase [] = [] increase (c:cs) + | c < head alphabet + = head alphabet : cs | nextChar == head alphabet = nextChar : increase cs - | nextChar == paddingChar - = head alphabet : cs | otherwise = nextChar : cs where @@ -603,9 +603,7 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences nextChar | c `elem` alphabet = dropWhile (/= c) alphabetCycle List.!! 1 - | c < head alphabet -- includes padding char - = head alphabet - | c > last alphabet -- basically all non-ascii printable characters + | otherwise -- includes padding char = head alphabet -- TODO what if the border is between to non-ascii characters? diff --git a/test/Handler/Utils/ExamSpec.hs b/test/Handler/Utils/ExamSpec.hs index c6a431222..9de995308 100644 --- a/test/Handler/Utils/ExamSpec.hs +++ b/test/Handler/Utils/ExamSpec.hs @@ -193,7 +193,7 @@ spec = do , "Martin", "Jackson", "Thompson", "White" , "Lopez", "Lee", "Gonzalez", "Harris" , "Clark", "Lewis", "Robinson", "Walker" - , "Perez", "Hall", "Young", "zu Allen" + , "Perez", "Hall", "Young", "zu Allen", "Fu" , "Únîcòdé", "Ähm-Ümlaüte", "von Leerzeichen" ] occurrenceMap :: Map UserId (Maybe ExamOccurrenceId) -> Map ExamOccurrenceId [UserId]