packages feed

GroteTrap-0.5.2: Tests.hs

module Main where

import Test.Framework (Test, defaultMain)
import Test.Framework.Providers.QuickCheck2 (testProperty)
import Test.QuickCheck ((==>))

import Language.GroteTrap.Range
  (validRange, includes, unionRange, distRange, size)
import Language.GroteTrap.Trees (up, down, left, right)

main :: IO ()
main  = defaultMain tests

tests :: [Test]
tests =
  [ testProperty "range/propUnionRange" propUnionRange
  , testProperty "range/propDistRange" propDistRange
  , testProperty "range/propDistRangeComm" propDistRangeComm
  , testProperty "trees/propDownUp" propDownUp
  , testProperty "trees/propUpDown" propUpDown
  , testProperty "trees/propLeftRight" propLeftRight
  , testProperty "trees/propRightLeft" propRightLeft
  ]

-- ranges

propUnionRange r1 r2 = validRange r1 && validRange r2 ==> u `includes` r1 && u `includes` r2
  where u = unionRange r1 r2

propDistRange r1 r2 = validRange r1 && validRange r2 && r1 `includes` r2 ==>
                        distRange r1 r2 <= size r1

propDistRangeComm r1 r2 = distRange r1 r2 == distRange r2 r1

-- tree paths

propDownUp     path  =  up (down path) == path
propUpDown     path  =  not (null path) ==> init (down (up path)) == init path
propLeftRight  path  =  not (null path) && last path > 0 ==> right (left path) == path
propRightLeft  path  =  not (null path) && last path >= 0 ==> left (right path) == path