Elm Exactly
Results / elm-bytes /

RoundtripUnsignedInt16Test

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
Integers survive an `unsignedInt16` encode and decode with elm/bytes in both byte orders.

The values 0, 0xFFFF and 0x1234 are each round-tripped big-endian and then
little-endian, and the program logs `True` only if all six come back unchanged.

Results

elm-0.19.1

passran in 59 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.1/optimize for better performance and smaller assets.
RoundtripUnsignedInt16Test: True

elm-0.19.2

passran in 47 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.2/optimize for better performance and smaller assets.
RoundtripUnsignedInt16Test: True

elm-0.19.3

passran in 39 ms
Output
Compiled in DEV mode. Follow the advice at https://elm-lang.org/0.19.3/optimize for better performance and smaller assets.
RoundtripUnsignedInt16Test: True

lamdera-1.5.0

passran in 46 ms
Output
RoundtripUnsignedInt16Test: True

Discussions

Discuss this test·Search the discussions on GitHub

Discussions are on GitHub; one about this test has [t:elm-bytes/RoundtripUnsignedInt16Test] in its title.

Source

The -- CHECK: lines give the expected output.

module RoundtripUnsignedInt16Test exposing (main)
{-| Integers survive an `unsignedInt16` encode and decode with elm/bytes in both byte orders.
The values 0, 0xFFFF and 0x1234 are each round-tripped big-endian and then
little-endian, and the program logs `True` only if all six come back unchanged.
-}
-- CHECK: RoundtripUnsignedInt16Test: True
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
roundtripBE : Int -> Bool
roundtripBE n =
D.decode (D.unsignedInt16 BE) (E.encode (E.unsignedInt16 BE n)) == Just n
roundtripLE : Int -> Bool
roundtripLE n =
D.decode (D.unsignedInt16 LE) (E.encode (E.unsignedInt16 LE n)) == Just n
main =
let
allPass =
roundtripBE 0
&& roundtripBE 0xFFFF
&& roundtripBE 0x1234
&& roundtripLE 0
&& roundtripLE 0xFFFF
&& roundtripLE 0x1234
_ =
Debug.log "RoundtripUnsignedInt16Test" allPass
in
text (if allPass then "True" else "False")