From 36999532c28c2630d1a36d10c8337cd5c35ab6bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20P=C3=A4tzel?= Date: Sat, 19 Oct 2019 15:56:44 +0200 Subject: [PATCH] Fix Seminar.switch bug if (i' == j') --- src/Seminar.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Seminar.hs b/src/Seminar.hs index d787cc6..8af77cc 100644 --- a/src/Seminar.hs +++ b/src/Seminar.hs @@ -146,8 +146,12 @@ instance Individual I where where f x v1 v2 i = if i <= x then v1 else v2 +{-| +Swaps topics at positions 'i'' and 'j'' in the given assignment. +-} switch :: Int -> Int -> Assignment -> Assignment switch i' j' xs + | i' == j' = xs | 0 <= i' && i' < length xs && 0 <= j' && j' < length xs = let i = min i' j' j = max i' j' @@ -159,6 +163,8 @@ switch i' j' xs in left ++ [(fst ei, snd ej)] ++ middle ++ [(fst ej, snd ei)] ++ right | otherwise = xs +prop_switch_keepsValid i j xs = valid xs == valid (switch i j xs) + {-| Whether the given assignment is valid (every student occurs at most once, as does every topic).