Skip to content
This repository

non-IO test driver (for multiple tests) #7

Closed
jwaldmann opened this Issue March 27, 2012 · 3 comments

2 participants

jwaldmann Roman Cheplyaka
jwaldmann

I want to write code like this:

append :: [a] -> [a] -> [a]
append a b = case a of
  [] -> b
  x : y -> x : append y b

assoc op = \ a b c ->
    op a (op b c) == op (op a b) c

comm op = \ a b -> op a b == op b a

left_neutral op a = \ b -> op a b == b 
right_neutral op b = \ a -> op a b == a 

tests :: Either String String
tests = do
    testE "assoc" 1000 
        $ assoc ( append ::[Bool] ->[Bool]->[Bool])
    testE "right_neutral" 1000 
        $ right_neutral ( append ::[Bool] ->[Bool]->[Bool]) []
    testE "left_neutral" 1000 
        $ left_neutral ( append ::[Bool] ->[Bool]->[Bool]) []

it should have

  • a pure test driver (no IO) so I can process the result in a pure program and without re-parsing
  • run several tests, give OK only if all pass
  • give human-readable output

I can achieve this with

import Test.SmallCheck.Property
import Control.Monad.Error

testE :: Testable a 
      => String -> Int -> a
      -> Either String String
testE name num prop 
  = case 
        filter ( \ r -> not (resultIsOk $ result r))
      $ take num
      $ do depth <- [0..] ; test prop depth
    of [] -> Right $ unwords 
          [ "property", name, "passed", show num , "tests" ]
       r : _ -> Left $ unwords $
         [ "property", name, "fails for inputs"
         ] ++ arguments r

so I guess I'd like to have that (or something similar to the same effect) in the library somewhere.

Roman Cheplyaka
Owner

I like the idea. Will add something like this.

jwaldmann

Here is some background on why I want such a feature:
http://dfa.imn.htwk-leipzig.de/bugzilla/show_bug.cgi?id=304

Roman Cheplyaka
Owner

Sorry for the delay.

This is added in cd42a8d. It's a bit different from what you proposed:

  • no pretty-printing is done, instead the raw data is returned
  • it doesn't accept an additional bound parameter ('num' in your code)

If you are happy with this, I'll upload an updated version to hackage.

Roman Cheplyaka feuerbach closed this September 11, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.