packages feed

sorted-list 0.2.1.1 → 0.2.1.2

raw patch · 5 files changed

+67/−11 lines, 5 filesdep +QuickCheckdep ~basePVP ok

version bump matches the API change (PVP)

Dependencies added: QuickCheck

Dependency ranges changed: base

API changes (from Hackage documentation)

Files

Data/SortedList.hs view
@@ -217,10 +217,11 @@ {-# INLINE delete #-} delete a (SortedList l) = SortedList $ go l   where-    go (x:xs)-      | x < a = x : go xs-      | x > a = x : xs-      | otherwise = xs+    go (x:xs) =+      case x `compare` a of+        LT -> x : go xs+        GT -> x : xs+        EQ -> xs     go [] = []  -- | Extract the prefix with the given length from a sorted list.
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2015, Daniel Díaz+Copyright (c) 2023, Daniel Casanueva  All rights reserved. @@ -13,7 +13,7 @@       disclaimer in the documentation and/or other materials provided       with the distribution. -    * Neither the name of Daniel Díaz nor the names of other+    * Neither the name of Daniel Casanueva nor the names of other       contributors may be used to endorse or promote products derived       from this software without specific prior written permission. 
changelog.md view
@@ -1,2 +1,6 @@+## 0.2.1.2+* Use `compare` instead of inequalities in `delete` implementation.+* Add test.+ ## 0.2.1.1 * Improve `delete` implementation.
sorted-list.cabal view
@@ -1,5 +1,5 @@ name:                sorted-list-version:             0.2.1.1+version:             0.2.1.2 synopsis:            Type-enforced sorted lists and related functions. description:         Type-enforced sorted lists and related functions.                      .@@ -35,18 +35,27 @@ extra-doc-files:     readme.md, changelog.md  library-  exposed-modules:     Data.SortedList-  build-depends:       base == 4.*-               ,       deepseq   default-language:    Haskell2010   ghc-options:         -Wall+  build-depends:       base == 4.*+               ,       deepseq+  exposed-modules:     Data.SortedList  benchmark sorted-list-map-bench   default-language: Haskell2010   type: exitcode-stdio-1.0   hs-source-dirs: bench   main-is: map.hs+  ghc-options: -O2 -Wall   build-depends: base == 4.*                , sorted-list                , criterion-  ghc-options: -O2 -Wall++test-suite sorted-list-tests+  default-language: Haskell2010+  type: exitcode-stdio-1.0+  hs-source-dirs: tests+  main-is: Main.hs+  ghc-options: -Wall+  default-extensions: ImportQualifiedPost+  build-depends: base, sorted-list, QuickCheck
+ tests/Main.hs view
@@ -0,0 +1,42 @@++{-# OPTIONS_GHC -Wno-orphans #-}++module Main (main) where++import Control.Monad (unless)+import Test.QuickCheck+  ( Testable, isSuccess, quickCheckResult+  , Arbitrary, arbitrary+    )+import System.Exit (exitFailure)+import Data.SortedList (SortedList)+import Data.SortedList qualified as SL+import Data.List qualified as List++-- | Test a property.+quickCheck :: Testable prop => String -> prop -> IO ()+quickCheck n p = do+  putStrLn $ "Testing property: " ++ n+  r <- quickCheckResult p+  unless (isSuccess r) exitFailure++instance (Arbitrary a, Ord a) => Arbitrary (SortedList a) where+  arbitrary = SL.toSortedList <$> arbitrary++applyAsList :: Ord a => ([a] -> [a]) -> SortedList a -> SortedList a+applyAsList f = SL.toSortedList . f . SL.fromSortedList++main :: IO ()+main = do+  quickCheck "toSortedList . fromSortedList = id" $+    \xs -> applyAsList id xs == (xs :: SortedList Int)+  quickCheck "insert" $+    \x xs -> SL.insert x xs == applyAsList ((:) x) (xs :: SortedList Int)+  quickCheck "delete" $+    \x xs -> let ys :: SortedList Int+                 ys = SL.toSortedList $ x : xs+             in  SL.delete x ys == applyAsList (List.delete x) ys+  quickCheck "elemOrd" $+    \x xs -> SL.elemOrd x xs == List.elem (x :: Int) (SL.fromSortedList xs)+  quickCheck "nub" $+    \xs -> SL.nub xs == applyAsList List.nub (xs :: SortedList Int)