packages feed

dequeue 0.1.7 → 0.1.8

raw patch · 2 files changed

+32/−17 lines, 2 files

Files

dequeue.cabal view
@@ -1,7 +1,7 @@ Build-Type: Simple Name: dequeue Category: Data Structures-Version: 0.1.7+Version: 0.1.8 Cabal-Version: >= 1.2 Synopsis: A typeclass and an implementation for double-ended queues. Description:@@ -26,4 +26,5 @@     Main-Is: Tests.hs     Hs-Source-Dirs: src     Build-Depends: base < 5, QuickCheck+    GHC-Options: -Wall 
src/Data/Dequeue.hs view
@@ -67,6 +67,10 @@     empty :: q a     -- | Returns 'True' if this queue is empty.     null :: q a -> Bool+#if !MIN_VERSION_base(4,8,0)+        -- | Returns the number of elements in this queue.+    length :: q a -> Int+#endif     -- | Returns the item on the front of the queue.     first :: q a -> Maybe a     -- | Returns the item on the end of the queue.@@ -197,12 +201,17 @@     foldl f a (BankersDequeue _ front _ rear) = foldl f a (front ++ reverse rear)     foldr1 f (BankersDequeue _ front _ rear) = foldr1 f (front ++ reverse rear)     foldl1 f (BankersDequeue _ front _ rear) = foldl1 f (front ++ reverse rear)+#if MIN_VERSION_base(4,8,0)     length (BankersDequeue sizeF _ sizeR _) = sizeF + sizeR+#endif  instance Dequeue BankersDequeue where     empty = BankersDequeue 0 [] 0 []     null (BankersDequeue 0 [] 0 []) = True     null _ = False+#if !MIN_VERSION_base(4,8,0)+    length (BankersDequeue sizeF _ sizeR _) = sizeF + sizeR+#endif     first (BankersDequeue _ [] _ [x]) = Just x     first (BankersDequeue _ front _ _) =  headMay front     last (BankersDequeue _ [x] _ []) = Just x@@ -316,35 +325,40 @@  -- | Validates that a 'BankersDequeue' remains balanced despite repeated --   pushes to the front.-prop_push_front_bq_balance :: BankersDequeue Int -> Int -> Bool-prop_push_front_bq_balance q count =-    let push _ = (flip pushFront) 0-        q' = foldr push q [0 .. count] in+prop_push_front_bq_balance :: BankersDequeue Int -> Int -> Gen Prop+prop_push_front_bq_balance q count = count < qcLimit ==>+    let push queue _ = pushFront queue 0+        q' = foldl push q [0 .. count] in     balanced q'  -- | Validates that a 'BankersDequeue' remains balanced despite repeated --   pushes to the back.-prop_push_back_bq_balance :: BankersDequeue Int -> Int -> Bool-prop_push_back_bq_balance q count =-    let push _ = (flip pushBack) 0-        q' = foldr push q [0 .. count] in+prop_push_back_bq_balance :: BankersDequeue Int -> Int -> Gen Prop+prop_push_back_bq_balance q count = count < qcLimit ==>+    let push queue _ = pushBack queue 0+        q' = foldl push q [0 .. count] in     balanced q'  -- | Validates that a 'BankersDequeue' remains balanced despite repeated --   pops from the front.-prop_pop_front_bq_balance :: BankersDequeue Int -> Int -> Bool-prop_pop_front_bq_balance q count =-    let pop _ queue = (fromJustDef queue . liftM snd . popFront) queue-        q' = foldr pop q [0 .. count] in+prop_pop_front_bq_balance :: BankersDequeue Int -> Int -> Gen Prop+prop_pop_front_bq_balance q count = count < qcLimit ==>+    let pop queue _ = (fromJustDef queue . liftM snd . popFront) queue+        q' = foldl pop q [0 .. count] in     balanced q'  -- | Validates that a 'BankersDequeue' remains balanced despite repeated --   pops from the back.-prop_pop_back_bq_balance :: BankersDequeue Int -> Int -> Bool-prop_pop_back_bq_balance q count =-    let pop _ queue = (fromJustDef queue . liftM snd . popBack) queue-        q' = foldr pop q [0 .. count] in+prop_pop_back_bq_balance :: BankersDequeue Int -> Int -> Gen Prop+prop_pop_back_bq_balance q count = count < qcLimit ==>+    let pop queue _ = (fromJustDef queue . liftM snd . popBack) queue+        q' = foldl pop q [0 .. count] in     balanced q'++-- | Limit quickcheck tests to this size of dequeue, to keep test time and+--   memory usage reasonable.+qcLimit :: Int+qcLimit = 10 ^ (6 :: Int)  -- | Validates that a 'BankersDequeue' has read and show instances that are --   the inverse of each other.