deque 0.2.5 → 0.2.6
raw patch · 3 files changed
+85/−37 lines, 3 filesdep +QuickCheckdep +dequedep +quickcheck-instancesPVP ok
version bump matches the API change (PVP)
Dependencies added: QuickCheck, deque, quickcheck-instances, rerebase, tasty, tasty-hunit, tasty-quickcheck
API changes (from Hackage documentation)
+ Deque: dropWhile :: (a -> Bool) -> Deque a -> Deque a
Files
- deque.cabal +33/−34
- library/Deque.hs +18/−3
- test/Main.hs +34/−0
deque.cabal view
@@ -1,45 +1,44 @@-name:- deque-version:- 0.2.5-synopsis:- Double-ended queue+name: deque+version: 0.2.6+synopsis: Double-ended queue description: An implementation of Double-Ended Queue (aka Dequeue or Deque) based on the head-tail linked list.-homepage:- https://github.com/nikita-volkov/deque-bug-reports:- https://github.com/nikita-volkov/deque/issues-author:- Nikita Volkov <nikita.y.volkov@mail.ru>-maintainer:- Nikita Volkov <nikita.y.volkov@mail.ru>-copyright:- (c) 2016, Nikita Volkov-license:- MIT-license-file:- LICENSE-build-type:- Simple-cabal-version:- >=1.10+homepage: https://github.com/nikita-volkov/deque+bug-reports: https://github.com/nikita-volkov/deque/issues+author: Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer: Nikita Volkov <nikita.y.volkov@mail.ru>+copyright: (c) 2016, Nikita Volkov+license: MIT+license-file: LICENSE+build-type: Simple+cabal-version: >=1.10 source-repository head- type:- git- location:- git://github.com/nikita-volkov/deque.git+ type: git+ location: git://github.com/nikita-volkov/deque.git library- hs-source-dirs:- library- default-extensions:- DeriveFunctor, StandaloneDeriving- default-language:- Haskell2010+ hs-source-dirs: library+ default-extensions: DeriveFunctor, ScopedTypeVariables, StandaloneDeriving+ default-language: Haskell2010 exposed-modules: Deque build-depends: base >= 4.9 && < 5++test-suite test+ type: exitcode-stdio-1.0+ hs-source-dirs: test+ default-extensions: DeriveFunctor, ScopedTypeVariables, StandaloneDeriving+ default-language: Haskell2010+ main-is:+ Main.hs+ build-depends:+ deque,+ QuickCheck >=2.8.1 && <3,+ quickcheck-instances >=0.3.11 && <0.4,+ rerebase <2,+ tasty >=0.12 && <2,+ tasty-hunit >=0.9 && <0.11,+ tasty-quickcheck >=0.9 && <0.11
library/Deque.hs view
@@ -30,9 +30,24 @@ takeWhile :: (a -> Bool) -> Deque a -> Deque a takeWhile predicate (Deque snocList consList) = let- newConsList = List.takeWhile predicate consList- newSnocList = List.takeWhile (not . predicate) snocList- in Deque newSnocList newConsList+ newConsList = List.foldr+ (\ a nextState -> if predicate a+ then a : nextState+ else [])+ (List.takeWhile predicate (List.reverse snocList))+ consList+ in Deque [] newConsList++-- |+-- /O(n)/.+-- Drop the first elements satisfying the predicate.+dropWhile :: (a -> Bool) -> Deque a -> Deque a+dropWhile predicate (Deque snocList consList) =+ let+ newConsList = List.dropWhile predicate consList+ in case newConsList of+ [] -> Deque [] (List.dropWhile predicate (List.reverse snocList))+ _ -> Deque snocList newConsList -- | -- /O(1)/, occasionally /O(n)/.
+ test/Main.hs view
@@ -0,0 +1,34 @@+module Main where++import Prelude+import Test.QuickCheck.Instances+import Test.Tasty+import Test.Tasty.Runners+import Test.Tasty.HUnit+import Test.Tasty.QuickCheck+import qualified Test.QuickCheck as QuickCheck+import qualified Test.QuickCheck.Property as QuickCheck+import qualified Deque as Deque+import qualified Data.List as List+++main =+ defaultMain $+ testGroup "List roundtrips" $ let+ testPredicateProperty name listOp dequeOp =+ testProperty name $ \ (list1 :: [Int], list2 :: [Int], threshold :: Int, direction :: Int) -> let+ compare = case mod direction 5 of+ 0 -> (>)+ 1 -> (>=)+ 2 -> (==)+ 3 -> (<=)+ 4 -> (<)+ predicate = compare threshold+ in+ listOp predicate (list1 <> list2) ===+ toList (dequeOp predicate (Deque.Deque (reverse list2) list1))+ in [+ testPredicateProperty "takeWhile" List.takeWhile Deque.takeWhile+ ,+ testPredicateProperty "dropWhile" List.dropWhile Deque.dropWhile+ ]