1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
|
{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DefaultSignatures #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Tests.Properties (
testTree
-- * Token type class and derived functions
, Token(..)
, serialiseRef
, serialiseImp
, deserialiseRef
, deserialiseImp
-- * Various test token types
, TokInt
, TokInt8
, TokInt16
, TokInt32
, TokInt64
, TokInteger
, TokWord
, TokWord8
, TokWord16
, TokWord32
, TokWord64
, TokHalf
, TokFloat
, TokDouble
, TokTag
, TokTag64
, Ref.Simple
, Ref.Term
) where
import Prelude hiding (decodeFloat, encodeFloat)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import Data.Word
import Data.Int
import Data.Bits (complement)
import qualified Numeric.Half as Half
import Data.Function (on)
import Data.Proxy
import Data.Kind (Type)
import GHC.Exts
import Codec.CBOR.ByteArray
import qualified Codec.CBOR.ByteArray.Sliced as Sliced
import Codec.CBOR.Term
import Codec.CBOR.Read
import Codec.CBOR.Write
import Codec.CBOR.Decoding
import Codec.CBOR.Encoding
import Test.Tasty (TestTree, testGroup, localOption)
import Test.Tasty.QuickCheck (testProperty, QuickCheckMaxSize(..))
import Test.QuickCheck
import Test.QuickCheck.Gen (Gen (MkGen))
import qualified Tests.Reference.Implementation as Ref
import Tests.Reference.Implementation (UInt(..), lengthUInt)
import Tests.Reference.Generators
import Tests.Term
( fromRefTerm, toRefTerm, eqTerm, canonicaliseTerm )
import Tests.Util
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative
#endif
#if MIN_VERSION_bytestring(0,11,1)
import qualified Data.ByteString.Short as SBS
#else
import qualified Data.ByteString.Short.Internal as SBS
#endif
import qualified Data.Primitive.ByteArray as Prim (ByteArray (..))
import System.Random.Stateful hiding (genByteString, genShortByteString)
-- | The CBOR implementation and its reference implementation satisfy all the
-- properties implied in the following commuting diagram.
--
-- The properties in this module exercise various paths throguh this diagram,
-- and do so for various different types.
--
-- > canon id
-- > Ref──────────▶Ref───────────▶Ref
-- > │ ▲ ╲ (ref) ╱ │
-- > │ │ ╲enc dec╱ │
-- > │ │ ╲ ╱ │
-- > │from to│ ▶Enc▶ │from
-- > │ │ ╱ ╲ │
-- > │ │ ╱enc dec╲ │
-- > ▼ │ ╱ (imp) ╲ ▼
-- > Imp──────────▶Imp───────────▶Imp
-- > id canon
--
-- Key
--
-- * Imp: Implementation token type
-- * Ref: Reference token type
-- * Enc: Encoding (ie bytes)
-- * canon: canonicaliseRef or canonicaliseImp
-- * enc: encodeRef or encodeImp
-- * dec: decodeRef or decodeImp
--
-- We capture these types and arrows with a type class and an associated type.
--
class (Eq t, Show t) => Token t where
type Imp t :: Type
encodeImp :: Proxy t -> Imp t -> Encoding
encodeRef :: Ref.Encoder t
decodeImp :: forall s. Proxy t -> Decoder s (Imp t)
decodeRef :: Proxy t -> Ref.Decoder t
canonicaliseImp :: Proxy t -> Imp t -> Imp t
canonicaliseRef :: t -> t
eqImp :: Proxy t -> Imp t -> Imp t -> Bool
toRef :: Proxy t -> Imp t -> t
fromRef :: t -> Imp t
-- defaults
canonicaliseImp _ = id
canonicaliseRef = toRef t . fromRef
where
t = Proxy :: Proxy t
default eqImp :: Eq (Imp t) => Proxy t -> Imp t -> Imp t -> Bool
eqImp _ = (==)
-- A few derived utils
serialiseRef :: forall t. Token t => t -> LBS.ByteString
serialiseRef = LBS.pack . encodeRef
serialiseImp :: forall t. Token t => Proxy t -> Imp t -> LBS.ByteString
serialiseImp _ = toLazyByteString . encodeImp t
where
t = Proxy :: Proxy t
deserialiseRef :: forall t. Token t => Proxy t -> LBS.ByteString -> t
deserialiseRef _ bytes =
case Ref.runDecoder (decodeRef t) (LBS.unpack bytes) of
Just (x, trailing)
| null trailing -> x
| otherwise -> error "deserialiseRef: trailing bytes"
Nothing -> error "deserialiseRef: decode failure"
where
t = Proxy :: Proxy t
deserialiseImp :: forall t. Token t => Proxy t -> LBS.ByteString -> Imp t
deserialiseImp _ bytes =
case deserialiseFromBytes (decodeImp t) bytes of
Right (trailing, x)
| LBS.null trailing -> x
| otherwise -> error "deserialiseImp: trailing data"
Left _failure -> error "deserialiseImp: decode failure"
where
t = Proxy :: Proxy t
--------------------------------------------------------------------------------
-- Properties
--
-- | The property corresponding to the following part of the commuting diagram.
--
-- > canon
-- > Ref──────────▶Ref . . . . . ▷.
-- > │ ▲ . . .
-- > │ │ . . .
-- > │ │ . . .
-- > │from to│ ▷ ▷ .
-- > │ │ . . .
-- > │ │ . . .
-- > ▼ │ . . ▽
-- > Imp──────────▶Imp . . . . . ▷.
-- > id
--
-- > to . id . from = canon_ref
--
prop_fromRefToRef :: Token t => Proxy t -> t -> Bool
prop_fromRefToRef _ x =
(toRef t . fromRef) x == canonicaliseRef x
where
t = Proxy :: Proxy t
-- | The property corresponding to the following part of the commuting diagram.
--
-- > id
-- > . . . . . .▷Ref───────────▶Ref
-- > . ▲ . . │
-- > . │ . . │
-- > . │ . . │
-- > . to│ ▷ ▷ │from
-- > . │ . . │
-- > . │ . . │
-- > ▽ │ . . ▼
-- > . . . . . .▶Imp───────────▶Imp
-- > canon
--
-- > from . id . to = canon_imp
--
prop_toRefFromRef :: forall t. Token t => Proxy t -> Imp t -> Bool
prop_toRefFromRef _ x =
(fromRef . toRef t) x `eq` canonicaliseImp t x
where
eq = eqImp t
t = Proxy :: Proxy t
-- | The property corresponding to the following part of the commuting diagram.
--
-- This is a round trip property, with the reference implementation of the
-- encoder and decoder.
--
-- > id
-- > . . . . . .▷Ref───────────▶Ref
-- > . △ ╲ ╱ .
-- > . . ╲enc dec╱ .
-- > . . ╲ ╱ .
-- > . . ▶Enc▶ .
-- > . . . . .
-- > . . . . .
-- > ▽ . . . ▽
-- > . . . . . . ▷.. . . . . . ▷.
--
-- > dec_ref . enc_ref = id
--
prop_encodeRefdecodeRef :: forall t. Token t => Proxy t -> t -> Bool
prop_encodeRefdecodeRef _ x =
(deserialiseRef t . serialiseRef) x == x
where
t = Proxy :: Proxy t
-- | The property corresponding to the following part of the commuting diagram.
--
-- This is a round trip property, with the production implementation of the
-- encoder and decoder.
--
-- > . . . . . . ▷. . . . . . .▷.
-- > . △ . . .
-- > . . . . .
-- > . . . . .
-- > . . ▶Enc▶ .
-- > . . ╱ ╲ .
-- > . . ╱enc dec╲ .
-- > ▽ . ╱ ╲ ▽
-- > . . . . . .▷Imp───────────▶Imp
-- > canon
--
-- > dec_imp . enc_imp = canon_imp
--
prop_encodeImpdecodeImp :: forall t. Token t => Proxy t -> Imp t -> Bool
prop_encodeImpdecodeImp _ x =
(deserialiseImp t . serialiseImp t) x `eq` canonicaliseImp t x
where
eq = eqImp t
t = Proxy :: Proxy t
-- | This is the same property as 'prop_encodeImpdecodeImp' but the encoded
-- data is split into two chunks provided as input into the decoder. All
-- possible 2-chunk splits are tried. This checks that the decoder gives the
-- same result irrespective of the chunk boundaries.
--
prop_encodeImpdecodeImp_splits2 :: forall t. Token t => Proxy t -> Imp t -> Bool
prop_encodeImpdecodeImp_splits2 _ x =
and [ deserialiseImp t enc' `eq` x'
| let enc = serialiseImp t x
x' = canonicaliseImp t x
, enc' <- splits2 enc ]
where
eq = eqImp t
t = Proxy :: Proxy t
-- | This is the same idea as 'prop_encodeImpdecodeImp_splits2' but with all
-- possible 3-chunk splits of the input data. This test is of course more
-- expensive and so the size of the input must be limited.
--
prop_encodeImpdecodeImp_splits3 :: forall t. Token t => Proxy t -> Imp t -> Bool
prop_encodeImpdecodeImp_splits3 _ x =
and [ deserialiseImp t enc' `eq` x'
| let enc = serialiseImp t x
x' = canonicaliseImp t x
, enc' <- splits3 enc ]
where
eq = eqImp t
t = Proxy :: Proxy t
-- | The property corresponding to the following part of the commuting diagram.
--
-- This checks that the reference and real implementation produce the same
-- encoded bytes. It starts from a value in the reference implementation.
--
-- > canon
-- > Ref──────────▶Ref . . . . . ▷.
-- > │ △ ╲ . .
-- > │ . ╲enc . .
-- > │ . ╲ . .
-- > │from . ▶Enc▷ .
-- > │ . ╱ . .
-- > │ . ╱enc . .
-- > ▼ . ╱ . ▽
-- > Imp──────────▶Imp . . . . . ▷.
-- > id
--
-- > enc_imp . id . from = enc_ref . canon_ref
--
prop_encodeRefencodeImp1 :: forall t. Token t => Proxy t -> t -> Bool
prop_encodeRefencodeImp1 _ x =
(serialiseImp t . fromRef) x == (serialiseRef . canonicaliseRef) x
where
t = Proxy :: Proxy t
-- | The property corresponding to the following part of the commuting diagram.
--
-- This checks that the reference and real implementation produce the same
-- encoded bytes. It starts from a value in the real implementation.
--
-- > . . . . . .▷Ref . . . . . ▷.
-- > . ▲ ╲ . .
-- > . │ ╲enc . .
-- > . │ ╲ . .
-- > . to│ ▶Enc▷ .
-- > . │ ╱ . .
-- > . │ ╱enc . .
-- > ▽ │ ╱ . ▽
-- > . . . . . .▷Imp . . . . . ▷.
--
-- > enc_ref . id . to = enc_imp
--
prop_encodeRefencodeImp2 :: forall t. Token t => Proxy t -> Imp t -> Bool
prop_encodeRefencodeImp2 _ x =
(serialiseRef . toRef t) x == serialiseImp t x
where
t = Proxy :: Proxy t
-- | The property corresponding to the following part of the commuting diagram.
--
-- This checks that starting from the same encoding, the reference and real
-- implementation deserialise to equivalent values.
--
-- > . . . . . .▷Ref . . . . . ▶Ref
-- > . △ ╲ ╱ │
-- > . . ╲enc dec╱ │
-- > . . ╲ ╱ │
-- > . . ▶Enc▶ │from
-- > . . . ╲ │
-- > . . . dec╲ │
-- > ▽ . . ╲ ▼
-- > . . . . . . ▷.. . . . . . ▶Imp
--
-- > dec_imp . enc_ref = from . dec_ref . enc_ref
--
prop_decodeRefdecodeImp :: forall t. Token t => Proxy t -> t -> Bool
prop_decodeRefdecodeImp _ x =
deserialiseImp t enc `eq` (fromRef . deserialiseRef t) enc
where
enc = serialiseRef x
eq = eqImp t
t = Proxy :: Proxy t
--------------------------------------------------------------------------------
-- Token class instances for unsigned types
--
newtype TokWord8 = TokWord8 { unTokWord8 :: UInt }
deriving (Eq, Show)
instance Token TokWord8 where
type Imp TokWord8 = Word8
fromRef = fromIntegral . Ref.fromUInt . unTokWord8
toRef _ = TokWord8 . Ref.toUInt . fromIntegral
encodeImp _ = encodeWord8
decodeImp _ = decodeWord8
encodeRef (TokWord8 n) = Ref.encodeToken (Ref.MT0_UnsignedInt n)
decodeRef _ = do Ref.MT0_UnsignedInt n <- Ref.decodeToken
return (TokWord8 n)
instance Arbitrary TokWord8 where
arbitrary = TokWord8 <$> oneof arbitraryUInt_Word8
arbitraryUInt_Word8 :: [Gen UInt]
arbitraryUInt_Word8 = [ UIntSmall <$> arbitrarySmall
, UInt8 <$> arbitrarySmall
, UInt8 <$> arbitraryUInt8
]
newtype TokWord16 = TokWord16 { unTokWord16 :: UInt }
deriving (Eq, Show)
instance Token TokWord16 where
type Imp TokWord16 = Word16
fromRef = fromIntegral . Ref.fromUInt . unTokWord16
toRef _ = TokWord16 . Ref.toUInt . fromIntegral
encodeImp _ = encodeWord16
decodeImp _ = decodeWord16
encodeRef (TokWord16 n) = Ref.encodeToken (Ref.MT0_UnsignedInt n)
decodeRef _ = do Ref.MT0_UnsignedInt n <- Ref.decodeToken
return (TokWord16 n)
instance Arbitrary TokWord16 where
arbitrary = TokWord16 <$> oneof arbitraryUInt_Word16
arbitraryUInt_Word16 :: [Gen UInt]
arbitraryUInt_Word16 = arbitraryUInt_Word8
++ [ UInt16 <$> arbitrarySmall
, UInt16 <$> arbitraryUInt8
, UInt16 <$> arbitraryUInt16
]
newtype TokWord32 = TokWord32 { unTokWord32 :: UInt }
deriving (Eq, Show)
instance Token TokWord32 where
type Imp TokWord32 = Word32
fromRef = fromIntegral . Ref.fromUInt . unTokWord32
toRef _ = TokWord32 . Ref.toUInt . fromIntegral
encodeImp _ = encodeWord32
decodeImp _ = decodeWord32
encodeRef (TokWord32 n) = Ref.encodeToken (Ref.MT0_UnsignedInt n)
decodeRef _ = do Ref.MT0_UnsignedInt n <- Ref.decodeToken
return (TokWord32 n)
instance Arbitrary TokWord32 where
arbitrary = TokWord32 <$> oneof arbitraryUInt_Word32
arbitraryUInt_Word32 :: [Gen UInt]
arbitraryUInt_Word32 = arbitraryUInt_Word16
++ [ UInt32 <$> arbitrarySmall
, UInt32 <$> arbitraryUInt8
, UInt32 <$> arbitraryUInt16
, UInt32 <$> arbitraryUInt32
]
newtype TokWord64 = TokWord64 { unTokWord64 :: UInt }
deriving (Eq, Show)
instance Token TokWord64 where
type Imp TokWord64 = Word64
fromRef = fromIntegral . Ref.fromUInt . unTokWord64
toRef _ = TokWord64 . Ref.toUInt . fromIntegral
encodeImp _ = encodeWord64
decodeImp _ = decodeWord64
encodeRef (TokWord64 n) = Ref.encodeToken (Ref.MT0_UnsignedInt n)
decodeRef _ = do Ref.MT0_UnsignedInt n <- Ref.decodeToken
return (TokWord64 n)
instance Arbitrary TokWord64 where
arbitrary = TokWord64 <$> oneof arbitraryUInt_Word64
arbitraryUInt_Word64 :: [Gen UInt]
arbitraryUInt_Word64 = arbitraryUInt_Word32
++ [ UInt64 <$> arbitrarySmall
, UInt64 <$> arbitraryUInt8
, UInt64 <$> arbitraryUInt16
, UInt64 <$> arbitraryUInt32
, UInt64 <$> arbitraryUInt64
]
newtype TokWord = TokWord { unTokWord :: UInt }
deriving (Eq, Show)
instance Arbitrary TokWord where
arbitrary = TokWord <$> oneof arbitraryUInt_Word
arbitraryUInt_Word :: [Gen UInt]
arbitraryUInt_Word = arbitraryUInt_Word32
++ [ UInt64 <$> arbitrarySmall
, UInt64 <$> arbitraryUInt8
, UInt64 <$> arbitraryUInt16
, UInt64 <$> arbitraryUInt32
#if defined(ARCH_64bit)
, UInt64 <$> arbitraryUInt64
#endif
]
instance Token TokWord where
type Imp TokWord = Word
fromRef = fromIntegral . Ref.fromUInt . unTokWord
toRef _ = TokWord . Ref.toUInt . fromIntegral
encodeImp _ = encodeWord
decodeImp _ = decodeWord
encodeRef (TokWord n) = Ref.encodeToken (Ref.MT0_UnsignedInt n)
decodeRef _ = do Ref.MT0_UnsignedInt n <- Ref.decodeToken
return (TokWord n)
--------------------------------------------------------------------------------
-- Token class instances for signed types
--
data TokInt8 = TokInt8 Bool UInt
deriving (Eq, Show)
instance Token TokInt8 where
type Imp TokInt8 = Int8
fromRef (TokInt8 True n) = (fromIntegral . Ref.fromUInt) n
fromRef (TokInt8 False n) = (complement . fromIntegral . Ref.fromUInt) n
toRef _ n
| n >= 0 = TokInt8 True ((Ref.toUInt . fromIntegral) n)
| otherwise = TokInt8 False ((Ref.toUInt . fromIntegral . complement) n)
encodeImp _ = encodeInt8
decodeImp _ = decodeInt8
encodeRef (TokInt8 True n) = Ref.encodeToken (Ref.MT0_UnsignedInt n)
encodeRef (TokInt8 False n) = Ref.encodeToken (Ref.MT1_NegativeInt n)
decodeRef _ = do
tok <- Ref.decodeToken
case tok of
Ref.MT0_UnsignedInt n -> return (TokInt8 True n)
Ref.MT1_NegativeInt n -> return (TokInt8 False n)
_ -> fail "decodeRef (TokInt)"
instance Arbitrary TokInt8 where
arbitrary = TokInt8 <$> arbitrary <*> oneof arbitraryUInt_Int8
shrink (TokInt8 sign n) = [ TokInt8 sign' n'
| (sign', n') <- shrink (sign, n) ]
arbitraryUInt_Int8 :: [Gen UInt]
arbitraryUInt_Int8 = [ UIntSmall <$> arbitrarySmall
, UInt8 <$> arbitrarySmall
, UInt8 <$> arbitraryUInt7
]
data TokInt16 = TokInt16 Bool UInt
deriving (Eq, Show)
instance Token TokInt16 where
type Imp TokInt16 = Int16
fromRef (TokInt16 True n) = (fromIntegral . Ref.fromUInt) n
fromRef (TokInt16 False n) = (complement . fromIntegral . Ref.fromUInt) n
toRef _ n
| n >= 0 = TokInt16 True ((Ref.toUInt . fromIntegral) n)
| otherwise = TokInt16 False ((Ref.toUInt . fromIntegral . complement) n)
encodeImp _ = encodeInt16
decodeImp _ = decodeInt16
encodeRef (TokInt16 True n) = Ref.encodeToken (Ref.MT0_UnsignedInt n)
encodeRef (TokInt16 False n) = Ref.encodeToken (Ref.MT1_NegativeInt n)
decodeRef _ = do
tok <- Ref.decodeToken
case tok of
Ref.MT0_UnsignedInt n -> return (TokInt16 True n)
Ref.MT1_NegativeInt n -> return (TokInt16 False n)
_ -> fail "decodeRef (TokInt16)"
instance Arbitrary TokInt16 where
arbitrary = TokInt16 <$> arbitrary <*> oneof arbitraryUInt_Int16
arbitraryUInt_Int16 :: [Gen UInt]
arbitraryUInt_Int16 = arbitraryUInt_Int8
++ [ UInt16 <$> arbitrarySmall
, UInt16 <$> arbitraryUInt7
, UInt16 <$> arbitraryUInt15
]
data TokInt32 = TokInt32 Bool UInt
deriving (Eq, Show)
instance Token TokInt32 where
type Imp TokInt32 = Int32
fromRef (TokInt32 True n) = (fromIntegral . Ref.fromUInt) n
fromRef (TokInt32 False n) = (complement . fromIntegral . Ref.fromUInt) n
toRef _ n
| n >= 0 = TokInt32 True ((Ref.toUInt . fromIntegral) n)
| otherwise = TokInt32 False ((Ref.toUInt . fromIntegral . complement) n)
encodeImp _ = encodeInt32
decodeImp _ = decodeInt32
encodeRef (TokInt32 True n) = Ref.encodeToken (Ref.MT0_UnsignedInt n)
encodeRef (TokInt32 False n) = Ref.encodeToken (Ref.MT1_NegativeInt n)
decodeRef _ = do
tok <- Ref.decodeToken
case tok of
Ref.MT0_UnsignedInt n -> return (TokInt32 True n)
Ref.MT1_NegativeInt n -> return (TokInt32 False n)
_ -> fail "decodeRef (TokInt32)"
instance Arbitrary TokInt32 where
arbitrary = TokInt32 <$> arbitrary <*> oneof arbitraryUInt_Int32
arbitraryUInt_Int32 :: [Gen UInt]
arbitraryUInt_Int32 = arbitraryUInt_Int16
++ [ UInt32 <$> arbitrarySmall
, UInt32 <$> arbitraryUInt7
, UInt32 <$> arbitraryUInt15
, UInt32 <$> arbitraryUInt31
]
data TokInt64 = TokInt64 Bool UInt
deriving (Eq, Show)
instance Token TokInt64 where
type Imp TokInt64 = Int64
fromRef (TokInt64 True n) = (fromIntegral . Ref.fromUInt) n
fromRef (TokInt64 False n) = (complement . fromIntegral . Ref.fromUInt) n
toRef _ n
| n >= 0 = TokInt64 True ((Ref.toUInt . fromIntegral) n)
| otherwise = TokInt64 False ((Ref.toUInt . fromIntegral . complement) n)
encodeImp _ = encodeInt64
decodeImp _ = decodeInt64
encodeRef (TokInt64 True n) = Ref.encodeToken (Ref.MT0_UnsignedInt n)
encodeRef (TokInt64 False n) = Ref.encodeToken (Ref.MT1_NegativeInt n)
decodeRef _ = do
tok <- Ref.decodeToken
case tok of
Ref.MT0_UnsignedInt n -> return (TokInt64 True n)
Ref.MT1_NegativeInt n -> return (TokInt64 False n)
_ -> fail "decodeRef (TokInt64)"
instance Arbitrary TokInt64 where
arbitrary = TokInt64 <$> arbitrary <*> oneof arbitraryUInt_Int64
arbitraryUInt_Int64 :: [Gen UInt]
arbitraryUInt_Int64 = arbitraryUInt_Int32
++ [ UInt64 <$> arbitrarySmall
, UInt64 <$> arbitraryUInt7
, UInt64 <$> arbitraryUInt15
, UInt64 <$> arbitraryUInt31
, UInt64 <$> arbitraryUInt63
]
data TokInt = TokInt Bool UInt
deriving (Eq, Show)
instance Token TokInt where
type Imp TokInt = Int
fromRef (TokInt True n) = (fromIntegral . Ref.fromUInt) n
fromRef (TokInt False n) = (complement . fromIntegral . Ref.fromUInt) n
toRef _ n
| n >= 0 = TokInt True ((Ref.toUInt . fromIntegral) n)
| otherwise = TokInt False ((Ref.toUInt . fromIntegral . complement) n)
encodeImp _ = encodeInt
decodeImp _ = decodeInt
encodeRef (TokInt True n) = Ref.encodeToken (Ref.MT0_UnsignedInt n)
encodeRef (TokInt False n) = Ref.encodeToken (Ref.MT1_NegativeInt n)
decodeRef _ = do
tok <- Ref.decodeToken
case tok of
Ref.MT0_UnsignedInt n -> return (TokInt True n)
Ref.MT1_NegativeInt n -> return (TokInt False n)
_ -> fail "decodeRef (TokInt)"
instance Arbitrary TokInt where
arbitrary = TokInt <$> arbitrary <*> oneof arbitraryUInt_Int
arbitraryUInt_Int :: [Gen UInt]
arbitraryUInt_Int = arbitraryUInt_Int32
++ [ UInt64 <$> arbitrarySmall
, UInt64 <$> arbitraryUInt7
, UInt64 <$> arbitraryUInt15
, UInt64 <$> arbitraryUInt31
#if defined(ARCH_64bit)
, UInt64 <$> arbitraryUInt63
#endif
]
data TokInteger = TokIntegerUInt UInt
| TokIntegerNInt UInt
| TokIntegerBig LargeInteger
deriving (Eq, Show)
instance Arbitrary TokInteger where
arbitrary = oneof [ TokIntegerUInt <$> arbitrary
, TokIntegerNInt <$> arbitrary
, TokIntegerBig <$> arbitrary
]
instance Token TokInteger where
type Imp TokInteger = Integer
fromRef (TokIntegerUInt n) = (fromIntegral . Ref.fromUInt) n
fromRef (TokIntegerNInt n) = (complement . fromIntegral . Ref.fromUInt) n
fromRef (TokIntegerBig n) = getLargeInteger n
toRef _ n
| n >= 0 && n <= fromIntegral (maxBound :: Word64)
= TokIntegerUInt ((Ref.toUInt . fromIntegral) n)
| n < 0 && complement n <= fromIntegral (maxBound :: Word64)
= TokIntegerNInt ((Ref.toUInt . fromIntegral . complement) n)
| otherwise = TokIntegerBig (LargeInteger n)
encodeImp _ = encodeInteger
decodeImp _ = decodeInteger
encodeRef (TokIntegerUInt n) = Ref.encodeToken (Ref.MT0_UnsignedInt n)
encodeRef (TokIntegerNInt n) = Ref.encodeToken (Ref.MT1_NegativeInt n)
encodeRef (TokIntegerBig n) = Ref.encodeTerm (Ref.TBigInt (getLargeInteger n))
decodeRef _ = do
tok <- Ref.decodeToken
case tok of
Ref.MT0_UnsignedInt n -> return (TokIntegerUInt n)
Ref.MT1_NegativeInt n -> return (TokIntegerNInt n)
Ref.MT6_Tag tag -> do Ref.TBigInt n <- Ref.decodeTagged tag
return (TokIntegerBig (LargeInteger n))
_ -> fail "decodeRef (TokInteger)"
--------------------------------------------------------------------------------
-- Arbitrary helpers for integer types
--
arbitrarySmall,
arbitraryUInt8, arbitraryUInt16, arbitraryUInt32, arbitraryUInt64,
arbitraryUInt7, arbitraryUInt15, arbitraryUInt31, arbitraryUInt63
:: (Num n, Random n) => Gen n
arbitrarySmall = chooseZeroToBound (23 :: Word)
arbitraryUInt8 = chooseZeroToBound (maxBound :: Word8)
arbitraryUInt16 = chooseZeroToBound (maxBound :: Word16)
arbitraryUInt32 = chooseZeroToBound (maxBound :: Word32)
arbitraryUInt64 = chooseZeroToBound (maxBound :: Word64)
arbitraryUInt7 = chooseZeroToBound (maxBound :: Int8)
arbitraryUInt15 = chooseZeroToBound (maxBound :: Int16)
arbitraryUInt31 = chooseZeroToBound (maxBound :: Int32)
arbitraryUInt63 = chooseZeroToBound (maxBound :: Int64)
chooseZeroToBound :: (Num a, Random a, Integral a1) => a1 -> Gen a
chooseZeroToBound bound =
frequency [ (9, choose (0, bound'))
, (1, pure bound') ]
where
bound' = fromIntegral bound
--------------------------------------------------------------------------------
-- Token class instances for floating point types
--
data TokHalf = TokHalf HalfSpecials
deriving (Eq, Show)
instance Arbitrary TokHalf where
arbitrary = TokHalf <$> arbitrary
instance Token TokHalf where
type Imp TokHalf = Float
eqImp _ = (==) `on` floatToWord
fromRef (TokHalf (HalfSpecials n)) = Half.fromHalf n
toRef _ = TokHalf
. canonicaliseNaN
. HalfSpecials
. Half.toHalf
canonicaliseImp _ = Half.fromHalf
. canonicaliseNaN
. Half.toHalf
canonicaliseRef (TokHalf n) = TokHalf (canonicaliseNaN n)
encodeImp _ = encodeFloat16
decodeImp _ = decodeFloat
encodeRef (TokHalf n) = Ref.encodeToken (Ref.MT7_Float16 n)
decodeRef _ = do Ref.MT7_Float16 n <- Ref.decodeToken
return (TokHalf n)
data TokFloat = TokFloat FloatSpecials
| TokFloatNan
deriving (Eq, Show)
instance Arbitrary TokFloat where
arbitrary = frequency [(19, TokFloat <$> arbitrary), (1, pure TokFloatNan)]
instance Token TokFloat where
type Imp TokFloat = Float
eqImp _ = (==) `on` floatToWord
fromRef (TokFloat n) = getFloatSpecials n
fromRef TokFloatNan = canonicalNaN
toRef _ n
| isNaN n = TokFloatNan
| otherwise = TokFloat (FloatSpecials n)
canonicaliseImp _ = canonicaliseNaN
canonicaliseRef TokFloatNan = TokFloatNan
canonicaliseRef (TokFloat (FloatSpecials n))
| isNaN n = TokFloatNan
| otherwise = TokFloat (FloatSpecials n)
encodeImp _ = encodeFloat
decodeImp _ = decodeFloat
encodeRef (TokFloat n) = Ref.encodeToken (Ref.MT7_Float32 n)
encodeRef TokFloatNan = Ref.encodeToken (Ref.MT7_Float16 canonicalNaN)
decodeRef _ = do
tok <- Ref.decodeToken
case tok of
Ref.MT7_Float16 n | isNaN n
-> return TokFloatNan
Ref.MT7_Float32 n -> return (TokFloat n)
_ -> fail "decodeRef (TokFloat)"
data TokDouble = TokDouble DoubleSpecials
| TokDoubleNan
deriving (Eq, Show)
instance Arbitrary TokDouble where
arbitrary = frequency [(19, TokDouble <$> arbitrary), (1, pure TokDoubleNan)]
instance Token TokDouble where
type Imp TokDouble = Double
eqImp _ = (==) `on` doubleToWord
fromRef (TokDouble n) = getDoubleSpecials n
fromRef TokDoubleNan = canonicalNaN
toRef _ n
| isNaN n = TokDoubleNan
| otherwise = TokDouble (DoubleSpecials n)
canonicaliseImp _ = canonicaliseNaN
canonicaliseRef TokDoubleNan = TokDoubleNan
canonicaliseRef (TokDouble (DoubleSpecials n))
| isNaN n = TokDoubleNan
| otherwise = TokDouble (DoubleSpecials n)
encodeImp _ = encodeDouble
decodeImp _ = decodeDouble
encodeRef (TokDouble n) = Ref.encodeToken (Ref.MT7_Float64 n)
encodeRef TokDoubleNan = Ref.encodeToken (Ref.MT7_Float16 canonicalNaN)
decodeRef _ = do
tok <- Ref.decodeToken
case tok of
Ref.MT7_Float16 n | isNaN n
-> return TokDoubleNan
Ref.MT7_Float64 n -> return (TokDouble n)
_ -> fail "decodeRef (TokDouble)"
--------------------------------------------------------------------------------
-- Miscelaneous token class instances
--
data TokTag = TokTag { unTokTag :: UInt }
deriving (Eq, Show)
instance Arbitrary TokTag where
arbitrary = TokTag <$> oneof arbitraryUInt_Word
instance Token TokTag where
type Imp TokTag = Word
fromRef = fromIntegral . Ref.fromUInt . unTokTag
toRef _ = TokTag . Ref.toUInt . fromIntegral
encodeImp _ = encodeTag
decodeImp _ = decodeTag
encodeRef (TokTag n) = Ref.encodeToken (Ref.MT6_Tag n)
decodeRef _ = do Ref.MT6_Tag n <- Ref.decodeToken
return (TokTag n)
data TokTag64 = TokTag64 { unTokTag64 :: UInt }
deriving (Eq, Show)
instance Arbitrary TokTag64 where
arbitrary = TokTag64 <$> oneof arbitraryUInt_Word64
instance Token TokTag64 where
type Imp TokTag64 = Word64
fromRef = fromIntegral . Ref.fromUInt . unTokTag64
toRef _ = TokTag64 . Ref.toUInt . fromIntegral
encodeImp _ = encodeTag64
decodeImp _ = decodeTag64
encodeRef (TokTag64 n) = Ref.encodeToken (Ref.MT6_Tag n)
decodeRef _ = do Ref.MT6_Tag n <- Ref.decodeToken
return (TokTag64 n)
instance Token Ref.Simple where
type Imp Ref.Simple = Word8
fromRef = Ref.fromSimple
toRef _ = Ref.toSimple
encodeImp _ = encodeSimple
decodeImp _ = decodeSimple
encodeRef n = Ref.encodeToken (Ref.MT7_Simple n)
decodeRef _ = do Ref.MT7_Simple n <- Ref.decodeToken
return n
--------------------------------------------------------------------------------
-- Token class instances for Term type
--
instance Token Ref.Term where
type Imp Ref.Term = Term
eqImp _ = eqTerm
fromRef = fromRefTerm
toRef _ = toRefTerm
canonicaliseImp _ = canonicaliseTerm
canonicaliseRef = Ref.canonicaliseTerm
encodeImp _ = encodeTerm
decodeImp _ = decodeTerm
encodeRef = Ref.encodeTerm
decodeRef _ = Ref.decodeTerm
--------------------------------------------------------------------------------
-- Token class instances for ByteArray tokens.
--
newtype TokByteArray = TokByteArray { unTokByteArray :: [Word8] }
deriving (Eq, Show)
instance Arbitrary TokByteArray where
arbitrary = TokByteArray <$> arbitrary
instance Token TokByteArray where
type Imp TokByteArray = Sliced.SlicedByteArray
eqImp _ = (==)
fromRef = Sliced.fromByteString . BS.pack . unTokByteArray
toRef _ = TokByteArray . toList
canonicaliseImp _ = id
canonicaliseRef = id
encodeImp _ = encodeByteArray
decodeImp _ = toSliced <$> decodeByteArray
encodeRef (TokByteArray bs) = Ref.encodeToken (Ref.MT2_ByteString (lengthUInt bs) bs)
decodeRef _ = do Ref.MT2_ByteString _n bs <- Ref.decodeToken
-- TODO? check _n == bs
return (TokByteArray bs)
instance Arbitrary Sliced.SlicedByteArray where
-- Taken from cardano-ledger-binary testlib.
arbitrary = do
NonNegative off <- arbitrary
Positive count <- arbitrary
NonNegative slack <- arbitrary
let len = off + count + slack
ba <- genByteArray len
pure $ Sliced.SBA ba off count
where
genShortByteString :: Int -> Gen SBS.ShortByteString
genShortByteString n = MkGen (\r _n -> runStateGen_ r (uniformShortByteString n))
genByteArray :: Int -> Gen Prim.ByteArray
genByteArray n = do
bss <- genShortByteString n
case bss of
SBS.SBS ba -> pure $ Prim.ByteArray ba
--------------------------------------------------------------------------------
-- TestTree API
testTree :: TestTree
testTree =
testGroup "properties"
[ testGroup "to . id . from = canon_ref"
[ testProperty "Word8" (prop_fromRefToRef (Proxy :: Proxy TokWord8))
, testProperty "Word16" (prop_fromRefToRef (Proxy :: Proxy TokWord16))
, testProperty "Word32" (prop_fromRefToRef (Proxy :: Proxy TokWord32))
, testProperty "Word64" (prop_fromRefToRef (Proxy :: Proxy TokWord64))
, testProperty "Word" (prop_fromRefToRef (Proxy :: Proxy TokWord))
-- , testProperty "NegWord" (prop_fromRefToRef (Proxy :: Proxy TokNegWord))
, testProperty "Int8" (prop_fromRefToRef (Proxy :: Proxy TokInt8))
, testProperty "Int16" (prop_fromRefToRef (Proxy :: Proxy TokInt16))
, testProperty "Int32" (prop_fromRefToRef (Proxy :: Proxy TokInt32))
, testProperty "Int64" (prop_fromRefToRef (Proxy :: Proxy TokInt64))
, testProperty "Int" (prop_fromRefToRef (Proxy :: Proxy TokInt))
, testProperty "Integer" (prop_fromRefToRef (Proxy :: Proxy TokInteger))
, testProperty "Half" (prop_fromRefToRef (Proxy :: Proxy TokHalf))
, testProperty "Float" (prop_fromRefToRef (Proxy :: Proxy TokFloat))
, testProperty "Double" (prop_fromRefToRef (Proxy :: Proxy TokDouble))
, testProperty "Tag" (prop_fromRefToRef (Proxy :: Proxy TokTag))
, testProperty "Tag64" (prop_fromRefToRef (Proxy :: Proxy TokTag64))
, testProperty "Simple" (prop_fromRefToRef (Proxy :: Proxy Ref.Simple))
, testProperty "Term" (prop_fromRefToRef (Proxy :: Proxy Ref.Term))
, testProperty "ByteArray" (prop_fromRefToRef (Proxy :: Proxy TokByteArray))
]
, testGroup "from . id . to = canon_imp"
[ testProperty "Word8" (prop_toRefFromRef (Proxy :: Proxy TokWord8))
, testProperty "Word16" (prop_toRefFromRef (Proxy :: Proxy TokWord16))
, testProperty "Word32" (prop_toRefFromRef (Proxy :: Proxy TokWord32))
, testProperty "Word64" (prop_toRefFromRef (Proxy :: Proxy TokWord64))
, testProperty "Word" (prop_toRefFromRef (Proxy :: Proxy TokWord))
-- , testProperty "NegWord" (prop_toRefFromRef (Proxy :: Proxy TokNegWord))
, testProperty "Int8" (prop_toRefFromRef (Proxy :: Proxy TokInt8))
, testProperty "Int16" (prop_toRefFromRef (Proxy :: Proxy TokInt16))
, testProperty "Int32" (prop_toRefFromRef (Proxy :: Proxy TokInt32))
, testProperty "Int64" (prop_toRefFromRef (Proxy :: Proxy TokInt64))
, testProperty "Int" (prop_toRefFromRef (Proxy :: Proxy TokInt))
, testProperty "Integer" (prop_toRefFromRef (Proxy :: Proxy TokInteger))
, testProperty "Half" (prop_toRefFromRef (Proxy :: Proxy TokHalf))
, testProperty "Float" (prop_toRefFromRef (Proxy :: Proxy TokFloat))
, testProperty "Double" (prop_toRefFromRef (Proxy :: Proxy TokDouble))
, testProperty "Tag" (prop_toRefFromRef (Proxy :: Proxy TokTag))
, testProperty "Tag64" (prop_toRefFromRef (Proxy :: Proxy TokTag64))
, testProperty "Simple" (prop_toRefFromRef (Proxy :: Proxy Ref.Simple))
, testProperty "Term" (prop_toRefFromRef (Proxy :: Proxy Ref.Term))
, testProperty "ByteArray" (prop_toRefFromRef (Proxy :: Proxy TokByteArray))
]
, testGroup "dec_ref . enc_ref = id"
[ testProperty "Word8" (prop_encodeRefdecodeRef (Proxy :: Proxy TokWord8))
, testProperty "Word16" (prop_encodeRefdecodeRef (Proxy :: Proxy TokWord16))
, testProperty "Word32" (prop_encodeRefdecodeRef (Proxy :: Proxy TokWord32))
, testProperty "Word64" (prop_encodeRefdecodeRef (Proxy :: Proxy TokWord64))
, testProperty "Word" (prop_encodeRefdecodeRef (Proxy :: Proxy TokWord))
-- , testProperty "NegWord" (prop_encodeRefdecodeRef (Proxy :: Proxy TokNegWord))
, testProperty "Int8" (prop_encodeRefdecodeRef (Proxy :: Proxy TokInt8))
, testProperty "Int16" (prop_encodeRefdecodeRef (Proxy :: Proxy TokInt16))
, testProperty "Int32" (prop_encodeRefdecodeRef (Proxy :: Proxy TokInt32))
, testProperty "Int64" (prop_encodeRefdecodeRef (Proxy :: Proxy TokInt64))
, testProperty "Int" (prop_encodeRefdecodeRef (Proxy :: Proxy TokInt))
, testProperty "Integer" (prop_encodeRefdecodeRef (Proxy :: Proxy TokInteger))
, testProperty "Half" (prop_encodeRefdecodeRef (Proxy :: Proxy TokHalf))
, testProperty "Float" (prop_encodeRefdecodeRef (Proxy :: Proxy TokFloat))
, testProperty "Double" (prop_encodeRefdecodeRef (Proxy :: Proxy TokDouble))
, testProperty "Tag" (prop_encodeRefdecodeRef (Proxy :: Proxy TokTag))
, testProperty "Tag64" (prop_encodeRefdecodeRef (Proxy :: Proxy TokTag64))
, testProperty "Simple" (prop_encodeRefdecodeRef (Proxy :: Proxy Ref.Simple))
, testProperty "Term" (prop_encodeRefdecodeRef (Proxy :: Proxy Ref.Term))
, testProperty "ByteArray" (prop_encodeRefdecodeRef (Proxy :: Proxy TokByteArray))
]
, testGroup "dec_imp . enc_imp = canon_imp"
[ testProperty "Word8" (prop_encodeImpdecodeImp (Proxy :: Proxy TokWord8))
, testProperty "Word16" (prop_encodeImpdecodeImp (Proxy :: Proxy TokWord16))
, testProperty "Word32" (prop_encodeImpdecodeImp (Proxy :: Proxy TokWord32))
, testProperty "Word64" (prop_encodeImpdecodeImp (Proxy :: Proxy TokWord64))
, testProperty "Word" (prop_encodeImpdecodeImp (Proxy :: Proxy TokWord))
-- , testProperty "NegWord" (prop_encodeImpdecodeImp (Proxy :: Proxy TokNegWord))
, testProperty "Int8" (prop_encodeImpdecodeImp (Proxy :: Proxy TokInt8))
, testProperty "Int16" (prop_encodeImpdecodeImp (Proxy :: Proxy TokInt16))
, testProperty "Int32" (prop_encodeImpdecodeImp (Proxy :: Proxy TokInt32))
, testProperty "Int64" (prop_encodeImpdecodeImp (Proxy :: Proxy TokInt64))
, testProperty "Int" (prop_encodeImpdecodeImp (Proxy :: Proxy TokInt))
, testProperty "Integer" (prop_encodeImpdecodeImp (Proxy :: Proxy TokInteger))
, testProperty "Half" (prop_encodeImpdecodeImp (Proxy :: Proxy TokHalf))
, testProperty "Float" (prop_encodeImpdecodeImp (Proxy :: Proxy TokFloat))
, testProperty "Double" (prop_encodeImpdecodeImp (Proxy :: Proxy TokDouble))
, testProperty "Tag" (prop_encodeImpdecodeImp (Proxy :: Proxy TokTag))
, testProperty "Tag64" (prop_encodeImpdecodeImp (Proxy :: Proxy TokTag64))
, testProperty "Simple" (prop_encodeImpdecodeImp (Proxy :: Proxy Ref.Simple))
, testProperty "Term" (prop_encodeImpdecodeImp (Proxy :: Proxy Ref.Term))
, testProperty "ByteArray" (prop_encodeImpdecodeImp (Proxy :: Proxy TokByteArray))
]
, testGroup "dec_imp . enc_imp = canon_imp (all 2-splits)"
[ testProperty "Word8" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokWord8))
, testProperty "Word16" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokWord16))
, testProperty "Word32" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokWord32))
, testProperty "Word64" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokWord64))
, testProperty "Word" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokWord))
-- , testProperty "NegWord" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokNegWord))
, testProperty "Int8" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokInt8))
, testProperty "Int16" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokInt16))
, testProperty "Int32" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokInt32))
, testProperty "Int64" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokInt64))
, testProperty "Int" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokInt))
, testProperty "Integer" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokInteger))
, testProperty "Half" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokHalf))
, testProperty "Float" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokFloat))
, testProperty "Double" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokDouble))
, testProperty "Tag" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokTag))
, testProperty "Tag64" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokTag64))
, testProperty "Simple" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy Ref.Simple))
, localOption (QuickCheckMaxSize 100) $
testProperty "Term" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy Ref.Term))
, testProperty "ByteArray" (prop_encodeImpdecodeImp_splits2 (Proxy :: Proxy TokByteArray))
]
, testGroup "dec_imp . enc_imp = canon_imp (all 3-splits)"
[ testProperty "Word8" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokWord8))
, testProperty "Word16" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokWord16))
, testProperty "Word32" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokWord32))
, testProperty "Word64" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokWord64))
, testProperty "Word" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokWord))
-- , testProperty "NegWord" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokNegWord))
, testProperty "Int8" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokInt8))
, testProperty "Int16" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokInt16))
, testProperty "Int32" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokInt32))
, testProperty "Int64" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokInt64))
, testProperty "Int" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokInt))
, testProperty "Integer" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokInteger))
, testProperty "Half" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokHalf))
, testProperty "Float" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokFloat))
, testProperty "Double" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokDouble))
, testProperty "Tag" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokTag))
, testProperty "Tag64" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokTag64))
, testProperty "Simple" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy Ref.Simple))
, localOption (QuickCheckMaxSize 25) $
testProperty "Term" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy Ref.Term))
, testProperty "ByteArray" (prop_encodeImpdecodeImp_splits3 (Proxy :: Proxy TokByteArray))
]
, testGroup "enc_imp . from = enc_ref . canon_ref"
[ testProperty "Word8" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokWord8))
, testProperty "Word16" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokWord16))
, testProperty "Word32" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokWord32))
, testProperty "Word64" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokWord64))
, testProperty "Word" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokWord))
-- , testProperty "NegWord" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokNegWord))
, testProperty "Int8" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokInt8))
, testProperty "Int16" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokInt16))
, testProperty "Int32" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokInt32))
, testProperty "Int64" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokInt64))
, testProperty "Int" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokInt))
, testProperty "Integer" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokInteger))
, testProperty "Half" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokHalf))
, testProperty "Float" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokFloat))
, testProperty "Double" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokDouble))
, testProperty "Tag" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokTag))
, testProperty "Tag64" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokTag64))
, testProperty "Simple" (prop_encodeRefencodeImp1 (Proxy :: Proxy Ref.Simple))
, testProperty "Term" (prop_encodeRefencodeImp1 (Proxy :: Proxy Ref.Term))
, testProperty "ByteArray" (prop_encodeRefencodeImp1 (Proxy :: Proxy TokByteArray))
]
, testGroup "enc_ref . to = enc_imp"
[ testProperty "Word8" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokWord8))
, testProperty "Word16" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokWord16))
, testProperty "Word32" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokWord32))
, testProperty "Word64" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokWord64))
, testProperty "Word" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokWord))
-- , testProperty "NegWord" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokNegWord))
, testProperty "Int8" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokInt8))
, testProperty "Int16" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokInt16))
, testProperty "Int32" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokInt32))
, testProperty "Int64" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokInt64))
, testProperty "Int" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokInt))
, testProperty "Integer" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokInteger))
, testProperty "Half" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokHalf))
, testProperty "Float" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokFloat))
, testProperty "Double" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokDouble))
, testProperty "Tag" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokTag))
, testProperty "Tag64" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokTag64))
, testProperty "Simple" (prop_encodeRefencodeImp2 (Proxy :: Proxy Ref.Simple))
, testProperty "Term" (prop_encodeRefencodeImp2 (Proxy :: Proxy Ref.Term))
, testProperty "ByteArray" (prop_encodeRefencodeImp2 (Proxy :: Proxy TokByteArray))
]
, testGroup "dec_imp . enc_ref = from . dec_ref . enc_ref"
[ testProperty "Word8" (prop_decodeRefdecodeImp (Proxy :: Proxy TokWord8))
, testProperty "Word16" (prop_decodeRefdecodeImp (Proxy :: Proxy TokWord16))
, testProperty "Word32" (prop_decodeRefdecodeImp (Proxy :: Proxy TokWord32))
, testProperty "Word64" (prop_decodeRefdecodeImp (Proxy :: Proxy TokWord64))
, testProperty "Word" (prop_decodeRefdecodeImp (Proxy :: Proxy TokWord))
-- , testProperty "NegWord" (prop_decodeRefdecodeImp (Proxy :: Proxy TokNegWord))
, testProperty "Int8" (prop_decodeRefdecodeImp (Proxy :: Proxy TokInt8))
, testProperty "Int16" (prop_decodeRefdecodeImp (Proxy :: Proxy TokInt16))
, testProperty "Int32" (prop_decodeRefdecodeImp (Proxy :: Proxy TokInt32))
, testProperty "Int64" (prop_decodeRefdecodeImp (Proxy :: Proxy TokInt64))
, testProperty "Int" (prop_decodeRefdecodeImp (Proxy :: Proxy TokInt))
, testProperty "Integer" (prop_decodeRefdecodeImp (Proxy :: Proxy TokInteger))
, testProperty "Half" (prop_decodeRefdecodeImp (Proxy :: Proxy TokHalf))
, testProperty "Float" (prop_decodeRefdecodeImp (Proxy :: Proxy TokFloat))
, testProperty "Double" (prop_decodeRefdecodeImp (Proxy :: Proxy TokDouble))
, testProperty "Tag" (prop_decodeRefdecodeImp (Proxy :: Proxy TokTag))
, testProperty "Tag64" (prop_decodeRefdecodeImp (Proxy :: Proxy TokTag64))
, testProperty "Simple" (prop_decodeRefdecodeImp (Proxy :: Proxy Ref.Simple))
, testProperty "Term" (prop_decodeRefdecodeImp (Proxy :: Proxy Ref.Term))
, testProperty "ByteArray" (prop_decodeRefdecodeImp (Proxy :: Proxy TokByteArray))
]
]
|