File: Binary.hs

package info (click to toggle)
haskell-linear 1.22-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 384 kB
  • sloc: haskell: 5,225; makefile: 4
file content (19 lines) | stat: -rw-r--r-- 585 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Binary (tests) where

import Data.Binary.Put
import Data.Binary.Get
import Linear
import qualified Data.ByteString.Lazy as BS
import Test.HUnit

originalVecs :: (V3 Float, V2 Char)
originalVecs = (V3 1 2 3, V2 'a' 'b')

bytes :: BS.ByteString
bytes = runPut $ do putLinear $ fst originalVecs
                    putLinear $ snd originalVecs

tests :: Test
tests = test [ "Serialized length" ~: BS.length bytes ~?= 3*13+2
             , "Deserialization" ~: deserialized ~?= originalVecs ]
  where deserialized = runGet ((,) <$> getLinear <*> getLinear) bytes