packages feed

ideas-0.7: src/Documentation/DerivationUnitTests.hs

-----------------------------------------------------------------------------
-- Copyright 2009, Open Universiteit Nederland. This file is distributed 
-- under the terms of the GNU General Public License. For more information, 
-- see the file "LICENSE.txt", which is included in the distribution.
-----------------------------------------------------------------------------
-- |
-- Maintainer  :  bastiaan.heeren@ou.nl
-- Stability   :  provisional
-- Portability :  portable (depends on ghc)
--
-----------------------------------------------------------------------------
module Documentation.DerivationUnitTests (main) where

import Control.Monad
import Common.Exercise
import Text.XML
import Domain.Math.Power.Exercises

base = "test/dwo-derivations"

main = make powerOfAExercise

make :: Exercise a -> IO ()
make ex = zipWithM_ (makeTest ex) [1 ..] (examples ex)

makeTest :: Exercise a -> Int -> a -> IO ()
makeTest ex n a = do
   let file = base ++ "/" ++ show (exerciseCode ex) ++ show n ++ ".xml"
   putStrLn $ "Writing " ++ file
   writeFile file $ showXML $ makeRequest a ex

makeRequest :: a -> Exercise a -> XML
makeRequest a ex = makeXML "request" $ do
   "service"    .=. "derivation"
   "exerciseid" .=. show (exerciseCode ex)
   "encoding"   .=. "string"
   element "state" $ 
      element "expr" $
         text $ prettyPrinter ex a