packages feed

hunit-gui-0.1: examples/Main.hs

module Main
where

import Test.HUnit
import Test.HUnit.Gui

main = do
  testInfo <- runTestGui bigLongTests
  exitWhenGuiCloses testInfo

-- First and third tests should pass; second and fourth should fail
bigLongTests :: Test
bigLongTests = test [ "first" ~: 224743 ~=? (head $ drop 20000 primes)
                    , "second" ~: 22 ~=? (head $ drop 40000 primes)
                    , "third" ~: 746777 ~=? (head $ drop 60000 primes)
                    , "fourth" ~: 44 ~=? (head $ drop 80000 primes)
                    ]
    where
      odds = [3,5..] :: [Integer]
      primeToList n = not . any (\p -> n `mod` p == 0)
      primes =
          let aux [] = []
              aux ns@(p:_) =
                  let (knownPrimes, remaining) = span (\n -> n < p*p) ns
                  in knownPrimes ++ (aux $ filter (\n -> primeToList n knownPrimes) remaining)
          in 2 : (aux odds)