From 67b421d09c4a2aba4f3175c7771ff4724aa66334 Mon Sep 17 00:00:00 2001 From: Don Stewart Date: Sun, 29 Apr 2007 05:58:23 +0200 Subject: add fromList to Properties.hs darcs-hash:20070429035823-9c5c1-37dc9df3086bb7672eeea83e4add3aeb4ffa0bd4 --- tests/Properties.hs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests') 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) -- cgit v1.2.3