diff --git a/tests/Main.hs b/tests/Main.hs index 3b920f5c..ff9122bc 100644 --- a/tests/Main.hs +++ b/tests/Main.hs @@ -32,7 +32,7 @@ main = hspec $ do prop "prop_rotate_some_anchors" $ RotateSome.prop_rotate_some_anchors prop "prop_rotate_some_rotate" $ RotateSome.prop_rotate_some_rotate prop "prop_rotate_some_focus" $ RotateSome.prop_rotate_some_focus - context "SwapWorkspaces" $ modifyMaxDiscardRatio (const 100) $ do + context "SwapWorkspaces" $ do prop "prop_double_swap" $ SwapWorkspaces.prop_double_swap prop "prop_invalid_swap" $ SwapWorkspaces.prop_invalid_swap prop "prop_swap_only_two" $ SwapWorkspaces.prop_swap_only_two diff --git a/tests/SwapWorkspaces.hs b/tests/SwapWorkspaces.hs index 1a70c030..f30cedad 100644 --- a/tests/SwapWorkspaces.hs +++ b/tests/SwapWorkspaces.hs @@ -10,15 +10,17 @@ import XMonad.Actions.SwapWorkspaces -- Ensures that no "loss of information" can happen from a swap. -prop_double_swap (ss :: T) (NonNegative t1) (NonNegative t2) = - t1 `tagMember` ss && t2 `tagMember` ss ==> - ss == swap (swap ss) - where swap = swapWorkspaces t1 t2 +prop_double_swap (ss :: T) = do + t1 <- arbitraryTag ss + t2 <- arbitraryTag ss + let swap = swapWorkspaces t1 t2 + return $ ss == swap (swap ss) -- Degrade nicely when given invalid data. -prop_invalid_swap (ss :: T) (NonNegative t1) (NonNegative t2) = - not (t1 `tagMember` ss || t2 `tagMember` ss) ==> - ss == swapWorkspaces t1 t2 ss +prop_invalid_swap (ss :: T) = do + t1 <- arbitrary `suchThat` (not . (`tagMember` ss)) + t2 <- arbitrary `suchThat` (not . (`tagMember` ss)) + return $ ss == swapWorkspaces t1 t2 ss -- This doesn't pass yet. Probably should. -- prop_half_invalid_swap (ss :: T) (NonNegative t1) (NonNegative t2) = @@ -32,14 +34,15 @@ zipWorkspacesWith f s t = f (workspace $ current s) (workspace $ current t) : zipWith f (hidden s) (hidden t) -- Swap only modifies the workspaces tagged t1 and t2 -- leaves all others alone. -prop_swap_only_two (ss :: T) (NonNegative t1) (NonNegative t2) = - t1 `tagMember` ss && t2 `tagMember` ss ==> - and $ zipWorkspacesWith mostlyEqual ss (swapWorkspaces t1 t2 ss) - where mostlyEqual w1 w2 = map tag [w1, w2] `elem` [[t1, t2], [t2, t1]] || w1 == w2 +prop_swap_only_two (ss :: T) = do + t1 <- arbitraryTag ss + t2 <- arbitraryTag ss + let mostlyEqual w1 w2 = map tag [w1, w2] `elem` [[t1, t2], [t2, t1]] || w1 == w2 + return $ and $ zipWorkspacesWith mostlyEqual ss (swapWorkspaces t1 t2 ss) -- swapWithCurrent stays on current -prop_swap_with_current (ss :: T) (NonNegative t) = - t `tagMember` ss ==> - layout before == layout after && stack before == stack after - where before = workspace $ current ss - after = workspace $ current $ swapWithCurrent t ss +prop_swap_with_current (ss :: T) = do + t <- arbitraryTag ss + let before = workspace $ current ss + let after = workspace $ current $ swapWithCurrent t ss + return $ layout before == layout after && stack before == stack after