packages feed

synthesizer-0.2: src/Test/Utility.hs

{-# LANGUAGE NoImplicitPrelude #-}
module Test.Utility where

import Test.QuickCheck (Arbitrary(..))

import qualified Algebra.Real                  as Real
import qualified Algebra.Ring                  as Ring

import qualified Data.Char as Char

import PreludeBase
import NumericPrelude


equalList :: Eq a => [a] -> Bool
equalList xs =
   -- 'drop 1' instead of 'take' for suppression of error
   and (zipWith (==) xs (drop 1 xs))


approxEqual :: (Real.C a) => a -> a -> a -> Bool
approxEqual eps x y =
   2 * abs (x-y) <= eps * (abs x + abs y)

approxEqualListRel :: (Real.C a) => a -> [a] -> Bool
approxEqualListRel eps xs =
   let n = fromIntegral $ length xs
   in  approxEqualListAbs (eps * n * sum (map abs xs)) xs

approxEqualListAbs :: (Real.C a) => a -> [a] -> Bool
approxEqualListAbs eps xs =
   let n = fromIntegral $ length xs
       s = sum xs
   in  sum (map (\x -> abs (n*x-s)) xs)  <=  eps


-- see event-list

newtype ArbChar = ArbChar Char
   deriving (Eq, Ord)

instance Show ArbChar where
   showsPrec n (ArbChar c) = showsPrec n c

instance Arbitrary ArbChar where
   arbitrary = fmap (ArbChar . Char.chr . (32+) . flip mod 96) arbitrary
   coarbitrary = undefined