From 4bb2b2a4071d74913065f53de901c7b82f5aecd6 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 2 Nov 2007 16:44:02 +0000 Subject: [PATCH] Moved mapPair into Utils, and renamed it to transformPair (to be consistent with the pre-existing transformX functions) --- common/FlowGraphTest.hs | 5 +---- common/Utils.hs | 4 ++++ transformations/RainUsageCheckTest.hs | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/common/FlowGraphTest.hs b/common/FlowGraphTest.hs index 3bf266e..0a3f236 100644 --- a/common/FlowGraphTest.hs +++ b/common/FlowGraphTest.hs @@ -96,15 +96,12 @@ testGraph testName nodes edges proc deNode :: FNode a -> (Meta, a) deNode (Node x) = x - mapPair :: (x -> a) -> (y -> b) -> (x,y) -> (a,b) - mapPair f g (x,y) = (f x, g y) - testOps :: GraphLabelFuncs (State (Map.Map Meta Int)) Int testOps = GLF nextId nextId nextId nextId (nextId' 100) (nextId' 100) checkGraphEquality :: (Graph g, Show b, Ord b) => ([(Int, Meta)], [(Int, Int, b)]) -> g (FNode Int) b -> Assertion checkGraphEquality (nodes, edges) g - = do let (remainingNodes, nodeLookup, ass) = foldl checkNodeEquality (Map.fromList (map revPair nodes),Map.empty, return ()) (map (mapPair id deNode) $ labNodes g) + = do let (remainingNodes, nodeLookup, ass) = foldl checkNodeEquality (Map.fromList (map revPair nodes),Map.empty, return ()) (map (transformPair id deNode) $ labNodes g) ass assertBool (testName ++ " Test graph had nodes not found in the real graph: " ++ show remainingNodes ++ ", real graph: " ++ showGraph g) (Map.null remainingNodes) edges' <- mapM (transformEdge nodeLookup) edges diff --git a/common/Utils.hs b/common/Utils.hs index 0193954..74ade88 100644 --- a/common/Utils.hs +++ b/common/Utils.hs @@ -102,3 +102,7 @@ combineCompare [] = EQ combineCompare (LT:_) = LT combineCompare (GT:_) = GT combineCompare (EQ:os) = combineCompare os + +-- | Maps two functions over members of a pair +transformPair :: (x -> a) -> (y -> b) -> (x,y) -> (a,b) +transformPair f g (x,y) = (f x, g y) diff --git a/transformations/RainUsageCheckTest.hs b/transformations/RainUsageCheckTest.hs index 3cbde03..76e46e7 100644 --- a/transformations/RainUsageCheckTest.hs +++ b/transformations/RainUsageCheckTest.hs @@ -28,6 +28,7 @@ import FlowGraph import Metadata import RainUsageCheck import TestUtil +import Utils --Shorthands for some variables to simplify the list of tests in this file