chore(test): respect users without matriculation number
This commit is contained in:
parent
317b95be31
commit
9d8a94717a
@ -80,12 +80,9 @@ spec = do
|
||||
where
|
||||
seed :: ()
|
||||
seed = ()
|
||||
-- TODO adjust with different nudges, depended on occurrences list/map
|
||||
-- def {eaocNudge = Map.singleton occ20Id (-11)}
|
||||
--ExamAutoOccurrenceConfig {eaocMinimizeRooms = False, eaocFinenessCost = 1 % 5, eaocNudge = fromList [(SqlBackendKey {unSqlBackendKey = 4},-11)], eaocNudgeSize = 1 % 20}
|
||||
propertyTest :: ExamOccurrenceRule -> Nudges -> Preselection -> Gen Property
|
||||
propertyTest rule nudges preselection = do
|
||||
(users, occurrences) <- genUsersWithOccurrences rule preselection
|
||||
(users, occurrences) <- genUsersWithOccurrences preselection
|
||||
eaocNudge <- case nudges of
|
||||
NoNudges -> pure Map.empty
|
||||
SmallNudges -> let nudgeFrequency = [(10, 0), (5, 1), (5, -1), (3, 2), (3, -2), (1, 3), (1, -3)]
|
||||
@ -97,9 +94,17 @@ spec = do
|
||||
config = def {eaocNudge}
|
||||
result@(_maybeMapping, userMap) = examAutoOccurrence seed rule config occurrences users
|
||||
pure $ ioProperty $ do
|
||||
-- every user got assigned a room
|
||||
-- every (relevant) user got assigned a room
|
||||
shouldBe (length userMap) (length users)
|
||||
shouldSatisfy userMap $ all isJust -- FIXME fails for users without a Just userMatrikelnummer
|
||||
let foldFn :: (UserId, Maybe ExamOccurrenceId) -> Bool -> Bool
|
||||
foldFn _userMapping False = False
|
||||
foldFn (_userId, Just _occurrenceId) True = True
|
||||
foldFn (userId, Nothing) True
|
||||
= (rule == ExamRoomMatriculation)
|
||||
-- every user with a userMatrikelnummer got a room
|
||||
-- fail on unknown user
|
||||
|| (fromMaybe False $ isNothing . userMatrikelnummer . fst <$> Map.lookup userId users)
|
||||
shouldSatisfy userMap $ foldr foldFn True . Map.toList
|
||||
-- no room is overfull
|
||||
let userProperties :: Map UserId (UserProperties, Maybe ExamOccurrenceId)
|
||||
userProperties = Map.map (first extractProperties) users
|
||||
@ -107,10 +112,8 @@ spec = do
|
||||
-- all users match the shown ranges
|
||||
shouldSatisfy (rule, userProperties, result) $ uncurry3 showsCorrectRanges
|
||||
-- | generate users without any pre-assigned rooms
|
||||
genUsersWithOccurrences :: ExamOccurrenceRule
|
||||
-> Preselection
|
||||
-> Gen (Map UserId (User, Maybe ExamOccurrenceId), Map ExamOccurrenceId Natural)
|
||||
genUsersWithOccurrences rule preselection = do
|
||||
genUsersWithOccurrences :: Preselection -> Gen (Map UserId (User, Maybe ExamOccurrenceId), Map ExamOccurrenceId Natural)
|
||||
genUsersWithOccurrences preselection = do
|
||||
rawUsers <- scale (50 *) $ listOf1 $ Entity <$> arbitrary <*> arbitrary
|
||||
occurrences <- genOccurrences $ length rawUsers
|
||||
-- user surnames anpassen, sodass interessante instanz
|
||||
@ -120,16 +123,7 @@ spec = do
|
||||
NoPreselection -> pure Nothing
|
||||
SomePreselection -> frequency [(97, pure Nothing), (3, elements $ map Just $ Map.keys occurrences)]
|
||||
pure (entityKey, (entityVal {userSurname}, assignedRoom))
|
||||
case rule of
|
||||
ExamRoomMatriculation | null matrUsersList -> discard
|
||||
where
|
||||
-- copied directly from examAutoOccurrence, user' definition
|
||||
-- FIXME if it is empty an error is raised
|
||||
matrUsersList = [ (map CI.mk $ unpack matriculation', Set.singleton uid)
|
||||
| (uid, (User{..}, Nothing)) <- Map.toList users
|
||||
, matriculation' <- userMatrikelnummer ^.. _Just . filtered (not . null)
|
||||
]
|
||||
_rule -> pure (users, occurrences)
|
||||
pure (users, occurrences)
|
||||
genOccurrences :: Int -> Gen (Map ExamOccurrenceId Natural)
|
||||
genOccurrences numUsers = do
|
||||
-- TODO is this realistic?
|
||||
|
||||
Loading…
Reference in New Issue
Block a user