packages feed

wav-0.1.0.0 / test / Main.hs

{-# LANGUAGE BinaryLiterals #-}module Main (main) whereimport Data.Binary.Putimport qualified Data.ByteString.Lazy as BSimport Data.Rapimport Data.Wavimport Test.Tastyimport Test.Tasty.HUnitmain :: IO ()main = defaultMain $ testGroup "Data.Wav" [toWavTest, toRapTest, denormTest  , normTest]toWavTest :: TestTreetoWavTest = testCaseSteps "toWav" $ \step -> do  step "basic"  toWav basicRap @?= Right basicWavtoRapTest :: TestTreetoRapTest = testCaseSteps "toRap" $ \step -> do  step "basic"  toRap basicWav @?= Right basicRapbasicRap :: RapbasicRap = Stanza "RIFF" "WAVE"  [ Verse "fmt " $ runPut $ do      putWord16le 1 -- PCM      putWord16le 1 -- MONO      putWord32le 44100 -- sample rate      putWord32le 2 -- bytes per second      putWord16le 2 -- block align      putWord16le 16 -- bits per sample  , Verse "data" $ BS.pack [0x00, 0x00, 0x00, 0x00]  ]basicWav :: WavbasicWav = Wav [Fmt $ Format 1 1 44100 2 2 16 Nothing, Aud [0, 0]]denormTest :: TestTreedenormTest = testCaseSteps "denorm" $ \step -> do  step "3-bit"  BS.unpack <$> denorm 3 [-1] @?= Right [0x00]  BS.unpack <$> denorm 3 [-0.5] @?= Right [0x40]  BS.unpack <$> denorm 3 [1] @?= Right [0xE0]  step "8-bit"  BS.unpack <$> denorm 8 [-1] @?= Right [0x00]  BS.unpack <$> denorm 8 [0]  @?= Right [128]  BS.unpack <$> denorm 8 [1]  @?= Right [0xFF]  step "16-bit"  denorm 16 [-1] @?= Right (runPut $ putInt16le minBound)  denorm 16 [0]  @?= Right (runPut $ putInt16le 0)  denorm 16 [1]  @?= Right (runPut $ putInt16le maxBound)  step "20-bit"  -- 0x12345 / (2^19 - 1)  BS.unpack <$> denorm 20 [0.1422214508] @?= Right [0x50, 0x34, 0x12]  BS.unpack <$> denorm 20 [-0.1422214508] @?= Right [0xB0, 0xCB, 0xED]  step "24-bit"  BS.unpack <$> denorm 24 [-1] @?= Right [0x00, 0x00, 0x80]  BS.unpack <$> denorm 24 [0]  @?= Right [0x00, 0x00, 0x00]  BS.unpack <$> denorm 24 [1]  @?= Right [0xFF, 0xFF, 0x7F]  BS.unpack <$> denorm 24 [1193046 / 8388608] @?= Right [0x56, 0x34, 0x12]  step "32-bit"  denorm 32 [-1] @?= Right (runPut $ putInt32le minBound)  denorm 32 [0]  @?= Right (runPut $ putInt32le 0)  denorm 32 [1]  @?= Right (runPut $ putInt32le maxBound)normTest :: TestTreenormTest = testCaseSteps "norm" $ \step -> do  step "3-bit"  norm 3 (BS.pack [0x00]) @?= Right [-1]  norm 3 (BS.pack [0x40]) @?= Right [-0.5]  norm 3 (BS.pack [0xE0]) @?= Right [0.75]  step "8-bit"  norm 8 (BS.pack [0x00]) @?= Right [-1]  norm 8 (BS.pack [128])  @?= Right [0]  norm 8 (BS.pack [0xFF]) @?= Right [0.9921875]  step "16-bit"  norm 16 (runPut $ putInt16le minBound) @?= Right [-1]  norm 16 (runPut $ putInt16le 0)        @?= Right [0]  norm 16 (runPut $ putInt16le maxBound) @?= Right [0.999969482421875]  step "20-bit"  -- 0x12345 / (2^19 - 1)  norm 20 (BS.pack [0x50, 0x32, 0x12]) @?= Right [0.14216041564941406]  norm 20 (BS.pack [0xB0, 0xCB, 0xED]) @?= Right [-0.14222145080566406]  step "24-bit"  norm 24 (BS.pack [0x00, 0x00, 0x80]) @?= Right [-1]  norm 24 (BS.pack [0x00, 0x00, 0x00]) @?= Right [0]  norm 24 (BS.pack [0xFF, 0xFF, 0x7F]) @?= Right [0.9999998807907104]  norm 24 (BS.pack [0x56, 0x34, 0x12]) @?= Right [1193046 / 8388608]  step "32-bit"  norm 32 (runPut $ putInt32le minBound) @?= Right [-1]  norm 32 (runPut $ putInt32le 0)        @?= Right [0]  norm 32 (runPut $ putInt32le maxBound) @?= Right [0.9999999995343387]