Skip to content

Instantly share code, notes, and snippets.

@fedelebron
Created October 5, 2012 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fedelebron/3840442 to your computer and use it in GitHub Desktop.
Save fedelebron/3840442 to your computer and use it in GitHub Desktop.
Small Haskell test suite, my first actual Haskell code, years ago :)
type CasoDePrueba = (String,Bool)
type ListaDePruebas = [CasoDePrueba]
type SuiteDePruebas = [(String, ListaDePruebas)]
imprimirListaDePruebas :: ListaDePruebas -> (Integer, Integer) -> IO (Integer, Integer)
imprimirListaDePruebas [] (total, pass) = do
return (total, pass)
imprimirListaDePruebas (t : ts) (total, passed) = do
n <- imprimirCasoDePrueba t
imprimirListaDePruebas ts (total+1, passed+n) -- querías contadores? tomá!
imprimirCasoDePrueba :: CasoDePrueba -> IO Integer -- mmmm, mooonadas
imprimirCasoDePrueba (a,b) = do
putStrLn ("\t"++(formatearResultado b))
return (if b then 1 else 0)
where
formatearResultado :: Bool -> String
formatearResultado True = "\ESC[1m\ESC[32m[PASS] "++a++"\ESC[22m\ESC[39m" -- nos gustan los colores
formatearResultado False = "\ESC[1m\ESC[31m[FAIL] "++a++"\ESC[22m\ESC[39m" -- si no soportás colores ANSI no estás en la onda.
imprimirSuiteDePruebas :: SuiteDePruebas -> (Integer, Integer) -> IO()
imprimirSuiteDePruebas [] (total, passed) = do
if (total-passed) == 0 then putStrLn ("\n\n\ESC[1mTotal: "++(show total)++"\nFallas: "++(show (total-passed))++"\ESC[22m\n") else putStrLn ("\n\n\ESC[1m\ESC[31mTotal: "++(show total)++"\nFallas: "++(show (total-passed))++"\ESC[22m\ESC[39m\n") -- faaa loco, no tenei una linea de Haskell (leer con acento cordobés)
imprimirSuiteDePruebas (listaDePruebas : listasDePruebas) (total, passed) = do
putStrLn("\n\nPruebas de "++(fst listaDePruebas)++":\n")
res <- imprimirListaDePruebas (snd listaDePruebas) (0, 0) -- 2 horas llevo esto :D matenme.
imprimirSuiteDePruebas listasDePruebas (total+(fst res), passed+(snd res))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment