fradrive/backend/test/Test/QuickCheck/Classes/Binary.hs
Sarah Vaupel 72f5a9fb37 build: move backend-related files into backend dir; implement and connect services via docker-compose
TODOs left: reimplement clean and help, sync static,well-known and assets between services
2025-03-23 04:52:49 +01:00

27 lines
821 B
Haskell

-- SPDX-FileCopyrightText: 2022 Gregor Kleen <gregor.kleen@ifi.lmu.de>,Sarah Vaupel <vaupel.sarah@campus.lmu.de>
--
-- SPDX-License-Identifier: AGPL-3.0-or-later
module Test.QuickCheck.Classes.Binary
( binaryLaws
) where
import ClassyPrelude
import Test.QuickCheck
import Test.QuickCheck.Classes
import Data.Proxy (Proxy(..))
import Data.Binary
import Data.Binary.Put
binaryLaws :: forall a. (Arbitrary a, Binary a, Eq a, Show a) => Proxy a -> Laws
binaryLaws _ = Laws "Binary"
[ ("Partial Isomorphism", property $ \(a :: a) -> decode' (encode a) === Just a)
, ("Valid list encoding", property $ \(as :: [a]) -> runPut (putList as) === runPut (put as))
]
where decode' inp = case decodeOrFail inp of
Right (unc, _, res)
| null unc -> Just res
_other
-> Nothing