mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 03:20:21 -07:00
Test that update preserves invariants of Selection
This commit is contained in:
parent
f0e835ebe2
commit
cd43a200bf
@ -25,7 +25,7 @@ import XMonad.StackSet
|
|||||||
import XMonad.Layout.LayoutModifier
|
import XMonad.Layout.LayoutModifier
|
||||||
import Control.Applicative ((<$>))
|
import Control.Applicative ((<$>))
|
||||||
|
|
||||||
-- invariant: 0 <= nMaster <= start; 0 <= nRest
|
-- invariant: 0 <= nMaster <= start; 1 <= nRest
|
||||||
data Selection = Sel { nMaster :: Int, start :: Int, nRest :: Int }
|
data Selection = Sel { nMaster :: Int, start :: Int, nRest :: Int }
|
||||||
deriving (Read, Show, Eq)
|
deriving (Read, Show, Eq)
|
||||||
|
|
||||||
|
@ -28,13 +28,11 @@ arbPos = (+1) . abs <$> arbitrary
|
|||||||
-- (when the selection is normalized)
|
-- (when the selection is normalized)
|
||||||
prop_select_length sel (stk :: Stack Int) =
|
prop_select_length sel (stk :: Stack Int) =
|
||||||
(length . integrate $ select sel' stk) == ((nMaster sel' + nRest sel') `min` length (integrate stk))
|
(length . integrate $ select sel' stk) == ((nMaster sel' + nRest sel') `min` length (integrate stk))
|
||||||
where
|
where sel' = update sel stk
|
||||||
sel' = update sel stk
|
|
||||||
|
|
||||||
-- update normalizes selections (is idempotent)
|
-- update normalizes selections (is idempotent)
|
||||||
prop_update_idem sel (stk :: Stack Int) = sel' == update sel' stk
|
prop_update_idem sel (stk :: Stack Int) = sel' == update sel' stk
|
||||||
where
|
where sel' = update sel stk
|
||||||
sel' = update sel stk
|
|
||||||
|
|
||||||
-- select selects the master pane
|
-- select selects the master pane
|
||||||
prop_select_master sel (stk :: Stack Int) =
|
prop_select_master sel (stk :: Stack Int) =
|
||||||
@ -42,8 +40,7 @@ prop_select_master sel (stk :: Stack Int) =
|
|||||||
|
|
||||||
-- the focus should always be selected in normalized selections
|
-- the focus should always be selected in normalized selections
|
||||||
prop_select_focus sel (stk :: Stack Int) = focus stk == (focus $ select sel' stk)
|
prop_select_focus sel (stk :: Stack Int) = focus stk == (focus $ select sel' stk)
|
||||||
where
|
where sel' = update sel stk
|
||||||
sel' = update sel stk
|
|
||||||
|
|
||||||
-- select doesn't change order (or duplicate elements)
|
-- select doesn't change order (or duplicate elements)
|
||||||
-- relies on the Arbitrary instance for Stack Int generating increasing stacks
|
-- relies on the Arbitrary instance for Stack Int generating increasing stacks
|
||||||
@ -51,6 +48,12 @@ prop_select_increasing sel (stk :: Stack Int) =
|
|||||||
let res = integrate $ select sel stk
|
let res = integrate $ select sel stk
|
||||||
in and . zipWith (<) res $ tail res
|
in and . zipWith (<) res $ tail res
|
||||||
|
|
||||||
|
-- update preserves invariants on selections
|
||||||
|
prop_update_nm sel (stk :: Stack Int) = nMaster (update sel stk) >= 0
|
||||||
|
prop_update_start sel (stk :: Stack Int) = nMaster sel' <= start sel'
|
||||||
|
where sel' = update sel stk
|
||||||
|
prop_update_nr sel (stk :: Stack Int) = nRest (update sel stk) >= 0
|
||||||
|
|
||||||
-- moving the focus to a window that's already selected doesn't change the selection
|
-- moving the focus to a window that's already selected doesn't change the selection
|
||||||
prop_update_focus_up sel (stk :: Stack Int) x' =
|
prop_update_focus_up sel (stk :: Stack Int) x' =
|
||||||
(length (up stk) >= x) && ((up stk !! (x-1)) `elem` integrate stk') ==>
|
(length (up stk) >= x) && ((up stk !! (x-1)) `elem` integrate stk') ==>
|
||||||
@ -68,7 +71,5 @@ prop_update_focus_down sel (stk :: Stack Int) x' =
|
|||||||
sel' = update sel stk
|
sel' = update sel stk
|
||||||
stk' = select sel' stk
|
stk' = select sel' stk
|
||||||
|
|
||||||
upSel sel stk = let sel' = update sel stk in (sel', select sel' stk)
|
|
||||||
|
|
||||||
focusUp stk = stk { up=tail (up stk), focus=head (up stk), down=focus stk:down stk }
|
focusUp stk = stk { up=tail (up stk), focus=head (up stk), down=focus stk:down stk }
|
||||||
focusDown stk = stk { down=tail (down stk), focus=head (down stk), up=focus stk:up stk }
|
focusDown stk = stk { down=tail (down stk), focus=head (down stk), up=focus stk:up stk }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user