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/Properties/Layout/Tall.hs | 116 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 tests/Properties/Layout/Tall.hs (limited to 'tests/Properties/Layout/Tall.hs') diff --git a/tests/Properties/Layout/Tall.hs b/tests/Properties/Layout/Tall.hs new file mode 100644 index 0000000..7464184 --- /dev/null +++ b/tests/Properties/Layout/Tall.hs @@ -0,0 +1,116 @@ +{-# LANGUAGE ScopedTypeVariables #-} +module Properties.Layout.Tall where + +import Test.QuickCheck +import Instances +import Utils + +import XMonad.StackSet hiding (filter) +import XMonad.Core +import XMonad.Layout + +import Graphics.X11.Xlib.Types (Rectangle(..)) + +import Data.Maybe +import Data.List (sort) +import Data.Ratio + +------------------------------------------------------------------------ +-- The Tall layout + +-- 1 window should always be tiled fullscreen +prop_tile_fullscreen rect = tile pct rect 1 1 == [rect] + where pct = 1/2 + +-- multiple windows +prop_tile_non_overlap rect windows nmaster = noOverlaps (tile pct rect nmaster windows) + where _ = rect :: Rectangle + pct = 3 % 100 + +-- splitting horizontally yields sensible results +prop_split_hoziontal (NonNegative n) x = + sum (map rect_width xs) == rect_width x + && + all (== rect_height x) (map rect_height xs) + && + (map rect_x xs) == (sort $ map rect_x xs) + + where + xs = splitHorizontally n x + +-- splitting horizontally yields sensible results +prop_splitVertically (r :: Rational) x = + + rect_x x == rect_x a && rect_x x == rect_x b + && + rect_width x == rect_width a && rect_width x == rect_width b + where + (a,b) = splitVerticallyBy r x + + +-- pureLayout works. +prop_purelayout_tall n r1 r2 rect = do + x <- (arbitrary :: Gen T) `suchThat` (isJust . peek) + let layout = Tall n r1 r2 + st = fromJust . stack . workspace . current $ x + ts = pureLayout layout rect st + return $ + length ts == length (index x) + && + noOverlaps (map snd ts) + && + description layout == "Tall" + + +-- Test message handling of Tall + +-- what happens when we send a Shrink message to Tall +prop_shrink_tall (NonNegative n) (NonZero (NonNegative delta)) (NonNegative frac) = + n == n' && delta == delta' -- these state components are unchanged + && frac' <= frac && (if frac' < frac then frac' == 0 || frac' == frac - delta + else frac == 0 ) + -- remaining fraction should shrink + where + l1 = Tall n delta frac + Just l2@(Tall n' delta' frac') = l1 `pureMessage` (SomeMessage Shrink) + -- pureMessage :: layout a -> SomeMessage -> Maybe (layout a) + + +-- what happens when we send a Shrink message to Tall +prop_expand_tall (NonNegative n) + (NonZero (NonNegative delta)) + (NonNegative n1) + (NonZero (NonNegative d1)) = + + n == n' + && delta == delta' -- these state components are unchanged + && frac' >= frac + && (if frac' > frac + then frac' == 1 || frac' == frac + delta + else frac == 1 ) + + -- remaining fraction should shrink + where + frac = min 1 (n1 % d1) + l1 = Tall n delta frac + Just l2@(Tall n' delta' frac') = l1 `pureMessage` (SomeMessage Expand) + -- pureMessage :: layout a -> SomeMessage -> Maybe (layout a) + +-- what happens when we send an IncMaster message to Tall +prop_incmaster_tall (NonNegative n) (NonZero (NonNegative delta)) (NonNegative frac) + (NonNegative k) = + delta == delta' && frac == frac' && n' == n + k + where + l1 = Tall n delta frac + Just l2@(Tall n' delta' frac') = l1 `pureMessage` (SomeMessage (IncMasterN k)) + -- pureMessage :: layout a -> SomeMessage -> Maybe (layout a) + + + + -- toMessage LT = SomeMessage Shrink + -- toMessage EQ = SomeMessage Expand + -- toMessage GT = SomeMessage (IncMasterN 1) + + +prop_desc_mirror n r1 r2 = description (Mirror $! t) == "Mirror Tall" + where t = Tall n r1 r2 -- cgit v1.2.3