module OFC.Spectral
- ( ContentType(..)
- , Frequency
+ ( Band(..)
+ , ContentType(..)
, constantFrequency
+ , constructEmptySpectrum
+ , containsBand
+ , containsFrequency
+ , Frequency
, frequencyMultiple
- , Band(..)
+ , isNullBand
+ , mergeContent
+ , multiplyBands
, negateBand
, nullBand
- , isNullBand
- , containsFrequency
- , containsBand
, Spectrum
- , constructEmptySpectrum
+ , wrapContent
) where
import OFC.Common(PrettyPrintable(..))
module Tests.Spectral (tests) where
-import Test.HUnit
+import Control.Applicative ((<$>))
+import Test.HUnit (Test(..), (~=?), (@?))
import OFC.Spectral
tests :: Test
tests = TestList
- [ TestCase negateNullBand
+ [ negateNullBand
+ , wrapEvenContent
+ , wrapOddContent
]
-negateNullBand :: Assertion
-negateNullBand = (isNullBand $ negateBand nullBand) @?
+square :: Frequency -> [Band]
+square freq = multiplyBands freqAsBand freqAsBand
+ where
+ freqAsBand = freqToBand freq
+
+freqToBand :: Frequency -> Band
+freqToBand freq = Band freq (freq + 1)
+
+bandsToContent :: [Band] -> ContentType -> [(Band, ContentType)]
+bandsToContent bands content = (\band -> (band, content)) <$> bands
+
+negateNullBand :: Test
+negateNullBand = TestCase $ (isNullBand $ negateBand nullBand) @?
"Negating the null band produced a non-null band."
+
+wrapEvenContent :: Test
+wrapEvenContent = [(freqToBand 0, Damaged)] ~=?
+ (mergeContent . concatMap (wrapContent 6) $ bandsToContent (square frequency) Present)
+ where
+ frequency = constantFrequency 3
+
+wrapOddContent :: Test
+wrapOddContent = [(freqToBand 0, Present), (freqToBand 1, Damaged)] ~=?
+ (mergeContent . concatMap (wrapContent 7) $ bandsToContent (square frequency) Present)
+ where
+ frequency = constantFrequency 3