Elm Exactly
Results / elm-bytes /

RoundtripSignedInt16Test

elm-0.19.1 passelm-0.19.2 passelm-0.19.3 passlamdera-1.5.0 pass
Integers survive a big-endian `signedInt16` encode and decode with elm/bytes, including both ends of the signed 16-bit range.

The values 0, 1, -1, 32767 and -32768 are each round-tripped, and the program
logs `True` only if all of them come back unchanged.

Results

elm-0.19.1

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

elm-0.19.2

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

elm-0.19.3

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

lamdera-1.5.0

passran in 56 ms
Output
RoundtripSignedInt16Test: True

Discussions

Discuss this test·Search the discussions on GitHub

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

Source

The -- CHECK: lines give the expected output.

module RoundtripSignedInt16Test exposing (main)
{-| Integers survive a big-endian `signedInt16` encode and decode with elm/bytes, including both ends of the signed 16-bit range.
The values 0, 1, -1, 32767 and -32768 are each round-tripped, and the program
logs `True` only if all of them come back unchanged.
-}
-- CHECK: RoundtripSignedInt16Test: True
import Bytes exposing (Bytes, Endianness(..))
import Bytes.Decode as D
import Bytes.Encode as E
import Html exposing (text)
roundtrip : Int -> Bool
roundtrip n =
D.decode (D.signedInt16 BE) (E.encode (E.signedInt16 BE n)) == Just n
main =
let
allPass =
roundtrip 0
&& roundtrip 1
&& roundtrip -1
&& roundtrip 32767
&& roundtrip -32768
_ =
Debug.log "RoundtripSignedInt16Test" allPass
in
text (if allPass then "True" else "False")