From: Francis Russell Date: Mon, 7 Jan 2013 18:43:27 +0000 (+0000) Subject: Add tests for content wrapping. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=8e749e13ba26ed7a70cf42fdaf9aea697199b5c2;p=francis%2Fofc.git Add tests for content wrapping. --- diff --git a/OFC/Spectral.hs b/OFC/Spectral.hs index bfac594..0464f8c 100644 --- a/OFC/Spectral.hs +++ b/OFC/Spectral.hs @@ -1,16 +1,19 @@ 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(..)) diff --git a/tests/Tests/Spectral.hs b/tests/Tests/Spectral.hs index 7d8c27c..d0bbc3a 100644 --- a/tests/Tests/Spectral.hs +++ b/tests/Tests/Spectral.hs @@ -1,14 +1,40 @@ 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