module Fourier.FFTSpec (main,spec) where

import Test.Hspec
import Test.QuickCheck()
import Data.Complex(Complex((:+)))
import Fourier.FFT(fft)

main :: IO ()
main = hspec spec

spec :: Spec
spec = do

  describe "FFT" $ do

    it "transform steady function" $ do
      let x = fft [0.0, 0.0, 0.0]
        in x `shouldBe` ([0.0, 0.0, 0.0])

    it "transform impulse function" $ do
      let x = fft [0.0, 0.0, 1.0, 0.0, 0.0]
        in x `shouldBe` ([
          1.0 :+ (-0.0),
          (-0.8090169943749473) :+ (-0.5877852522924732),
          0.30901699437494723 :+ 0.9510565162951536,
          0.30901699437494773 :+ (-0.9510565162951534),
          (-0.8090169943749477) :+ 0.5877852522924728])

    it "transform sinusoid function" $ do
      let x = fft [sin x | x <- [0,0.3 .. pi]]
        in x `shouldBe` ([
          6.654043728627056 :+ (-0.0),
          (-2.495308482972513) :+ (-0.3737795890019122)
          ,(-0.46503997943364506) :+ (-0.1328809251599644),
          (-0.1886713255075324) :+ (-7.112462151227344e-2),
          (-0.10350867238552199) :+ (-3.701914259223908e-2),
          (-7.449340401431373e-2) :+ (-1.1604714311766413e-2),
          (-7.449340401431312e-2) :+ 1.1604714311764401e-2,
          (-0.10350867238552014) :+ 3.701914259223764e-2,
          (-0.18867132550753074) :+ 7.112462151227178e-2,
          (-0.46503997943364067) :+ 0.13288092515996228,
          (-2.4953084829725105) :+ 0.3737795890019047])


