]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Add tests for content wrapping.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Mon, 7 Jan 2013 18:43:27 +0000 (18:43 +0000)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Mon, 7 Jan 2013 18:43:27 +0000 (18:43 +0000)
OFC/Spectral.hs
tests/Tests/Spectral.hs

index bfac594ae083fd1c757f4650771547aee377b5fa..0464f8cca0adb8cce986a730289f0a2ff54c78c8 100644 (file)
@@ -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(..))
index 7d8c27c2a71be88f0363d5fef06a4815c624f79d..d0bbc3ad9560f2e2ecbc6523d30de4f3394b0ec9 100644 (file)
@@ -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