mirror of
https://github.com/xmonad/xmonad.git
synced 2025-08-01 12:41:53 -07:00
fromList/toList have # of screens + another QC property
This commit is contained in:
19
StackSet.hs
19
StackSet.hs
@@ -80,20 +80,21 @@ size = M.size . stacks
|
|||||||
|
|
||||||
-- | fromList. Build a new StackSet from a list of list of elements
|
-- | fromList. Build a new StackSet from a list of list of elements
|
||||||
-- If there are duplicates in the list, the last occurence wins.
|
-- If there are duplicates in the list, the last occurence wins.
|
||||||
-- FIXME: This always makes a StackSet with 1 screen.
|
fromList :: Ord a => (Int,Int,[[a]]) -> StackSet a
|
||||||
fromList :: Ord a => (Int,[[a]]) -> StackSet a
|
fromList (_,_,[]) = error "Cannot build a StackSet from an empty list"
|
||||||
fromList (_,[]) = error "Cannot build a StackSet from an empty list"
|
|
||||||
|
|
||||||
fromList (n,xs) | n < 0 || n >= length xs
|
fromList (n,m,xs) | n < 0 || n >= length xs
|
||||||
= error $ "Cursor index is out of range: " ++ show (n, length xs)
|
= error $ "Cursor index is out of range: " ++ show (n, length xs)
|
||||||
|
| m < 1 || m > length xs
|
||||||
|
= error $ "Can't have more screens than workspaces: " ++ show (m, length xs)
|
||||||
|
|
||||||
fromList (o,xs) = view o $ foldr (\(i,ys) s ->
|
fromList (o,m,xs) = view o $ foldr (\(i,ys) s ->
|
||||||
foldr (\a t -> insert a i t) s ys)
|
foldr (\a t -> insert a i t) s ys)
|
||||||
(empty (length xs) 1) (zip [0..] xs)
|
(empty (length xs) m) (zip [0..] xs)
|
||||||
|
|
||||||
-- | toList. Flatten a stackset to a list of lists
|
-- | toList. Flatten a stackset to a list of lists
|
||||||
toList :: StackSet a -> (Int,[[a]])
|
toList :: StackSet a -> (Int,Int,[[a]])
|
||||||
toList x = (current x, map snd $ M.toList (stacks x))
|
toList x = (current x, M.size $ screen2ws x, map snd $ M.toList (stacks x))
|
||||||
|
|
||||||
-- | Push. Insert an element onto the top of the current stack.
|
-- | Push. Insert an element onto the top of the current stack.
|
||||||
-- If the element is already in the current stack, it is moved to the top.
|
-- If the element is already in the current stack, it is moved to the top.
|
||||||
|
@@ -24,8 +24,9 @@ instance (Ord a, Arbitrary a) => Arbitrary (StackSet a) where
|
|||||||
arbitrary = do
|
arbitrary = do
|
||||||
sz <- choose (1,20)
|
sz <- choose (1,20)
|
||||||
n <- choose (0,sz-1)
|
n <- choose (0,sz-1)
|
||||||
|
sc <- choose (1,sz)
|
||||||
ls <- vector sz
|
ls <- vector sz
|
||||||
return $ fromList (n,ls)
|
return $ fromList (n,sc,ls)
|
||||||
coarbitrary = error "no coarbitrary for StackSet"
|
coarbitrary = error "no coarbitrary for StackSet"
|
||||||
|
|
||||||
prop_id x = fromList (toList x) == x
|
prop_id x = fromList (toList x) == x
|
||||||
@@ -96,6 +97,12 @@ prop_ws2screen_screen2ws x = (ws == ws') && (sc == sc')
|
|||||||
sc' = sort . elems $ ws2screen x
|
sc' = sort . elems $ ws2screen x
|
||||||
_ = x :: T
|
_ = x :: T
|
||||||
|
|
||||||
|
prop_screenworkspace x = all test [0..((size x)-1)]
|
||||||
|
where test ws = case screen ws x of
|
||||||
|
Nothing -> True
|
||||||
|
Just sc -> workspace sc x == Just ws
|
||||||
|
_ = x :: T
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
@@ -122,6 +129,7 @@ main = do
|
|||||||
,("fullcache ", mytest prop_fullcache)
|
,("fullcache ", mytest prop_fullcache)
|
||||||
,("currentwsvisible ", mytest prop_currentwsvisible)
|
,("currentwsvisible ", mytest prop_currentwsvisible)
|
||||||
,("ws screen mapping", mytest prop_ws2screen_screen2ws)
|
,("ws screen mapping", mytest prop_ws2screen_screen2ws)
|
||||||
|
,("screen/workspace ", mytest prop_screenworkspace)
|
||||||
]
|
]
|
||||||
|
|
||||||
debug = False
|
debug = False
|
||||||
|
Reference in New Issue
Block a user