chore(test): property test with preselected users
This commit is contained in:
parent
5de8f0ae23
commit
4d9ef2a64d
@ -41,29 +41,47 @@ instance Arbitrary ExamOccurrence where
|
|||||||
spec :: Spec
|
spec :: Spec
|
||||||
spec = do
|
spec = do
|
||||||
describe "examAutoOccurrence" $ do
|
describe "examAutoOccurrence" $ do
|
||||||
prop "Surname, no Nudges, no preselection" $ do -- TODO
|
describe "Surname" $ do
|
||||||
users <- genUsers
|
let rule :: ExamOccurrenceRule
|
||||||
occurrences <- genOccurrences $ length users
|
rule = ExamRoomSurname
|
||||||
let result@(_maybeMapping, userMap) = examAutoOccurrence seed rule config occurrences users
|
prop "no Nudges, no preselection" $ do
|
||||||
pure $ ioProperty $ do
|
(users, occurrences) <- genUsersWithOccurrences False
|
||||||
-- every user got assigned a room
|
let result@(_maybeMapping, userMap) = examAutoOccurrence seed rule config occurrences users
|
||||||
shouldBe (length userMap) (length users)
|
pure $ ioProperty $ do
|
||||||
shouldSatisfy userMap $ all isJust
|
-- every user got assigned a room
|
||||||
-- no room is overfull
|
shouldBe (length userMap) (length users)
|
||||||
shouldSatisfy userMap $ fitsInRooms occurrences
|
shouldSatisfy userMap $ all isJust
|
||||||
-- all users match the shown ranges
|
-- no room is overfull
|
||||||
shouldSatisfy result $ showsCorrectRanges users
|
shouldSatisfy (occurrences, userMap) $ uncurry fitsInRooms
|
||||||
|
-- all users match the shown ranges
|
||||||
|
shouldSatisfy (users, result) $ uncurry showsCorrectRanges
|
||||||
|
prop "no Nudges, some preselected" $ do
|
||||||
|
(users, occurrences) <- genUsersWithOccurrences True
|
||||||
|
let result@(_maybeMapping, userMap) = examAutoOccurrence seed rule config occurrences users
|
||||||
|
pure $ ioProperty $ do
|
||||||
|
-- every user got assigned a room
|
||||||
|
shouldBe (length userMap) (length users)
|
||||||
|
shouldSatisfy userMap $ all isJust
|
||||||
|
-- no room is overfull
|
||||||
|
shouldSatisfy (occurrences, userMap) $ uncurry fitsInRooms
|
||||||
|
-- all users match the shown ranges or their preselection
|
||||||
|
shouldSatisfy (users, result) $ uncurry showsCorrectRanges
|
||||||
-- TODO test with some users fixed/preselected to certain rooms
|
-- TODO test with some users fixed/preselected to certain rooms
|
||||||
-- TODO test with ExamRoomManual, ExamRoomFifo, (ExamRoomSurname), ExamRoomMatriculation, ExamRoomRandom
|
-- TODO test with ExamRoomManual, ExamRoomFifo, (ExamRoomSurname), ExamRoomMatriculation, ExamRoomRandom
|
||||||
where
|
where
|
||||||
-- | generate users without any pre-assigned rooms
|
-- | generate users without any pre-assigned rooms
|
||||||
genUsers :: Gen (Map UserId (User, Maybe ExamOccurrenceId))
|
genUsersWithOccurrences :: Bool -> Gen (Map UserId (User, Maybe ExamOccurrenceId), Map ExamOccurrenceId Natural)
|
||||||
genUsers = do
|
genUsersWithOccurrences assignSomeUsers = do
|
||||||
rawUsers <- listOf1 $ Entity <$> arbitrary <*> arbitrary
|
rawUsers <- listOf1 $ Entity <$> arbitrary <*> arbitrary
|
||||||
|
occurrences <- genOccurrences $ length rawUsers
|
||||||
-- user surnames anpassen, sodass interessante instanz
|
-- user surnames anpassen, sodass interessante instanz
|
||||||
fmap Map.fromList $ forM rawUsers $ \Entity {entityKey, entityVal} -> do
|
users <- fmap Map.fromList $ forM rawUsers $ \Entity {entityKey, entityVal} -> do
|
||||||
userSurname <- elements surnames
|
userSurname <- elements surnames
|
||||||
pure (entityKey, (entityVal {userSurname}, Nothing))
|
assignedRoom <- if assignSomeUsers
|
||||||
|
then frequency [(97, pure Nothing), (3, elements $ map Just $ Map.keys occurrences)]
|
||||||
|
else pure Nothing
|
||||||
|
pure (entityKey, (entityVal {userSurname}, assignedRoom))
|
||||||
|
pure (users, occurrences)
|
||||||
genOccurrences :: Int -> Gen (Map ExamOccurrenceId Natural)
|
genOccurrences :: Int -> Gen (Map ExamOccurrenceId Natural)
|
||||||
genOccurrences numUsers = do
|
genOccurrences numUsers = do
|
||||||
-- TODO is this realistic?
|
-- TODO is this realistic?
|
||||||
@ -89,8 +107,6 @@ spec = do
|
|||||||
]
|
]
|
||||||
seed :: ()
|
seed :: ()
|
||||||
seed = ()
|
seed = ()
|
||||||
rule :: ExamOccurrenceRule
|
|
||||||
rule = ExamRoomSurname
|
|
||||||
config :: ExamAutoOccurrenceConfig
|
config :: ExamAutoOccurrenceConfig
|
||||||
config = def
|
config = def
|
||||||
-- TODO adjust with different nudges, depended on occurrences list/map
|
-- TODO adjust with different nudges, depended on occurrences list/map
|
||||||
@ -117,13 +133,15 @@ spec = do
|
|||||||
-> (Maybe (ExamOccurrenceMapping ExamOccurrenceId), Map UserId (Maybe ExamOccurrenceId))
|
-> (Maybe (ExamOccurrenceMapping ExamOccurrenceId), Map UserId (Maybe ExamOccurrenceId))
|
||||||
-> Bool
|
-> Bool
|
||||||
showsCorrectRanges _users (Nothing, _userMap) = False
|
showsCorrectRanges _users (Nothing, _userMap) = False
|
||||||
showsCorrectRanges users (Just (examOccurrenceMappingMapping -> m), userMap)
|
showsCorrectRanges users (Just (examOccurrenceMappingMapping -> mappingRanges), userMap)
|
||||||
= all userFitsInRange $ Map.toAscList $ occurrenceMap userMap
|
= all userFitsInRange $ Map.toAscList $ occurrenceMap userMap
|
||||||
where
|
where
|
||||||
userFitsInRange :: (ExamOccurrenceId, [UserId]) -> Bool
|
userFitsInRange :: (ExamOccurrenceId, [UserId]) -> Bool
|
||||||
userFitsInRange (roomId, userIds) = flip all userIds $ \userId ->
|
userFitsInRange (roomId, userIds) = flip all userIds $ \userId ->
|
||||||
case (Map.lookup roomId m, Map.lookup userId users) of
|
case (Map.lookup roomId mappingRanges, Map.lookup userId users) of
|
||||||
(Just ranges, Just (User {userSurname}, _fixedRoom))
|
(_maybeRanges, Just (User {}, Just fixedRoomId))
|
||||||
|
-> roomId == fixedRoomId
|
||||||
|
(Just ranges, Just (User {userSurname}, Nothing))
|
||||||
-> any fitsInRange ranges
|
-> any fitsInRange ranges
|
||||||
where
|
where
|
||||||
ciSurname :: [CI Char]
|
ciSurname :: [CI Char]
|
||||||
|
|||||||
Reference in New Issue
Block a user