packages feed

numeric-prelude-0.2.1: test/Test/Number/ComplexSquareRoot.hs

{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module Test.Number.ComplexSquareRoot where

import qualified Number.ComplexSquareRoot as S
import qualified Number.Complex as Complex

-- import qualified Algebra.Ring           as Ring

import qualified Algebra.Laws as Laws

import Test.NumericPrelude.Utility (testUnit)
import Test.QuickCheck (Testable, quickCheck, (==>), )
import qualified Test.HUnit as HUnit

import NumericPrelude.Base as P
import NumericPrelude.Numeric as NP


simple ::
   (Testable t) =>
   (S.T Rational -> t) -> IO ()
simple = quickCheck

tests :: HUnit.Test
tests =
   HUnit.TestLabel "complex square root" $
   HUnit.TestList $
   map testUnit $
   testList

testList :: [(String, IO ())]
testList =
   ("multiplication, one",
      simple $ Laws.identity S.mul S.one) :
   ("multiplication, commutative",
      simple $ Laws.commutative S.mul) :
   ("multiplication, associative",
      simple $ Laws.associative S.mul) :
   ("multiplication, homomorphism",
      quickCheck $ Laws.homomorphism S.fromNumber
         (\x y -> (x :: Complex.T Rational) * y) S.mul) :
   ("division, one",
      simple $ Laws.rightIdentity S.div S.one) :
   ("recip recip",
      simple $ \x -> not (isZero x) ==> S.recip (S.recip x) == x) :
   ("recip inverts multiplication",
      simple $ \x -> not (isZero x) ==> Laws.inverse S.mul S.recip S.one x) :
   []