[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36

John Goerzen jgoerzen at complete.org
Fri Apr 23 14:44:42 UTC 2010


The following commit has been merged in the master branch:
commit 559b7107547637e5933f55d6b0c95e1fdd2ba541
Author: John Goerzen <jgoerzen at complete.org>
Date:   Mon Oct 18 21:02:44 2004 +0100

    Preparing 0.4.2 with addition of contains
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--1.0--patch-70)

diff --git a/ChangeLog b/ChangeLog
index 7994a42..ca81034 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,19 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--1.0
 #
 
+2004-10-18 15:02:44 GMT	John Goerzen <jgoerzen at complete.org>	patch-70
+
+    Summary:
+      Preparing 0.4.2 with addition of contains
+    Revision:
+      missingh--head--1.0--patch-70
+
+
+    modified files:
+     ChangeLog debian/changelog libsrc/MissingH/List.hs
+     testsrc/Listtest.hs
+
+
 2004-10-15 20:47:35 GMT	John Goerzen <jgoerzen at complete.org>	patch-69
 
     Summary:
diff --git a/debian/changelog b/debian/changelog
index 8a9f2a6..d2e4b85 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+missingh (0.4.2) unstable; urgency=low
+
+  * Added MissingH.List.contains
+
+ -- John Goerzen <jgoerzen at complete.org>  Mon, 18 Oct 2004 10:02:03 -0500
+
 missingh (0.4.1) unstable; urgency=low
 
   * Added haskell-src to build-depends.
diff --git a/libsrc/MissingH/List.hs b/libsrc/MissingH/List.hs
index f9f5db8..f46dc75 100644
--- a/libsrc/MissingH/List.hs
+++ b/libsrc/MissingH/List.hs
@@ -22,7 +22,7 @@ Written by John Goerzen, jgoerzen\@complete.org
 n-}
 
 module MissingH.List(-- * Tests
-                     startswith, endswith,
+                     startswith, endswith, contains,
                      -- * Association List Utilities
                      {- | These functions are designed to augment the
                      association list functions in "Data.List" and
@@ -107,12 +107,29 @@ Examples:
 genericJoin :: Show a => String -> [a] -> String
 genericJoin delim l = join delim (map show l)
 
+{- | Returns true if the given parameter is a sublist of the given list;
+false otherwise.
+
+Example:
+
+> contains "Haskell" "I really like Haskell." -> True
+> contains "Haskell" "OCaml is great." -> False
+-}
+
+contains :: Eq a => [a] -> [a] -> Bool
+contains [] _ = True                    -- Sub is empty; matches anything
+contains _ [] = False                   -- List is empty; matches nothing
+contains sub searchlist =
+    let testlist = take (length sub) searchlist
+        in
+        case sub == testlist of
+                             True -> True
+                             False -> contains sub (tail searchlist)
+
 {- | Given a length and a list, remove any elements at the end of the list
 that make it longer than the length.  If the list is shorter than the
 length, do nothing.
 
-Example:
-
 > trunc 2 "Hello" -> "He"
 -}
 
diff --git a/testsrc/Listtest.hs b/testsrc/Listtest.hs
index f9d111e..424eb16 100644
--- a/testsrc/Listtest.hs
+++ b/testsrc/Listtest.hs
@@ -79,12 +79,28 @@ test_trunc =
         f 0 "" ""
                       
 
+test_contains =
+    let f msg sub testlist exp = assertEqual msg exp (contains sub testlist) in
+        do
+        f "t1" "Haskell" "I really like Haskell." True
+        f "t2" "" "Foo" True
+        f "t3" "" "" True
+        f "t4" "Hello" "" False
+        f "t5" "Haskell" "Haskell" True
+        f "t6" "Haskell" "1Haskell" True
+        f "t7" "Haskell" "Haskell1" True
+        f "t8" "Haskell" "Ocaml" False
+        f "t9" "Haskell" "OCamlasfasfasdfasfd" False
+        f "t10" "a" "Hello" False
+        f "t11" "e" "Hello" True
+
 tests = TestList [TestLabel "delFromAL" (TestCase test_delFromAL),
                   TestLabel "addToAL" (TestCase test_addToAL),
                   TestLabel "split" (TestCase test_split),
                   TestLabel "join" (TestCase test_join),
                   TestLabel "genericJoin" (TestCase test_genericJoin),
-                  TestLabel "trunc" (TestCase test_trunc)]
+                  TestLabel "trunc" (TestCase test_trunc),
+                  TestLabel "contains" (TestCase test_contains)]
 
 
 

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list