diff --git a/test/Handler/Utils/ExamSpec.hs b/test/Handler/Utils/ExamSpec.hs index 8f7fc1e02..c1e078334 100644 --- a/test/Handler/Utils/ExamSpec.hs +++ b/test/Handler/Utils/ExamSpec.hs @@ -225,28 +225,36 @@ spec = do where descriptionValid:: ExamOccurrenceId -> ExamOccurrenceMappingDescription -> Bool descriptionValid roomId description - = endAfterStart description && all (all $ noDirectOverlap description) (Map.delete roomId examOccurrenceMappingMapping) + = endAfterStart description + && all (all $ noDirectOverlap description) (Map.delete roomId examOccurrenceMappingMapping) endAfterStart :: ExamOccurrenceMappingDescription -> Bool endAfterStart ExamOccurrenceMappingRange {eaomrStart=(pack . map CI.foldedCase -> start), eaomrEnd=(pack . map CI.foldedCase -> end)} = RFC5051.compareUnicode start end /= GT endAfterStart ExamOccurrenceMappingSpecial {} = True + -- also check for equal length with ExamRoomMatriculation noDirectOverlap :: ExamOccurrenceMappingDescription -> ExamOccurrenceMappingDescription -> Bool noDirectOverlap - ExamOccurrenceMappingRange {eaomrStart=(pack . map CI.foldedCase -> s0), eaomrEnd=(pack . map CI.foldedCase -> e0)} - ExamOccurrenceMappingRange {eaomrStart=(pack . map CI.foldedCase -> s1), eaomrEnd=(pack . map CI.foldedCase -> e1)} - = (RFC5051.compareUnicode s0 s1 == LT && RFC5051.compareUnicode e0 s1 == LT) - || (RFC5051.compareUnicode s0 e1 == GT && RFC5051.compareUnicode e0 s1 == GT) + ExamOccurrenceMappingRange {eaomrStart=cs0@(pack . map CI.foldedCase -> s0), eaomrEnd=ce0@(pack . map CI.foldedCase -> e0)} + ExamOccurrenceMappingRange {eaomrStart=cs1@(pack . map CI.foldedCase -> s1), eaomrEnd=ce1@(pack . map CI.foldedCase -> e1)} + = equalLengthForMatriculation [cs0, ce0, cs1, ce1] + && ((RFC5051.compareUnicode s0 s1 == LT && RFC5051.compareUnicode e0 s1 == LT) + || (RFC5051.compareUnicode s0 e1 == GT && RFC5051.compareUnicode e0 s1 == GT)) noDirectOverlap ExamOccurrenceMappingRange {eaomrStart, eaomrEnd} ExamOccurrenceMappingSpecial {eaomrSpecial} - = noDirectOverlapRangeSpecial eaomrStart eaomrEnd eaomrSpecial + = equalLengthForMatriculation [eaomrStart, eaomrEnd, eaomrSpecial] + && noDirectOverlapRangeSpecial eaomrStart eaomrEnd eaomrSpecial noDirectOverlap ExamOccurrenceMappingSpecial {eaomrSpecial} ExamOccurrenceMappingRange {eaomrStart, eaomrEnd} - = noDirectOverlapRangeSpecial eaomrStart eaomrEnd eaomrSpecial - noDirectOverlap ExamOccurrenceMappingSpecial {eaomrSpecial=s1} ExamOccurrenceMappingSpecial {eaomrSpecial=s2} - = s1 /= s2 + = equalLengthForMatriculation [eaomrStart, eaomrEnd, eaomrSpecial] + && noDirectOverlapRangeSpecial eaomrStart eaomrEnd eaomrSpecial + noDirectOverlap ExamOccurrenceMappingSpecial {eaomrSpecial=s0} ExamOccurrenceMappingSpecial {eaomrSpecial=s1} + = equalLengthForMatriculation [s0, s1] && s0 /= s1 + equalLengthForMatriculation :: [[CI Char]] -> Bool + equalLengthForMatriculation [] = True + equalLengthForMatriculation (h:t) = (rule /= ExamRoomMatriculation) || all (== Text.length h) (Text.length <$> t) noDirectOverlapRangeSpecial :: [CI Char] -> [CI Char] -> [CI Char] -> Bool noDirectOverlapRangeSpecial (pack . map CI.foldedCase -> start)