packages feed

ideas-1.0: src/Text/OpenMath/Tests.hs

-----------------------------------------------------------------------------
-- Copyright 2011, 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 Text.OpenMath.Tests (propEncoding) where

import Control.Monad
import Test.QuickCheck
import Text.OpenMath.Dictionary.Arith1
import Text.OpenMath.Dictionary.Calculus1
import Text.OpenMath.Dictionary.Fns1
import Text.OpenMath.Dictionary.Linalg2
import Text.OpenMath.Dictionary.List1
import Text.OpenMath.Dictionary.Logic1
import Text.OpenMath.Dictionary.Nums1
import Text.OpenMath.Dictionary.Quant1
import Text.OpenMath.Dictionary.Relation1
import Text.OpenMath.Dictionary.Transc1
import Text.OpenMath.Object

arbOMOBJ :: Gen OMOBJ
arbOMOBJ = sized rec
 where
   symbols = arith1List ++ calculus1List ++ fns1List ++ linalg2List ++
      list1List ++ logic1List ++ nums1List ++ quant1List ++
      relation1List ++ transc1List

   rec 0 = frequency
      [ (1, liftM OMI arbitrary)
      , (1, liftM (\n -> OMF (fromInteger n / 1000)) arbitrary)
      , (1, liftM OMV arbitrary)
      , (5, elements $ map OMS symbols)
      ]
   rec n = frequency
      [ (1, rec 0)
      , (3, choose (1,4) >>= liftM OMA . (`replicateM` f))
      , (1, liftM3 OMBIND f arbitrary f)
      ]
    where
      f = rec (n `div` 2)

propEncoding :: Property
propEncoding = forAll arbOMOBJ $ \x -> xml2omobj (omobj2xml x) == Right x