{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module Test.MathObj.Polynomial where
import qualified MathObj.Polynomial as Poly
import qualified Algebra.IntegralDomain as Integral
import qualified Algebra.Ring as Ring
import qualified Algebra.ZeroTestable as ZeroTestable
import qualified Algebra.Laws as Laws
import qualified Data.List as List
import Test.NumericPrelude.Utility (testUnit)
import Test.QuickCheck (Property, quickCheck, (==>))
import qualified Test.HUnit as HUnit
import PreludeBase as P
import NumericPrelude as NP
tensorProductTranspose :: (Ring.C a, Eq a) => [a] -> [a] -> Property
tensorProductTranspose xs ys =
not (null xs) && not (null ys) ==>
Poly.tensorProduct xs ys == List.transpose (Poly.tensorProduct ys xs)
mul :: (Ring.C a, Eq a, ZeroTestable.C a) => [a] -> [a] -> Bool
mul xs ys = Poly.equal (Poly.mul xs ys) (Poly.mulShear xs ys)
tests :: HUnit.Test
tests =
HUnit.TestLabel "polynomial" $
HUnit.TestList $
map testUnit $
("tensor product", quickCheck (tensorProductTranspose :: [Integer] -> [Integer] -> Property)) :
("mul speed", quickCheck (mul :: [Integer] -> [Integer] -> Bool)) :
("addition, zero", quickCheck (\x -> Laws.identity (+) zero (x :: Poly.T Integer))) :
("addition, commutative", quickCheck (\x -> Laws.commutative (+) (x :: Poly.T Integer))) :
("addition, associative", quickCheck (\x -> Laws.associative (+) (x :: Poly.T Integer))) :
("multiplication, one", quickCheck (\x -> Laws.identity (*) one (x :: Poly.T Integer))) :
("multiplication, commutative", quickCheck (\x -> Laws.commutative (*) (x :: Poly.T Integer))) :
("multiplication, associative", quickCheck (\x -> Laws.associative (*) (x :: Poly.T Integer))) :
("multiplication and addition, distributive", quickCheck (\x -> Laws.leftDistributive (*) (+) (x :: Poly.T Integer))) :
("division", quickCheck (\x -> Integral.propInverse (x :: Poly.T Rational))) :
[]