[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:45:09 UTC 2010


The following commit has been merged in the master branch:
commit 5326afcc8eec86df0ec981628c7fceff28b2d5ce
Author: John Goerzen <jgoerzen at complete.org>
Date:   Thu Oct 21 20:17:52 2004 +0100

    Added FlippedLookupFM and a test for it
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--1.0--patch-92)

diff --git a/ChangeLog b/ChangeLog
index 291d55b..461b14a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,19 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--1.0
 #
 
+2004-10-21 14:17:52 GMT	John Goerzen <jgoerzen at complete.org>	patch-92
+
+    Summary:
+      Added FlippedLookupFM and a test for it
+    Revision:
+      missingh--head--1.0--patch-92
+
+
+    modified files:
+     ChangeLog libsrc/MissingH/FiniteMap.hs
+     testsrc/FiniteMaptest.hs
+
+
 2004-10-21 14:06:53 GMT	John Goerzen <jgoerzen at complete.org>	patch-91
 
     Summary:
diff --git a/libsrc/MissingH/FiniteMap.hs b/libsrc/MissingH/FiniteMap.hs
index 2da6261..f3a22e7 100644
--- a/libsrc/MissingH/FiniteMap.hs
+++ b/libsrc/MissingH/FiniteMap.hs
@@ -34,7 +34,7 @@ In addition to the functions exported, this module also makes a FiniteMap
 showable.
 -}
 
-module MissingH.FiniteMap (flipFM)
+module MissingH.FiniteMap (flipFM, flippedLookupFM)
 where
 
 import Data.FiniteMap
@@ -46,6 +46,15 @@ function for lists. -}
 flipFM :: (Ord key, Ord val) => FiniteMap key val -> FiniteMap val [key]
 flipFM = listToFM . flipAL . fmToList
 
+{- | Returns a list of all keys in the finite map whose value matches the
+parameter. -}
+
+flippedLookupFM :: (Ord val, Ord key) => FiniteMap key val -> val-> [key]
+flippedLookupFM fm v =
+    case lookupFM (flipFM fm) v of
+                                Nothing -> []
+                                Just x -> x
+
 {- | Makes a FiniteMap showable. -}
 instance (Show a, Show b) => Show (FiniteMap a b) where
     show fm = show (fmToList fm)
diff --git a/testsrc/FiniteMaptest.hs b/testsrc/FiniteMaptest.hs
index 0de8ed8..3f2ec77 100644
--- a/testsrc/FiniteMaptest.hs
+++ b/testsrc/FiniteMaptest.hs
@@ -32,5 +32,14 @@ test_flipFM =
            ("b", "b")] [("b", ["c", "b", "a"]),
                         ("e", ["d"])]
 
-tests = TestList [TestLabel "flipFM" (TestCase test_flipFM)
+test_flippedLookupFM =
+    let f item inp exp = exp @=? flippedLookupFM (listToFM inp) item in
+        do
+        f 'a' ([]::[(Char, Char)]) []
+        f 'a' [("Test1", 'a'), ("Test2", 'b')] ["Test1"]
+        f 'a' [("Test1", 'b'), ("Test2", 'b')] []
+        f 'a' [("Test1", 'a'), ("Test2", 'a')] ["Test2", "Test1"]
+
+tests = TestList [TestLabel "flipFM" (TestCase test_flipFM),
+                  TestLabel "flippedLookupFM" (TestCase test_flippedLookupFM)
                  ]
\ No newline at end of file

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list