RoundtripMixedTypesTest
A sequence of an 8-bit integer, a big-endian 16-bit integer and a big-endian 64-bit float is encoded with elm/bytes and decoded back with `Bytes.Decode.map3`. The values 42, 1000 and 3.14 are encoded, and the program logs `True` only if all three decoded fields equal the originals exactly.
Results
elm-0.19.1
passran in 45 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets. RoundtripMixedTypesTest: True
elm-0.19.2
passran in 48 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets. RoundtripMixedTypesTest: True
elm-0.19.3
passran in 62 msOutput
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets. RoundtripMixedTypesTest: True
lamdera-1.5.0
passran in 54 msOutput
RoundtripMixedTypesTest: True
Discussions
Discuss this test·Search the discussions on GitHub
Discussions are on GitHub; one about this test has [t:elm-bytes/RoundtripMixedTypesTest] in its title.
Source
The -- CHECK: lines give the expected output.
module RoundtripMixedTypesTest exposing (main)
{-| A sequence of an 8-bit integer, a big-endian 16-bit integer and a big-endian 64-bit float is encoded with elm/bytes and decoded back with `Bytes.Decode.map3`.
The values 42, 1000 and 3.14 are encoded, and the program logs `True` only if
all three decoded fields equal the originals exactly.
-}
-- CHECK: RoundtripMixedTypesTest: True
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
type alias Record =
{ a : Int
, b : Int
, c : Float
}
main =
let
original =
{ a = 42, b = 1000, c = 3.14 }
encoded =
E.encode
(E.sequence
[ E.unsignedInt8 original.a
, E.unsignedInt16 BE original.b
, E.float64 BE original.c
]
)
decoder =
D.map3 Record
D.unsignedInt8
(D.unsignedInt16 BE)
(D.float64 BE)
decoded =
D.decode decoder encoded
result =
case decoded of
Just r ->
r.a == original.a && r.b == original.b && r.c == original.c
Nothing ->
False
_ =
Debug.log "RoundtripMixedTypesTest" result
in
text (if result then "True" else "False")