From 9660a7a64c749e181d2114cc4b66a8aa4f88be0f Mon Sep 17 00:00:00 2001 From: Adam Vogt Date: Fri, 2 May 2014 20:01:46 +0200 Subject: update testsuite (mostly due Jesper Reenberg) Ignore-this: a5e926aa4e397e70d56e3c9db7108d5b * use quickcheck2 * run them using cabal's test-suite field * split up Properties into separate files darcs-hash:20140502180146-1499c-dc8c09c3ec76a42a0e146925adce960435dc81db.gz --- tests/Utils.hs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/Utils.hs (limited to 'tests/Utils.hs') diff --git a/tests/Utils.hs b/tests/Utils.hs new file mode 100644 index 0000000..2d9df81 --- /dev/null +++ b/tests/Utils.hs @@ -0,0 +1,39 @@ +module Utils where + +import XMonad.StackSet hiding (filter) +import Graphics.X11.Xlib.Types (Rectangle(..)) +import Data.List (sortBy) + +-- Useful operation, the non-local workspaces +hidden_spaces x = map workspace (visible x) ++ hidden x + + +-- normalise workspace list +normal s = s { hidden = sortBy g (hidden s), visible = sortBy f (visible s) } + where + f = \a b -> tag (workspace a) `compare` tag (workspace b) + g = \a b -> tag a `compare` tag b + + +noOverlaps [] = True +noOverlaps [_] = True +noOverlaps xs = and [ verts a `notOverlap` verts b + | a <- xs + , b <- filter (a /=) xs + ] + where + verts (Rectangle a b w h) = (a,b,a + fromIntegral w - 1, b + fromIntegral h - 1) + + notOverlap (left1,bottom1,right1,top1) + (left2,bottom2,right2,top2) + = (top1 < bottom2 || top2 < bottom1) + || (right1 < left2 || right2 < left1) + + +applyN :: (Integral n) => Maybe n -> (a -> a) -> a -> a +applyN Nothing f v = v +applyN (Just 0) f v = v +applyN (Just n) f v = applyN (Just $ n-1) f (f v) + + +tags x = map tag $ workspaces x -- cgit v1.2.3