packages feed

synthesizer-core-0.2: src/Test/Sound/Synthesizer/Plain/Control.hs

module Test.Sound.Synthesizer.Plain.Control (tests) where

import qualified Synthesizer.Plain.Control as Control

import Test.QuickCheck (test, Property, (==>))
import Test.Utility (equalList, approxEqualListAbs, approxEqualListRel, )

-- import qualified Algebra.Ring                  as Ring
-- import qualified Algebra.Additive              as Additive

import Data.List (transpose)

import NumericPrelude
import PreludeBase
import Prelude ()


linearRing :: Int -> Int -> Bool
linearRing d y0 =
--   Control.linear d y0  ==  Control.linearMultiscale d y0
   all equalList $ take 100 $ transpose $
      Control.linear d y0 :
      Control.linearMultiscale d y0 :
      Control.linearStable d y0 :
      []

{-
*Synthesizer.Plain.Control> propLinearApprox (-2/3) 2
False

Need a different definition of approximate equality.
-}
linearApprox :: Double -> Double -> Bool
linearApprox d y0 =
   all (approxEqualListAbs (1e-10 * max (abs d) (abs y0))) $
   take 100 $ transpose $
      Control.linear d y0 :
      Control.linearMean d y0 :
      Control.linearMultiscale d y0 :
      Control.linearStable d y0 :
      []

linearExact :: Rational -> Rational -> Bool
linearExact d y0 =
   all equalList $ take 100 $ transpose $
      Control.linear d y0 :
      Control.linearMean d y0 :
      Control.linearMultiscale d y0 :
      Control.linearStable d y0 :
      []

{-
Plain.Control.exponential: Falsifiable, after 88 tests:
-8.333333333333326e-2
3.375

Plain.Control.exponential: Falsifiable, after 69 tests:
9.090909090909083e-2
-10.0

Plain.Control.exponential: Falsifiable, after 73 tests:
-0.125
-1.1428571428571428

Plain.Control.exponential2: Falsifiable, after 33 tests:
-7.692307692307687e-2
9.5
-}
exponential :: Double -> Double -> Bool
exponential time y0 =
   all (approxEqualListRel (1e-10)) $ take 100 $ transpose $
      Control.exponential time y0 :
      Control.exponentialMultiscale time y0 :
      Control.exponentialStable time y0 :
      []

exponential2 :: Double -> Double -> Bool
exponential2 time y0 =
   all (approxEqualListRel (1e-10)) $ take 100 $ transpose $
      Control.exponential2 time y0 :
      Control.exponential2Multiscale time y0 :
      Control.exponential2Stable time y0 :
      []

cosine :: Double -> Double -> Property
cosine t0 t1  =  t0/=t1 ==>
   all (approxEqualListAbs (1e-10)) $
   take 100 $ transpose $
      Control.cosine t0 t1 :
      Control.cosineMultiscale t0 t1 :
      Control.cosineStable t0 t1 :
      []


cubic :: (Rational, (Rational, Rational)) ->
   (Rational, (Rational, Rational)) -> Property
cubic node0 node1  =  fst node0 /= fst node1 ==>
   take 100 (Control.cubicHermite node0 node1)  ==
   take 100 (Control.cubicHermiteStable node0 node1)



tests :: [(String, IO ())]
tests =
   ("linearRing", test linearRing) :
   ("linearApprox", test linearApprox) :
   ("linearExact", test linearExact) :
   ("exponential", test exponential) :
   ("exponential2", test exponential2) :
   ("cosine", test cosine) :
   ("cubic", test cubic) :
   []