diff options
author | Don Stewart <dons@cse.unsw.edu.au> | 2007-04-29 05:58:23 +0200 |
---|---|---|
committer | Don Stewart <dons@cse.unsw.edu.au> | 2007-04-29 05:58:23 +0200 |
commit | 67b421d09c4a2aba4f3175c7771ff4724aa66334 (patch) | |
tree | 9ab4e188588c6abdf9bd09abd3bfc3b3df62d3cf | |
parent | b510eb1321800274da9d6e38ec89ced9c46b8430 (diff) | |
download | metatile-67b421d09c4a2aba4f3175c7771ff4724aa66334.tar metatile-67b421d09c4a2aba4f3175c7771ff4724aa66334.zip |
add fromList to Properties.hs
darcs-hash:20070429035823-9c5c1-37dc9df3086bb7672eeea83e4add3aeb4ffa0bd4
-rw-r--r-- | tests/Properties.hs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/Properties.hs b/tests/Properties.hs index c55a632..83aba87 100644 --- a/tests/Properties.hs +++ b/tests/Properties.hs @@ -15,12 +15,31 @@ import Test.QuickCheck hiding (promote) import System.IO import System.Random import Text.Printf -import Data.List (nub,sort,group,sort,intersperse) +import Data.List (nub,sort,group,sort,intersperse,genericLength) import Data.Map (keys,elems) -- --------------------------------------------------------------------- -- QuickCheck properties for the StackSet + +-- | fromList. Build a new StackSet from a list of list of elements, +-- keeping track of the currently focused workspace, and the total +-- number of workspaces. If there are duplicates in the list, the last +-- occurence wins. +fromList :: (Integral i, Integral j, Ord a) => (i, Int,[[a]]) -> StackSet i j a +fromList (_,_,[]) = error "Cannot build a StackSet from an empty list" + +fromList (n,m,xs) | n < 0 || n >= genericLength xs + = error $ "Cursor index is out of range: " ++ show (n, length xs) + | m < 1 || m > genericLength xs + = error $ "Can't have more screens than workspaces: " ++ show (m, length xs) + +fromList (o,m,xs) = view o $ foldr (\(i,ys) s -> + foldr (\a t -> insert a i t) s ys) + (empty (length xs) m) (zip [0..] xs) + +-- --------------------------------------------------------------------- + -- | Height of stack 'n' height :: Int -> T -> Int height i w = length (index i w) |