getting the name of a function for test diagnostic purposes

{- I have written a program (below) to run a test suite for a list of functions: [isTotalJunc, isPartialJunc] where each function receives a datum of type ApplyArg whose value slot is one element at a time of the list of types below: [JNone, JOne, JAny, JAll] I therefore must run 8 tests (the cross product of functions and types). Right now, here is the output: *Main> test_total_partial ["fun: (->)input: JNoneoutput: True","fun: (->)input: JOneoutput: False","fun: (->)input: JAnyoutput: False","fun: (->)input: JAlloutput: True","fun: (->)input: JNoneoutput: False","fun: (->)input: JOneoutput: True","fun: (->)input: JAnyoutput: True","fun: (->)input: JAlloutput: False"] -- One problem is that functions do not print as their name. The call to (show f) in showres simply yields (->) -- Another problem is that I cannot manage to separate each string with a carriage return. Any help with these problems is appreciated. -} test_total_partial = let funs = [isTotalJunc, isPartialJunc] types = [JNone, JOne, JAny, JAll] mkdat typ = ApplyArg "somename" (VJunc $ Junc typ emptySet emptySet) False showres f t r = "fun: " ++ (show f) ++ "input: " ++ (show t) ++ "output: " ++ (show r) runtest f t = do { retval <- f (mkdat t); return $ (showres f t retval) } in [ (showres f t (f (mkdat t))) | f <- funs, t <- types ] -- Carter's Compass: I know I'm on the right track when, by deleting something, I'm adding functionality.

Am Donnerstag, 3. März 2005 14:28 schrieb Terrence Brannon:
{- I have written a program (below) to run a test suite for a list of functions:
[isTotalJunc, isPartialJunc]
where each function receives a datum of type ApplyArg whose value slot is one element at a time of the list of types below:
[JNone, JOne, JAny, JAll]
I therefore must run 8 tests (the cross product of functions and types).
Right now, here is the output:
*Main> test_total_partial ["fun: (->)input: JNoneoutput: True","fun: (->)input: JOneoutput: False","fun: (->)input: JAnyoutput: False","fun: (->)input: JAlloutput: True","fun: (->)input: JNoneoutput: False","fun: (->)input: JOneoutput: True","fun: (->)input: JAnyoutput: True","fun: (->)input: JAlloutput: False"]
-- One problem is that functions do not print as their name. The call to (show f) in showres simply yields (->)
-- Another problem is that I cannot manage to separate each string with a carriage return.
Any help with these problems is appreciated.
-}
test_total_partial = let funs = [isTotalJunc, isPartialJunc] types = [JNone, JOne, JAny, JAll] mkdat typ = ApplyArg "somename" (VJunc $ Junc typ emptySet emptySet) False showres f t r = "fun: " ++ (show f) ++ "input: " ++ (show t) ++ "output: " ++ (show r) runtest f t = do { retval <- f (mkdat t); return $ (showres f t retval) } in [ (showres f t (f (mkdat t))) | f <- funs, t <- types ]
Well, getting the name of a function, I don't know how to. But as for separating the Strings, what about 'unlines'? Daniel

Am Donnerstag, 3. März 2005 14:28 schrieb Terrence Brannon:
{- I have written a program (below) to run a test suite for a list of functions:
[isTotalJunc, isPartialJunc]
where each function receives a datum of type ApplyArg whose value slot is one element at a time of the list of types below:
[JNone, JOne, JAny, JAll]
I therefore must run 8 tests (the cross product of functions and types).
Right now, here is the output:
*Main> test_total_partial ["fun: (->)input: JNoneoutput: True","fun: (->)input: JOneoutput: False","fun: (->)input: JAnyoutput: False","fun: (->)input: JAlloutput: True","fun: (->)input: JNoneoutput: False","fun: (->)input: JOneoutput: True","fun: (->)input: JAnyoutput: True","fun: (->)input: JAlloutput: False"]
-- One problem is that functions do not print as their name. The call to (show f) in showres simply yields (->)
-- Another problem is that I cannot manage to separate each string with a carriage return.
Any help with these problems is appreciated.
-}
test_total_partial = let funs = [isTotalJunc, isPartialJunc] types = [JNone, JOne, JAny, JAll] mkdat typ = ApplyArg "somename" (VJunc $ Junc typ emptySet emptySet) False showres f t r = "fun: " ++ (show f) ++ "input: " ++ (show t) ++ ^ "output: " ++ (show r) runtest f t = do { ^ insert a space here?
retval <- f (mkdat t); return $ (showres f t retval) } in [ (showres f t (f (mkdat t))) | f <- funs, t <- types ]
In the case where you want to test a few known functions, you might do something like [(fun1,"fun1"),(fun2,"fun2")] and ... in putStr . unlines $ [showRes fname t (f (mkdat t)) | (f,fname) <- funns, t <- types] Of course, it's very specific, but it will produce better formatted output. Daniel
participants (2)
-
Daniel Fischer
-
Terrence Brannon