File: Binary.hs

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

import Data.Binary.Put
import Data.Binary.Get
import Linear
import qualified Data.ByteString.Lazy as BS
import Test.Tasty (TestTree)
import Test.Tasty.HUnit ((@?=), testCase)

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 :: [TestTree]
tests = [ testCase "Serialized length" $ BS.length bytes @?= 3*13+2
        , testCase "Deserialization" $ deserialized @?= originalVecs ]
  where deserialized = runGet ((,) <$> getLinear <*> getLinear) bytes